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

Dual map plugin #933

Merged
merged 21 commits into from
Jan 3, 2019
Merged

Dual map plugin #933

merged 21 commits into from
Jan 3, 2019

Conversation

Conengmo
Copy link
Member

@Conengmo Conengmo commented Aug 12, 2018

I made a plugin using the Leaflet.Sync plugin: https://github.com/jieter/Leaflet.Sync

You can create two maps in the same screen, where position and zoom level are synchronized. This is handy when you want to compare two datasets that don't display well when put on the same map.

I tried to make this as close to the regular Map class as possible.

  • You can use the same arguments on initialization as Map (except the positioning arguments).
  • If you add objects to DualMap, they are added to both the submaps. Data is duplicated.
  • The order in which items are added is maintained in both maps.
  • The individual maps are accessible by the attributes DualMap.m1 and DualMap.m2.
  • Adding LayerControl before saving/rendering works.

Here's a minimal working example:

m = folium.plugins.DualMap(location=(0, 0), tiles='cartodbpositron',  zoom_start=5)
fg_both = folium.FeatureGroup(name='markers_both').add_to(m)
fg_1 = folium.FeatureGroup(name='markers_1').add_to(m.m1)
fg_2 = folium.FeatureGroup(name='markers_2').add_to(m.m2)
folium.Marker((0, 0), popup='both').add_to(fg_both)
folium.Marker((0, 1), popup='1').add_to(fg_1)
folium.Marker((1, 0), popup='2').add_to(fg_2)
folium.LayerControl(collapsed=False).add_to(m)
m.save('_map.html')

I would like to get some feedback on this before adding tests and an example in the notebooks.

@Conengmo Conengmo requested a review from ocefpaf August 12, 2018 11:55
@Conengmo Conengmo added the waiting for review PR is waiting to be reviewed label Oct 15, 2018
Copy link
Member

@ocefpaf ocefpaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I did not test the code snippet but the plugin code is great. Thanks @Conengmo!

folium/plugins/dual_map.py Outdated Show resolved Hide resolved
@ocefpaf
Copy link
Member

ocefpaf commented Nov 7, 2018

@Conengmo the saved HTML worked just fine but it is not rendering on the notebook (both Firefox and Chrome/Chromium). Rendering on the notebook is nice to have but not a blocker to merge this.That

@Conengmo
Copy link
Member Author

Conengmo commented Nov 7, 2018

Thanks for reviewing this @ocefpaf, nice that you approve. I'll fix the rawgit thing and look into making tests and an example notebook. But then I'll get it to work in a notebook first :)

@Conengmo Conengmo added waiting for changes This PR has been reviewed and changes are needed before merging and removed waiting for review PR is waiting to be reviewed labels Nov 7, 2018
@ocefpaf
Copy link
Member

ocefpaf commented Nov 7, 2018

Thanks for reviewing this @ocefpaf, nice that you approve. I'll fix the rawgit thing and look into making tests and an example notebook. But then I'll get it to work in a notebook first :)

No rush. Just ping me again when you are done.

@Conengmo
Copy link
Member Author

I think it's done. Here is an example notebook (and the entry in the Plugins notebook):
https://nbviewer.jupyter.org/github/conengmo/folium/blob/sync/examples/plugin-DualMap.ipynb
https://nbviewer.jupyter.org/github/conengmo/folium/blob/sync/examples/Plugins.ipynb#DualMap

@ocefpaf do you want to review?

@Conengmo Conengmo added waiting for review PR is waiting to be reviewed and removed waiting for changes This PR has been reviewed and changes are needed before merging labels Dec 31, 2018
@ocefpaf ocefpaf merged commit 588670c into python-visualization:master Jan 3, 2019
@Conengmo Conengmo deleted the sync branch January 12, 2019 10:35
@Conengmo Conengmo removed the waiting for review PR is waiting to be reviewed label Jan 12, 2019
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.

2 participants