Leaflet layers Z-index

后端 未结 1 1815
时光说笑
时光说笑 2021-01-14 08:40

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

相关标签:
1条回答
  • 2021-01-14 08:51

    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.

    0 讨论(0)
提交回复
热议问题