Skip to content

Create Scale control class #1873

Closed

Description

@berrfred

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 ...

Activity

  1. berrfred commented on Feb 6, 2024

    @berrfred
    ContributorAuthor

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

  2. berrfred commented on Feb 25, 2024

    @berrfred
    ContributorAuthor

    @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.

  3. hansthen commented on Apr 7, 2024

    @hansthen
    Collaborator

    @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.

  4. Conengmo commented on Apr 9, 2024

    @Conengmo
    Member

    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.

  5. added
    enhancement
    on Apr 9, 2024
  6. hhalaby commented on May 23, 2024

    @hhalaby

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

  7. added
    help wanted
    on May 23, 2024
  8. changed the title [-]Time to have Control Scale as a plugin ?[/-] [+]Create Scale control class[/+] on May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions