python-visualization / folium

Python Data. Leaflet.js Maps.

Home Page:https://python-visualization.github.io/folium/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Map parameter to set position of zoom control buttons

berrfred opened this issue · comments

I've been searching the past issues for such a feature but to my surprise I could not find anything.

All other plugins I've tried (Fullscreen, Geocoder, LocateControl, MousePosition) offer such a position parameter (topleft, topright, bottomleft, bottomright).

Why should we not be able to set it directly in folium without being forced to move a div in the html ?
Thanks

image

This is how I achieve it currently, it does work but it's not very cool ...

map_script_zoom_control = '<script>document.addEventListener("DOMContentLoaded", function() {\
	document.querySelector("div.leaflet-bottom.leaflet-right").insertBefore(\
		document.querySelector("div.leaflet-control-zoom"), document.querySelector("div.leaflet-control-attribution")\
	);\
});</script>'

map.get_root().html.add_child(folium.Element(map_script_zoom_control))

The same request could be made to position a colormap legend ... currently solved with the same approach (moved to topleft in this case).

map_script_legend_control = '<script>document.addEventListener("DOMContentLoaded", function() {\
	document.querySelector("div.leaflet-top.leaflet-left").prepend(\
		document.querySelector("div.legend.leaflet-control")\
	);\
});</script>'

fmap.get_root().html.add_child(folium.Element(map_script_legend_control))

Hi Frederic, that’s an interesting question. I agree it would be nice to be able to set the position of the zoom control. Currently, they are controlled by setting a Boolean argument on the Map class.

I’d rather not add any more arguments to the Map class. What would be another way to allow defining the position? I’m thinking now we could make the zoom_control argument not only allow a boolean, but also a string containing a position.

what do you think?

Your proposal makes sense to me, this way you keep backwards compatibility for True/False but also adds the usual four position strings that are an implicit True with additional positon information.

Good to hear, would you like to make a PR?

I'd like to do that but it is not completely clear to me (yet) how to achieve that ... currently I see the zoom control creation is delegated to L.map() so does that mean I should pass False to the map leaflet and create myself the L.control.zoom() with its position in the template part ?

Okay, looks like I got it right, PR coming ...