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
I am trying to add a legend to the map using instructions in here. It works great, but as soon as I use full screen, the legend disappears.
I understand it is probably the legend code which should be modified but since it relays deeply on how full screen works, I would appreciate any help. Also, this is most likely the issue with any other method which adds elements to the map via html. It would be very nice to have a way around it.
Here is a simple code snippet to reproduce the problem in jupyter lab:
That's because your custom div is not under Leaflets control, so it the Fullscreen plugin doesn't know about its existence. This can be solved by putting the legend on the map as a Leaflet Control object. Here's a folium class you can use for this:
class CustomControl(MacroElement):
"""
Based on https://leafletjs.com/examples/extending/extending-3-controls.html
"""
_template = Template("""
{% macro script(this, kwargs) %}
L.Control.CustomControl = L.Control.extend({
onAdd: function(map) {
let div = L.DomUtil.create('div');
div.innerHTML = `{{ this.html }}`;
return div;
},
onRemove: function(map) {
// Nothing to do here
}
});
L.control.customControl = function(opts) {
return new L.Control.CustomControl(opts);
}
L.control.customControl(
{ position: "{{ this.position }}" }
).addTo({{ this._parent.get_name() }});
{% endmacro %}
""")
def __init__(self, html, position='bottomleft'):
super().__init__()
self.html = escape_backticks(html)
self.position = position
I am trying to add a legend to the map using instructions in here. It works great, but as soon as I use full screen, the legend disappears.
I understand it is probably the legend code which should be modified but since it relays deeply on how full screen works, I would appreciate any help. Also, this is most likely the issue with any other method which adds elements to the map via html. It would be very nice to have a way around it.
Here is a simple code snippet to reproduce the problem in jupyter lab:
Another method to add legend via branca elements is available here which results in the same issue.
folium version: 0.11.0
The text was updated successfully, but these errors were encountered: