Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/snapshots/modules/geoman_customizations.py
1602 views
1
import folium
2
from folium import JsCode
3
from folium.plugins import GeoMan, MousePosition
4
5
m = folium.Map(tiles=None, location=[39.949610, -75.150282], zoom_start=5)
6
MousePosition().add_to(m)
7
8
# This can be used to test the connection to streamlit
9
# by returning the resulting GeoJson
10
handler = JsCode(
11
"""
12
(e) => {
13
var map = %(map)s;
14
var layers = L.PM.Utils.findLayers(map);
15
var lg = L.layerGroup(layers);
16
console.log(lg.toGeoJSON());
17
}
18
""" # noqa: UP031
19
% dict(map=m.get_name())
20
)
21
22
# For manual testing
23
click = JsCode(
24
"""
25
(e) => {
26
console.log(e.target);
27
console.log(e.target.toGeoJSON());
28
}
29
"""
30
)
31
32
# Just a few customizations for the snapshot tests
33
# The test succeeds if the position is to the right
34
# and if the buttons for markers and circles are not
35
# shown.
36
gm = GeoMan(
37
position="topright", draw_marker=False, draw_circle=False, on={"click": click}
38
).add_to(m)
39
40
# For manual testing of the global options
41
gm.set_global_options(
42
{
43
"snappable": True,
44
"snapDistance": 20,
45
}
46
)
47
48
# Make rectangles green
49
gm.enable_draw("Rectangle", path_options={"color": "green"})
50
gm.disable_draw()
51
52
# On any event that updates the layers, we trigger the handler
53
event_handlers = {
54
"pm:create": handler,
55
"pm:remove": handler,
56
"pm:update": handler,
57
"pm:rotateend": handler,
58
"pm:cut": handler,
59
"pm:undoremove": handler,
60
}
61
62
m.on(**event_handlers)
63
64