MCPcopy Index your code
hub / github.com/python-visualization/folium / EventHandler

Class EventHandler

folium/elements.py:70–142  ·  view source on GitHub ↗

Add javascript event handlers. Examples -------- >>> import folium >>> from folium.utilities import JsCode >>> >>> m = folium.Map() >>> >>> geo_json_data = { ... "type": "FeatureCollection", ... "features": [ ... { ...

Source from the content-addressed store, hash-verified

68
69
70class EventHandler(MacroElement):
71 '''
72 Add javascript event handlers.
73
74 Examples
75 --------
76 >>> import folium
77 >>> from folium.utilities import JsCode
78 >>>
79 >>> m = folium.Map()
80 >>>
81 >>> geo_json_data = {
82 ... "type": "FeatureCollection",
83 ... "features": [
84 ... {
85 ... "type": "Feature",
86 ... "geometry": {
87 ... "type": "Polygon",
88 ... "coordinates": [
89 ... [
90 ... [100.0, 0.0],
91 ... [101.0, 0.0],
92 ... [101.0, 1.0],
93 ... [100.0, 1.0],
94 ... [100.0, 0.0],
95 ... ]
96 ... ],
97 ... },
98 ... "properties": {"prop1": {"title": "Somewhere on Sumatra"}},
99 ... }
100 ... ],
101 ... }
102 >>>
103 >>> g = folium.GeoJson(geo_json_data).add_to(m)
104 >>>
105 >>> highlight = JsCode(
106 ... """
107 ... function highlight(e) {
108 ... e.target.original_color = e.layer.options.color;
109 ... e.target.setStyle({ color: "green" });
110 ... }
111 ... """
112 ... )
113 >>>
114 >>> reset = JsCode(
115 ... """
116 ... function reset(e) {
117 ... e.target.setStyle({ color: e.target.original_color });
118 ... }
119 ... """
120 ... )
121 >>>
122 >>> g.add_child(EventHandler("mouseover", highlight))
123 >>> g.add_child(EventHandler("mouseout", reset))
124 '''
125
126 _template = Template(
127 """

Callers 2

_addMethod · 0.90

Calls 1

TemplateClass · 0.90

Tested by 1