mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

draw layer doesn't stay on top when added new layers on Mapbox gl

Open ZhenanH opened this issue 9 years ago • 5 comments

is there a way the update the z position of the draw layer?

ZhenanH avatar Feb 24 '17 00:02 ZhenanH

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 avatar Feb 27 '17 03:02 kriscarle

@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.

ZhenanH avatar Feb 27 '17 20:02 ZhenanH

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.

mcwhittemore avatar Feb 28 '17 19:02 mcwhittemore

This can be managed via editing of the style by adding a layer before the draw layers.

mcwhittemore avatar May 16 '17 15:05 mcwhittemore

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');

MinaMalak-cmd avatar Aug 30 '23 09:08 MinaMalak-cmd