diff --git a/ios/Classes/EmbeddedNavigationView.swift b/ios/Classes/EmbeddedNavigationView.swift index f071434e..8a9a52c7 100644 --- a/ios/Classes/EmbeddedNavigationView.swift +++ b/ios/Classes/EmbeddedNavigationView.swift @@ -105,55 +105,58 @@ 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!)!) - } - - var currentLocation: CLLocation! +private func setupMapView() { + navigationMapView = NavigationMapView(frame: frame) + navigationMapView.delegate = self - 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)!) + } - } + // 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) + } - 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 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 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]) diff --git a/lib/src/embedded/view.dart b/lib/src/embedded/view.dart index 48e2b77c..4400845d 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, + creationParamsCodec: _decoder, + ), +) +; } else { return Container(); } diff --git a/lib/src/flutter_mapbox_navigation.dart b/lib/src/flutter_mapbox_navigation.dart index 19219269..b8a33e18 100644 --- a/lib/src/flutter_mapbox_navigation.dart +++ b/lib/src/flutter_mapbox_navigation.dart @@ -14,22 +14,24 @@ class MapBoxNavigation { /// get current instance of this class static MapBoxNavigation get instance => _instance; - MapBoxOptions _defaultOptions = MapBoxOptions( - zoom: 15, - 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', - ); + 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) { 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);