draw a rectangle
Hi,
Is there any way to draw a rectangle like in https://trafficonese.github.io/leaflet.extras/reference/draw.html ?
Absolutely! Use add_draw_control().
maplibre() |> add_draw_control()
That said - I don't have support for perfect rectangles through click-and-drag; right now there are two polygon modes supported, vertex-by-vertex and freehand. Is the click-and-drag rectangle what you're looking for?
Thanks for the quick reply. The rectangle I need is the click-and-drag.
I see.
The way this sort of functionality gets added to Mapbox / MapLibre is via custom "modes" which are typically installed via node (see https://github.com/mapbox/mapbox-gl-draw/blob/main/docs/MODES.md#available-custom-modes). That doesn't really work for us, so I'd need to work in some sort of implementation into the package.
For the freehand draw mode that does exist in the package, I ended up writing (well Claude and I collaborated) a custom plugin for this that didn't use the existing mode. So I'd probably need to do the same for other modes as well, or a user could submit a PR following the template used for the freehand mode.
this is now implemented, try it out with rectangle = TRUE!