Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 42 additions & 39 deletions ios/Classes/EmbeddedNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 23 additions & 17 deletions ios/Classes/NavigationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
16 changes: 10 additions & 6 deletions lib/src/embedded/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
34 changes: 18 additions & 16 deletions lib/src/flutter_mapbox_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the variable spelling

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) {
Expand Down
15 changes: 9 additions & 6 deletions lib/src/models/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,15 @@ class MapBoxOptions {
}
if (isOptimized != null) optionsMap['isOptimized'] = isOptimized;

addIfNonNull('padding', <double?>[
padding?.top,
padding?.left,
padding?.bottom,
padding?.right,
]);
if (padding != null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the addIfNotNull function for consistency?

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);
Expand Down