Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Mapbox Road Hardcoding #43

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Updated MapLibre Native dependency to ios-v6.0.0 (https://github.com/maplibre/maplibre-native/releases/tag/ios-v6.0.0). Implementers need to change the prefix MGL to MLN for all MapLibre Native classes that are referenced.
- Only snap location to route if the location is within the `RouteControllerUserLocationSnappingDistance`
- Add support for Swift Package Manager while dropping Carthage and Cocoapods.
- Initialization no longer tries to add mapbox://mapbox.mapbox-streets-v7 to all mapstyles.

## v2.0.0 (May 23, 2023)
- Upgrade minimum iOS version from 11.0 to 12.0.
Expand Down
21 changes: 1 addition & 20 deletions MapboxNavigation/RouteMapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -682,31 +682,12 @@ extension RouteMapViewController: NavigationViewDelegate {
}

func labelCurrentRoadFeature(at location: CLLocation) {
guard let style = mapView.style, let stepCoordinates = routeController.routeProgress.currentLegProgress.currentStep.coordinates else {
guard let stepCoordinates = routeController.routeProgress.currentLegProgress.currentStep.coordinates else {
return
}

let closestCoordinate = location.coordinate
let roadLabelLayerIdentifier = "roadLabelLayer"
var streetsSources: [MLNVectorTileSource] = style.sources.compactMap {
$0 as? MLNVectorTileSource
}.filter(\.isMapboxStreets)

// Add Mapbox Streets if the map does not already have it
if streetsSources.isEmpty {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you expect that there are valid reasons for the person to be in this state where they would want to silently proceed without error?

If not, though we don't have a reasonable default layer to fall back to like mapbox did, could we instead help the user out with an assertionFailure or a log message here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't really see a way or reason for this. I would assume Mapbox added this because they were getting support emails from users saying "my custom style is not showing roads during navigation", and a common reason was that the users had removed or restyled the road layer to be incompatible with the styling of maplibre navigation.

If I'm a german developer and name my sources and layers for roads "strassennetz" things will work perfectly fine - and yet maplibre would now throw a warning that it can't find a road layer. So unless we want to enforce a certain naming scheme for things in the style.json for maplibre navigation, I don't think emitting warnings would be helpful.

let source = MLNVectorTileSource(identifier: "mapboxStreetsv7", configurationURL: URL(string: "mapbox://mapbox.mapbox-streets-v7")!)
style.addSource(source)
streetsSources.append(source)
}

if let mapboxSteetsSource = streetsSources.first, style.layer(withIdentifier: roadLabelLayerIdentifier) == nil {
let streetLabelLayer = MLNLineStyleLayer(identifier: roadLabelLayerIdentifier, source: mapboxSteetsSource)
streetLabelLayer.sourceLayerIdentifier = "road_label"
streetLabelLayer.lineOpacity = NSExpression(forConstantValue: 1)
streetLabelLayer.lineWidth = NSExpression(forConstantValue: 20)
streetLabelLayer.lineColor = NSExpression(forConstantValue: UIColor.white)
style.insertLayer(streetLabelLayer, at: 0)
}

let userPuck = self.mapView.convert(closestCoordinate, toPointTo: self.mapView)
let features = self.mapView.visibleFeatures(at: userPuck, styleLayerIdentifiers: Set([roadLabelLayerIdentifier]))
Expand Down
Loading