mapgl icon indicating copy to clipboard operation
mapgl copied to clipboard

draw a rectangle

Open fg-sempre opened this issue 8 months ago • 3 comments

Hi,

Is there any way to draw a rectangle like in https://trafficonese.github.io/leaflet.extras/reference/draw.html ?

fg-sempre avatar Apr 12 '25 20:04 fg-sempre

Absolutely! Use add_draw_control().

maplibre() |> add_draw_control()

Image

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?

walkerke avatar Apr 14 '25 15:04 walkerke

Thanks for the quick reply. The rectangle I need is the click-and-drag.

Image

fg-sempre avatar Apr 14 '25 20:04 fg-sempre

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.

walkerke avatar Apr 16 '25 15:04 walkerke

this is now implemented, try it out with rectangle = TRUE!

walkerke avatar Sep 22 '25 13:09 walkerke