I'm using Mapbox iOS SDK v6.3.0
I have an MGLOverlay on my map, but whenever I add a MGLRasterTileSource it appears above the overlay and hides it!
I have currently fixed it by randomly inserting numbers into style.insertLayer(layer, at: x)
There must be a cleaner way of doing this right?
The default map styleURLs work fine, it's only my custom raster tiles where I have to manually edit the style to add sources and layers.
There are 2 different kinds of maps I'm loading
mapView.styleURL
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.