Leaflet.js 中的层排序 [英] Layer Ordering in leaflet.js
问题描述
如何强制在 Leaflet 中添加到地图的新图层成为底图上的第一个图层?
How can I force a new layer added to the map in Leaflet to be the first over the basemap?
我找不到一种可以轻松更改图层顺序的方法,这是一个非常基本的 GIS 功能.我错过了什么吗?
I could not find a method to easily change the order of the layers, which is a very basic GIS feature. Am I missing something?
推荐答案
Leaflet 地图由一组窗格"组成,其视图顺序使用 z-index 控制.每个窗格包含一个图层集合默认窗格显示顺序是瓷砖->阴影->叠加->标记->弹出窗口.就像 Etienne 描述的那样,您可以通过调用 bringToFront()
或 bringToBack()
来控制覆盖窗格中路径的显示顺序.L.FeatureGroup
也有这些方法,因此您可以根据需要一次更改叠加组的顺序.
A Leaflet map consists of a collection of "Panes" whose view order is controlled using z-index. Each pane contains a collection of Layers The default pane display order is tiles->shadows->overlays->markers->popups. Like Etienne described, you can control the display order of Paths within the overlays pane by calling bringToFront()
or bringToBack()
. L.FeatureGroup
also has these methods so you can change the order of groups of overlays at once if you need to.
如果要更改整个窗格的显示顺序,只需使用 CSS 更改窗格的 z-index.
If you want to change the display order of a whole pane then you just change the z-index of the pane using CSS.
如果你想添加一个新的地图窗格......我还不确定如何做.
If you want to add a new Map pane...well I'm not sure how to do that yet.
http://leafletjs.com/reference.html#map-panes
http://leafletjs.com/reference.html#featuregroup
这篇关于Leaflet.js 中的层排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!