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
2533 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
(e) => {
12
var map = %(map)s;
13
var layers = L.PM.Utils.findLayers(map);
14
var lg = L.layerGroup(layers);
15
console.log(lg.toGeoJSON());
16
}
17
""" % dict(map=m.get_name())) # noqa: UP031
18
19
# For manual testing
20
click = JsCode("""
21
(e) => {
22
console.log(e.target);
23
console.log(e.target.toGeoJSON());
24
}
25
""")
26
27
# Just a few customizations for the snapshot tests
28
# The test succeeds if the position is to the right
29
# and if the buttons for markers and circles are not
30
# shown.
31
gm = GeoMan(
32
position="topright", draw_marker=False, draw_circle=False, on={"click": click}
33
).add_to(m)
34
35
# For manual testing of the global options
36
gm.set_global_options(
37
{
38
"snappable": True,
39
"snapDistance": 20,
40
}
41
)
42
43
# Make rectangles green
44
gm.enable_draw("Rectangle", path_options={"color": "green"})
45
gm.disable_draw()
46
47
# On any event that updates the layers, we trigger the handler
48
event_handlers = {
49
"pm:create": handler,
50
"pm:remove": handler,
51
"pm:update": handler,
52
"pm:rotateend": handler,
53
"pm:cut": handler,
54
"pm:undoremove": handler,
55
}
56
57
m.on(**event_handlers)
58
59