Commit 2eb52068 authored by Clouard Regis's avatar Clouard Regis
Browse files

Added display map with zoom

parent 2af3f893
......@@ -3,6 +3,7 @@ import 'dart:io';
import 'dart:math';
import 'dart:ui' as ui;
import 'package:Vikazimut_flutter/map/lat_lon_box.dart';
import 'package:Vikazimut_flutter/map/orienteering_map.dart';
import 'package:Vikazimut_flutter/result/Result.dart';
import 'package:flutter/material.dart';
......@@ -32,18 +33,8 @@ StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locat
print(position == null ? 'Unknown' : position.latitude.toString() + ', ' + position.longitude.toString());
});
*/
//class SportModeCourseWidgetState extends State<SportModeCourseWidget> {
SportModeCourseWidget(OrienteeringMap selectedMap) : map = selectedMap;
// void initState() {
// super.initState();
// init();
// }
//
// Future<Null> init() async {
// _image = await _loadImage(File(widget.map.getDrawableName()));
// }
SportModeCourseWidget(OrienteeringMap selectedMap) : map = selectedMap {}
Future<ui.Image> _loadImage(File file) async {
final _img = file.readAsBytesSync();
......@@ -90,7 +81,7 @@ StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locat
return new Text('Error: ${snapshot.error}');
else
// TODO Occuper tout l'espace
return MapView(snapshot.data);
return MapView(snapshot.data, map.getBoundingBox());
}
},
)),
......@@ -101,11 +92,14 @@ StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locat
class MapView extends StatefulWidget {
// TODO Dans le ficher mapView
final ui.Image _image;
final LatLonBox _geoPosition;
const MapView(
ui.Image image, {
ui.Image image,
LatLonBox geoPosition, {
Key key,
}) : _image = image,
_geoPosition = geoPosition,
super(key: key);
@override
......@@ -114,41 +108,10 @@ class MapView extends StatefulWidget {
class _MapViewState extends State<MapView> {
double _len = 0.0;
double _x = 0.0;
double _y = 0.0;
Offset _startingFocalPoint;
Offset _previousOffset;
Offset _offset = Offset.zero;
double _previousZoom;
double _zoom = 1.0;
bool _forward = true;
bool _scaleEnabled = true;
bool _tapEnabled = false;
bool _doubleTapEnabled = false;
bool _longPressEnabled = false;
// void _handleScaleStart(ScaleStartDetails details) {
// setState(() {
// _startingFocalPoint = details.focalPoint;
// _previousOffset = _offset;
// _previousZoom = _zoom;
// });
// }
//
// void _handleScaleUpdate(ScaleUpdateDetails details) {
// setState(() {
// _zoom = _previousZoom * details.scale;
// print("zoom = $_zoom");
// // // Ensure that item under the focal point stays in the same place despite zooming
// final Offset normalizedOffset = (_startingFocalPoint - _previousOffset) / _previousZoom;
// _offset = details.focalPoint - normalizedOffset * _zoom;
// });
// }
double actualZoom = 1;
double currentZoom= 1;
double currentZoom = 1;
@override
Widget build(BuildContext context) {
......@@ -162,7 +125,7 @@ class _MapViewState extends State<MapView> {
currentZoom = actualZoom * scaleUpdateDetails.scale;
if (currentZoom > 5) currentZoom = 5;
if (currentZoom < 1) currentZoom = 1;
setState(() { });
setState(() {});
},
onInteractionEnd: (details) {
actualZoom = currentZoom;
......@@ -172,58 +135,120 @@ class _MapViewState extends State<MapView> {
// Use the Controller Matrix4 to get the correct scale.
},
child: CustomPaint(
painter: FaceOutlinePainter(
painter: MapPainter(
image: widget._image,
zoom: _zoom,
offset: _offset,
len: _len,
forward: _forward,
),
),
),
),
Container(
child: Text("Echelle $currentZoom"),
child: CustomPaint(
painter: ScalePainter(currentZoom: currentZoom), // TODO Compute the scale
),
),
]);
}
}
class FaceOutlinePainter extends CustomPainter {
class MapPainter extends CustomPainter {
// TODO - MapView
const FaceOutlinePainter({
const MapPainter({
this.image,
this.zoom,
this.offset,
this.len,
this.forward,
});
final ui.Image image;
final double zoom;
final Offset offset;
final double len;
final bool forward;
@override
void paint(Canvas canvas, Size size) {
// Define a paint object
print("PAINT");
final paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 4.0
..color = Colors.indigo;
var paint2 = new Paint();
// Offset imageSize = Offset(image.width.toDouble(), image.height.toDouble());
var paint = new Paint();
// static double _computeImageScale( int width, int height, int leftBound, int topBound, int rightBound, int bottomBound ) {
// int boundWidth = rightBound - leftBound;
// int boundHeight = bottomBound - topBound;
// return Math.min(boundWidth / (double) width, boundHeight / (double) height);
// }
var scale = size.width / image.width;
canvas.scale(scale * zoom);
canvas.translate(image.width / 2 * scale, image.height / 2 * scale);
canvas.rotate(10 * pi / 180);
canvas.drawImage(image, offset, paint2);
canvas.drawImage(image, offset, paint);
}
@override
bool shouldRepaint(FaceOutlinePainter oldPainter) {
return oldPainter.zoom != zoom || oldPainter.len != len || oldPainter.offset != offset || oldPainter.forward != forward;
bool shouldRepaint(MapPainter oldPainter) {
return oldPainter.zoom != zoom || oldPainter.len != len || oldPainter.offset != offset;
}
// private void updateScale() {
// if (_mapScaleView != null) {
// double imageScale = _computeImageScale(_image.getWidth(), _image.getHeight(), _bounds.left, _bounds.top, _bounds.right, _bounds.bottom);
// double scale = _pixelsByMeter * imageScale * _currentScale;
// _mapScaleView.updateScale(scale);
// }
// }
// static double _computeImageScale( int width, int height, int leftBound, int topBound, int rightBound, int bottomBound ) {
// int boundWidth = rightBound - leftBound;
// int boundHeight = bottomBound - topBound;
// return Math.min(boundWidth / (double) width, boundHeight / (double) height);
// }
// private void computePixelsByMeter() {
// GeodesicPoint geodesicPoint1 = new GeodesicPoint(_geoPosition.north, _geoPosition.west);
// GeodesicPoint geodesicPoint2 = new GeodesicPoint(_geoPosition.south, _geoPosition.east);
// double distanceInMeters = geodesicPoint1.distanceToInMeters(geodesicPoint2);
// _pixelsByMeter = Math.sqrt((double)_image.getHeight() * _image.getHeight() + _image.getWidth() * _image.getWidth()) / distanceInMeters;
// }
/////
}
class ScalePainter extends CustomPainter {
double currentZoom;
ScalePainter({this.currentZoom});
@override
void paint(Canvas canvas, Size size) {
final p1 = Offset(10, 10);
final p2 = Offset(25, 25);
final paint = Paint()
..color = Colors.black
..strokeWidth = 4;
canvas.drawLine(p1, p2, paint);
}
@override
bool shouldRepaint(ScalePainter oldDelegate) {
return currentZoom != oldDelegate.currentZoom;
}
}
// public void updateScale( double numberOfPixelsPerMeter ) {
// _numberOfPixelsPerMeter = numberOfPixelsPerMeter;
// invalidate();
// }
// int lengthInMeters = _computeLineLengthInMeters(_width, _numberOfPixelsPerMeter);
// int lengthInPixels = (int) (lengthInMeters * _numberOfPixelsPerMeter);
//
// static int _computeLineLengthInMeters( int width, double numberOfPixelsPerMeter ) {
// int i = 5000;
// while (i * numberOfPixelsPerMeter > width - 10.0) {
// if (i <= 50) {
// i -= 10;
// } else if (i <= 100) {
// i -= 50;
// } else {
// i -= 100;
// }
// }
// return i;
// }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment