I have a map with different polygons on it which intersect at a lot of points and which can be on top of each other randomly due to some calculation and drawing processes. But there is one group of polygons which should be always on top, because they have popups attached to it.
Unfortunately anything like
leafletProxy("map") %>% showGroup("Layer1") %>% showGroup("Layer2")
or
leafletProxy("map") %>% hideGroup("Layer1") %>% hideGroup("Layer2") %>%
showGroup("Layer1") %>% showGroup("Layer2")
does not change the order of the polygons.
Is there anything like bringToFront
possible with leaflet
package and shiny
?
Realizing this is now four years old, but I just came across this same problem and it can be solved with addMapPane. In the example above
leafletProxy("map") %>% addMapPane("layer1", zIndex=420) %>% addMapPane("layer2",zIndex=410)
That will keep layer1 above layer2 everywhere they intersect. Then it is just a question of assigning the layers to your polygons or whatever they are. For example:
leafletProxy("map") %>% addPolygons(data=layer1_data,options = pathOptions(pane = "layer1")) %>% addPolygons(data=layer2_data, options= options = pathOptions(pane = "layer2"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With