Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet layers Z-index

Tags:

leaflet

I need to set z-index (control what is in foreground) between leaflet layers.

It is possible to e.g. control between 2 (or more) geoJson layers or between 2 (or more) ImageOverlay layers, with bringToFront, bringToBack functions.

L.geoJson layer is always over L.imageOverlay layer and I need to set imageOverlay to be over GeojJson.

Is this possible in Leaflet?

like image 998
Amir Avatar asked Feb 08 '26 03:02

Amir


1 Answers

Yes, but not using bringToFront and bringToBack. You need to use custom panes in the 1.0.0 version. See this post on GIS.SE and this tutorial on the Leaflet site. To summarize, you need to create a new pane for your image overlay, set its z-index, and then set the pane option when you create the layer. The following will add an image overlay above your GeoJSON layers:

map.createPane('imagePane');
map.getPane('imagePane').style.zIndex = 401;
var imageLayer = L.imageOverlay(imageUrl, imageBounds, {
  pane: 'imagePane'
}).addTo(map);

Of course, you can also place GeoJSON layers in their own pane(s) and manipulate their z-indexing as well.

like image 196
nathansnider Avatar answered Feb 12 '26 05:02

nathansnider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!