···11+# Widget-Leaflet Extensions Design
22+33+## Goal
44+55+Extend the existing leaflet map widget adapter with bounding box drawing, image overlay, and marker support for the tessera geospatial classification workflow.
66+77+## Architecture
88+99+All changes are to the JS adapter code embedded in `widget_leaflet.ml`. No changes to the OCaml widget API — the existing `Widget.command` and handler system is sufficient. We add new command names and event types to the adapter.
1010+1111+## New Commands
1212+1313+### Bounding box drawing
1414+1515+- `enableBboxDraw` — enables rectangle drawing mode via mousedown/mousemove/mouseup
1616+- User drags to draw a rectangle with visual feedback (dashed while dragging, solid green when complete)
1717+- Drawing a new rectangle replaces the previous one
1818+- New event `bbox_drawn` fires with `{south, west, north, east}` payload
1919+2020+### Image overlay
2121+2222+- `addImageOverlay` — takes `{url, bounds: [[south, west], [north, east]], opacity?}`. URL is typically a `data:image/png;base64,...` from tessera-viz-jsoo.
2323+- `removeImageOverlay` — removes the current overlay
2424+2525+### Markers
2626+2727+- `addMarker` — takes `{lat, lng, label?, color?}`. Adds a circle marker at the location.
2828+- `clearMarkers` — removes all markers
2929+3030+## Usage from OCaml
3131+3232+```ocaml
3333+(* Enable bbox drawing *)
3434+Widget.command ~id:"map" "enableBboxDraw" "";
3535+3636+(* Handle bbox drawn event *)
3737+let on_bbox = function
3838+ | Some json -> (* parse {south, west, north, east} *)
3939+ | None -> ()
4040+in
4141+Widget.display_managed ~id:"map" ~kind:"leaflet-map" ~config ~handlers:[
4242+ "click", on_click;
4343+ "bbox_drawn", on_bbox;
4444+]
4545+4646+(* Add image overlay *)
4747+Widget.command ~id:"map" "addImageOverlay"
4848+ {|{"url":"data:image/png;base64,...","bounds":[[52.0,0.0],[52.1,0.2]]}|};
4949+5050+(* Add training point markers *)
5151+Widget.command ~id:"map" "addMarker" {|{"lat":52.05,"lng":0.1,"color":"red"}|};
5252+```
5353+5454+## Implementation approach
5555+5656+Custom lightweight rectangle drawing using Leaflet's built-in `L.rectangle` + mouse events (~30 lines JS). No Leaflet.draw plugin dependency — avoids the toolbar UI issues the Python version fights against.
5757+5858+## Testing
5959+6060+Playwright test with a standalone HTML page that embeds the adapter JS directly, exercises commands, and verifies DOM state.