传单:如何在多边形后面显示标记? [英] Leaflet: How to display markers behind polygons?

查看:79
本文介绍了传单:如何在多边形后面显示标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的地图上需要图标(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)

  1. objectsPane
  1. objectsPane
  1. popupPane
  2. markerPane< =所有标记图标(L.CircleMarker除外)
  3. shadowPane< =所有标记图标阴影
  4. overlayPane< =所有矢量(包括L.CircleMarker)
  1. popupPane
  2. markerPane <= all markers icon (other than L.CircleMarker)
  3. shadowPane <= all markers icon shadow
  4. overlayPane <= all vectors (including L.CircleMarker)

  • tilePane
  • 因此仅使用标记的图标阴影是不够的.您必须在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):

    1. popupPane
    2. markerPane< =所有标记图标(L.CircleMarker除外)
    3. overlayPane< =所有矢量(包括L.CircleMarker)
    4. shadowPane< =所有标记图标阴影
    5. tilePane
    1. popupPane
    2. markerPane <= all markers icon (other than L.CircleMarker)
    3. overlayPane <= all vectors (including L.CircleMarker)
    4. shadowPane <= all markers icon shadow
    5. 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).

    这篇关于传单:如何在多边形后面显示标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆