From d02bf1d5cb5090a1baacbc967241a2c9184d94a8 Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Tue, 25 Jun 2024 23:18:57 +0200 Subject: [PATCH] Add mapbox draw func --- docs/examples/mapbox_draw_plugin/app.py | 12 ++++++++---- maplibre/plugins.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 maplibre/plugins.py diff --git a/docs/examples/mapbox_draw_plugin/app.py b/docs/examples/mapbox_draw_plugin/app.py index 78b1545a..9fd4f919 100644 --- a/docs/examples/mapbox_draw_plugin/app.py +++ b/docs/examples/mapbox_draw_plugin/app.py @@ -5,7 +5,8 @@ from maplibre import Map, MapOptions, render_maplibregl from maplibre.basemaps import Carto -from maplibre.controls import ControlPosition, NavigationControl +from maplibre.controls import ControlPosition, NavigationControl, ScaleControl +from maplibre.plugins import add_mapbox_draw from maplibre.ui import use_mapboxgl_draw # from shiny import reactive @@ -48,9 +49,12 @@ "trash": True, }, } -m.add_call( - "addMapboxDraw", draw_options, ControlPosition.TOP_LEFT.value, geojson_feature -) +add_mapbox_draw(m, geojson=geojson_feature, position=ControlPosition.BOTTOM_LEFT) +m.add_control(ScaleControl(), ControlPosition.BOTTOM_RIGHT) + +# m.add_call( +# "addMapboxDraw", draw_options, ControlPosition.TOP_LEFT.value, geojson_feature +# ) # Shiny Express use_mapboxgl_draw() diff --git a/maplibre/plugins.py b/maplibre/plugins.py new file mode 100644 index 00000000..253605b0 --- /dev/null +++ b/maplibre/plugins.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from .controls import ControlPosition +from .map import Map + + +def add_mapbox_draw( + map_: Map, + options: dict = None, + position: str | ControlPosition = ControlPosition.TOP_LEFT, + geojson: dict = None, +) -> None: + map_.add_call( + "addMapboxDraw", options or {}, ControlPosition(position).value, geojson + )