问题描述
我的地图上需要图标(PNG)和多边形.因此,我将图标创建为标记,将多边形创建为多边形.不幸的是,无论创建顺序如何,都将在下方"标记中显示多边形.反之亦然.有办法,怎么做?
I need icons (PNG) and polygons on my map. So I create icons as markers and polygons as polygons. Unfortunately regardless of creation order polygons are displayed "below" markers. I need is vice-versa. Is there a way, how to do it?
推荐答案
在Leaflet 0.x中更正默认窗格的顺序:(从最顶部到最底部)
Correct default panes order in Leaflet 0.x: (from top-most to bottom-most)
- objectsPane
- objectsPane
- popupPane
- markerPane< =所有标记图标(
L.CircleMarker
除外) - shadowPane< =所有标记图标阴影
- overlayPane< =所有矢量(包括
L.CircleMarker
)
- popupPane
- markerPane <= all markers icon (other than
L.CircleMarker
) - shadowPane <= all markers icon shadow
- overlayPane <= all vectors (including
L.CircleMarker
)
因此仅使用标记的图标阴影是不够的.您必须在CSS中(或通过JS)手动更改这些窗格的z-index
.
So just using the marker's icon shadow is not enough. You have to manually change the z-index
of those panes in CSS (or through JS).
另请参见传单:标记上方的折线.
原始答案:
矢量(如多边形)和标记的堆叠顺序在Leaflet 0.x中是固定的.它们被插入到"窗格"中,顺序为(从最顶部到底部,大多数):
The stack order of vectors (like your polygons) and Markers is fixed in Leaflet 0.x. They are inserted into "panes" which order is (from top-most to bottom-most):
- popupPane
- markerPane< =所有标记图标(
L.CircleMarker
除外) - overlayPane< =所有矢量(包括
L.CircleMarker
) - shadowPane< =所有标记图标阴影
- tilePane
- popupPane
- markerPane <= all markers icon (other than
L.CircleMarker
) - overlayPane <= all vectors (including
L.CircleMarker
) - shadowPane <= all markers icon shadow
- tilePane
因此,您应该可以使用标记的图标阴影 .如果您仍然希望用户能够单击您的标记,只需对普通图标使用透明图像,其大小与阴影图像相同.
So you should be able to easily workaround this fixed order by using the Marker's Icon shadow. If you still want the user to be able to click on your marker, simply use a transparent image for the normal icon, with the same size as your shadow image.
Leaflet 1.0中的情况有所不同.您可以创建自己的窗格(map.createPane
),通过指定其zIndex
设置其顺序(可能通过CSS),并通过使用其pane
(对于标记为shadowPane
)来指定矢量和标记的位置(s).
The situation is different in Leaflet 1.0. You can create your own panes (map.createPane
), set their order by specifying their zIndex
(possibly through CSS), and specify where your vectors and markers go by using their pane
(and shadowPane
for markers) option(s).
这篇关于传单:如何在多边形后面显示标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!