@@ -44,9 +44,10 @@ class PolyLine(Marker):
44
44
See http://leafletjs.com/reference-1.2.0.html#polyline for more options.
45
45
46
46
"""
47
- def __init__ (self , locations , popup = None , ** kw ):
47
+ def __init__ (self , locations , popup = None , tooltip = None , ** kw ):
48
48
super (PolyLine , self ).__init__ (location = locations , popup = popup )
49
49
self ._name = 'PolyLine'
50
+ self .tooltip = tooltip
50
51
options = _parse_path (** kw )
51
52
options .update (
52
53
{
@@ -61,30 +62,13 @@ def __init__(self, locations, popup=None, **kw):
61
62
{% macro script(this, kwargs) %}
62
63
var {{this.get_name()}} = L.polyline(
63
64
{{this.location}},
64
- {{ this.options }}).addTo({{this._parent.get_name()}});
65
+ {{ this.options }}
66
+ )
67
+ {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
68
+ .addTo({{this._parent.get_name()}});
65
69
{% endmacro %}
66
70
""" ) # noqa
67
71
68
- def _get_self_bounds (self ):
69
- """
70
- Computes the bounds of the object itself (not including it's children)
71
- in the form [[lat_min, lon_min], [lat_max, lon_max]]
72
-
73
- """
74
- bounds = [[None , None ], [None , None ]]
75
- for point in iter_points (self .location ):
76
- bounds = [
77
- [
78
- none_min (bounds [0 ][0 ], point [0 ]),
79
- none_min (bounds [0 ][1 ], point [1 ]),
80
- ],
81
- [
82
- none_max (bounds [1 ][0 ], point [0 ]),
83
- none_max (bounds [1 ][1 ], point [1 ]),
84
- ],
85
- ]
86
- return bounds
87
-
88
72
89
73
class WmsTileLayer (Layer ):
90
74
"""
@@ -464,10 +448,11 @@ class GeoJson(Layer):
464
448
"""
465
449
def __init__ (self , data , style_function = None , name = None ,
466
450
overlay = True , control = True , smooth_factor = None ,
467
- highlight_function = None ):
451
+ highlight_function = None , tooltip = None ):
468
452
super (GeoJson , self ).__init__ (name = name , overlay = overlay ,
469
453
control = control )
470
454
self ._name = 'GeoJson'
455
+ self .tooltip = tooltip
471
456
if isinstance (data , dict ):
472
457
self .embed = True
473
458
self .data = data
@@ -542,7 +527,9 @@ def highlight_function(x):
542
527
{% endif %}
543
528
}
544
529
{% endif %}
545
- ).addTo({{this._parent.get_name()}});
530
+ )
531
+ {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
532
+ .addTo({{this._parent.get_name()}});
546
533
{{this.get_name()}}.setStyle(function(feature) {return feature.properties.style;});
547
534
548
535
{% endmacro %}
@@ -566,7 +553,7 @@ def style_data(self):
566
553
feature .setdefault ('properties' , {}).setdefault ('highlight' , {}).update (self .highlight_function (feature )) # noqa
567
554
return json .dumps (self .data , sort_keys = True )
568
555
569
- def _get_self_bounds (self ):
556
+ def get_bounds (self ):
570
557
"""
571
558
Computes the bounds of the object itself (not including it's children)
572
559
in the form [[lat_min, lon_min], [lat_max, lon_max]]
@@ -646,10 +633,12 @@ class TopoJson(Layer):
646
633
647
634
"""
648
635
def __init__ (self , data , object_path , style_function = None ,
649
- name = None , overlay = True , control = True , smooth_factor = None ):
636
+ name = None , overlay = True , control = True , smooth_factor = None ,
637
+ tooltip = None ):
650
638
super (TopoJson , self ).__init__ (name = name , overlay = overlay ,
651
639
control = control )
652
640
self ._name = 'TopoJson'
641
+ self .tooltip = tooltip
653
642
if 'read' in dir (data ):
654
643
self .embed = True
655
644
self .data = json .load (data )
@@ -677,7 +666,10 @@ def style_function(x):
677
666
{{this.get_name()}}_data.{{this.object_path}})
678
667
{% if this.smooth_factor is not none %}
679
668
, {smoothFactor: {{this.smooth_factor}}}
680
- {% endif %}).addTo({{this._parent.get_name()}});
669
+ {% endif %}
670
+ )
671
+ {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
672
+ .addTo({{this._parent.get_name()}});
681
673
{{this.get_name()}}.setStyle(function(feature) {return feature.properties.style;});
682
674
683
675
{% endmacro %}
@@ -711,7 +703,7 @@ def render(self, **kwargs):
711
703
JavascriptLink ('https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js' ), # noqa
712
704
name = 'topojson' )
713
705
714
- def _get_self_bounds (self ):
706
+ def get_bounds (self ):
715
707
"""
716
708
Computes the bounds of the object itself (not including it's children)
717
709
in the form [[lat_min, lon_min], [lat_max, lon_max]]
@@ -822,21 +814,24 @@ class Circle(Marker):
822
814
See http://leafletjs.com/reference-1.2.0.html#path for more otions.
823
815
824
816
"""
825
- def __init__ (self , location , radius = 10 , popup = None , ** kwargs ):
817
+ def __init__ (self , location , radius = 10 , popup = None , tooltip = None , ** kwargs ):
826
818
super (Circle , self ).__init__ (location = location , popup = popup )
827
819
self ._name = 'circle'
828
- options = _parse_path ( ** kwargs )
820
+ self . tooltip = tooltip
829
821
822
+ options = _parse_path (** kwargs )
830
823
options .update ({'radius' : radius })
831
824
self .options = json .dumps (options , sort_keys = True , indent = 2 )
832
825
833
826
self ._template = Template (u"""
834
827
{% macro script(this, kwargs) %}
835
828
836
829
var {{this.get_name()}} = L.circle(
837
- [{{this.location[0]}},{{this.location[1]}}],
830
+ [{{this.location[0]}}, {{this.location[1]}}],
838
831
{{ this.options }}
839
- ).addTo({{this._parent.get_name()}});
832
+ )
833
+ {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
834
+ .addTo({{this._parent.get_name()}});
840
835
{% endmacro %}
841
836
""" )
842
837
@@ -866,130 +861,111 @@ class CircleMarker(Marker):
866
861
See http://leafletjs.com/reference-1.2.0.html#path for more otions.
867
862
868
863
"""
869
- def __init__ (self , location , radius = 10 , popup = None , ** kw ):
864
+ def __init__ (self , location , radius = 10 , popup = None , tooltip = None , ** kw ):
870
865
super (CircleMarker , self ).__init__ (location = location , popup = popup )
871
866
self ._name = 'CircleMarker'
872
- options = _parse_path ( ** kw )
867
+ self . tooltip = tooltip
873
868
869
+ options = _parse_path (** kw )
874
870
options .update ({'radius' : radius })
875
871
self .options = json .dumps (options , sort_keys = True , indent = 2 )
876
872
877
873
self ._template = Template (u"""
878
874
{% macro script(this, kwargs) %}
879
875
var {{this.get_name()}} = L.circleMarker(
880
- [{{this.location[0]}},{{this.location[1]}}],
876
+ [{{this.location[0]}}, {{this.location[1]}}],
881
877
{{ this.options }}
882
- ).addTo({{this._parent.get_name()}});
878
+ )
879
+ {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
880
+ .addTo({{this._parent.get_name()}});
883
881
{% endmacro %}
884
882
""" )
885
883
886
884
887
- class RectangleMarker (Marker ):
888
- def __init__ (self , bounds , color = 'black' , weight = 1 , fill_color = 'black' ,
889
- fill_opacity = 0.6 , popup = None ):
890
- """
891
- Creates a RectangleMarker object for plotting on a Map.
892
-
893
- Parameters
894
- ----------
895
- bounds: tuple or list, default None
896
- Latitude and Longitude of Marker (southWest and northEast)
897
- color: string, default ('black')
898
- Edge color of a rectangle.
899
- weight: float, default (1)
900
- Edge line width of a rectangle.
901
- fill_color: string, default ('black')
902
- Fill color of a rectangle.
903
- fill_opacity: float, default (0.6)
904
- Fill opacity of a rectangle.
905
- popup: string or folium.Popup, default None
906
- Input text or visualization for object.
907
-
908
- Returns
909
- -------
910
- folium.features.RectangleMarker object
911
-
912
- Example
913
- -------
914
- >>> RectangleMarker(
915
- ... bounds=[[35.681, 139.766], [35.691, 139.776]],
916
- ... color='blue', fill_color='red', popup='Tokyo, Japan'
917
- ... )
885
+ class Rectangle (Marker ):
886
+ """
887
+ Creates a Rectangle Marker object for plotting on a Map.
888
+
889
+ Parameters
890
+ ----------
891
+ bounds: tuple or list, default None
892
+ Latitude and Longitude of Marker (southWest and northEast)
893
+ color: string, default ('black')
894
+ Edge color of a rectangle.
895
+ weight: float, default (1)
896
+ Edge line width of a rectangle.
897
+ fill_color: string, default ('black')
898
+ Fill color of a rectangle.
899
+ fill_opacity: float, default (0.6)
900
+ Fill opacity of a rectangle.
901
+ popup: string or folium.Popup, default None
902
+ Input text or visualization for object.
903
+
904
+ See http://leafletjs.com/reference-1.2.0.html#path for more otions.
905
+
906
+ """
907
+ def __init__ (self , bounds , popup = None , tooltip = None , ** kwargs ):
908
+ super (Rectangle , self ).__init__ (location = bounds , popup = popup )
909
+ self ._name = 'rectangle'
910
+ self .tooltip = tooltip
911
+
912
+ options = _parse_path (** kwargs )
913
+ self .options = json .dumps (options , sort_keys = True , indent = 2 )
918
914
919
- """
920
- super (RectangleMarker , self ).__init__ (bounds , popup = popup )
921
- self ._name = 'RectangleMarker'
922
- self .color = color
923
- self .weight = weight
924
- self .fill_color = fill_color
925
- self .fill_opacity = fill_opacity
926
915
self ._template = Template (u"""
927
916
{% macro script(this, kwargs) %}
917
+
928
918
var {{this.get_name()}} = L.rectangle(
929
- [[{{this.location[0]}},{{this.location[1]}}],
930
- [{{this.location[2]}},{{this.location[3]}}]],
931
- {
932
- color: '{{ this.color }}',
933
- fillColor: '{{ this.fill_color }}',
934
- fillOpacity: {{ this.fill_opacity }},
935
- weight: {{ this.weight }}
936
- }).addTo({{this._parent.get_name()}});
919
+ {{this.location}},
920
+ {{ this.options }}
921
+ )
922
+ {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
923
+ .addTo({{this._parent.get_name()}});
937
924
938
925
{% endmacro %}
939
926
""" )
940
927
941
928
942
- class PolygonMarker (Marker ):
943
- def __init__ (self , locations , color = 'black' , weight = 1 , fill_color = 'black' ,
944
- fill_opacity = 0.6 , popup = None ):
945
- """
946
- Creates a PolygonMarker object for plotting on a Map.
947
-
948
- Parameters
949
- ----------
950
- locations: tuple or list, default None
951
- Latitude and Longitude of Polygon
952
- color: string, default ('black')
953
- Edge color of a polygon.
954
- weight: float, default (1)
955
- Edge line width of a polygon.
956
- fill_color: string, default ('black')
957
- Fill color of a polygon.
958
- fill_opacity: float, default (0.6)
959
- Fill opacity of a polygon.
960
- popup: string or folium.Popup, default None
961
- Input text or visualization for object.
962
-
963
- Returns
964
- -------
965
- folium.features.Polygon object
966
-
967
- Examples
968
- --------
969
- >>> locations = [[35.6762, 139.7795],
970
- ... [35.6718, 139.7831],
971
- ... [35.6767, 139.7868],
972
- ... [35.6795, 139.7824],
973
- ... [35.6787, 139.7791]]
974
- >>> Polygon(locations, color='blue', weight=10, fill_color='red',
975
- ... fill_opacity=0.5, popup='Tokyo, Japan'))
929
+ class Polygon (Marker ):
930
+ """
931
+ Creates a Polygon Marker object for plotting on a Map.
932
+
933
+ Parameters
934
+ ----------
935
+ locations: tuple or list, default None
936
+ Latitude and Longitude of Polygon
937
+ color: string, default ('black')
938
+ Edge color of a polygon.
939
+ weight: float, default (1)
940
+ Edge line width of a polygon.
941
+ fill_color: string, default ('black')
942
+ Fill color of a polygon.
943
+ fill_opacity: float, default (0.6)
944
+ Fill opacity of a polygon.
945
+ popup: string or folium.Popup, default None
946
+ Input text or visualization for object.
947
+
948
+ See http://leafletjs.com/reference-1.2.0.html#path for more otions.
949
+
950
+ """
951
+ def __init__ (self , locations , popup = None , tooltip = None , ** kwargs ):
952
+ super (Polygon , self ).__init__ (locations , popup = popup )
953
+ self ._name = 'Polygon'
954
+ self .tooltip = tooltip
955
+
956
+ options = _parse_path (** kwargs )
957
+ self .options = json .dumps (options , sort_keys = True , indent = 2 )
976
958
977
- """
978
- super (PolygonMarker , self ).__init__ (locations , popup = popup )
979
- self ._name = 'PolygonMarker'
980
- self .color = color
981
- self .weight = weight
982
- self .fill_color = fill_color
983
- self .fill_opacity = fill_opacity
984
959
self ._template = Template (u"""
985
960
{% macro script(this, kwargs) %}
986
- var {{this.get_name()}} = L.polygon({{this.location}},
987
- {
988
- color: '{{ this.color }}',
989
- fillColor: '{{ this.fill_color }}',
990
- fillOpacity: {{ this.fill_opacity }},
991
- weight: {{ this.weight }}
992
- }).addTo({{this._parent.get_name()}});
961
+
962
+ var {{this.get_name()}} = L.polygon(
963
+ {{this.location}},
964
+ {{ this.options }}
965
+ )
966
+ {% if this.tooltip %}.bindTooltip("{{this.tooltip.__str__()}}"){% endif %}
967
+ .addTo({{this._parent.get_name()}});
968
+
993
969
{% endmacro %}
994
970
""" )
995
971
0 commit comments