Path: blob/main/tests/snapshots/modules/geoman_customizations.py
1602 views
import folium1from folium import JsCode2from folium.plugins import GeoMan, MousePosition34m = folium.Map(tiles=None, location=[39.949610, -75.150282], zoom_start=5)5MousePosition().add_to(m)67# This can be used to test the connection to streamlit8# by returning the resulting GeoJson9handler = JsCode(10"""11(e) => {12var map = %(map)s;13var layers = L.PM.Utils.findLayers(map);14var lg = L.layerGroup(layers);15console.log(lg.toGeoJSON());16}17""" # noqa: UP03118% dict(map=m.get_name())19)2021# For manual testing22click = JsCode(23"""24(e) => {25console.log(e.target);26console.log(e.target.toGeoJSON());27}28"""29)3031# Just a few customizations for the snapshot tests32# The test succeeds if the position is to the right33# and if the buttons for markers and circles are not34# shown.35gm = GeoMan(36position="topright", draw_marker=False, draw_circle=False, on={"click": click}37).add_to(m)3839# For manual testing of the global options40gm.set_global_options(41{42"snappable": True,43"snapDistance": 20,44}45)4647# Make rectangles green48gm.enable_draw("Rectangle", path_options={"color": "green"})49gm.disable_draw()5051# On any event that updates the layers, we trigger the handler52event_handlers = {53"pm:create": handler,54"pm:remove": handler,55"pm:update": handler,56"pm:rotateend": handler,57"pm:cut": handler,58"pm:undoremove": handler,59}6061m.on(**event_handlers)626364