There are 2 different kinds of maps I'm loading
- Mapbox styleURLs: These are very simple to set, as you just set the
mapView.styleURL
- Raster Tiles: These are more complex to add and you have call
addSource()
and addLayer()
(or in my case insertLayer(layer: below:)
)
My initial implementation of route lines using MGLPolyline
worked fine on styleURL maps, but was having trouble with raster tile maps as I described in the question.
Mapbox Support (Megan, the other answer) mentioned I should try to use MGLLineStyleLayer
instead since it is more performant and I can better control the z-order since it's in the same style.layers
array and I can insertLayer(below:)
(which I can't seem to use with MGLPolyline
).
However, once I did that, the styleURL maps no longer worked, since when I switched to that style of map, it clears out all the style layers and rebuilds it!!
So to finally solve my problem I had to re-add the MGLLineStyleLayer
(and source) every time I switch to a styleURL type of map.
A GOTCHYA! Now this does work, but for some reason I couldn't cache the MGLLineStyleLayer
and MGLShapeSource
and re-add it directly using addSource
and addLayer
from the source and layers I had cached...
I had to initialize them again from scratch or Mapbox would throw an exception that I hadn't created them right. I couldn't figure out what was wrong and this was the only thing that seemed to work.
Who knows I got way off track and there is an easier solution, but this is what is working for me.