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
Popups get hidden below overlay layers by LayerControl #826
If you add popups to a map along with an overlay layer, controlled with the LayerControl, the popups will get buried when the overlay layer is turned off and back on again. They are still there, but are now behind the overlay and therefore don't respond as long as the overlay layers is visible.
(u""" var {{this.get_name()}} = L.popup({maxWidth: '{{this.max_width}}'}); {% for name, element in this.html._children.items() %} var {{name}} = $('{{element.render(**kwargs).replace('\\n',' ')}}')[0]; {{this.get_name()}}.setContent({{name}}); {% endfor %} {{this._parent.get_name()}}.bindPopup({{this.get_name()}}); {{this._parent._parent.get_name()}}.on('overlayadd', function(){ {{this._parent.get_name()}}.bringToFront(); }); {% for name, element in this.script._children.items() %} {{element.render()}} {% endfor %} """)
That snippet indeed reproduced the problem. So we got two overlays, a geojson and a polygon, and when the geojson layer is untoggled and toggled again, it moves in front of the polygon. And what you want is the polygon to stay in front. It's not really about the popups, but about the polygon.
I don't think your solution is the right fix. Firstly it only works if the polygon is directly added to the map, and not to another layer (but that can be fixed). More importantly, whenever an overlay is toggled, layers with popups get put on front. I suppose that shouldn't be the default behavior, because then other users who want another ordering get in trouble.
An easy solution is to add the polygon to a FeatureGroup, so you can also toggle it in LayerControl. This would require you toggling the group to put it in front again after it got to the back. We don't have to change anything to folium for this. Like this:
You do have a point that the overlayadd event and bringToFront method can be useful. What about adding an option to folium to define which layers should always stay in front? To try this out I added it to the Map class in my own branch: https://github.com/Conengmo/folium/tree/keep-in-front. You can try it out with this code snippet:
At load the red marker is in front, because it got added to the map last. When one of the two overlays is untoggled, nothing changes. But when the untoggled overlay is toggled again, the blue marker gets in front and stays there.
If you do m.keep_in_front(marker), the red marker starts and stays in front.
@Conengmo I defer to your judgement completely on this. Your logic sounds right -- my code fixed my particular use case but isn't general purpose enough. Just wanted to raise this issue as a potential limitation of the current capabilities.
Activity
Conengmo commentedon Mar 26, 2018
I'm unable to reproduce your problem. Could you provide a code snippit that produces it? Also, which version are you on, 0.5.0 or the Github master?
I tried this, but the popup stays above the overlay:
mjgleason commentedon Mar 27, 2018
@Conengmo I'm on 0.5.0. Here's a snippet that should reproduce the problem:
Conengmo commentedon Mar 27, 2018
That snippet indeed reproduced the problem. So we got two overlays, a geojson and a polygon, and when the geojson layer is untoggled and toggled again, it moves in front of the polygon. And what you want is the polygon to stay in front. It's not really about the popups, but about the polygon.
I don't think your solution is the right fix. Firstly it only works if the polygon is directly added to the map, and not to another layer (but that can be fixed). More importantly, whenever an overlay is toggled, layers with popups get put on front. I suppose that shouldn't be the default behavior, because then other users who want another ordering get in trouble.
An easy solution is to add the polygon to a FeatureGroup, so you can also toggle it in LayerControl. This would require you toggling the group to put it in front again after it got to the back. We don't have to change anything to folium for this. Like this:
You do have a point that the
overlayaddevent andbringToFrontmethod can be useful. What about adding an option to folium to define which layers should always stay in front? To try this out I added it to the Map class in my own branch: https://github.com/Conengmo/folium/tree/keep-in-front. You can try it out with this code snippet:At load the red marker is in front, because it got added to the map last. When one of the two overlays is untoggled, nothing changes. But when the untoggled overlay is toggled again, the blue marker gets in front and stays there.
If you do
m.keep_in_front(marker), the red marker starts and stays in front.mjgleason commentedon Mar 28, 2018
@Conengmo I defer to your judgement completely on this. Your logic sounds right -- my code fixed my particular use case but isn't general purpose enough. Just wanted to raise this issue as a potential limitation of the current capabilities.
ocefpaf commentedon May 7, 2018
Close in #840