Skip to content

Commit 50ac6c9

Browse files
author
Martin Journois
committed
RegularPolygonMarker and CircleMarker are instances of Marker
1 parent 1366528 commit 50ac6c9

3 files changed

Lines changed: 21 additions & 20 deletions

File tree

folium/features.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
_locations_mirror, _locations_tolist, image_to_url)
1313

1414
from .element import Element, Figure, JavascriptLink, CssLink, MacroElement
15-
from .map import TileLayer, Icon
15+
from .map import TileLayer, Icon, Marker
1616

1717

1818
class WmsTileLayer(TileLayer):
@@ -48,7 +48,7 @@ def __init__(self, url, name=None,
4848
""") # noqa
4949

5050

51-
class RegularPolygonMarker(MacroElement):
51+
class RegularPolygonMarker(Marker):
5252
def __init__(self, location, color='black', opacity=1, weight=2,
5353
fill_color='blue', fill_opacity=1,
5454
number_of_sides=4, rotation=0, radius=15, popup=None):
@@ -85,9 +85,8 @@ def __init__(self, location, color='black', opacity=1, weight=2,
8585
8686
For more information, see https://humangeo.github.io/leaflet-dvf/
8787
"""
88-
super(RegularPolygonMarker, self).__init__()
88+
super(RegularPolygonMarker, self).__init__(location, popup=popup)
8989
self._name = 'RegularPolygonMarker'
90-
self.location = location
9190
self.color = color
9291
self.opacity = opacity
9392
self.weight = weight
@@ -96,8 +95,6 @@ def __init__(self, location, color='black', opacity=1, weight=2,
9695
self.number_of_sides = number_of_sides
9796
self.rotation = rotation
9897
self.radius = radius
99-
if popup is not None:
100-
self.add_children(popup)
10198

10299
self._template = Template(u"""
103100
{% macro script(this, kwargs) %}
@@ -420,22 +417,19 @@ def __init__(self, html=None, icon_size=None, icon_anchor=None,
420417
""") # noqa
421418

422419

423-
class CircleMarker(MacroElement):
420+
class CircleMarker(Marker):
424421
def __init__(self, location, radius=500, color='black',
425422
fill_color='black', fill_opacity=0.6, popup=None):
426423
"""
427424
TODO docstring here
428425
429426
"""
430-
super(CircleMarker, self).__init__()
427+
super(CircleMarker, self).__init__(location, popup=popup)
431428
self._name = 'CircleMarker'
432-
self.location = location
433429
self.radius = radius
434430
self.color = color
435431
self.fill_color = fill_color
436432
self.fill_opacity = fill_opacity
437-
if popup is not None:
438-
self.add_children(popup)
439433

440434
self._template = Template(u"""
441435
{% macro script(this, kwargs) %}

folium/map.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,8 @@ def __init__(self, location, popup=None, icon=None):
363363
----------
364364
location: tuple or list, default None
365365
Latitude and Longitude of Marker (Northing, Easting)
366-
popup: string or tuple, default 'Pop Text'
367-
Input text or visualization for object. Can pass either text,
368-
or a tuple of the form (Vincent object, 'vis_path.json')
369-
It is possible to adjust the width of text/HTML popups
370-
using the optional keywords `popup_width` (default is 300px).
366+
popup: string or folium.Popup, default None
367+
Input text or visualization for object.
371368
icon: Icon plugin
372369
the Icon plugin to use to render the marker.
373370
@@ -378,15 +375,16 @@ def __init__(self, location, popup=None, icon=None):
378375
Example
379376
-------
380377
>>>map.simple_marker(location=[45.5, -122.3], popup='Portland, OR')
381-
>>>map.simple_marker(location=[45.5, -122.3], popup=(vis, 'vis.json'))
382-
378+
>>>map.simple_marker(location=[45.5, -122.3], popup=folium.Popup('Portland, OR'))
383379
"""
384380
super(Marker, self).__init__()
385381
self._name = 'Marker'
386382
self.location = location
387383
if icon is not None:
388384
self.add_children(icon)
389-
if popup is not None:
385+
if isinstance(popup, text_type) or isinstance(popup, binary_type):
386+
self.add_children(Popup(popup))
387+
elif popup is not None:
390388
self.add_children(popup)
391389

392390
self._template = Template(u"""

tests/test_features.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import os
9-
from folium import Map
9+
from folium import Map, Popup
1010
from folium import features
1111
from folium.six import text_type
1212
from folium.element import Element
@@ -79,6 +79,15 @@ def test_figure_double_rendering():
7979
out2 = f.render()
8080
assert out == out2
8181

82+
def test_marker_popups():
83+
m = Map()
84+
features.Marker([45,-180],popup='-180').add_to(m)
85+
features.Marker([45,-120],popup=Popup('-120')).add_to(m)
86+
features.RegularPolygonMarker([45,-60],popup='-60').add_to(m)
87+
features.RegularPolygonMarker([45,0],popup=Popup('0')).add_to(m)
88+
features.CircleMarker([45,60],popup='60').add_to(m)
89+
features.CircleMarker([45,120],popup=Popup('120')).add_to(m)
90+
m._repr_html_()
8291

8392
# DivIcon.
8493
def test_divicon():

0 commit comments

Comments
 (0)