Skip to content

Create and test FeatureGroup #242

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
merged 1 commit into from
Nov 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,34 @@ def __init__(self, tiles='OpenStreetMap', name=None,
{% endmacro %}
""")

class FeatureGroup(TileLayer):
def __init__(self, name=None, overlay=True):
"""Create a FeatureGroup layer ; you can put things in it and handle them as a
Copy link
Member

Choose a reason for hiding this comment

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

I guess my comment did not make it in the first try! I have a flaky connection today 😒

Please change overlay = True to overlay=True

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 and rebased

single layer. For example, you can add a LayerControl to tick/untick the whole group.

Parameters
----------
name : str, default None
The name of the featureGroup layer. It will be displayed in the LayerControl.
If None, get_name() will be called to get the object's technical (ugly) name.
overlay : bool, default True
Whether your layer will be an overlay (ticked with a checkbox in LayerControls)
or a base layer (ticked with a radio button).
"""
super(TileLayer, self).__init__()
self._name = 'FeatureGroup'

self.tile_name = name if name is not None else self.get_name()

self.overlay = overlay

self._template = Template(u"""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = L.featureGroup(
).addTo({{this._parent.get_name()}});
{% endmacro %}
""")

class LayerControl(MacroElement):
"""Adds a layer control to the map."""
def __init__(self):
Expand Down
14 changes: 13 additions & 1 deletion tests/test_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from folium.six import PY3
from folium.plugins import ScrollZoomToggler, MarkerCluster
from folium.element import Html
from folium.map import Popup, Marker, Icon, FitBounds
from folium.map import Popup, Marker, Icon, FitBounds, FeatureGroup
from folium.features import (DivIcon, CircleMarker, LatLngPopup, GeoJson,
GeoJsonStyle, ColorScale, TopoJson, PolyLine,
MultiPolyLine, ImageOverlay)
Expand Down Expand Up @@ -157,6 +157,18 @@ def test_wms_layer(self):
assert (''.join(wms.split())[:-1] in
''.join(map.get_root().render().split()))

def test_feature_group(self):
"""Test FeatureGroup."""

map = folium.Map()
feature_group = FeatureGroup()
feature_group.add_children(Marker([45,-30],popup=Popup('-30')))
feature_group.add_children(Marker([45, 30],popup=Popup('30')))
map.add_children(feature_group)
map.add_children(folium.map.LayerControl())

map._repr_html_()

def test_simple_marker(self):
"""Test simple marker addition."""

Expand Down