I am trying to achieve requirement like – Help user for Turn-By-Turn Navigation between 2 locations using NavigationViewController of mapbox-maps-navigation.
Over the NavigationMapView, i add tiles Overlay, and i want to show routeline over that Tile overlay.
Using my below code, My source and destination pin is showing on overlay, But not Routeline:
func addRasterSource(for mapView: NavigationMapView) {
let sourceId = "raster-source"
let sourceUrl = "URL-FOR_TILE_OVERLAY"
var rasterSource = RasterSource(id: sourceId)
rasterSource.tiles = [sourceUrl]
rasterSource.tileSize = 256 //.above("pitch-outline")
let rasterLayer = RasterLayer(id: "raster-layer", source: sourceId)
let layerPosition = getLayerPositionBelowNavigation(for: mapView)
do {
try mapView.mapView.mapboxMap.addSource(rasterSource)
try mapView.mapView.mapboxMap.addLayer(rasterLayer, layerPosition: layerPosition)
} catch {
print("Failed to update the style. Error: (error)")
}
}
func getLayerPositionBelowNavigation(for mapView: NavigationMapView) -> LayerPosition {
// Fetch all layers from the style
guard let layers = try? mapView.mapView.mapboxMap.style.allLayerIdentifiers else {
return .above("pitch-outline")
}
if let routeLayer = layers.first(where: { $0.id.contains("navigation")}) {
return .below(routeLayer.id) //.below(routeLayer.id)
}
return .above("water")
}
New contributor
user26555745 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.