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

Possible to change bounds of map based on what is selected by LayerControl #1313

Closed
galewis2 opened this issue Apr 27, 2020 · 4 comments · Fixed by #1693
Closed

Possible to change bounds of map based on what is selected by LayerControl #1313

galewis2 opened this issue Apr 27, 2020 · 4 comments · Fixed by #1693
Labels
enhancement Feature request or idea about how to make folium better work in progress Work is in progress on a PR, check the PR to see its status

Comments

@galewis2
Copy link

In short, is it possible to have Folium generate a map whereby the map is zoomed and/or bounding box changed when the user changes the layer?

I'm currently using FeatureGroups added to the map, overlay off (so one layer can be viewed at a time). I would like to automatically have the map zoom to the featuregroup extent when selected.

Thanks!

@Conengmo Conengmo added the enhancement Feature request or idea about how to make folium better label Apr 29, 2020
@Conengmo
Copy link
Member

Hi @galewis2 , I don't think this is currently implemented in folium. It sounds like a nice feature. If someone wants to whip up a PR for this I'd gladly review it.

Some thoughts:

  • For starters we could apply this to the FeatureGroup class.
  • I suppose this doesn't apply to tile layers because they cover the whole map.
  • Does this apply to other classes as well? I'd rather not make it too complicated.
  • The Leaflet FeatureGroup class has a get_bounds method we could use.
  • The map has a method to fit to bounds. Haven't tried this approach though.

@galewis2
Copy link
Author

Duly noted, I had a look at the code and it's not too bad. I have some experience with Jinja2 and way back used Leaflet quite a bit.

As a first attempt, I'm considering doing this as a boolean on LayerControl and drop in a map.on action when BaseLayer change as a first step. Unfortunately that only covers overlays, may need a bit more work to cover featuregroups.

That way if a FeatureGroup is specifically excluded from LayerControl, it won't have those properties as they're irrelevant to zoom to function

@galewis2
Copy link
Author

@Conengmo I assume this would be best placed in a plugin as it's not core Leaflet functionality?

@Conengmo Conengmo added the work in progress Work is in progress on a PR, check the PR to see its status label Apr 30, 2020
@Conengmo
Copy link
Member

You don't have to move it to a plugin, because it uses only Leaflet native stuff. Plugins are for things that use other external resources, such as Leaflet plugins.

Let's take the rest of the discussion to the PR.

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 work in progress Work is in progress on a PR, check the PR to see its status
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants