You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
maintain the layer order (z level) when using the check boxes in layer control dropdown #767
Thank you for this amazing tool. Being able to create these types of visualizations in python is a game changer for me at work. Quick question:
I am able to create layers of polygons on the map using the GeoJson method. However, when I toggle the checkbox from "unchecked" to "checked" in the dropdown menu, the recently "checked" layer is placed on top of all other layers. So if there is a layer with popup properties (e.g., a set of markers), they can become covered up by the topmost polygon, and are then unclickable.
Is there a way to maintain the layer ordering so that the layers are always placed in the order that they were added to the map during creation? I'm sure this is possible, but I haven't been able to figure it out. Any tip would be appreciated.
Here is a simple example and screenshot. This issue is that I cannot seem to get the geoJson layer to stay on the bottom so that the markers/heat stays on top:
I think it has to do with Leaflet, not Folium. I tested combining a heatmap with a geojson polygon layer. The order in which you add them to the map does not matter. autoZIndex also does not seem to do anything. I wonder in what cases that option does work.
If you look in the html, both are in the overlay pane. The heatmap is a canvas and gets a z-index of 100, while the geojson layer is a svg and gets a z-index of 200. This seems fixed in the leaflet css file. So to fix this you would need to look at leaflet, or maybe the leaflet.heat plugin that Folium uses for the heatmaps.
A quick dirty fix is to append the following to your html file: <style>.leaflet-heatmap-layer{z-index:300 !important}</style> Any z-index higher than 200 does the trick. You can add it to a custom template as described in #86.
@Conengmo you are correct. I'll keep this open in case we can come up with an easier zorder for all objects in folium, without relying on leaflet. Not sure what would take to implement that in a sane way though 😄
We have a keep_in_front method in Map that can be used to define which object should stay in front and in what order. See #840. I think that solves this issue. Feel free to add other info, we can reopen if needed.
No, you've did it as intended. But I guess it doesn't work with heatmap. As described earlier in this thread the heatmap layer is on a different z-index, so apperently keep_in_front doesn't help there. When I made that function I made it with regular vector and raster layers.
Activity
Alcampopiano commentedon Nov 13, 2017
Here is a simple example and screenshot. This issue is that I cannot seem to get the geoJson layer to stay on the bottom so that the markers/heat stays on top:
Alcampopiano commentedon Nov 27, 2017
Hi guys,
Any hints about keeping the heat map above the choropleth?
Conengmo commentedon Nov 28, 2017
I think it has to do with Leaflet, not Folium. I tested combining a heatmap with a geojson polygon layer. The order in which you add them to the map does not matter.
autoZIndexalso does not seem to do anything. I wonder in what cases that option does work.If you look in the html, both are in the overlay pane. The heatmap is a canvas and gets a z-index of 100, while the geojson layer is a svg and gets a z-index of 200. This seems fixed in the leaflet css file. So to fix this you would need to look at leaflet, or maybe the leaflet.heat plugin that Folium uses for the heatmaps.
A quick dirty fix is to append the following to your html file:
<style>.leaflet-heatmap-layer{z-index:300 !important}</style>Any z-index higher than 200 does the trick. You can add it to a custom template as described in #86.ocefpaf commentedon Nov 28, 2017
@Conengmo you are correct. I'll keep this open in case we can come up with an easier zorder for all objects in
folium, without relying onleaflet. Not sure what would take to implement that in a sane way though 😄Alcampopiano commentedon Nov 28, 2017
Fantastic guys. Thanks very much for the info.
Conengmo commentedon Oct 12, 2018
We have a
keep_in_frontmethod inMapthat can be used to define which object should stay in front and in what order. See #840. I think that solves this issue. Feel free to add other info, we can reopen if needed.bfmcneill commentedon Nov 29, 2018
keep_in_front is not working for me
Am I implementing it wrong?
with CSS hack
without CSS hack
Conengmo commentedon Nov 30, 2018
No, you've did it as intended. But I guess it doesn't work with heatmap. As described earlier in this thread the heatmap layer is on a different z-index, so apperently
keep_in_frontdoesn't help there. When I made that function I made it with regular vector and raster layers.JavierParada commentedon Dec 5, 2020
How can we solve this same issue with HeatMapWithTime instead of HeatMap?