Leaflet layers Z-index

守給你的承諾、 提交于 2020-01-21 23:44:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/36594994/leaflet-layers-z-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!