diff options
Diffstat (limited to 'lib/navigation')
| -rw-r--r-- | lib/navigation/HERENavigation.dart | 46 | ||||
| -rw-r--r-- | lib/navigation/baseNavigation.dart | 7 | ||||
| -rw-r--r-- | lib/navigation/openstreetmapNavigation.dart | 274 |
3 files changed, 306 insertions, 21 deletions
diff --git a/lib/navigation/HERENavigation.dart b/lib/navigation/HERENavigation.dart index 1ccae29..6855124 100644 --- a/lib/navigation/HERENavigation.dart +++ b/lib/navigation/HERENavigation.dart @@ -96,20 +96,22 @@ class _HERENavigationState extends BaseNavigationState { }); widget.stopCompletedEvent = eventBus.on<StopCompletedEvent>().listen((e) { - routeSectionCursor += 1; - if (routeSectionCursor >= widget.allTasks.length) { - routeSectionCursor = widget.allTasks.length - 1; + widget.routeSectionCursor += 1; + if (widget.routeSectionCursor >= widget.allTasks.length) { + widget.routeSectionCursor = widget.allTasks.length - 1; } updateHighlightedRouteSections(); - eventBus.fire(NextStopLoadedEvent(widget.allTasks[routeSectionCursor])); + eventBus.fire( + NextStopLoadedEvent(widget.allTasks[widget.routeSectionCursor])); }); widget.stopIncompletedEvent = eventBus.on<StopIncompletedEvent>().listen((e) { - routeSectionCursor -= 1; - if (routeSectionCursor < 0) routeSectionCursor = 0; + widget.routeSectionCursor -= 1; + if (widget.routeSectionCursor < 0) widget.routeSectionCursor = 0; updateHighlightedRouteSections(force: true); - eventBus.fire(NextStopLoadedEvent(widget.allTasks[routeSectionCursor])); + eventBus.fire( + NextStopLoadedEvent(widget.allTasks[widget.routeSectionCursor])); }); blacklistProvider @@ -251,14 +253,17 @@ class _HERENavigationState extends BaseNavigationState { DestinationPin pin = widget.parcelNumberPins.elementAt(i); Color color = Color.fromARGB(200, 0, 144, 138); - if (i == routeSectionCursor) color = Color.fromARGB(199, 143, 8, 31); - if (i == routeSectionCursor + 1) color = Color.fromARGB(197, 13, 36, 241); + if (i == widget.routeSectionCursor) + color = Color.fromARGB(199, 143, 8, 31); + if (i == widget.routeSectionCursor + 1) + color = Color.fromARGB(197, 13, 36, 241); if (destinationPinIsInBlacklist(widget.parcelNumberPins[i])) { color = Color.fromRGBO(143, 8, 31, 0.78); } - bool forceUpdateThisPin = - force && (i > routeSectionCursor - 3 && i < routeSectionCursor + 3); + bool forceUpdateThisPin = force && + (i > widget.routeSectionCursor - 3 && + i < widget.routeSectionCursor + 3); if (!shouldDoublePlannedAddressBeVisible(pin)) { pin.pin?.unpin(); @@ -266,7 +271,8 @@ class _HERENavigationState extends BaseNavigationState { continue; } - if (i > routeSectionCursor + 1 && i < routeSectionCursor + maxPins) { + if (i > widget.routeSectionCursor + 1 && + i < widget.routeSectionCursor + maxPins) { if (forceUpdateThisPin) { pin.pin?.unpin(); pin.pin = null; @@ -281,7 +287,8 @@ class _HERENavigationState extends BaseNavigationState { pin.pin = null; } - if (i == routeSectionCursor || i == routeSectionCursor + 1) { + if (i == widget.routeSectionCursor || + i == widget.routeSectionCursor + 1) { var widgetPin = createPinWidget(pin, color, widget.destinationCoords[i]); pin.pin = widgetPin; @@ -296,15 +303,17 @@ class _HERENavigationState extends BaseNavigationState { MapPolyline path = _pathSections.elementAt(i); // previous section - if (i == routeSectionCursor - 1) { + if (i == widget.routeSectionCursor - 1) { section.lineColor = Color.fromARGB(160, 168, 113, 108); path.lineColor = Color.fromARGB(0, 255, 255, 255); } // current and next 5 sections - else if (i >= routeSectionCursor && - i < routeSectionCursor + maxSections) { + else if (i >= widget.routeSectionCursor && + i < widget.routeSectionCursor + maxSections) { section.lineColor = Color.fromARGB( - (255 - ((255 / (maxSections + 1)) * (i - routeSectionCursor))) + (255 - + ((255 / (maxSections + 1)) * + (i - widget.routeSectionCursor))) .toInt(), 0, 144, @@ -313,7 +322,8 @@ class _HERENavigationState extends BaseNavigationState { section.lineColor = Color.fromARGB(0, 255, 255, 255); } - if (i >= routeSectionCursor && i < routeSectionCursor + maxWalkPaths) { + if (i >= widget.routeSectionCursor && + i < widget.routeSectionCursor + maxWalkPaths) { path.lineColor = Color.fromARGB(160, 255, 0, 0); } else { path.lineColor = Color.fromARGB(0, 255, 255, 255); diff --git a/lib/navigation/baseNavigation.dart b/lib/navigation/baseNavigation.dart index 78e5f1c..1aed658 100644 --- a/lib/navigation/baseNavigation.dart +++ b/lib/navigation/baseNavigation.dart @@ -65,6 +65,7 @@ abstract class BaseNavigation extends StatefulWidget { bool isLookingAround = false; double currentZoom = 20; DHLCoordinates lastPosition = DHLCoordinates(0, 0); + int routeSectionCursor = 0; StreamSubscription? stopCompletedEvent; StreamSubscription? stopIncompletedEvent; @@ -79,8 +80,6 @@ abstract class BaseNavigation extends StatefulWidget { } abstract class BaseNavigationState extends State<BaseNavigation> { - int routeSectionCursor = 0; - StreamSubscription? changeZoomEvent; StreamSubscription? flyToEvent; @@ -166,7 +165,9 @@ abstract class BaseNavigationState extends State<BaseNavigation> { // if address is double planned and there is a stop before this one. bool shouldDoublePlannedAddressBeVisible(DestinationPin taskToCheck) { if (!taskToCheck.isDoublePlannedAddress) return true; - for (int i = routeSectionCursor; i < widget.parcelNumberPins.length; i++) { + for (int i = widget.routeSectionCursor; + i < widget.parcelNumberPins.length; + i++) { var item = widget.parcelNumberPins[i]; if (item == taskToCheck) { diff --git a/lib/navigation/openstreetmapNavigation.dart b/lib/navigation/openstreetmapNavigation.dart new file mode 100644 index 0000000..f8f37df --- /dev/null +++ b/lib/navigation/openstreetmapNavigation.dart @@ -0,0 +1,274 @@ +import 'dart:async'; +import 'package:flutter_osm_plugin/flutter_osm_plugin.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:geolocator/geolocator.dart'; +import 'package:training_planner/events/MapPanningEvent.dart'; +import 'package:training_planner/events/NextStopLoadedEvent.dart'; +import 'package:training_planner/events/RouteLoadedEvent.dart'; +import 'package:training_planner/events/StopCompletedEvent.dart'; +import 'package:training_planner/main.dart'; +import 'package:training_planner/navigation/baseNavigation.dart'; +import 'package:training_planner/pages/navigation_page.dart'; +import 'package:training_planner/route.dart'; +import '../route.dart' as DHLRoute; + +class OpenstreetmapNavigation extends BaseNavigation { + OpenstreetmapNavigation({Key? key, required route}) + : super(key: key, route: route); + + @override + _OpenstreetNavigationState createState() => _OpenstreetNavigationState(); +} + +class _OpenstreetNavigationState extends BaseNavigationState + with OSMMixinObserver { + late List<RoadInfo> roads; + late MapController controller; + + @override + void initState() { + widget.routeSectionCursor = 0; + widget.currentZoom = 10; + controller = MapController( + initMapWithUserPosition: true, + areaLimit: BoundingBox( + east: 7.601818, + north: 53.703101, + south: 50.679237, + west: 2.894101, + )); + + widget.isLookingAround = true; + eventBus.fire(MapPanningEvent(true)); + + widget.stopCompletedEvent = eventBus.on<StopCompletedEvent>().listen((e) { + widget.routeSectionCursor += 1; + if (widget.routeSectionCursor >= widget.allTasks.length) { + widget.routeSectionCursor = widget.allTasks.length - 1; + } + updateHighlightedRouteSections(); + eventBus.fire( + NextStopLoadedEvent(widget.allTasks[widget.routeSectionCursor])); + }); + + widget.stopIncompletedEvent = + eventBus.on<StopIncompletedEvent>().listen((e) { + widget.routeSectionCursor -= 1; + if (widget.routeSectionCursor < 0) widget.routeSectionCursor = 0; + updateHighlightedRouteSections(force: true); + eventBus.fire( + NextStopLoadedEvent(widget.allTasks[widget.routeSectionCursor])); + }); + + blacklistProvider + .getBlacklist() + .then((value) => {widget.blacklist = value}); + + super.initState(); + controller.addObserver(this); + + addRoute(widget.route); + } + + @override + Future<void> mapIsReady(bool isReady) async { + addRoute(widget.route); + } + + @override + Future<void> addRoute(DHLRoute.Route route) async { + print( + "ASGOPDJS_GH DS*()FHY DS()UFHY) DSU(FHY)DSU( FH)DSUHF)UDS HF)UDSUHF "); + if (route.tasks == null) return; + + print("234"); + + GeoPoint routeStartCoords = await controller.myLocation(); + + List<GeoPoint> waypoints = [routeStartCoords]; + //List<MultiRoadConfiguration> configs = []; + + groupTasksIntoGroups(route); + /* + GeoPoint prevCoord = routeStartCoords; + for (var item in widget.parcelNumberPins) { + GeoPoint point = GeoPoint( + latitude: item.coords.lattitude, longitude: item.coords.longitude); + + waypoints.add(point); + + //configs.add(MultiRoadConfiguration( + // startPoint: prevCoord, + // destinationPoint: point, + //)); + + prevCoord = point; + } + + for (var item in widget.parcelNumberPins) { + item.isDoublePlannedAddress = isAddressDoublePlanned(item); + } +*/ + /* + roads = await controller.drawMultipleRoad( + configs, + commonRoadOption: MultiRoadOption( + roadWidth: 10, + roadColor: Colors.blue, + ), + ); + */ + + eventBus.fire(NextStopLoadedEvent(widget.allTasks[0])); + + updateHighlightedRouteSections(); + } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + var mapPointers = 0; + var mapPosition; + + void onMoveStart() { + widget.isLookingAround = true; + eventBus.fire(MapPanningEvent(true)); + } + + void onMoveEnd() {} + + @override + Widget build(BuildContext context) { + return Listener( + onPointerDown: (details) { + if (mapPointers == 0) onMoveStart(); + mapPointers++; + }, + onPointerUp: (details) { + mapPointers--; + if (mapPointers == 0) onMoveEnd(); + }, + behavior: HitTestBehavior.deferToChild, + child: OSMFlutter( + controller: controller, + trackMyPosition: true, + initZoom: widget.currentZoom, + minZoomLevel: 2, + maxZoomLevel: 18, + stepZoom: 1.0, + userLocationMarker: UserLocationMaker( + personMarker: MarkerIcon( + assetMarker: AssetMarker( + image: AssetImage('assets/package.png'), + scaleAssetImage: 1.0), + ), + directionArrowMarker: MarkerIcon( + assetMarker: AssetMarker( + image: AssetImage('assets/package.png'), + scaleAssetImage: 1.0), + ), + ), + roadConfiguration: RoadOption( + roadColor: Colors.yellowAccent, + ), + markerOption: MarkerOption( + defaultMarker: MarkerIcon( + icon: Icon( + Icons.person_pin_circle, + color: Colors.blue, + size: 56, + ), + ), + ), + )); + } + + @override + void changeZoom(double newVal) async { + if (newVal > 18) newVal = 18; + if (newVal < 10) newVal = 10; + widget.currentZoom = newVal; + await controller.setZoom(zoomLevel: newVal); + } + + @override + createPinWidget( + DestinationPin pin, Color color, DHLCoordinates coords) async { + await controller.addMarker( + GeoPoint( + latitude: pin.coords.lattitude, longitude: pin.coords.longitude), + markerIcon: MarkerIcon( + iconWidget: Container( + height: 65, + width: 150, + child: createPin(pin, color, + isDoublePlannedAddress: pin.isDoublePlannedAddress), + ), + ), + angle: 0); + } + + @override + void flyTo(DHLCoordinates coords) async { + await controller.enableTracking( + enableStopFollow: false, + ); + } + + @override + void updateHighlightedRouteSections({bool force = false}) { + int maxPins = 300; + + for (int i = widget.parcelNumberPins.length - 1; i >= 0; i--) { + DestinationPin pin = widget.parcelNumberPins.elementAt(i); + + Color color = Color.fromARGB(200, 0, 144, 138); + if (i == widget.routeSectionCursor) + color = Color.fromARGB(199, 143, 8, 31); + if (i == widget.routeSectionCursor + 1) + color = Color.fromARGB(197, 13, 36, 241); + if (destinationPinIsInBlacklist(widget.parcelNumberPins[i])) { + color = Color.fromRGBO(143, 8, 31, 0.78); + } + + bool forceUpdateThisPin = force && + (i > widget.routeSectionCursor - 3 && + i < widget.routeSectionCursor + 3); + + /* + if (!shouldDoublePlannedAddressBeVisible(pin)) { + pin.pin?.unpin(); + pin.pin = null; + continue; + } + + + if (i > routeSectionCursor + 1 && i < routeSectionCursor + maxPins) { + if (forceUpdateThisPin) { + pin.pin?.unpin(); + pin.pin = null; + } else if (pin.pin != null) { + continue; + } + var widgetPin = + createPinWidget(pin, color, widget.destinationCoords[i]); + pin.pin = widgetPin; + } else { + pin.pin?.unpin(); + pin.pin = null; + }*/ + + if (i == widget.routeSectionCursor || + i == widget.routeSectionCursor + 1) { + var widgetPin = + createPinWidget(pin, color, widget.destinationCoords[i]); + pin.pin = widgetPin; + } + } + } +} |
