Reputation: 305
I'm coding an iOS app with a Mapbox MGLMapView
displayed on my view controller, on this mapView I draw a route using a MGLShapeSource
, MGLLineStyleLayer
and MGLPolylineFeature
objects.
Here is the code :
let newSource = MGLShapeSource(identifier: "polylineBlue", shape: self.polylines, options: nil)
mapView.style?.addSource(newSource)
let newStyle = MGLLineStyleLayer(identifier: "polylineBlueLayer", source: source)
...styling my layer...
mapView.style?.addLayer(newStyle)
source.shape = self.polylines // a MGLPolylineFeature object
Works great for the route but there is one issue : is appears on top of my annotations.
I add the annotation with regular mapView function :
mapView.addAnnotations([..my MGLPointAnnotation objects...])
I've tried searching here and other websites, I only found one topic and there is nothing helpful except someone saying that we can't set a z layer position on annotations so no fix for that.
Does someone know a workaround ? Do I have to use that : https://docs.mapbox.com/ios/maps/examples/add-marker-symbol/ ?
if so, do I need to create one MGLSymbolStyleLayer
per annotation ?
Sounds like a painful solution for a so basic need...
Thanks !
Upvotes: 0
Views: 1082
Reputation: 321
In the code snippets that you provided, it appears that your annotations are MGLPointAnnotations
. If this is the case, you would need to add your MGLPointAnnotations
to an MGLShapeSource
using MGLShapeSource(initWithIdentifier:shapes:) and then use this shape source to create your MGLSymbolStyleLayer
.
To ensure that the annotations show on top of your route, you will need to verify when each layer is being added, as layers are “baked” into the map before rendering. If you add the MGLSymbolStyleLayer
responsible for the annotations after the route is added to the map, they will appear on top. If you add them before the route loads, they will appear below the route line layer. Only one MGLSymbolStyleLayer
is needed.
For additional information on markers and annotations, please take a look at Mapbox’s documentation here.
Upvotes: 1