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

Add layers in Layer #1690

Merged
merged 13 commits into from
Jan 11, 2023
Merged

Add layers in Layer #1690

merged 13 commits into from
Jan 11, 2023

Conversation

Conengmo
Copy link
Member

@Conengmo Conengmo commented Jan 4, 2023

Our current approach to adding layers to the map and how that works with LayerControl is:

  • each Layer subclass adds itself to its parent
  • then when rendering LayerControl we remove the layers that have show=False.

This has two issues, one big and one minor:

Address this by letting subclasses of Layer only add themselves to their parent if show=True.

We can remove the code from each of the subclasses and render it in Layer instead.

If you're asking, whoever did this in the first place? It was me, my first PR on this project :) #772. Then slight changes were made in LayerControl in #1101.

Downsides

Order of multiple base layers

The downside is that this changes behavior when you add multiple base layers. Currently only the first one is enabled. With this change the last one added will be enabled.

I'm conflicted whether this is something we should want to avoid. It does fit more closely to how Leaflet works. If you want to add multiple TileLayers, you will have to use the show parameter to define which one you want to see. For example:

m = Map(tiles='cartodbpositron')
TileLayer('stamen toner', show=False).add_to(m)

Downstream packages

Packages that use folium might suffer from this change, which I would call an internal breaking change. End-users shouldn't notice it, but others that develop using folium may. For example tests that test the correctness of renders will have to update.

folium convention

It may confuse folium developers that Layer subclasses don't add themselves to their parent, while other classes do.

Change parent class of two plugins

  • SideBySideLayers currently inherits from Layer, but is not actually a layer-type class. Inherit from MacroElement instead.
  • Same for TimestampedWmsTileLayers`, it's not a layer itself.

I'll probably split these two changes of into separate PRs.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@Conengmo Conengmo changed the title Add layers in Layer [draft] Add layers in Layer Jan 7, 2023
@Conengmo Conengmo marked this pull request as ready for review January 7, 2023 17:20
@ocefpaf
Copy link
Member

ocefpaf commented Jan 9, 2023

I'm OK with this change. It made sense in the past but getting closer to leaflet and snappier maps are worth the breaking changes. We should probably aim to a 1.0 release anyway. So, if you have more breaking changes, now is the time ;-p

@Conengmo
Copy link
Member Author

Thank you for the review.

We should probably aim to a 1.0 release anyway.

Agreed. I'd like to include the improved documentation, other than that I don't have big ideas for 1.0.

If you have more breaking changes, now is the time

That's a good point. I'll think on it.

I did consider doing a refactor of our modules, especially map.py and features.py. But in the end I don't think it's worth the hassle.

@Conengmo
Copy link
Member Author

Conengmo commented Jan 10, 2023

@randyzwitch @giswqs since I know you both have projects that use folium, I wanted to give you a heads-up about this upcoming (breaking) change.

  • If you have tests that use the 'raw' templates of Layer subclasses, you may need to make changes to those.
  • It's not inconceivable this change introduces a bug in functionality, please let us know if that's the case.
  • We will require the user to explicitly define what base maps they want to show. If you have code that adds base maps, you may need to add the show parameter.

Please let me know if you have questions or comments.

@giswqs
Copy link
Contributor

giswqs commented Jan 10, 2023

Thanks for the heads up. I will keep an eye on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants