@defra/interactive-map 0.0.56-alpha → 0.0.58-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/dist/umd/index.js +1 -1
  4. package/docs/api/button-definition.md +11 -0
  5. package/docs/api/context.md +2 -0
  6. package/docs/api.md +3 -1
  7. package/docs/assets/css/docusaurus.scss +7 -1
  8. package/docs/plugins/draw.md +326 -121
  9. package/package.json +1 -1
  10. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  11. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  12. package/plugins/datasets/dist/umd/index.js +1 -1
  13. package/plugins/datasets/src/initialise/DatasetsInit.jsx +6 -17
  14. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +3 -43
  15. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  16. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  17. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  18. package/plugins/draw/dist/esm/index.js +1 -1
  19. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  20. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  21. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  22. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  23. package/plugins/draw/dist/umd/index.js +1 -1
  24. package/plugins/draw/src/DrawInit.jsx +9 -6
  25. package/plugins/draw/src/DrawInit.test.jsx +15 -0
  26. package/plugins/draw/src/adapterEvents.js +82 -44
  27. package/plugins/draw/src/adapters/adapterContract.test.js +3 -3
  28. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +18 -10
  29. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +31 -22
  30. package/plugins/draw/src/adapters/maplibre/drawEvents.js +2 -1
  31. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +13 -12
  32. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +5 -5
  33. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +1 -1
  34. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +2 -2
  35. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +6 -9
  36. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +4 -4
  37. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +6 -9
  38. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +1 -1
  39. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +8 -14
  40. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +37 -8
  41. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +11 -1
  42. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +14 -19
  43. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +41 -4
  44. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +12 -1
  45. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +3 -1
  46. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +9 -10
  47. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +5 -24
  48. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -7
  49. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +12 -7
  50. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +5 -0
  51. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +7 -3
  52. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +11 -11
  53. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +15 -15
  54. package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +21 -28
  55. package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +26 -5
  56. package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +5 -6
  57. package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +2 -12
  58. package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +9 -0
  59. package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +7 -0
  60. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +6 -9
  61. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +3 -3
  62. package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +18 -9
  63. package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +29 -4
  64. package/plugins/draw/src/adapters/openlayers/point/pointOps.js +3 -2
  65. package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +6 -0
  66. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +3 -4
  67. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +2 -12
  68. package/plugins/draw/src/api/createNewShape.js +4 -4
  69. package/plugins/draw/src/api/createNewShape.test.js +1 -1
  70. package/plugins/draw/src/api/editFeature.js +8 -11
  71. package/plugins/draw/src/api/editFeature.test.js +33 -22
  72. package/plugins/draw/src/api/newLine.test.js +3 -3
  73. package/plugins/draw/src/api/newPoint.js +4 -5
  74. package/plugins/draw/src/api/newPoint.test.js +11 -3
  75. package/plugins/draw/src/api/newPolygon.test.js +11 -3
  76. package/plugins/draw/src/api/recheckGeometry.js +32 -0
  77. package/plugins/draw/src/api/recheckGeometry.test.js +55 -0
  78. package/plugins/draw/src/api/setGeometry.js +33 -0
  79. package/plugins/draw/src/api/setGeometry.test.js +48 -0
  80. package/plugins/draw/src/api/split.js +26 -22
  81. package/plugins/draw/src/api/split.test.js +38 -18
  82. package/plugins/draw/src/events.js +269 -77
  83. package/plugins/draw/src/events.test.js +779 -34
  84. package/plugins/draw/src/hooks/useSpatialList.js +10 -11
  85. package/plugins/draw/src/hooks/useSpatialList.test.js +3 -3
  86. package/plugins/draw/src/manifest.js +30 -15
  87. package/plugins/draw/src/manifest.test.js +91 -9
  88. package/plugins/draw/src/reducer.js +31 -9
  89. package/plugins/draw/src/reducer.test.js +35 -3
  90. package/plugins/draw/src/utils/drawModes.js +27 -0
  91. package/plugins/draw/src/utils/drawModes.test.js +27 -0
  92. package/plugins/draw/src/utils/needsDrawTarget.js +1 -5
  93. package/plugins/draw/src/utils/needsDrawTarget.test.js +1 -11
  94. package/plugins/draw/src/utils/touchTarget.js +34 -26
  95. package/plugins/draw/src/utils/touchTarget.test.js +32 -20
  96. package/plugins/draw/src/validation/commitChecks.js +187 -0
  97. package/plugins/draw/src/validation/commitChecks.test.js +209 -0
  98. package/plugins/draw/src/validation/liveDrawChecks.js +11 -11
  99. package/plugins/draw/src/validation/liveDrawChecks.test.js +37 -37
  100. package/plugins/draw/src/validation/liveStroke.js +6 -6
  101. package/plugins/draw/src/validation/liveStroke.test.js +27 -27
  102. package/plugins/draw/src/validation/rules.js +16 -14
  103. package/plugins/draw/src/validation/rules.test.js +5 -5
  104. package/plugins/draw/src/validation/validateGeometry.js +58 -31
  105. package/plugins/draw/src/validation/validateGeometry.test.js +68 -44
  106. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  107. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  108. package/plugins/interact/dist/umd/index.js +1 -1
  109. package/plugins/interact/src/hooks/useInteractionHandlers.js +3 -5
  110. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +4 -3
  111. package/plugins/interact/src/hooks/useSpatialList.js +16 -17
  112. package/plugins/interact/src/hooks/useSpatialList.test.js +9 -9
  113. package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  114. package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  115. package/plugins/map-styles/src/MapStyles.jsx +2 -2
  116. package/providers/maplibre/dist/esm/index.js +1 -1
  117. package/providers/maplibre/dist/umd/index.js +1 -1
  118. package/providers/maplibre/src/index.js +11 -2
  119. package/providers/maplibre/src/index.test.js +23 -1
  120. package/providers/maplibre/src/utils/detectModuleWorker.js +8 -19
  121. package/providers/maplibre/src/utils/detectModuleWorker.test.js +19 -23
  122. package/providers/maplibre/src/utils/workerUrl.js +12 -0
  123. package/providers/maplibre/src/utils/workerUrl.test.js +14 -1
  124. package/src/App/components/MapButton/MapButton.jsx +6 -0
  125. package/src/App/components/MapButton/MapButton.test.jsx +10 -0
  126. package/src/App/components/Markers/Markers.jsx +3 -5
  127. package/src/App/components/Markers/Markers.test.jsx +9 -11
  128. package/src/App/components/Panel/Panel.jsx +2 -9
  129. package/src/App/hooks/useInterfaceAPI.js +16 -4
  130. package/src/App/hooks/useInterfaceAPI.test.js +66 -1
  131. package/src/App/renderer/mapButtons.js +2 -1
  132. package/src/App/renderer/mapButtons.test.js +9 -0
  133. package/src/App/store/MapProvider.jsx +3 -0
  134. package/src/App/store/MapProvider.test.jsx +24 -0
  135. package/src/config/mapSizeScales.js +3 -0
  136. package/src/types.js +4 -0
  137. package/src/utils/focusAfterPanelClose.js +9 -0
  138. package/src/utils/focusAfterPanelClose.test.js +40 -0
@@ -71,11 +71,27 @@ createDrawPlugin({
71
71
 
72
72
  ---
73
73
 
74
+ ### `onGeometryPreview`
75
+
76
+ **Type:** `Function`
77
+
78
+ Plugin-level synchronous check, called while a shape is drawn or dragged and when a vertex is about to be placed. Can be overridden per call. See [`onGeometryPreview`](#ongeometrypreviewevent).
79
+
80
+ ---
81
+
74
82
  ### `onGeometryChange`
75
83
 
76
84
  **Type:** `Function`
77
85
 
78
- Plugin-level validation callback, called throughout the draw/edit lifecycle so you can enforce your own rules (e.g. "shapes must stay inside a boundary") alongside the built-in ones. Can be overridden per call — see [Validation](#validation) below for the full contract, and `newPolygon`, `newLine`, `newPoint`, `editFeature` for the per-call override.
86
+ Plugin-level check, called after each committed change to a shape. Can return a Promise, so the shape can be checked against a service. Can be overridden per call. See [`onGeometryChange`](#ongeometrychangeevent-context).
87
+
88
+ ---
89
+
90
+ ### `onGeometryFinish`
91
+
92
+ **Type:** `Function`
93
+
94
+ Plugin-level check, called when a shape is finished. Can return a Promise. Can be overridden per call. See [`onGeometryFinish`](#ongeometryfinishevent-context).
79
95
 
80
96
  ---
81
97
 
@@ -84,23 +100,23 @@ Plugin-level validation callback, called throughout the draw/edit lifecycle so y
84
100
  > [!NOTE]
85
101
  > Each colour accepts a plain colour string or a style-keyed object (e.g. `{ light: '#1d70b8', dark: '#ffffff' }`).
86
102
 
87
- | Property | Type | Description |
88
- |----------|------|-------------|
89
- | `shapeStroke` | `string \| Record<string, string>` | Default stroke colour for an inactive (not being drawn/edited) shape, when the feature sets no `stroke` of its own |
90
- | `shapeFill` | `string \| Record<string, string>` | Default fill colour for an inactive shape, when the feature sets no `fill` of its own |
91
- | `strokeWidth` | `number` | Default stroke width in pixels. **Default:** `2` |
92
- | `editStroke` | `string \| Record<string, string>` | Stroke colour of the shape currently being drawn or edited |
93
- | `editFill` | `string \| Record<string, string>` | Fill colour of the shape currently being drawn or edited |
94
- | `editVertex` | `string \| Record<string, string>` | Colour of placed, unselected vertex handles |
95
- | `editMidpoint` | `string \| Record<string, string>` | Colour of the midpoint handles used to insert a new vertex on an edge |
96
- | `editActive` | `string \| Record<string, string>` | Colour of the currently selected/active vertex handle |
97
- | `editHalo` | `string \| Record<string, string>` | Colour of the halo drawn behind vertex/midpoint handles for contrast |
98
- | `invalidStroke` | `string \| Record<string, string>` | Stroke colour of the dashed outline shown while the shape fails validation |
99
- | `splitValid` | `string \| Record<string, string>` | Colour of the split line while it would produce a valid split |
100
- | `splitInvalid` | `string \| Record<string, string>` | Colour of the split line while it would not produce a valid split |
101
- | `snapVertex` | `string \| Record<string, string>` | Colour of the snap indicator shown over a vertex |
102
- | `snapEdge` | `string \| Record<string, string>` | Colour of the snap indicator shown over an edge |
103
- | `snapRadius` | `number` | Snap tolerance in pixels. **Default:** `12` |
103
+ | Property | Description |
104
+ |----------|-------------|
105
+ | `shapeStroke` | **Type:** `string \| Record<string, string>`<br />Default stroke colour for an inactive (not being drawn/edited) shape, when the feature sets no `stroke` of its own |
106
+ | `shapeFill` | **Type:** `string \| Record<string, string>`<br />Default fill colour for an inactive shape, when the feature sets no `fill` of its own |
107
+ | `strokeWidth` | **Type:** `number`<br />**Default:** `2`<br />Default stroke width in pixels |
108
+ | `editStroke` | **Type:** `string \| Record<string, string>`<br />Stroke colour of the shape currently being drawn or edited |
109
+ | `editFill` | **Type:** `string \| Record<string, string>`<br />Fill colour of the shape currently being drawn or edited |
110
+ | `editVertex` | **Type:** `string \| Record<string, string>`<br />Colour of placed, unselected vertex handles |
111
+ | `editMidpoint` | **Type:** `string \| Record<string, string>`<br />Colour of the midpoint handles used to insert a new vertex on an edge |
112
+ | `editActive` | **Type:** `string \| Record<string, string>`<br />Colour of the currently selected/active vertex handle |
113
+ | `editHalo` | **Type:** `string \| Record<string, string>`<br />Colour of the halo drawn behind vertex/midpoint handles for contrast |
114
+ | `invalidStroke` | **Type:** `string \| Record<string, string>`<br />Stroke colour of the dashed outline shown while the shape fails validation |
115
+ | `splitValid` | **Type:** `string \| Record<string, string>`<br />Colour of the split line while it would produce a valid split |
116
+ | `splitInvalid` | **Type:** `string \| Record<string, string>`<br />Colour of the split line while it would not produce a valid split |
117
+ | `snapVertex` | **Type:** `string \| Record<string, string>`<br />Colour of the snap indicator shown over a vertex |
118
+ | `snapEdge` | **Type:** `string \| Record<string, string>`<br />Colour of the snap indicator shown over an edge |
119
+ | `snapRadius` | **Type:** `number`<br />**Default:** `12`<br />Snap tolerance in pixels |
104
120
 
105
121
  ```js
106
122
  createDrawPlugin({
@@ -113,66 +129,139 @@ createDrawPlugin({
113
129
 
114
130
  ## Validation
115
131
 
116
- Every geometry change — placing a vertex, dragging one, finishing a shape — is checked against a set of built-in rules before it's accepted, plus your own `onGeometryChange` callback if you provide one.
132
+ Every change is checked against the built-in rules, then against your own callbacks if you set them.
117
133
 
118
134
  ### Built-in rules
119
135
 
120
- | Rule | Applies to | Behaviour |
121
- |------|-----------|-----------|
122
- | Minimum vertices | Polygon (3), Line (2) | Gates the Done button — a shape below the minimum can't be finished |
123
- | Self-intersection | Polygon | Gates the Done button — a self-crossing shape can't be finished |
124
- | Self-intersection (placement) | Polygon | Rejects a vertex placement outright if it would make the drawn path cross itself — the vertex never appears |
125
- | Non-zero area | Polygon | Gates the Done button — a collinear/degenerate ring can't be finished |
136
+ | Rule | Description |
137
+ |------|-------------|
138
+ | Minimum vertices | A polygon needs 3 vertices and a line 2 before it can be finished |
139
+ | Self-intersection | A polygon that crosses itself can't be finished. A vertex that would make the drawn path cross itself is rejected and never placed |
140
+ | Non-zero area | A flat polygon, with all its vertices in a line, can't be finished |
141
+
142
+ While a rule fails, the shape has a dashed outline.
143
+
144
+ ### Callbacks
126
145
 
127
- Rule failures gate the Done button (the shape can pass through interim invalid states while being built or reshaped, shown with a dashed outline) except the placement-time self-intersection check, which is a hard veto — that specific vertex is rejected and never placed.
146
+ | Callback | Description |
147
+ |----------|-------------|
148
+ | [`onGeometryPreview`](#ongeometrypreviewevent) | Live checks while a shape is drawn or dragged, and before a vertex is placed. Must answer straight away |
149
+ | [`onGeometryChange`](#ongeometrychangeevent-context) | After each change. Can return a Promise. The latest result enables or disables Done |
150
+ | [`onGeometryFinish`](#ongeometryfinishevent-context) | When a shape is finished. Can return a Promise. Decides whether the shape is created, or the edit finishes |
128
151
 
129
- ### `onGeometryChange` callback
152
+ #### Setting the callbacks
130
153
 
131
- Set at the plugin level (`createDrawPlugin({ onGeometryChange })`) or per call (`newPolygon`/`newLine`/`newPoint`/`editFeature`'s `options.onGeometryChange`, which takes precedence when given). Not used by `split` (which validates that the line actually bisects the shape) or `merge`/`addFeature`/`setStyle` (no validation). For a `Point`, only the `'place'` phase applies — placing or dragging a point can be vetoed, but there's no minimum-vertices/self-intersection/area check.
154
+ Set them at plugin level, `createDrawPlugin({ onGeometryPreview, onGeometryChange, onGeometryFinish })`, or per call in the options of `newPolygon`, `newLine`, `newPoint` and `editFeature`. Each per-call callback replaces only its plugin-level equivalent for that session. The others still apply. To do more than one thing on a change, call each from one callback.
132
155
 
133
- **Signature:** `onGeometryChange(event) => boolean | { valid: boolean, reason?: string } | undefined`
156
+ They aren't used by `split`, `merge`, `addFeature` or `setStyle`.
134
157
 
135
- | Return value | Meaning |
136
- |---|---|
137
- | `true` / `undefined` | Valid |
138
- | `false` | Invalid, no reason shown |
139
- | `{ valid, reason }` | Valid or invalid, with an optional reason surfaced as a hint toast (except for placement, which never toasts — see `phase` below) |
158
+ #### What they return
140
159
 
141
- **Event payload:**
160
+ | Value | Description |
161
+ |-------|-------------|
162
+ | `true` | Valid |
163
+ | `undefined` | Valid |
164
+ | `false` | Invalid, with no reason shown |
165
+ | `result.valid` | Whether the shape is valid |
166
+ | `result.reason` | Why the shape is invalid. Shown as a hint and sent with [`draw:geometryinvalid`](#drawgeometryinvalid) |
167
+ | `result.announcement` | Read out by screen readers instead of draw's own message. When it's set, `reason` isn't shown as a hint, so you can show it yourself. From `onGeometryPreview`, it's only read out for a rejected vertex |
142
168
 
143
- | Property | Type | Description |
144
- |----------|------|-------------|
145
- | `feature` | `GeoJSON.Feature` | The shape at this point — the in-progress feature during `'preview'`, the committed/candidate feature at every other phase |
146
- | `phase` | `string` | See table below |
147
- | `mode` | `'draw_polygon' \| 'draw_line' \| 'draw_point' \| 'edit_vertex' \| 'edit_point'` | The active draw mode |
148
- | `vertexIndex` | `number` | Index of the vertex being placed/added/moved/inserted/deleted. Present on `'place'` and every `'commit-*'` phase |
149
- | `numVertices` | `number` | Count of already-committed vertices, excluding any in-progress cursor point. Present on every `'preview'` call |
169
+ #### What they receive
150
170
 
151
- **Phases:**
171
+ | Property | Description |
172
+ |----------|-------------|
173
+ | `event.feature` | The shape being checked, as a GeoJSON feature |
174
+ | `event.phase` | Why the callback was called. See each callback below |
175
+ | `event.mode` | The draw mode: `'draw_polygon'`, `'draw_line'`, `'draw_point'`, `'edit_vertex'` or `'edit_point'` |
176
+ | `event.vertexIndex` | The vertex being placed or changed. Only on `'place'`, and on a `'change'` to a single vertex |
177
+ | `event.numVertices` | How many vertices have been placed, not counting the one following the pointer. Only on `'preview'` |
178
+ | `event.detail` | The `detail` passed to [`recheckGeometry`](#recheckgeometrydetail). Only on `'recheck'` |
179
+ | `context.signal` | An `AbortSignal`, aborted when a newer check starts or the session ends. Pass it to `fetch` to cancel the request. Not passed to `onGeometryPreview` |
180
+ | `context.revision` | A number that increases with every check. Not passed to `onGeometryPreview` |
152
181
 
153
- | Phase | When | Can veto? |
154
- |-------|------|-----------|
155
- | `'preview'` | Live feedback on every rubber-band move while drawing/dragging, throttled to once per frame. Drives both the dashed-outline check and the Add-point button | No — display only |
156
- | `'place'` | A real click/tap/Add-point press, evaluated once, synchronously | Yes — a hard rule or your callback returning invalid rejects the vertex outright; it never appears |
157
- | `'create'` | A whole new feature just finished being drawn | Gates whether it's accepted as-is or reopened in edit mode |
158
- | `'edit-start'` | An existing feature was just loaded into an edit session — the baseline check before anything has changed | Gates the initial Done state |
159
- | `'commit-add'` | A vertex was added while drawing | Gates Done |
160
- | `'commit-move'` | A vertex was dragged/nudged while editing | Gates Done |
161
- | `'commit-insert'` | A vertex was inserted at a midpoint while editing | Gates Done |
162
- | `'commit-delete'` | A vertex was removed while editing | Gates Done |
182
+ #### Debouncing
183
+
184
+ Debouncing and timeouts are up to you. Waiting on `signal` gives a debounce that cancels itself when the shape changes again:
163
185
 
164
186
  ```js
187
+ const wait = (ms, signal) => new Promise((resolve, reject) => {
188
+ const timer = setTimeout(resolve, ms)
189
+ signal.addEventListener('abort', () => { clearTimeout(timer); reject(signal.reason) }, { once: true })
190
+ })
191
+
165
192
  createDrawPlugin({
166
- onGeometryChange: (event) => ({
193
+ onGeometryPreview: (event) => ({
167
194
  valid: isEastOfWalesBorder(event.feature.geometry),
168
195
  reason: 'Points must be placed east of the England/Wales border'
169
- })
196
+ }),
197
+ onGeometryChange: async ({ feature }, { signal }) => {
198
+ infoPanel.update(measureArea(feature))
199
+ await wait(300, signal)
200
+ const response = await fetch('/api/boundary-checks', { method: 'POST', body: JSON.stringify(feature), signal })
201
+ return response.json() // { valid, reason }
202
+ }
170
203
  })
171
204
  ```
172
205
 
206
+ ## `onGeometryPreview(event)`
207
+
208
+ **Signature:** `onGeometryPreview(event) => result`
209
+
210
+ Must answer straight away. A Promise counts as valid. It runs on every frame of a drag, so keep it quick.
211
+
212
+ | Phase | When |
213
+ |-------|------|
214
+ | `'preview'` | While a shape is drawn or dragged. Drives the dashed outline and the Add point button. While editing, it also enables or disables Done |
215
+ | `'place'` | Before a vertex is placed by a click, tap, <kbd>Enter</kbd> or Add point. An invalid result rejects the vertex |
216
+
217
+ Use it for rules about a single vertex, such as where the first point can go. `onGeometryChange` isn't called until the shape has its minimum number of vertices.
218
+
219
+ ## `onGeometryChange(event, context)`
220
+
221
+ **Signature:** `onGeometryChange(event, context) => result | Promise<result>`
222
+
223
+ Called after each change to a shape.
224
+
225
+ | Phase | When |
226
+ |-------|------|
227
+ | `'change'` | The shape changed, including with [`setGeometry`](#setgeometrygeometry) or undo |
228
+ | `'edit-start'` | `editFeature` opened the shape |
229
+ | `'recheck'` | [`recheckGeometry`](#recheckgeometrydetail) was called |
230
+ | `'create'` | Only without `onGeometryFinish`. A new shape was finished without a passing result, such as a new point |
231
+ | `'edit-finish'` | Only without `onGeometryFinish`, when the last result set `recheckOnFinish`. Done was pressed on an edit |
232
+
233
+ It's only called once the built-in rules pass, and only the result for the latest change counts. If it fails, throws or rejects, the shape can't be finished: call `recheckGeometry()` to retry. If the shape is finished while a check is running, draw waits for the result.
234
+
235
+ ## `onGeometryFinish(event, context)`
236
+
237
+ **Signature:** `onGeometryFinish(event, context) => result | Promise<result>`
238
+
239
+ Called when a shape is finished, to check the whole shape once. Without it, finishing uses the latest `onGeometryChange` result. If `onGeometryChange` already checks the shape with your service, you don't need `onGeometryFinish`.
240
+
241
+ | Phase | When |
242
+ |-------|------|
243
+ | `'create'` | A new shape or point was finished |
244
+ | `'edit-finish'` | Done was pressed on an edit |
245
+
246
+ Draw waits for the result. A new shape that fails reopens in edit mode ([`draw:reopened`](#drawreopened)), where Undo starts empty and Cancel discards it. An edit that fails stays open. If the latest `onGeometryChange` result failed, the shape can't be finished, so `onGeometryFinish` isn't called.
247
+
248
+ This updates a panel on every change, and validates the shape once it's finished:
249
+
250
+ ```js
251
+ createDrawPlugin({
252
+ // Returns nothing, so every change counts as valid
253
+ onGeometryChange: ({ feature }, { signal }) => {
254
+ contextPanel.update(feature, { signal })
255
+ },
256
+ onGeometryFinish: ({ feature }, { signal }) => validateWithService(feature, { signal })
257
+ })
258
+ ```
259
+
260
+ Don't `await` the panel update. `onGeometryChange` would then be pending until the panel replies, and finishing would wait for it.
261
+
173
262
  ## Methods
174
263
 
175
- Methods are called on the plugin instance. `newPolygon`, `newLine`, `newPoint`, `editFeature`, `addFeature`, `setStyle`, `deleteFeature`, `split`, and `merge` all need `mapProvider.draw` to be ready — call them after [`draw:ready`](#drawready).
264
+ Methods are called on the plugin instance. `newPolygon`, `newLine`, `newPoint`, `editFeature`, `addFeature`, `setStyle`, `deleteFeature`, `split`, `merge`, `setGeometry` and `recheckGeometry` all need `mapProvider.draw` to be ready — call them after [`draw:ready`](#drawready).
176
265
 
177
266
  ---
178
267
 
@@ -180,15 +269,17 @@ Methods are called on the plugin instance. `newPolygon`, `newLine`, `newPoint`,
180
269
 
181
270
  Start drawing a new polygon.
182
271
 
183
- | Argument | Type | Description |
184
- |----------|------|-------------|
185
- | `featureId` | `string` | **Required.** ID to assign the finished feature |
186
- | `options.snapLayers` | `string[]` | Overrides the plugin-level `snapLayers` for this session |
187
- | `options.onGeometryChange` | `Function` | Overrides the plugin-level `onGeometryChange` for this session — see [Validation](#validation) |
188
- | `options.stroke` | `string \| Record<string, string>` | Stroke colour for this shape |
189
- | `options.fill` | `string \| Record<string, string>` | Fill colour for this shape |
190
- | `options.strokeWidth` | `number` | Stroke width in pixels for this shape |
191
- | `options.properties` | `Object` | Custom GeoJSON properties to set on the finished feature |
272
+ | Argument | Description |
273
+ |----------|-------------|
274
+ | `featureId` | **Type:** `string`<br />**Required**<br />ID to assign the finished feature |
275
+ | `options.snapLayers` | **Type:** `string[]`<br />Overrides the plugin-level `snapLayers` for this session |
276
+ | `options.onGeometryPreview` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryPreview` for this session — see [Validation](#validation) |
277
+ | `options.onGeometryChange` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryChange` for this session — see [Validation](#validation) |
278
+ | `options.onGeometryFinish` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryFinish` for this session — see [Validation](#validation) |
279
+ | `options.stroke` | **Type:** `string \| Record<string, string>`<br />Stroke colour for this shape |
280
+ | `options.fill` | **Type:** `string \| Record<string, string>`<br />Fill colour for this shape |
281
+ | `options.strokeWidth` | **Type:** `number`<br />Stroke width in pixels for this shape |
282
+ | `options.properties` | **Type:** `Object`<br />Custom GeoJSON properties to set on the finished feature |
192
283
 
193
284
  ```js
194
285
  drawPlugin.newPolygon(crypto.randomUUID(), {
@@ -216,21 +307,23 @@ drawPlugin.newLine(crypto.randomUUID(), {
216
307
 
217
308
  Start drawing a new point. Unlike `newPolygon`/`newLine`, it commits as soon as a point is placed — there's no Done step.
218
309
 
219
- | Argument | Type | Description |
220
- |----------|------|-------------|
221
- | `featureId` | `string` | **Required.** ID to assign the finished feature |
222
- | `options.snapLayers` | `string[]` | Overrides the plugin-level `snapLayers` for this session |
223
- | `options.onGeometryChange` | `Function` | Overrides the plugin-level `onGeometryChange` for this session — see [Validation](#validation) |
224
- | `options.properties` | `Object` | Custom GeoJSON properties to set on the finished feature |
225
- | `options.symbol` | `string` | Built-in symbol id — `'pin'`, `'circle'`, `'square'`, `'hexagon'`, `'triangle'`, or `'diamond'` |
226
- | `options.symbolSvgContent` | `string` | Custom SVG markup, used instead of `symbol` |
227
- | `options.symbolBackgroundColor` | `string \| Record<string, string>` | Symbol background colour |
228
- | `options.symbolForegroundColor` | `string \| Record<string, string>` | Symbol foreground colour |
229
- | `options.symbolGraphic` | `string` | Overrides the symbol's inner graphic (built-in name or SVG path data) |
230
- | `options.symbolHaloWidth` | `number` | Symbol halo width |
231
- | `options.symbolViewBox` | `string` | SVG `viewBox`, for use with `symbolSvgContent` |
232
- | `options.symbolAnchor` | `[number, number]` | Normalised `[x, y]` anchor point |
233
- | `options.symbolSize` | `'small' \| 'medium' \| 'large'` | Symbol size — see [Symbol Config](../api/symbol-config.md#size) |
310
+ | Argument | Description |
311
+ |----------|-------------|
312
+ | `featureId` | **Type:** `string`<br />**Required**<br />ID to assign the finished feature |
313
+ | `options.snapLayers` | **Type:** `string[]`<br />Overrides the plugin-level `snapLayers` for this session |
314
+ | `options.onGeometryPreview` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryPreview` for this session — see [Validation](#validation) |
315
+ | `options.onGeometryChange` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryChange` for this session — see [Validation](#validation) |
316
+ | `options.onGeometryFinish` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryFinish` for this session — see [Validation](#validation) |
317
+ | `options.properties` | **Type:** `Object`<br />Custom GeoJSON properties to set on the finished feature |
318
+ | `options.symbol` | **Type:** `string`<br />Built-in symbol id — `'pin'`, `'circle'`, `'square'`, `'hexagon'`, `'triangle'`, or `'diamond'` |
319
+ | `options.symbolSvgContent` | **Type:** `string`<br />Custom SVG markup, used instead of `symbol` |
320
+ | `options.symbolBackgroundColor` | **Type:** `string \| Record<string, string>`<br />Symbol background colour |
321
+ | `options.symbolForegroundColor` | **Type:** `string \| Record<string, string>`<br />Symbol foreground colour |
322
+ | `options.symbolGraphic` | **Type:** `string`<br />Overrides the symbol's inner graphic (built-in name or SVG path data) |
323
+ | `options.symbolHaloWidth` | **Type:** `number`<br />Symbol halo width |
324
+ | `options.symbolViewBox` | **Type:** `string`<br />SVG `viewBox`, for use with `symbolSvgContent` |
325
+ | `options.symbolAnchor` | **Type:** `[number, number]`<br />Normalised `[x, y]` anchor point |
326
+ | `options.symbolSize` | **Type:** `'small' \| 'medium' \| 'large'`<br />Symbol size — see [Symbol Config](../api/symbol-config.md#size) |
234
327
 
235
328
  These mirror [MarkerOptions](../api/marker-config.md#markeroptions)' `symbol`-family properties (prefixed with `symbol` here to sit alongside other feature properties) — see [Symbol Config](../api/symbol-config.md) for the full resolution order and SVG token structure. Points with no symbol config render with the plugin's default marker.
236
329
 
@@ -247,11 +340,13 @@ drawPlugin.newPoint(crypto.randomUUID(), {
247
340
 
248
341
  Open an existing feature in edit mode — vertex-edit for a `Polygon`/`LineString`, single-coordinate drag for a `Point`. Returns `false` (without doing anything) if the feature doesn't exist or the plugin isn't ready yet — check the return value before assuming the edit session started.
249
342
 
250
- | Argument | Type | Description |
251
- |----------|------|-------------|
252
- | `featureId` | `string` | **Required.** ID of the feature to edit |
253
- | `options.snapLayers` | `string[]` | Overrides the plugin-level `snapLayers` for this session |
254
- | `options.onGeometryChange` | `Function` | Overrides the plugin-level `onGeometryChange` for this session |
343
+ | Argument | Description |
344
+ |----------|-------------|
345
+ | `featureId` | **Type:** `string`<br />**Required**<br />ID of the feature to edit |
346
+ | `options.snapLayers` | **Type:** `string[]`<br />Overrides the plugin-level `snapLayers` for this session |
347
+ | `options.onGeometryPreview` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryPreview` for this session — see [Validation](#validation) |
348
+ | `options.onGeometryChange` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryChange` for this session — see [Validation](#validation) |
349
+ | `options.onGeometryFinish` | **Type:** `Function`<br />Replaces the plugin-level `onGeometryFinish` for this session — see [Validation](#validation) |
255
350
 
256
351
  ```js
257
352
  const editSuccess = drawPlugin.editFeature(selectedFeatureId)
@@ -266,15 +361,15 @@ if (!editSuccess) {
266
361
 
267
362
  Add a `Point`, `LineString`, or `Polygon` feature directly to the map without a draw session — e.g. loading in existing shapes on `draw:ready`.
268
363
 
269
- | Argument | Type | Description |
270
- |----------|------|-------------|
271
- | `feature.id` | `string` | **Required.** Feature ID |
272
- | `feature.type` | `string` | Defaults to `'Feature'` if omitted |
273
- | `feature.geometry` | `GeoJSON.Geometry` | **Required.** `Point`, `LineString`, or `Polygon` geometry |
274
- | `feature.stroke` | `string \| Record<string, string>` | Stroke colour (`LineString`/`Polygon`) |
275
- | `feature.fill` | `string \| Record<string, string>` | Fill colour (`Polygon`) |
276
- | `feature.strokeWidth` | `number` | Stroke width in pixels (`LineString`/`Polygon`) |
277
- | `feature.properties` | `Object` | Custom GeoJSON properties — a `Point`'s `symbol`-family properties go here (see `newPoint` above) |
364
+ | Argument | Description |
365
+ |----------|-------------|
366
+ | `feature.id` | **Type:** `string`<br />**Required**<br />Feature ID |
367
+ | `feature.type` | **Type:** `string`<br />Defaults to `'Feature'` if omitted |
368
+ | `feature.geometry` | **Type:** `GeoJSON.Geometry`<br />**Required**<br />`Point`, `LineString`, or `Polygon` geometry |
369
+ | `feature.stroke` | **Type:** `string \| Record<string, string>`<br />Stroke colour (`LineString`/`Polygon`) |
370
+ | `feature.fill` | **Type:** `string \| Record<string, string>`<br />Fill colour (`Polygon`) |
371
+ | `feature.strokeWidth` | **Type:** `number`<br />Stroke width in pixels (`LineString`/`Polygon`) |
372
+ | `feature.properties` | **Type:** `Object`<br />Custom GeoJSON properties — a `Point`'s `symbol`-family properties go here (see `newPoint` above) |
278
373
 
279
374
  A feature with a missing/unsupported `geometry.type` or no `geometry.coordinates` is logged as a warning and ignored.
280
375
 
@@ -304,10 +399,10 @@ interactiveMap.on('draw:ready', () => {
304
399
 
305
400
  Update an existing feature's style — stroke/fill/strokeWidth or, for a `Point`, its `symbol`-family properties (see `newPoint` above). Only the keys you pass are changed; anything else the feature already has is left alone. Returns `false` if the feature doesn't exist.
306
401
 
307
- | Argument | Type | Description |
308
- |----------|------|-------------|
309
- | `featureId` | `string` | **Required.** ID of the feature to update |
310
- | `styleChanges` | `Object` | **Required.** Any mix of `stroke`, `fill`, `strokeWidth`, or `symbol`-family properties |
402
+ | Argument | Description |
403
+ |----------|-------------|
404
+ | `featureId` | **Type:** `string`<br />**Required**<br />ID of the feature to update |
405
+ | `styleChanges` | **Type:** `Object`<br />**Required**<br />Any mix of `stroke`, `fill`, `strokeWidth`, or `symbol`-family properties |
311
406
 
312
407
  ```js
313
408
  drawPlugin.setStyle('monument1', { symbolBackgroundColor: { outdoor: '#1d70b8', dark: '#4c9ed9' } })
@@ -319,9 +414,9 @@ drawPlugin.setStyle('monument1', { symbolBackgroundColor: { outdoor: '#1d70b8',
319
414
 
320
415
  Remove one or more features from the map.
321
416
 
322
- | Argument | Type | Description |
323
- |----------|------|-------------|
324
- | `featureIds` | `string[]` | IDs of the features to remove |
417
+ | Argument | Description |
418
+ |----------|-------------|
419
+ | `featureIds` | **Type:** `string[]`<br />IDs of the features to remove |
325
420
 
326
421
  ```js
327
422
  drawPlugin.deleteFeature(['test1234'])
@@ -335,10 +430,10 @@ Start drawing a line across a polygon to split it in two. Splitting is a pure co
335
430
 
336
431
  Always snaps to the polygon's own outline, in addition to any layers in `snapLayers`.
337
432
 
338
- | Argument | Type | Description |
339
- |----------|------|-------------|
340
- | `featureId` | `string` | **Required.** ID of the polygon to split |
341
- | `options.snapLayers` | `string[]` | Additional layers to snap against, on top of the polygon's own outline |
433
+ | Argument | Description |
434
+ |----------|-------------|
435
+ | `featureId` | **Type:** `string`<br />**Required**<br />ID of the polygon to split |
436
+ | `options.snapLayers` | **Type:** `string[]`<br />Additional layers to snap against, on top of the polygon's own outline |
342
437
 
343
438
  ```js
344
439
  drawPlugin.split(selectedFeatureId)
@@ -362,9 +457,9 @@ interactiveMap.on('draw:split', (event) => {
362
457
 
363
458
  Merge multiple contiguous polygons into one. Like `split`, this is a pure computation — it does not touch the map. Listen for the return value or [`draw:merge`](#drawmerge) and call `deleteFeature`/`addFeature` yourself.
364
459
 
365
- | Argument | Type | Description |
366
- |----------|------|-------------|
367
- | `featureIds` | `string[]` | IDs of the polygons to merge |
460
+ | Argument | Description |
461
+ |----------|-------------|
462
+ | `featureIds` | **Type:** `string[]`<br />IDs of the polygons to merge |
368
463
 
369
464
  **Returns:** the merged GeoJSON feature, or `null` if the merge failed (e.g. the polygons aren't actually contiguous).
370
465
 
@@ -382,6 +477,55 @@ interactiveMap.on('draw:merge', (event) => {
382
477
  })
383
478
  ```
384
479
 
480
+ ---
481
+
482
+ ### `setGeometry(geometry)`
483
+
484
+ Replace the shape in the current edit session, for example with a corrected boundary from a service. The change can be undone, and is checked like any other change, with phase `'change'`. Returns `false` (without doing anything) outside an edit session, or when the geometry type differs from the shape being edited.
485
+
486
+ | Argument | Description |
487
+ |----------|-------------|
488
+ | `geometry` | **Type:** `GeoJSON.Geometry`<br />**Required**<br />The new geometry, of the same type as the shape being edited |
489
+
490
+ ```js
491
+ drawPlugin.setGeometry(correctedBoundary)
492
+ ```
493
+
494
+ ---
495
+
496
+ ### `recheckGeometry(detail?)`
497
+
498
+ Call `onGeometryChange` again for the current shape, unchanged, with phase `'recheck'`. Use it when your answer may have changed without the shape changing — for example after the user chooses to ignore a warning — or to retry a check that failed. Returns `false` (without doing anything) outside a draw or edit session, or before the shape has been checked.
499
+
500
+ | Argument | Description |
501
+ |----------|-------------|
502
+ | `detail` | **Type:** `any`<br />Passed to `onGeometryChange` as `event.detail`, for example to tell an ignored warning from a retry |
503
+
504
+ ```js
505
+ const ignoredWarnings = new Set()
506
+
507
+ let warnings = []
508
+
509
+ createDrawPlugin({
510
+ onGeometryChange: async ({ feature, detail }, { signal }) => {
511
+ // Ignoring a warning reuses the last answer; anything else, including a retry, asks again
512
+ if (detail?.reason !== 'ignore') {
513
+ warnings = await checkBoundary(feature, { signal })
514
+ }
515
+ return { valid: warnings.every((warning) => ignoredWarnings.has(warning.id)) }
516
+ }
517
+ })
518
+
519
+ const onIgnoreWarning = (warning) => {
520
+ ignoredWarnings.add(warning.id)
521
+ drawPlugin.recheckGeometry({ reason: 'ignore' })
522
+ }
523
+
524
+ const onRetry = () => drawPlugin.recheckGeometry({ reason: 'retry' })
525
+ ```
526
+
527
+ ---
528
+
385
529
  ## Application mode
386
530
 
387
531
  While drawing or editing, the plugin sets the `'draw'` [application mode](../api.md#setapplicationmodeid-options), which gives the interface over to drawing: every button, panel and control, in every slot, is hidden except draw's own and these defaults:
@@ -447,7 +591,12 @@ Emitted once the draw plugin has initialised. Safe to call API methods from here
447
591
 
448
592
  Emitted when `newPolygon`, `newLine`, or `newPoint` starts a new draw session.
449
593
 
450
- **Payload:** `{ mode: 'draw_polygon' | 'draw_line' | 'draw_point' }`
594
+ **Payload:**
595
+
596
+ | Property | Description |
597
+ |----------|-------------|
598
+ | `payload.mode` | **Type:** `'draw_polygon' \| 'draw_line' \| 'draw_point'`<br />The draw mode |
599
+ | `payload.featureId` | **Type:** `string`<br />ID of the new feature |
451
600
 
452
601
  ---
453
602
 
@@ -455,13 +604,18 @@ Emitted when `newPolygon`, `newLine`, or `newPoint` starts a new draw session.
455
604
 
456
605
  Emitted when `editFeature` opens an existing feature for editing.
457
606
 
458
- **Payload:** `{ mode: 'edit_polygon' | 'edit_line' | 'edit_point' }`
607
+ **Payload:**
608
+
609
+ | Property | Description |
610
+ |----------|-------------|
611
+ | `payload.mode` | **Type:** `'edit_polygon' \| 'edit_line' \| 'edit_point'`<br />The kind of shape being edited |
612
+ | `payload.featureId` | **Type:** `string`<br />ID of the feature being edited |
459
613
 
460
614
  ---
461
615
 
462
616
  ### `draw:created`
463
617
 
464
- Emitted when a new shape finishes drawing and passes validation. Also fires for a shape that finished invalid, was automatically reopened in edit mode, and was then fixed and finished — from the caller's perspective it's still a creation, not an edit.
618
+ Emitted when a new shape finishes drawing and passes its checks. Also fires for a shape that finished invalid, was automatically reopened in edit mode, and was then fixed and finished — from the caller's perspective it's still a creation, not an edit.
465
619
 
466
620
  **Payload:** the finished `GeoJSON.Feature`
467
621
 
@@ -475,9 +629,23 @@ Emitted when an existing feature finishes an edit session (via `editFeature`).
475
629
 
476
630
  ---
477
631
 
632
+ ### `draw:reopened`
633
+
634
+ Emitted when a new shape is finished, its check fails, and it reopens in edit mode. See [Validation](#validation).
635
+
636
+ **Payload:**
637
+
638
+ | Property | Description |
639
+ |----------|-------------|
640
+ | `payload.feature` | **Type:** `GeoJSON.Feature`<br />The reopened shape |
641
+ | `payload.status` | **Type:** `'invalid' \| 'error'`<br />`'invalid'` if the check failed, `'error'` if it threw or rejected |
642
+ | `payload.reason` | **Type:** `string \| null`<br />Why the check failed, or `null` if the result gave no reason |
643
+
644
+ ---
645
+
478
646
  ### `draw:cancelled`
479
647
 
480
- Emitted when the Cancel button is pressed during a draw or edit session.
648
+ Emitted when the Cancel button is pressed during a draw or edit session. Cancelling a new shape that's waiting on its check, or has reopened in edit mode, removes it from the map. Also emitted when a new session starts while a finished shape is still waiting on its check, which discards it.
481
649
 
482
650
  **Payload:** the feature being drawn/edited at the time of cancellation
483
651
 
@@ -485,7 +653,7 @@ Emitted when the Cancel button is pressed during a draw or edit session.
485
653
 
486
654
  ### `draw:updated`
487
655
 
488
- Emitted after a committed vertex operation (add/move/insert/delete) while editing.
656
+ Emitted after a committed vertex operation (add/move/insert/delete) while editing. It isn't emitted while a new shape is being drawn. To keep a panel up to date while drawing and editing, use [`onGeometryChange`](#ongeometrychangeevent-context).
489
657
 
490
658
  **Payload:** the updated `GeoJSON.Feature`
491
659
 
@@ -495,7 +663,12 @@ Emitted after a committed vertex operation (add/move/insert/delete) while editin
495
663
 
496
664
  Emitted when the selected vertex changes in edit mode.
497
665
 
498
- **Payload:** `{ index: number, numVertices: number }` — `index` is `-1` when nothing is selected
666
+ **Payload:**
667
+
668
+ | Property | Description |
669
+ |----------|-------------|
670
+ | `payload.index` | **Type:** `number`<br />The selected vertex, or `-1` when nothing is selected |
671
+ | `payload.numVertices` | **Type:** `number`<br />How many vertices the shape has |
499
672
 
500
673
  ---
501
674
 
@@ -503,15 +676,28 @@ Emitted when the selected vertex changes in edit mode.
503
676
 
504
677
  Emitted when the input device changes mid-session (e.g. switching from mouse to touch and panning via the Move control) — sync your own `interfaceType` state from this if you're tracking it independently.
505
678
 
506
- **Payload:** `{ interfaceType: 'mouse' | 'touch' | 'keyboard' }`
679
+ **Payload:**
680
+
681
+ | Property | Description |
682
+ |----------|-------------|
683
+ | `payload.interfaceType` | **Type:** `'mouse' \| 'touch' \| 'keyboard'`<br />The input device now in use |
507
684
 
508
685
  ---
509
686
 
510
687
  ### `draw:geometryinvalid`
511
688
 
512
- Emitted whenever a validation check — a built-in rule or your `onGeometryChange` callback — fails, alongside the same hint toast shown to the user (skipped only for an in-progress shape that simply hasn't reached its minimum vertex count yet). See [Validation](#validation).
689
+ Emitted whenever a check — a built-in rule, a placement rejected by `onGeometryPreview`, or an invalid result from `onGeometryChange` for the latest change — fails. Not emitted for the `'edit-start'` check of a feature that was already invalid. The `reason` is also shown as a hint toast, unless the result has its own `announcement`, or the shape simply hasn't reached its minimum vertex count yet. See [Validation](#validation).
513
690
 
514
- **Payload:** `{ feature, reason, phase, mode, vertexIndex? }`
691
+ **Payload:**
692
+
693
+ | Property | Description |
694
+ |----------|-------------|
695
+ | `payload.feature` | **Type:** `GeoJSON.Feature`<br />The shape that failed the check |
696
+ | `payload.reason` | **Type:** `string`<br />Why the check failed |
697
+ | `payload.source` | **Type:** `'rules' \| 'callback'`<br />`'rules'` for a built-in rule, `'callback'` for `onGeometryPreview`, `onGeometryChange` or `onGeometryFinish` |
698
+ | `payload.phase` | **Type:** `string`<br />The phase of the check that failed. See [Validation](#validation) |
699
+ | `payload.mode` | **Type:** `string`<br />The draw mode |
700
+ | `payload.vertexIndex` | **Type:** `number`<br />The vertex involved, when there is one |
515
701
 
516
702
  ---
517
703
 
@@ -527,7 +713,11 @@ Emitted after `addFeature` adds a feature to the map.
527
713
 
528
714
  Emitted after `deleteFeature` removes a feature.
529
715
 
530
- **Payload:** `{ featureId: string }`
716
+ **Payload:**
717
+
718
+ | Property | Description |
719
+ |----------|-------------|
720
+ | `payload.featureId` | **Type:** `string[]`<br />The IDs passed to `deleteFeature` |
531
721
 
532
722
  ---
533
723
 
@@ -535,7 +725,12 @@ Emitted after `deleteFeature` removes a feature.
535
725
 
536
726
  Emitted after `setStyle` updates a feature's style.
537
727
 
538
- **Payload:** `{ featureId: string, properties: Object }` — the flattened style/symbol properties that were applied
728
+ **Payload:**
729
+
730
+ | Property | Description |
731
+ |----------|-------------|
732
+ | `payload.featureId` | **Type:** `string`<br />ID of the updated feature |
733
+ | `payload.properties` | **Type:** `Object`<br />The style and symbol properties that were applied |
539
734
 
540
735
  ---
541
736
 
@@ -543,7 +738,12 @@ Emitted after `setStyle` updates a feature's style.
543
738
 
544
739
  Emitted when `split` computes a successful split.
545
740
 
546
- **Payload:** `{ originalFeatureId: string, featureCollection: GeoJSON.FeatureCollection }` — the two resulting polygons
741
+ **Payload:**
742
+
743
+ | Property | Description |
744
+ |----------|-------------|
745
+ | `payload.originalFeatureId` | **Type:** `string`<br />ID of the polygon that was split |
746
+ | `payload.featureCollection` | **Type:** `GeoJSON.FeatureCollection`<br />The two resulting polygons |
547
747
 
548
748
  ---
549
749
 
@@ -551,7 +751,12 @@ Emitted when `split` computes a successful split.
551
751
 
552
752
  Emitted when `merge` computes a successful merge.
553
753
 
554
- **Payload:** `{ originalFeatureIds: string[], feature: GeoJSON.Feature }` — the single merged polygon
754
+ **Payload:**
755
+
756
+ | Property | Description |
757
+ |----------|-------------|
758
+ | `payload.originalFeatureIds` | **Type:** `string[]`<br />IDs of the polygons that were merged |
759
+ | `payload.feature` | **Type:** `GeoJSON.Feature`<br />The merged polygon |
555
760
 
556
761
  ```js
557
762
  interactiveMap.on('draw:created', (feature) => {