Path: blob/main/tests/snapshots/modules/geoman_customizations.py
2533 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(e) => {11var map = %(map)s;12var layers = L.PM.Utils.findLayers(map);13var lg = L.layerGroup(layers);14console.log(lg.toGeoJSON());15}16""" % dict(map=m.get_name())) # noqa: UP0311718# For manual testing19click = JsCode("""20(e) => {21console.log(e.target);22console.log(e.target.toGeoJSON());23}24""")2526# Just a few customizations for the snapshot tests27# The test succeeds if the position is to the right28# and if the buttons for markers and circles are not29# shown.30gm = GeoMan(31position="topright", draw_marker=False, draw_circle=False, on={"click": click}32).add_to(m)3334# For manual testing of the global options35gm.set_global_options(36{37"snappable": True,38"snapDistance": 20,39}40)4142# Make rectangles green43gm.enable_draw("Rectangle", path_options={"color": "green"})44gm.disable_draw()4546# On any event that updates the layers, we trigger the handler47event_handlers = {48"pm:create": handler,49"pm:remove": handler,50"pm:update": handler,51"pm:rotateend": handler,52"pm:cut": handler,53"pm:undoremove": handler,54}5556m.on(**event_handlers)575859