如何为 geoJson 图层设置 zIndex 图层顺序? [英] How to set the zIndex layer order for geoJson layers?

查看:66
本文介绍了如何为 geoJson 图层设置 zIndex 图层顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望某些图层始终位于其他图层之上,无论它们以何种顺序添加到地图中.我知道 bringToFront(),但它不符合我的要求.我想根据属性动态设置 zIndex.

I would like to have certain layers to be always on top of others, no matter in which order they are added to the map. I am aware of bringToFront(), but it does not meet my requirements. I would like to set the zIndex dynamically based on properties.

Leaflet 有方法 setZIndex(),但这显然不适用于 geoJson 层:https://jsfiddle.net/jw2srhwn/

Leaflet has the method setZIndex(), but this apparently does not work for geoJson layers: https://jsfiddle.net/jw2srhwn/

有什么想法吗?

推荐答案

这是在 Leaflet 1.0(与 0.x 版本相比)中实现用户定义的窗格"的原因之一.

This is one of the reason for the implementation of user defined "panes" in Leaflet 1.0 (compared to versions 0.x).

  1. 创建窗格:var myPane = map.createPane("myPaneName")
  2. 如有必要,设置窗格元素的类/z-index:myPane.style.zIndex = 450(参考内置窗格的z-index值)
  3. 创建图层时,指定它们的目标pane 选项:L.rectangle(corners, { pane: "myPaneName" })
  4. 通过 L.geoJSON 工厂构建时,您可以使用 onEachFeature 选项循环遍历您的功能,以使用指定的目标 pane.
  1. Create panes: var myPane = map.createPane("myPaneName")
  2. If necessary, set the class / z-index of the pane element: myPane.style.zIndex = 450 (refer to z-index values of built-in panes)
  3. When creating your layers, specify their target pane option: L.rectangle(corners, { pane: "myPaneName" })
  4. When building through the L.geoJSON factory, you can loop through your features with the onEachFeature option to clone your layers with specified target pane.

演示:https://jsfiddle.net/3v7hd2vx/90/

这篇关于如何为 geoJson 图层设置 zIndex 图层顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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