How to set the zIndex layer order for geoJson layers?

前端 未结 3 1573
[愿得一人]
[愿得一人] 2021-01-02 02:23

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 doe

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 02:43

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

    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.

    Demo: https://jsfiddle.net/3v7hd2vx/90/

提交回复
热议问题