Skip to content

Commit 3cc571b

Browse files
authored
Merge pull request #447 from BibMartin/feature/circle_circle_marker
Separate Circle from CircleMarker
2 parents 3d54633 + 2c896cf commit 3cc571b

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

folium/features.py

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,51 @@ def __init__(self, html=None, icon_size=None, icon_anchor=None,
634634
""") # noqa
635635

636636

637+
class Circle(Marker):
638+
"""Creates a Circle object for plotting on a Map.
639+
640+
Parameters
641+
----------
642+
location: tuple or list, default None
643+
Latitude and Longitude of Marker (Northing, Easting)
644+
radius: int
645+
The radius of the circle in meters. For setting the radius in pixel,
646+
use CircleMarker.
647+
color: str, default 'black'
648+
The color of the marker's edge in a HTML-compatible format.
649+
fill_color: str, default 'black'
650+
The fill color of the marker in a HTML-compatible format.
651+
fill_opacity: float, default 0.6
652+
The fill opacity of the marker, between 0. and 1.
653+
popup: string or folium.Popup, default None
654+
Input text or visualization for object.
655+
"""
656+
def __init__(self, location, radius=500, color='black',
657+
fill_color='black', fill_opacity=0.6, popup=None):
658+
super(Circle, self).__init__(location, popup=popup)
659+
self._name = 'Circle'
660+
self.radius = radius
661+
self.color = color
662+
self.fill_color = fill_color
663+
self.fill_opacity = fill_opacity
664+
665+
self._template = Template(u"""
666+
{% macro script(this, kwargs) %}
667+
668+
var {{this.get_name()}} = L.circle(
669+
[{{this.location[0]}},{{this.location[1]}}],
670+
{{ this.radius }},
671+
{
672+
color: '{{ this.color }}',
673+
fillColor: '{{ this.fill_color }}',
674+
fillOpacity: {{ this.fill_opacity }}
675+
}
676+
)
677+
.addTo({{this._parent.get_name()}});
678+
{% endmacro %}
679+
""")
680+
681+
637682
class CircleMarker(Marker):
638683
"""Creates a CircleMarker object for plotting on a Map.
639684
@@ -642,12 +687,13 @@ class CircleMarker(Marker):
642687
location: tuple or list, default None
643688
Latitude and Longitude of Marker (Northing, Easting)
644689
radius: int
645-
The radius of the circle in pixels.
690+
The radius of the circle in pixels. For setting the radius in meter,
691+
use Circle.
646692
color: str, default 'black'
647693
The color of the marker's edge in a HTML-compatible format.
648694
fill_color: str, default 'black'
649695
The fill color of the marker in a HTML-compatible format.
650-
fill_opacity: float, default à.6
696+
fill_opacity: float, default 0.6
651697
The fill opacity of the marker, between 0. and 1.
652698
popup: string or folium.Popup, default None
653699
Input text or visualization for object.
@@ -664,15 +710,15 @@ def __init__(self, location, radius=500, color='black',
664710
self._template = Template(u"""
665711
{% macro script(this, kwargs) %}
666712
667-
var {{this.get_name()}} = L.circle(
713+
var {{this.get_name()}} = L.circleMarker(
668714
[{{this.location[0]}},{{this.location[1]}}],
669-
{{ this.radius }},
670715
{
671716
color: '{{ this.color }}',
672717
fillColor: '{{ this.fill_color }}',
673718
fillOpacity: {{ this.fill_opacity }}
674719
}
675720
)
721+
.setRadius({{ this.radius }})
676722
.addTo({{this._parent.get_name()}});
677723
{% endmacro %}
678724
""")

folium/templates/circle_marker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var {{ circle }} = L.circle([{{ lat }}, {{ lon }}], {{ radius }}, {
1+
var {{ circle }} = L.circleMarker([{{ lat }}, {{ lon }}], {
22
color: '{{ line_color }}',
33
fillColor: '{{ fill_color }}',
44
fillOpacity: {{ fill_opacity }}
5-
});
5+
}).setRadius({{ radius }})

tests/test_folium.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ def test_circle_marker(self):
212212
circ_templ = self.env.get_template('circle_marker.js')
213213

214214
# Single Circle marker.
215-
self.map.circle_marker(location=[45.60, -122.8], popup='Hi')
216-
marker = list(self.map._children.values())[-1]
215+
marker = folium.features.CircleMarker([45.60, -122.8], popup='Hi')
216+
self.map.add_child(marker)
217217
circle_1 = circ_templ.render({'circle': marker.get_name(),
218218
'lat': 45.60,
219219
'lon': -122.8, 'radius': 500,
@@ -224,8 +224,8 @@ def test_circle_marker(self):
224224
''.join(self.map.get_root().render().split()))
225225

226226
# Second circle marker.
227-
self.map.circle_marker(location=[45.70, -122.9], popup='Hi')
228-
marker = list(self.map._children.values())[-1]
227+
marker = folium.features.CircleMarker([45.70, -122.9], popup='Hi')
228+
self.map.add_child(marker)
229229
circle_2 = circ_templ.render({'circle': marker.get_name(),
230230
'lat': 45.70,
231231
'lon': -122.9, 'radius': 500,

0 commit comments

Comments
 (0)