From 1263a5bf442c9211ffe81d797289d34cf86dd847 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:33:21 +0500 Subject: [PATCH 1/8] Update flutter_mapbox_navigation.dart --- lib/src/flutter_mapbox_navigation.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/flutter_mapbox_navigation.dart b/lib/src/flutter_mapbox_navigation.dart index 19219269..1f7151e1 100644 --- a/lib/src/flutter_mapbox_navigation.dart +++ b/lib/src/flutter_mapbox_navigation.dart @@ -15,7 +15,7 @@ class MapBoxNavigation { static MapBoxNavigation get instance => _instance; MapBoxOptions _defaultOptions = MapBoxOptions( - zoom: 15, + zoom: 20, tilt: 0, bearing: 0, enableRefresh: false, @@ -29,6 +29,7 @@ class MapBoxNavigation { animateBuildRoute: true, longPressDestinationEnabled: true, language: 'en', + padding: EdgeInsets.all(20) ); /// setter to set default options From 0d6b6d99e64ddee07f345166fa77953c5d5d70c7 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:37:43 +0500 Subject: [PATCH 2/8] Update flutter_mapbox_navigation.dart --- lib/src/flutter_mapbox_navigation.dart | 35 +++++++++++++------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/src/flutter_mapbox_navigation.dart b/lib/src/flutter_mapbox_navigation.dart index 1f7151e1..b8a33e18 100644 --- a/lib/src/flutter_mapbox_navigation.dart +++ b/lib/src/flutter_mapbox_navigation.dart @@ -14,23 +14,24 @@ class MapBoxNavigation { /// get current instance of this class static MapBoxNavigation get instance => _instance; - MapBoxOptions _defaultOptions = MapBoxOptions( - zoom: 20, - tilt: 0, - bearing: 0, - enableRefresh: false, - alternatives: true, - voiceInstructionsEnabled: true, - bannerInstructionsEnabled: true, - allowsUTurnAtWayPoints: true, - mode: MapBoxNavigationMode.drivingWithTraffic, - units: VoiceUnits.imperial, - simulateRoute: false, - animateBuildRoute: true, - longPressDestinationEnabled: true, - language: 'en', - padding: EdgeInsets.all(20) - ); + MapBoxOptions _defaultPptions = MapBoxOptions( + zoom: 20, + tilt: 10, + bearing: 10, + enableRefresh: true, + alternatives: true, + voiceInstructionsEnabled: true, + bannerInstructionsEnabled: true, + allowsUTurnAtWayPoints: true, + mode: MapBoxNavigationMode.driving, + units: VoiceUnits.imperial, + simulateRoute: true, + animateBuildRoute: true, + longPressDestinationEnabled: true, + language: 'en', + padding: const EdgeInsets.only( + top: 20), // top, left, bottom, right + ); /// setter to set default options void setDefaultOptions(MapBoxOptions options) { From 4590b576eedfd2bc5babc0766f1b9374133b6117 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:44:35 +0500 Subject: [PATCH 3/8] Update options.dart --- lib/src/models/options.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/src/models/options.dart b/lib/src/models/options.dart index c90203be..f6dc213f 100644 --- a/lib/src/models/options.dart +++ b/lib/src/models/options.dart @@ -215,12 +215,15 @@ class MapBoxOptions { } if (isOptimized != null) optionsMap['isOptimized'] = isOptimized; - addIfNonNull('padding', [ - padding?.top, - padding?.left, - padding?.bottom, - padding?.right, - ]); + if (padding != null) { + optionsMap['padding'] = [ + padding?.top ?? 10.0, // Default top padding + padding?.left ?? 20.0, // Default left padding + padding?.bottom ?? 10.0, // Default bottom padding + padding?.right ?? 20.0, // Default right padding + ]; +} + addIfNonNull('showReportFeedbackButton', showReportFeedbackButton); addIfNonNull('showEndOfRouteFeedback', showEndOfRouteFeedback); From 87bc8fc7b924608ca3ed43c09557e8bb4dfbbac6 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:46:58 +0500 Subject: [PATCH 4/8] Update view.dart --- lib/src/embedded/view.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/src/embedded/view.dart b/lib/src/embedded/view.dart index 48e2b77c..9dba296b 100644 --- a/lib/src/embedded/view.dart +++ b/lib/src/embedded/view.dart @@ -72,12 +72,16 @@ class MapBoxNavigationView extends StatelessWidget { }, ); } else if (Platform.isIOS) { - return UiKitView( - viewType: 'FlutterMapboxNavigationView', - onPlatformViewCreated: _onPlatformViewCreated, - creationParams: options!.toMap(), - creationParamsCodec: _decoder, - ); + return Padding( + padding: const EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 20.0), // Add your desired padding here + child: UiKitView( + viewType: 'FlutterMapboxNavigationView', + onPlatformViewCreated: _onPlatformViewCreated, + creationParams: options!.toMap(), + creationParamsCodec: _decoder, + ), +) +; } else { return Container(); } From 75634a8fb19674d57c110a3c5cab6f27881f0036 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:47:43 +0500 Subject: [PATCH 5/8] Update view.dart --- lib/src/embedded/view.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/embedded/view.dart b/lib/src/embedded/view.dart index 9dba296b..4400845d 100644 --- a/lib/src/embedded/view.dart +++ b/lib/src/embedded/view.dart @@ -77,7 +77,7 @@ class MapBoxNavigationView extends StatelessWidget { child: UiKitView( viewType: 'FlutterMapboxNavigationView', onPlatformViewCreated: _onPlatformViewCreated, - creationParams: options!.toMap(), + creationParams: options, creationParamsCodec: _decoder, ), ) From 1994113756c84d41aea68de6c02b91f22a4a6cf4 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:51:40 +0500 Subject: [PATCH 6/8] Update EmbeddedNavigationView.swift --- ios/Classes/EmbeddedNavigationView.swift | 76 +++++++++++------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/ios/Classes/EmbeddedNavigationView.swift b/ios/Classes/EmbeddedNavigationView.swift index f071434e..17897e92 100644 --- a/ios/Classes/EmbeddedNavigationView.swift +++ b/ios/Classes/EmbeddedNavigationView.swift @@ -105,55 +105,51 @@ public class FlutterMapboxNavigationView : NavigationFactory, FlutterPlatformVie } - private func setupMapView() - { - navigationMapView = NavigationMapView(frame: frame) - navigationMapView.delegate = self - - if(self.arguments != nil) - { - - parseFlutterArguments(arguments: arguments) - - if(_mapStyleUrlDay != nil) - { - navigationMapView.mapView.mapboxMap.style.uri = StyleURI.init(url: URL(string: _mapStyleUrlDay!)!) - } + private func setupMapView() { + navigationMapView = NavigationMapView(frame: frame) + navigationMapView.delegate = self - var currentLocation: CLLocation! - - locationManager.requestWhenInUseAuthorization() + if let arguments = self.arguments { + parseFlutterArguments(arguments: arguments) - if(CLLocationManager.authorizationStatus() == .authorizedWhenInUse || - CLLocationManager.authorizationStatus() == .authorizedAlways) { - currentLocation = locationManager.location + if let mapStyleUrlDay = _mapStyleUrlDay { + navigationMapView.mapView.mapboxMap.style.uri = StyleURI(url: URL(string: mapStyleUrlDay)!) + } - } - - let initialLatitude = arguments?["initialLatitude"] as? Double ?? currentLocation?.coordinate.latitude - let initialLongitude = arguments?["initialLongitude"] as? Double ?? currentLocation?.coordinate.longitude - if(initialLatitude != nil && initialLongitude != nil) - { - moveCameraToCoordinates(latitude: initialLatitude!, longitude: initialLongitude!) - } + var currentLocation: CLLocation! + locationManager.requestWhenInUseAuthorization() + if CLLocationManager.authorizationStatus() == .authorizedWhenInUse || CLLocationManager.authorizationStatus() == .authorizedAlways { + currentLocation = locationManager.location } - if _longPressDestinationEnabled - { - let gesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:))) - gesture.delegate = self - navigationMapView?.addGestureRecognizer(gesture) - } - - if _enableOnMapTapCallback { - let onTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:))) - onTapGesture.numberOfTapsRequired = 1 - onTapGesture.delegate = self - navigationMapView?.addGestureRecognizer(onTapGesture) + let initialLatitude = arguments["initialLatitude"] as? Double ?? currentLocation?.coordinate.latitude + let initialLongitude = arguments["initialLongitude"] as? Double ?? currentLocation?.coordinate.longitude + if let initialLatitude = initialLatitude, let initialLongitude = initialLongitude { + moveCameraToCoordinates(latitude: initialLatitude, longitude: initialLongitude) } } + if _longPressDestinationEnabled { + let gesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:))) + gesture.delegate = self + navigationMapView.addGestureRecognizer(gesture) + } + + if _enableOnMapTapCallback { + let onTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:))) + onTapGesture.numberOfTapsRequired = 1 + onTapGesture.delegate = self + navigationMapView.addGestureRecognizer(onTapGesture) + } + + // Apply padding to the map + let padding: CGFloat = 20.0 // Change this value to whatever padding you prefer + navigationMapView.translatesAutoresizingMaskIntoConstraints = false + constraintsWithPaddingBetween(holderView: self.navigationMapView, topView: navigationMapView, padding: padding) +} + + func clearRoute(arguments: NSDictionary?, result: @escaping FlutterResult) { if routeResponse == nil From 718e5e0186ae3f19657bbccde2a45f343938fe39 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:56:26 +0500 Subject: [PATCH 7/8] Update NavigationFactory.swift --- ios/Classes/NavigationFactory.swift | 40 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/ios/Classes/NavigationFactory.swift b/ios/Classes/NavigationFactory.swift index c6f847db..a089435e 100644 --- a/ios/Classes/NavigationFactory.swift +++ b/ios/Classes/NavigationFactory.swift @@ -209,24 +209,30 @@ public class NavigationFactory : NSObject, FlutterStreamHandler } func parseFlutterArguments(arguments: NSDictionary?) { - _language = arguments?["language"] as? String ?? _language - _voiceUnits = arguments?["units"] as? String ?? _voiceUnits - _simulateRoute = arguments?["simulateRoute"] as? Bool ?? _simulateRoute - _isOptimized = arguments?["isOptimized"] as? Bool ?? _isOptimized - _allowsUTurnAtWayPoints = arguments?["allowsUTurnAtWayPoints"] as? Bool - _navigationMode = arguments?["mode"] as? String ?? "drivingWithTraffic" - _showReportFeedbackButton = arguments?["showReportFeedbackButton"] as? Bool ?? _showReportFeedbackButton - _showEndOfRouteFeedback = arguments?["showEndOfRouteFeedback"] as? Bool ?? _showEndOfRouteFeedback - _enableOnMapTapCallback = arguments?["enableOnMapTapCallback"] as? Bool ?? _enableOnMapTapCallback - _mapStyleUrlDay = arguments?["mapStyleUrlDay"] as? String - _mapStyleUrlNight = arguments?["mapStyleUrlNight"] as? String - _zoom = arguments?["zoom"] as? Double ?? _zoom - _bearing = arguments?["bearing"] as? Double ?? _bearing - _tilt = arguments?["tilt"] as? Double ?? _tilt - _animateBuildRoute = arguments?["animateBuildRoute"] as? Bool ?? _animateBuildRoute - _longPressDestinationEnabled = arguments?["longPressDestinationEnabled"] as? Bool ?? _longPressDestinationEnabled - _alternatives = arguments?["alternatives"] as? Bool ?? _alternatives + _language = arguments?["language"] as? String ?? _language + _voiceUnits = arguments?["units"] as? String ?? _voiceUnits + _simulateRoute = arguments?["simulateRoute"] as? Bool ?? _simulateRoute + _isOptimized = arguments?["isOptimized"] as? Bool ?? _isOptimized + _allowsUTurnAtWayPoints = arguments?["allowsUTurnAtWayPoints"] as? Bool + _navigationMode = arguments?["mode"] as? String ?? "drivingWithTraffic" + _showReportFeedbackButton = arguments?["showReportFeedbackButton"] as? Bool ?? _showReportFeedbackButton + _showEndOfRouteFeedback = arguments?["showEndOfRouteFeedback"] as? Bool ?? _showEndOfRouteFeedback + _enableOnMapTapCallback = arguments?["enableOnMapTapCallback"] as? Bool ?? _enableOnMapTapCallback + _mapStyleUrlDay = arguments?["mapStyleUrlDay"] as? String + _mapStyleUrlNight = arguments?["mapStyleUrlNight"] as? String + _zoom = arguments?["zoom"] as? Double ?? _zoom + _bearing = arguments?["bearing"] as? Double ?? _bearing + _tilt = arguments?["tilt"] as? Double ?? _tilt + _animateBuildRoute = arguments?["animateBuildRoute"] as? Bool ?? _animateBuildRoute + _longPressDestinationEnabled = arguments?["longPressDestinationEnabled"] as? Bool ?? _longPressDestinationEnabled + _alternatives = arguments?["alternatives"] as? Bool ?? _alternatives + + // Parse padding + if let paddingArgs = arguments?["padding"] as? [Double], paddingArgs.count == 4 { + _padding = UIEdgeInsets(top: paddingArgs[0], left: paddingArgs[1], bottom: paddingArgs[2], right: paddingArgs[3]) } +} + func continueNavigationWithWayPoints(wayPoints: [Waypoint]) From e6c8d138cdc336b42d35cb46fe96aa3cc06cb726 Mon Sep 17 00:00:00 2001 From: YersultanSS <104438473+ErsultanSs@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:57:15 +0500 Subject: [PATCH 8/8] Update EmbeddedNavigationView.swift --- ios/Classes/EmbeddedNavigationView.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ios/Classes/EmbeddedNavigationView.swift b/ios/Classes/EmbeddedNavigationView.swift index 17897e92..8a9a52c7 100644 --- a/ios/Classes/EmbeddedNavigationView.swift +++ b/ios/Classes/EmbeddedNavigationView.swift @@ -105,7 +105,7 @@ public class FlutterMapboxNavigationView : NavigationFactory, FlutterPlatformVie } - private func setupMapView() { +private func setupMapView() { navigationMapView = NavigationMapView(frame: frame) navigationMapView.delegate = self @@ -116,6 +116,12 @@ public class FlutterMapboxNavigationView : NavigationFactory, FlutterPlatformVie navigationMapView.mapView.mapboxMap.style.uri = StyleURI(url: URL(string: mapStyleUrlDay)!) } + // Apply the parsed padding + if let padding = _padding { + navigationMapView.mapView.ornaments.options.compass.margins = CGPoint(x: padding.left, y: padding.top) + navigationMapView.mapView.ornaments.options.scaleBar.margins = CGPoint(x: padding.left, y: padding.bottom) + } + var currentLocation: CLLocation! locationManager.requestWhenInUseAuthorization() @@ -143,13 +149,14 @@ public class FlutterMapboxNavigationView : NavigationFactory, FlutterPlatformVie navigationMapView.addGestureRecognizer(onTapGesture) } - // Apply padding to the map - let padding: CGFloat = 20.0 // Change this value to whatever padding you prefer - navigationMapView.translatesAutoresizingMaskIntoConstraints = false - constraintsWithPaddingBetween(holderView: self.navigationMapView, topView: navigationMapView, padding: padding) + // Apply padding to the map view using constraints + if let padding = _padding { + constraintsWithPaddingBetween(holderView: self.navigationMapView, topView: navigationMapView, padding: padding.top) + } } + func clearRoute(arguments: NSDictionary?, result: @escaping FlutterResult) { if routeResponse == nil