Skip to content

Add FeatureGroupSubGroup plugin #875

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

Merged

Conversation

shtrom
Copy link
Contributor

@shtrom shtrom commented Jun 2, 2018

This plugin [0] allows can be used to either:

  • create nested overlays that can be turned on or off together or separately,
fg = folium.FeatureGroup()
m.add_child(fg)

g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')
m.add_child(g2)

l = folium.LayerControl().add_to(m)
  • make multiple overlays part of the same MarkerCluster,
mcg = folium.plugins.MarkerCluster(control=False)
m.add_child(mcg)

g1 = folium.plugins.FeatureGroupSubGroup(mcg, 'g1')
m.add_child(g1)
g2 = folium.plugins.FeatureGroupSubGroup(mcg, 'g2')
m.add_child(g2)

l = folium.LayerControl().add_to(m)

[0] https://github.com/ghybs/Leaflet.FeatureGroup.SubGroup

Signed-off-by: Olivier Mehani [email protected]


def __init__(self, group, name=None, overlay=True, control=True, show=True):
super(FeatureGroupSubGroup, self).__init__(name=name, overlay=overlay,
control=control, show=show)

Choose a reason for hiding this comment

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

E128 continuation line under-indented for visual indent

@shtrom
Copy link
Contributor Author

shtrom commented Jun 2, 2018

@ghybs FYI.

@shtrom shtrom force-pushed the plugin-featuregroup-subgroup branch from 409f72a to b1880ce Compare June 2, 2018 13:04
This plugin [0] allows can be used to either:
* create nested overlays that can be turned on or off together or separately,

```python
fg = folium.FeatureGroup()
m.add_child(fg)

g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')
m.add_child(g2)

folium.LayerControl().add_to(m)
```

* make multiple overlays part of the same MarkerCluster,

```python
mcg = folium.plugins.MarkerCluster(control=False)
m.add_child(mcg)

g1 = folium.plugins.FeatureGroupSubGroup(mcg, 'g1')
m.add_child(g1)
g2 = folium.plugins.FeatureGroupSubGroup(mcg, 'g2')
m.add_child(g2)

folium.LayerControl().add_to(m)
```

[0] https://github.com/ghybs/Leaflet.FeatureGroup.SubGroup

Signed-off-by: Olivier Mehani <[email protected]>
@shtrom shtrom force-pushed the plugin-featuregroup-subgroup branch from b1880ce to d5c3342 Compare June 2, 2018 13:13
@Conengmo
Copy link
Member

Conengmo commented Jun 6, 2018

This looks great, well done. This fits in well I think. Before I merge I have two requests:

  • Your docstring is already very thorough. But a lot of our users check the Jupyter Notebook examples to see how stuff works. Could you add an example to the plugins notebook?
  • Please add a line to the changelog.

Also, if you have the time, I would welcome a test. You could for example look at tests/plugins/test_marker_cluster.py for a way to do this.


import folium

from folium import plugins

Choose a reason for hiding this comment

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

F401 'folium.plugins' imported but unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


from jinja2 import Template

import numpy as np

Choose a reason for hiding this comment

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

F401 'numpy as np' imported but unused

m.add_child(fg)
g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
folium.Marker([1,1]).add_to(g1)

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
folium.Marker([1,1]).add_to(g1)
folium.Marker([-1,-1]).add_to(g1)

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

folium.Marker([1,1]).add_to(g1)
folium.Marker([-1,-1]).add_to(g1)
g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')
folium.Marker([-1,1]).add_to(g2)

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

folium.Marker([-1,-1]).add_to(g1)
g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')
folium.Marker([-1,1]).add_to(g2)
folium.Marker([1,-1]).add_to(g2)

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

folium.Marker([-1,1]).add_to(g2)
folium.Marker([1,-1]).add_to(g2)
m.add_child(g2)
l = folium.LayerControl().add_to(m)

Choose a reason for hiding this comment

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

F841 local variable 'l' is assigned to but never used

@shtrom
Copy link
Contributor Author

shtrom commented Jun 6, 2018

I added a test, quickly hacked from what I could gather from the MarkerCluster one, but couldn't work out how to exercise it. Neither running python setup.py test nor even running the script manually seems to do the right thing (I didn't get a failure with a purposefully failing assert).

@shtrom shtrom force-pushed the plugin-featuregroup-subgroup branch from ca5983b to 16bb591 Compare June 6, 2018 12:40
m.add_child(fg)
g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
folium.Marker( [1,1] ).add_to(g1)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
folium.Marker( [1,1] ).add_to(g1)
folium.Marker( [-1,-1] ).add_to(g1)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

folium.Marker( [1,1] ).add_to(g1)
folium.Marker( [-1,-1] ).add_to(g1)
g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')
folium.Marker( [-1,1] ).add_to(g2)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

folium.Marker( [-1,-1] ).add_to(g1)
g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')
folium.Marker( [-1,1] ).add_to(g2)
folium.Marker( [1,-1] ).add_to(g2)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

@shtrom shtrom force-pushed the plugin-featuregroup-subgroup branch from 16bb591 to 926c41d Compare June 6, 2018 12:42
m.add_child(fg)
g1 = plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
folium.Marker( [1,1] ).add_to(g1)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

g1 = plugins.FeatureGroupSubGroup(fg, 'g1')
m.add_child(g1)
folium.Marker( [1,1] ).add_to(g1)
folium.Marker( [-1,-1] ).add_to(g1)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

folium.Marker( [1,1] ).add_to(g1)
folium.Marker( [-1,-1] ).add_to(g1)
g2 = plugins.FeatureGroupSubGroup(fg, 'g2')
folium.Marker( [-1,1] ).add_to(g2)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

folium.Marker( [-1,-1] ).add_to(g1)
g2 = plugins.FeatureGroupSubGroup(fg, 'g2')
folium.Marker( [-1,1] ).add_to(g2)
folium.Marker( [1,-1] ).add_to(g2)

Choose a reason for hiding this comment

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

E201 whitespace after '('
E231 missing whitespace after ','
E202 whitespace before ')'

@shtrom shtrom force-pushed the plugin-featuregroup-subgroup branch from 926c41d to d9b6fe1 Compare June 6, 2018 12:43
Conengmo and others added 3 commits June 7, 2018 09:41
The code that adds markers was copied from test_marker_cluster.py. It does nothing here since the FeatureGroupSubGroup object has no children.
@Conengmo Conengmo merged commit 5bcb7b9 into python-visualization:master Jun 10, 2018
@Conengmo
Copy link
Member

Merged. Thanks @shtrom! Your test was fine and thanks also for adding the examples to the notebook.

@shtrom shtrom deleted the plugin-featuregroup-subgroup branch June 11, 2018 00:40
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.

3 participants