@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.
- package/dist/esm/im-core.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/button-definition.md +11 -0
- package/docs/api/context.md +2 -0
- package/docs/api.md +3 -1
- package/docs/assets/css/docusaurus.scss +7 -1
- package/docs/plugins/draw.md +326 -121
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +6 -17
- package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +3 -43
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +9 -6
- package/plugins/draw/src/DrawInit.test.jsx +15 -0
- package/plugins/draw/src/adapterEvents.js +82 -44
- package/plugins/draw/src/adapters/adapterContract.test.js +3 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +18 -10
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +31 -22
- package/plugins/draw/src/adapters/maplibre/drawEvents.js +2 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +13 -12
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +5 -5
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +2 -2
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +6 -9
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +4 -4
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +6 -9
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +8 -14
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +37 -8
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +11 -1
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +14 -19
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +41 -4
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +12 -1
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +3 -1
- package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +9 -10
- package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +5 -24
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -7
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +12 -7
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +5 -0
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +7 -3
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +11 -11
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +15 -15
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +21 -28
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +26 -5
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +5 -6
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +2 -12
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +9 -0
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +7 -0
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +6 -9
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +3 -3
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +18 -9
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +29 -4
- package/plugins/draw/src/adapters/openlayers/point/pointOps.js +3 -2
- package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +6 -0
- package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +3 -4
- package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +2 -12
- package/plugins/draw/src/api/createNewShape.js +4 -4
- package/plugins/draw/src/api/createNewShape.test.js +1 -1
- package/plugins/draw/src/api/editFeature.js +8 -11
- package/plugins/draw/src/api/editFeature.test.js +33 -22
- package/plugins/draw/src/api/newLine.test.js +3 -3
- package/plugins/draw/src/api/newPoint.js +4 -5
- package/plugins/draw/src/api/newPoint.test.js +11 -3
- package/plugins/draw/src/api/newPolygon.test.js +11 -3
- package/plugins/draw/src/api/recheckGeometry.js +32 -0
- package/plugins/draw/src/api/recheckGeometry.test.js +55 -0
- package/plugins/draw/src/api/setGeometry.js +33 -0
- package/plugins/draw/src/api/setGeometry.test.js +48 -0
- package/plugins/draw/src/api/split.js +26 -22
- package/plugins/draw/src/api/split.test.js +38 -18
- package/plugins/draw/src/events.js +269 -77
- package/plugins/draw/src/events.test.js +779 -34
- package/plugins/draw/src/hooks/useSpatialList.js +10 -11
- package/plugins/draw/src/hooks/useSpatialList.test.js +3 -3
- package/plugins/draw/src/manifest.js +30 -15
- package/plugins/draw/src/manifest.test.js +91 -9
- package/plugins/draw/src/reducer.js +31 -9
- package/plugins/draw/src/reducer.test.js +35 -3
- package/plugins/draw/src/utils/drawModes.js +27 -0
- package/plugins/draw/src/utils/drawModes.test.js +27 -0
- package/plugins/draw/src/utils/needsDrawTarget.js +1 -5
- package/plugins/draw/src/utils/needsDrawTarget.test.js +1 -11
- package/plugins/draw/src/utils/touchTarget.js +34 -26
- package/plugins/draw/src/utils/touchTarget.test.js +32 -20
- package/plugins/draw/src/validation/commitChecks.js +187 -0
- package/plugins/draw/src/validation/commitChecks.test.js +209 -0
- package/plugins/draw/src/validation/liveDrawChecks.js +11 -11
- package/plugins/draw/src/validation/liveDrawChecks.test.js +37 -37
- package/plugins/draw/src/validation/liveStroke.js +6 -6
- package/plugins/draw/src/validation/liveStroke.test.js +27 -27
- package/plugins/draw/src/validation/rules.js +16 -14
- package/plugins/draw/src/validation/rules.test.js +5 -5
- package/plugins/draw/src/validation/validateGeometry.js +58 -31
- package/plugins/draw/src/validation/validateGeometry.test.js +68 -44
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/interact/src/hooks/useInteractionHandlers.js +3 -5
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +4 -3
- package/plugins/interact/src/hooks/useSpatialList.js +16 -17
- package/plugins/interact/src/hooks/useSpatialList.test.js +9 -9
- package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/map-styles/src/MapStyles.jsx +2 -2
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +11 -2
- package/providers/maplibre/src/index.test.js +23 -1
- package/providers/maplibre/src/utils/detectModuleWorker.js +8 -19
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +19 -23
- package/providers/maplibre/src/utils/workerUrl.js +12 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -1
- package/src/App/components/MapButton/MapButton.jsx +6 -0
- package/src/App/components/MapButton/MapButton.test.jsx +10 -0
- package/src/App/components/Markers/Markers.jsx +3 -5
- package/src/App/components/Markers/Markers.test.jsx +9 -11
- package/src/App/components/Panel/Panel.jsx +2 -9
- package/src/App/hooks/useInterfaceAPI.js +16 -4
- package/src/App/hooks/useInterfaceAPI.test.js +66 -1
- package/src/App/renderer/mapButtons.js +2 -1
- package/src/App/renderer/mapButtons.test.js +9 -0
- package/src/App/store/MapProvider.jsx +3 -0
- package/src/App/store/MapProvider.test.jsx +24 -0
- package/src/config/mapSizeScales.js +3 -0
- package/src/types.js +4 -0
- package/src/utils/focusAfterPanelClose.js +9 -0
- package/src/utils/focusAfterPanelClose.test.js +40 -0
package/docs/plugins/draw.md
CHANGED
|
@@ -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
|
|
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 |
|
|
88
|
-
|
|
89
|
-
| `shapeStroke` | `string \| Record<string, string
|
|
90
|
-
| `shapeFill` | `string \| Record<string, string
|
|
91
|
-
| `strokeWidth` | `number`
|
|
92
|
-
| `editStroke` | `string \| Record<string, string
|
|
93
|
-
| `editFill` | `string \| Record<string, string
|
|
94
|
-
| `editVertex` | `string \| Record<string, string
|
|
95
|
-
| `editMidpoint` | `string \| Record<string, string
|
|
96
|
-
| `editActive` | `string \| Record<string, string
|
|
97
|
-
| `editHalo` | `string \| Record<string, string
|
|
98
|
-
| `invalidStroke` | `string \| Record<string, string
|
|
99
|
-
| `splitValid` | `string \| Record<string, string
|
|
100
|
-
| `splitInvalid` | `string \| Record<string, string
|
|
101
|
-
| `snapVertex` | `string \| Record<string, string
|
|
102
|
-
| `snapEdge` | `string \| Record<string, string
|
|
103
|
-
| `snapRadius` | `number`
|
|
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
|
|
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 |
|
|
121
|
-
|
|
122
|
-
| Minimum vertices |
|
|
123
|
-
| Self-intersection |
|
|
124
|
-
|
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
152
|
+
#### Setting the callbacks
|
|
130
153
|
|
|
131
|
-
Set at
|
|
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
|
-
|
|
156
|
+
They aren't used by `split`, `merge`, `addFeature` or `setStyle`.
|
|
134
157
|
|
|
135
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
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 `
|
|
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 |
|
|
184
|
-
|
|
185
|
-
| `featureId` | `string
|
|
186
|
-
| `options.snapLayers` | `string[]
|
|
187
|
-
| `options.
|
|
188
|
-
| `options.
|
|
189
|
-
| `options.
|
|
190
|
-
| `options.
|
|
191
|
-
| `options.
|
|
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 |
|
|
220
|
-
|
|
221
|
-
| `featureId` | `string
|
|
222
|
-
| `options.snapLayers` | `string[]
|
|
223
|
-
| `options.
|
|
224
|
-
| `options.
|
|
225
|
-
| `options.
|
|
226
|
-
| `options.
|
|
227
|
-
| `options.
|
|
228
|
-
| `options.
|
|
229
|
-
| `options.
|
|
230
|
-
| `options.
|
|
231
|
-
| `options.
|
|
232
|
-
| `options.
|
|
233
|
-
| `options.
|
|
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 |
|
|
251
|
-
|
|
252
|
-
| `featureId` | `string
|
|
253
|
-
| `options.snapLayers` | `string[]
|
|
254
|
-
| `options.
|
|
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 |
|
|
270
|
-
|
|
271
|
-
| `feature.id` | `string
|
|
272
|
-
| `feature.type` | `string
|
|
273
|
-
| `feature.geometry` | `GeoJSON.Geometry
|
|
274
|
-
| `feature.stroke` | `string \| Record<string, string
|
|
275
|
-
| `feature.fill` | `string \| Record<string, string
|
|
276
|
-
| `feature.strokeWidth` | `number
|
|
277
|
-
| `feature.properties` | `Object
|
|
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 |
|
|
308
|
-
|
|
309
|
-
| `featureId` | `string
|
|
310
|
-
| `styleChanges` | `Object
|
|
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 |
|
|
323
|
-
|
|
324
|
-
| `featureIds` | `string[]
|
|
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 |
|
|
339
|
-
|
|
340
|
-
| `featureId` | `string
|
|
341
|
-
| `options.snapLayers` | `string[]
|
|
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 |
|
|
366
|
-
|
|
367
|
-
| `featureIds` | `string[]
|
|
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:**
|
|
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:**
|
|
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
|
|
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:**
|
|
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:**
|
|
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
|
|
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:**
|
|
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:**
|
|
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:**
|
|
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:**
|
|
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:**
|
|
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) => {
|