draw layer doesn't stay on top when added new layers on Mapbox gl
is there a way the update the z position of the draw layer?
I just encountered this too. You can specify the layer to insert before, see (https://www.mapbox.com/mapbox-gl-js/api/#Map#addLayer) The first layer added by mapbox-gl-draw depends on whether you are passing in custom styles or using the defaults. mapbox-gl-draw also appends '.cold' and '.hot' to the end of the style ids.
So if you are using default styles try map.addLayer(layer, 'gl-draw-polygon-fill-inactive.cold'); or for your own styles try map.addLayer(layer, 'my-first-draw-layer.cold');
@kriscarle thanks for your advice. However, the way I update my layers is by updating the 'layers' object inside the map's style object. which results in adding new layers. I guess I was finding a way to do something similar as the 'map.addLayer(layer,before)' approach as you suggested, but in the 'layers' object. Hopping to find something like 'before' and set the attribute in layers object. But I was not able to find such attribute.
I ended up doing remove and add the draw control again to make it stay on top.
Should Draw's layers always the top most layers?
My gut says that 90% of the time this is true, but maybe not 100% of the time?
We need to think more about how Draw's style and the maps style work together.
This can be managed via editing of the style by adding a layer before the draw layers.
Hi, I handled this using map.moveLayer('my-layer','gl-draw-polygon-and-line-vertex-stroke-inactive.cold'); map.moveLayer('my-layer','gl-draw-polygon-fill-inactive.cold');