99import json
1010
1111from .utilities import (color_brewer , _parse_size , legend_scaler ,
12- _locations_mirror , _locations_tolist , image_to_url )
12+ _locations_mirror , _locations_tolist , image_to_url ,
13+ text_type , binary_type )
1314
1415from .element import Element , Figure , JavascriptLink , CssLink , MacroElement
15- from .map import TileLayer , Icon
16+ from .map import TileLayer , Icon , Marker , Popup
1617
1718
1819class WmsTileLayer (TileLayer ):
@@ -48,7 +49,7 @@ def __init__(self, url, name=None,
4849 """ ) # noqa
4950
5051
51- class RegularPolygonMarker (MacroElement ):
52+ class RegularPolygonMarker (Marker ):
5253 def __init__ (self , location , color = 'black' , opacity = 1 , weight = 2 ,
5354 fill_color = 'blue' , fill_opacity = 1 ,
5455 number_of_sides = 4 , rotation = 0 , radius = 15 , popup = None ):
@@ -85,9 +86,8 @@ def __init__(self, location, color='black', opacity=1, weight=2,
8586
8687 For more information, see https://humangeo.github.io/leaflet-dvf/
8788 """
88- super (RegularPolygonMarker , self ).__init__ ()
89+ super (RegularPolygonMarker , self ).__init__ (location , popup = popup )
8990 self ._name = 'RegularPolygonMarker'
90- self .location = location
9191 self .color = color
9292 self .opacity = opacity
9393 self .weight = weight
@@ -96,8 +96,6 @@ def __init__(self, location, color='black', opacity=1, weight=2,
9696 self .number_of_sides = number_of_sides
9797 self .rotation = rotation
9898 self .radius = radius
99- if popup is not None :
100- self .add_children (popup )
10199
102100 self ._template = Template (u"""
103101 {% macro script(this, kwargs) %}
@@ -420,22 +418,19 @@ def __init__(self, html=None, icon_size=None, icon_anchor=None,
420418 """ ) # noqa
421419
422420
423- class CircleMarker (MacroElement ):
421+ class CircleMarker (Marker ):
424422 def __init__ (self , location , radius = 500 , color = 'black' ,
425423 fill_color = 'black' , fill_opacity = 0.6 , popup = None ):
426424 """
427425 TODO docstring here
428426
429427 """
430- super (CircleMarker , self ).__init__ ()
428+ super (CircleMarker , self ).__init__ (location , popup = popup )
431429 self ._name = 'CircleMarker'
432- self .location = location
433430 self .radius = radius
434431 self .color = color
435432 self .fill_color = fill_color
436433 self .fill_opacity = fill_opacity
437- if popup is not None :
438- self .add_children (popup )
439434
440435 self ._template = Template (u"""
441436 {% macro script(this, kwargs) %}
@@ -508,7 +503,7 @@ def __init__(self, popup=None):
508503
509504class PolyLine (MacroElement ):
510505 def __init__ (self , locations , color = None , weight = None ,
511- opacity = None , latlon = True ):
506+ opacity = None , latlon = True , popup = None ):
512507 """
513508 Creates a PolyLine object to append into a map with
514509 Map.add_children.
@@ -525,6 +520,8 @@ def __init__(self, locations, color=None, weight=None,
525520 or not ([[lon, lat]] if False).
526521 Note that the default GeoJson format is latlon=False,
527522 while Leaflet polyline's default is latlon=True.
523+ popup: string or folium.Popup, default None
524+ Input text or visualization for object.
528525 """
529526 super (PolyLine , self ).__init__ ()
530527 self ._name = 'PolyLine'
@@ -533,6 +530,10 @@ def __init__(self, locations, color=None, weight=None,
533530 self .color = color
534531 self .weight = weight
535532 self .opacity = opacity
533+ if isinstance (popup , text_type ) or isinstance (popup , binary_type ):
534+ self .add_children (Popup (popup ))
535+ elif popup is not None :
536+ self .add_children (popup )
536537
537538 self ._template = Template (u"""
538539 {% macro script(this, kwargs) %}
@@ -550,7 +551,7 @@ def __init__(self, locations, color=None, weight=None,
550551
551552class MultiPolyLine (MacroElement ):
552553 def __init__ (self , locations , color = None , weight = None ,
553- opacity = None , latlon = True ):
554+ opacity = None , latlon = True , popup = None ):
554555 """
555556 Creates a MultiPolyLine object to append into a map with
556557 Map.add_children.
@@ -567,6 +568,8 @@ def __init__(self, locations, color=None, weight=None,
567568 or not ([[lon, lat]] if False).
568569 Note that the default GeoJson format is latlon=False,
569570 while Leaflet polyline's default is latlon=True.
571+ popup: string or folium.Popup, default None
572+ Input text or visualization for object.
570573 """
571574 super (MultiPolyLine , self ).__init__ ()
572575 self ._name = 'MultiPolyLine'
@@ -575,6 +578,10 @@ def __init__(self, locations, color=None, weight=None,
575578 self .color = color
576579 self .weight = weight
577580 self .opacity = opacity
581+ if isinstance (popup , text_type ) or isinstance (popup , binary_type ):
582+ self .add_children (Popup (popup ))
583+ elif popup is not None :
584+ self .add_children (popup )
578585
579586 self ._template = Template (u"""
580587 {% macro script(this, kwargs) %}
0 commit comments