Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Scale control class #1873

Open
berrfred opened this issue Feb 6, 2024 · 5 comments
Open

Create Scale control class #1873

berrfred opened this issue Feb 6, 2024 · 5 comments
Labels
enhancement Feature request or idea about how to make folium better help wanted Help is welcome for this issue or PR

Comments

@berrfred
Copy link
Contributor

berrfred commented Feb 6, 2024

Is your feature request related to a problem? Please describe.
It looks like L.control.scale() now has several useful options (e.g. position. metric, imperial), wouldn't it make sense to have it as a separate plugin as initially suggested by @BibMartin ? #270

Describe the solution you'd like
I am interested in showing only the metric scale at bottomrigth ... and maybe trick the css to integrate it in the attributions but this is another story. Today without a plugin it would require some dirty css and js to achieve it.

Describe alternatives you've considered
This is where I got with my usual script approach, moving control-scale to bottomright before attribution and assuming imperial is the second child, then delete it:

map_script_scale_control = '<script>document.addEventListener("DOMContentLoaded", function() {\
	var leafletControlScale = document.querySelector("div.leaflet-control-scale");\
	document.querySelector("div.leaflet-bottom.leaflet-right").insertBefore(\
		leafletControlScale, document.querySelector("div.leaflet-control-attribution")\
	);\
	leafletControlScale.removeChild(leafletControlScale.children[1]);\
});</script>'

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

image

Additional context
Also adding the following css I've been able to display attribution and scale on the same row ... not sure if this could also become a parameter to handle in the plugin.

map_style_scale_inline = '<style>\
	.leaflet-control-scale { margin-bottom: 0 !important; }\
	.leaflet-control-attribution { clear: none !important; }\
</style>'

map.get_root().header.add_child(folium.Element(map_style_scale_inline))

image

Implementation
Definitely missing experience on making a PR but taking inspiration from existing plugins I am willing to learn and might be able to achieve it ...

@berrfred
Copy link
Contributor Author

berrfred commented Feb 6, 2024

Also not sure how to best handle backward compatibility with current control_scale map parameter that should probably be removed ...

@berrfred
Copy link
Contributor Author

@Conengmo Any interest for a control scale plugin ??? The alternative would be to extend the control_scale variable to also handle position (same as zoom_control) but we still miss the ability to set a single unit (metric or imperial), maxWidth or updateWhenIdle.

@hansthen
Copy link
Collaborator

hansthen commented Apr 7, 2024

@berrfred I think it would be a useful addition. If you are still interested in making it please checkout our contribution guidelines: https://github.com/python-visualization/folium/blob/main/.github/CONTRIBUTING.md

I would not worry about removing control_scale for now, since users can always set control_scale to False when they add the Plugin.

@Conengmo
Copy link
Member

Conengmo commented Apr 9, 2024

Thanks @hansthen for chiming in on this one! I'll share my 2 cents as well:

Since Scale is part of core Leaflet, this shouldn't be a plugin, but be part of core Folium.

I can imagine we add a new class Scale that wraps L.control.scale.

Then in Map we can handle it flexibly, with backwards compatibility. We keep the control_scale argument as True by default, and when True internally add a new Scale instance to the map. We can also extend the control_scale argument to also allow a Scale instance to be passed.

@Conengmo Conengmo added the enhancement Feature request or idea about how to make folium better label Apr 9, 2024
@hhalaby
Copy link

hhalaby commented May 23, 2024

+1 for this, adding a bottom left watermark for example hides the scale and it would be useful to move it around

@Conengmo Conengmo added the help wanted Help is welcome for this issue or PR label May 23, 2024
@Conengmo Conengmo changed the title Time to have Control Scale as a plugin ? Create Scale control class May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or idea about how to make folium better help wanted Help is welcome for this issue or PR
Projects
None yet
Development

No branches or pull requests

4 participants