@defra/interactive-map 0.0.56-alpha → 0.0.57-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/plugins/draw.md +189 -33
- 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 +78 -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 +3 -3
- package/plugins/draw/src/api/newPolygon.test.js +3 -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 +23 -22
- package/plugins/draw/src/api/split.test.js +33 -18
- package/plugins/draw/src/events.js +265 -77
- package/plugins/draw/src/events.test.js +708 -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 +185 -0
- package/plugins/draw/src/validation/commitChecks.test.js +205 -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
|
@@ -175,6 +175,11 @@ export class OLDrawManager {
|
|
|
175
175
|
this._modeInstance?.insertVertexAtMidpoint?.(index)
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
// Replaces the edited shape as one undoable commit. Only the edit modes implement it.
|
|
179
|
+
setGeometry (geometry) {
|
|
180
|
+
this._modeInstance?.setGeometry?.(geometry)
|
|
181
|
+
}
|
|
182
|
+
|
|
178
183
|
// Show/hide the dashed invalid stroke on the active draw sketch or edit feature.
|
|
179
184
|
setInvalid (invalid) {
|
|
180
185
|
this._modeInstance?.setInvalid?.(invalid)
|
|
@@ -29,7 +29,8 @@ jest.mock('../edit/EditMode.js', () => ({
|
|
|
29
29
|
setInvalid: jest.fn(),
|
|
30
30
|
getVertexItems: jest.fn(() => ({ vertices: [[0, 0]], midpoints: [] })),
|
|
31
31
|
selectVertex: jest.fn(),
|
|
32
|
-
insertVertexAtMidpoint: jest.fn()
|
|
32
|
+
insertVertexAtMidpoint: jest.fn(),
|
|
33
|
+
setGeometry: jest.fn()
|
|
33
34
|
}))
|
|
34
35
|
}))
|
|
35
36
|
jest.mock('../point/editPointMode.js', () => ({
|
|
@@ -144,7 +145,7 @@ describe('mode machine', () => {
|
|
|
144
145
|
manager.done(); manager.undo(); manager.deleteVertex(); manager.nudgeSelectedVertex(1, 0, true); manager.setInterfaceType('touch'); manager.setInvalid(true) // no mode — no throw
|
|
145
146
|
manager.setDrawingPreviewProperty('splitter', 'valid') // no mode — no throw
|
|
146
147
|
expect(manager.getVertexItems()).toEqual({ vertices: [], midpoints: [] }) // no mode — safe default
|
|
147
|
-
manager.selectVertex(1); manager.insertVertexAtMidpoint(1) // no mode — no throw
|
|
148
|
+
manager.selectVertex(1); manager.insertVertexAtMidpoint(1); manager.setGeometry({}) // no mode — no throw
|
|
148
149
|
|
|
149
150
|
manager.changeMode('draw_polygon')
|
|
150
151
|
const instance = createDrawMode.mock.results[0].value
|
|
@@ -172,7 +173,7 @@ describe('mode machine', () => {
|
|
|
172
173
|
expect(manager.getMode()).toBe('disabled')
|
|
173
174
|
})
|
|
174
175
|
|
|
175
|
-
test('getVertexItems/selectVertex/insertVertexAtMidpoint delegate to the edit_vertex mode instance', () => {
|
|
176
|
+
test('getVertexItems/selectVertex/insertVertexAtMidpoint/setGeometry delegate to the edit_vertex mode instance', () => {
|
|
176
177
|
const { manager } = setup()
|
|
177
178
|
manager.changeMode('edit_vertex', { featureId: 'f1' })
|
|
178
179
|
const instance = createEditMode.mock.results[0].value
|
|
@@ -180,8 +181,11 @@ describe('mode machine', () => {
|
|
|
180
181
|
expect(manager.getVertexItems()).toEqual({ vertices: [[0, 0]], midpoints: [] })
|
|
181
182
|
manager.selectVertex(2)
|
|
182
183
|
manager.insertVertexAtMidpoint(3)
|
|
184
|
+
const geometry = { type: 'Polygon', coordinates: [] }
|
|
185
|
+
manager.setGeometry(geometry)
|
|
183
186
|
expect(instance.selectVertex).toHaveBeenCalledWith(2)
|
|
184
187
|
expect(instance.insertVertexAtMidpoint).toHaveBeenCalledWith(3)
|
|
188
|
+
expect(instance.setGeometry).toHaveBeenCalledWith(geometry)
|
|
185
189
|
})
|
|
186
190
|
})
|
|
187
191
|
|
|
@@ -3,7 +3,7 @@ import { noModifierKeys } from 'ol/events/condition.js'
|
|
|
3
3
|
import { createDrawInput } from './drawInput.js'
|
|
4
4
|
import { getPlacedSketchCoords, getLastPlacedSketchCoord } from '../utils/sketchHelpers.js'
|
|
5
5
|
import { TOLERANCES } from '../defaults.js'
|
|
6
|
-
import { ADAPTER_EVENTS } from '../../../adapterEvents.js'
|
|
6
|
+
import { ADAPTER_EVENTS, CHANGE_PHASE } from '../../../adapterEvents.js'
|
|
7
7
|
import { STYLES_CHANGED_EVENT } from '../core/internalEvents.js'
|
|
8
8
|
import { attemptPlacement, MODE_BY_GEOMETRY } from '../../../validation/validateGeometry.js'
|
|
9
9
|
import { MIN_VERTICES } from '../../../validation/rules.js'
|
|
@@ -52,7 +52,7 @@ const placedFeatureGeoJSON = (store, sketchFeature) => {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// Attempt a placement (mouse click, crosshair tap, Enter) through the shared
|
|
55
|
-
//
|
|
55
|
+
// placement rules + user callback. On a veto the vertex never appears and a
|
|
56
56
|
// PLACEMENT_BLOCKED event carries the reason.
|
|
57
57
|
export const buildCanPlaceVertex = ({ manager, geometryType, getSketch }) => (coordinate) => {
|
|
58
58
|
const sketch = getSketch()
|
|
@@ -60,7 +60,7 @@ export const buildCanPlaceVertex = ({ manager, geometryType, getSketch }) => (co
|
|
|
60
60
|
placed: sketch ? getPlacedSketchCoords(sketch.getGeometry()) : [],
|
|
61
61
|
point: coordinate,
|
|
62
62
|
geometryType,
|
|
63
|
-
|
|
63
|
+
onGeometryPreview: manager._previewValidator
|
|
64
64
|
})
|
|
65
65
|
if (!result.valid) {
|
|
66
66
|
manager.emit(ADAPTER_EVENTS.PLACEMENT_BLOCKED, result.blocked)
|
|
@@ -102,15 +102,15 @@ const attachDrawListeners = (drawInteraction, { manager, featureId, properties,
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
// Tracks placed-vertex count and emits VERTEX_CHANGE plus, on each genuine placement,
|
|
105
|
-
// a commit-level GEOMETRY_CHANGE ('
|
|
106
|
-
//
|
|
105
|
+
// a commit-level GEOMETRY_CHANGE ('change') for validation. Deferred a tick so it
|
|
106
|
+
// reports the shape after the current click settles.
|
|
107
107
|
const createVertexTracker = (manager, getSketch) => {
|
|
108
108
|
let lastPlacedCount = 0
|
|
109
|
-
const emit = (
|
|
109
|
+
const emit = (vertexIndex) => {
|
|
110
110
|
setTimeout(() => {
|
|
111
111
|
const sketch = getSketch()
|
|
112
112
|
if (!sketch) { return }
|
|
113
|
-
manager.emit(ADAPTER_EVENTS.GEOMETRY_CHANGE, { feature: placedFeatureGeoJSON(manager.store, sketch), phase, vertexIndex })
|
|
113
|
+
manager.emit(ADAPTER_EVENTS.GEOMETRY_CHANGE, { feature: placedFeatureGeoJSON(manager.store, sketch), phase: CHANGE_PHASE, vertexIndex })
|
|
114
114
|
}, 0)
|
|
115
115
|
}
|
|
116
116
|
return {
|
|
@@ -120,7 +120,7 @@ const createVertexTracker = (manager, getSketch) => {
|
|
|
120
120
|
if (!sketch) { return }
|
|
121
121
|
const placed = getPlacedSketchCoords(sketch.getGeometry()).length
|
|
122
122
|
manager.emit(ADAPTER_EVENTS.VERTEX_CHANGE, { numVertices: placed })
|
|
123
|
-
if (placed > lastPlacedCount) { emit(
|
|
123
|
+
if (placed > lastPlacedCount) { emit(placed - 1) }
|
|
124
124
|
lastPlacedCount = placed
|
|
125
125
|
},
|
|
126
126
|
// An undo commits a vertex removal, so it must re-validate like any other
|
|
@@ -128,7 +128,7 @@ const createVertexTracker = (manager, getSketch) => {
|
|
|
128
128
|
emitUndoValidation: () => {
|
|
129
129
|
const sketch = getSketch()
|
|
130
130
|
if (!sketch) { return }
|
|
131
|
-
emit(
|
|
131
|
+
emit(getPlacedSketchCoords(sketch.getGeometry()).length)
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
}
|
|
@@ -196,7 +196,7 @@ export const createDrawMode = ({ map, manager, options }) => {
|
|
|
196
196
|
snapTolerance: TOLERANCES.snapRadius,
|
|
197
197
|
condition: buildCondition(map, geometryType, () => sketchFeature, canPlaceVertex),
|
|
198
198
|
// Block finish gestures (double-click / click-to-close) while the shape is invalid.
|
|
199
|
-
finishCondition: () => manager.
|
|
199
|
+
finishCondition: () => manager._canFinish !== false
|
|
200
200
|
})
|
|
201
201
|
map.addInteraction(drawInteraction)
|
|
202
202
|
|
|
@@ -221,7 +221,7 @@ export const createDrawMode = ({ map, manager, options }) => {
|
|
|
221
221
|
const updateLiveValidity = () => {
|
|
222
222
|
if (!sketchFeature) { return }
|
|
223
223
|
const { feature, numVertices } = displayedSketch(geometryType, sketchFeature)
|
|
224
|
-
liveDrawChecks.update({ feature, context: { mode: liveMode }, numVertices,
|
|
224
|
+
liveDrawChecks.update({ feature, context: { mode: liveMode }, numVertices, onGeometryPreview: manager._previewValidator })
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
// Update sketch style when map style changes
|
|
@@ -87,7 +87,7 @@ describe('buildCanPlaceVertex', () => {
|
|
|
87
87
|
const gateFor = (ring, manager) =>
|
|
88
88
|
buildCanPlaceVertex({ manager, geometryType: 'Polygon', getSketch: () => (ring ? polygonFeature(ring) : null) })
|
|
89
89
|
|
|
90
|
-
test('a
|
|
90
|
+
test('a placement-rule veto emits PLACEMENT_BLOCKED with the candidate and reason', () => {
|
|
91
91
|
const manager = createFakeManager()
|
|
92
92
|
const gate = gateFor([[0, 0], [2, 2], [2, 0], [9, 9], [0, 0]], manager)
|
|
93
93
|
expect(gate([0, 2])).toBe(false)
|
|
@@ -102,7 +102,7 @@ describe('buildCanPlaceVertex', () => {
|
|
|
102
102
|
|
|
103
103
|
test('the user callback can veto a placement (and receives phase "place")', () => {
|
|
104
104
|
const manager = createFakeManager()
|
|
105
|
-
manager.
|
|
105
|
+
manager._previewValidator = jest.fn((event) =>
|
|
106
106
|
event.phase === 'place' ? { valid: false, reason: 'outside region' } : { valid: true })
|
|
107
107
|
const gate = gateFor([[0, 0], [2, 0], [9, 9], [0, 0]], manager)
|
|
108
108
|
expect(gate([5, 5])).toBe(false)
|
|
@@ -112,7 +112,7 @@ describe('buildCanPlaceVertex', () => {
|
|
|
112
112
|
|
|
113
113
|
test('the user callback can veto the very first vertex (no sketch yet)', () => {
|
|
114
114
|
const manager = createFakeManager()
|
|
115
|
-
manager.
|
|
115
|
+
manager._previewValidator = () => ({ valid: false, reason: 'outside region' })
|
|
116
116
|
const gate = gateFor(null, manager)
|
|
117
117
|
expect(gate([5, 5])).toBe(false)
|
|
118
118
|
expect(manager.emit).toHaveBeenCalledWith(ADAPTER_EVENTS.PLACEMENT_BLOCKED,
|
|
@@ -121,7 +121,7 @@ describe('buildCanPlaceVertex', () => {
|
|
|
121
121
|
|
|
122
122
|
test('a valid placement passes and emits nothing', () => {
|
|
123
123
|
const manager = createFakeManager()
|
|
124
|
-
manager.
|
|
124
|
+
manager._previewValidator = jest.fn(() => true)
|
|
125
125
|
const gate = gateFor([[0, 0], [2, 0], [9, 9], [0, 0]], manager)
|
|
126
126
|
expect(gate([2, 2])).toBe(true)
|
|
127
127
|
expect(manager.emit).not.toHaveBeenCalled()
|
|
@@ -139,9 +139,9 @@ describe('drawing lifecycle', () => {
|
|
|
139
139
|
|
|
140
140
|
test('finishCondition blocks finishing while the geometry is invalid', () => {
|
|
141
141
|
const { manager, interaction } = setup()
|
|
142
|
-
manager.
|
|
142
|
+
manager._canFinish = false
|
|
143
143
|
expect(interaction.finishCondition_()).toBe(false)
|
|
144
|
-
manager.
|
|
144
|
+
manager._canFinish = true
|
|
145
145
|
expect(interaction.finishCondition_()).toBe(true)
|
|
146
146
|
})
|
|
147
147
|
|
|
@@ -239,14 +239,14 @@ describe('drawing lifecycle', () => {
|
|
|
239
239
|
test('the user callback runs ONCE per sketch change, with phase preview, driving both the stroke and Add point from that single call', () => {
|
|
240
240
|
jest.useFakeTimers()
|
|
241
241
|
const { manager, emitted, interaction } = setup('Polygon')
|
|
242
|
-
manager.
|
|
242
|
+
manager._previewValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
|
|
243
243
|
const sketch = polygonFeature([[0, 0], [5, 5], [0, 0]])
|
|
244
244
|
interaction.dispatchEvent({ type: 'drawstart', feature: sketch })
|
|
245
245
|
sketch.getGeometry().setCoordinates([[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]])
|
|
246
|
-
expect(manager.
|
|
246
|
+
expect(manager._previewValidator).not.toHaveBeenCalled() // deferred to the frame
|
|
247
247
|
jest.runAllTimers()
|
|
248
|
-
expect(manager.
|
|
249
|
-
expect(manager.
|
|
248
|
+
expect(manager._previewValidator).toHaveBeenCalledTimes(1) // not once per gate
|
|
249
|
+
expect(manager._previewValidator).toHaveBeenCalledWith(expect.objectContaining({ phase: 'preview' }))
|
|
250
250
|
expect(manager.styles.createSketchStyle).toHaveBeenLastCalledWith('Polygon', true)
|
|
251
251
|
expect(emitted().find((e) => e.type === ADAPTER_EVENTS.CAN_PLACE_CHANGE)?.payload)
|
|
252
252
|
.toEqual(expect.objectContaining({ canPlace: false, reason: 'outside region' }))
|
|
@@ -256,12 +256,12 @@ describe('drawing lifecycle', () => {
|
|
|
256
256
|
test('the user callback runs even before any vertex is placed, gating Add point from the very first candidate point', () => {
|
|
257
257
|
jest.useFakeTimers()
|
|
258
258
|
const { manager, emitted, interaction } = setup('Polygon')
|
|
259
|
-
manager.
|
|
259
|
+
manager._previewValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
|
|
260
260
|
const sketch = polygonFeature([[5, 5], [5, 5]]) // no committed vertices yet — rubber-band + closing dupe only
|
|
261
261
|
interaction.dispatchEvent({ type: 'drawstart', feature: sketch })
|
|
262
262
|
sketch.getGeometry().setCoordinates([[[5, 5], [5, 5]]])
|
|
263
263
|
jest.runAllTimers()
|
|
264
|
-
expect(manager.
|
|
264
|
+
expect(manager._previewValidator).toHaveBeenCalledWith(expect.objectContaining({ numVertices: 0, phase: 'preview' }))
|
|
265
265
|
expect(emitted().find((e) => e.type === ADAPTER_EVENTS.CAN_PLACE_CHANGE)?.payload)
|
|
266
266
|
.toEqual(expect.objectContaining({ canPlace: false, reason: 'outside region' }))
|
|
267
267
|
jest.useRealTimers()
|
|
@@ -294,7 +294,7 @@ describe('drawing lifecycle', () => {
|
|
|
294
294
|
expect(changed).toHaveBeenCalled()
|
|
295
295
|
})
|
|
296
296
|
|
|
297
|
-
test('undo re-validates the committed shape (deferred, phase
|
|
297
|
+
test('undo re-validates the committed shape (deferred, phase change)', () => {
|
|
298
298
|
jest.useFakeTimers()
|
|
299
299
|
const { mode, manager, emitted, interaction } = setup()
|
|
300
300
|
const sketch = polygonFeature([[0, 0], [10, 0], [5, 5], [0, 0]])
|
|
@@ -304,7 +304,7 @@ describe('drawing lifecycle', () => {
|
|
|
304
304
|
mode.undo()
|
|
305
305
|
jest.runAllTimers()
|
|
306
306
|
expect(emitted().filter((e) => e.type === ADAPTER_EVENTS.GEOMETRY_CHANGE).pop()?.payload).toEqual(
|
|
307
|
-
expect.objectContaining({ phase: '
|
|
307
|
+
expect.objectContaining({ phase: 'change', feature: expect.any(Object) }))
|
|
308
308
|
jest.useRealTimers()
|
|
309
309
|
})
|
|
310
310
|
|
|
@@ -318,7 +318,7 @@ describe('drawing lifecycle', () => {
|
|
|
318
318
|
expect(emitted().some((e) => e.type === ADAPTER_EVENTS.GEOMETRY_CHANGE)).toBe(false)
|
|
319
319
|
jest.runAllTimers()
|
|
320
320
|
const geom = emitted().find((e) => e.type === ADAPTER_EVENTS.GEOMETRY_CHANGE)
|
|
321
|
-
expect(geom.payload).toEqual(expect.objectContaining({ phase: '
|
|
321
|
+
expect(geom.payload).toEqual(expect.objectContaining({ phase: 'change' }))
|
|
322
322
|
jest.useRealTimers()
|
|
323
323
|
})
|
|
324
324
|
|
|
@@ -14,25 +14,6 @@ import { createLiveStroke } from '../../../validation/liveStroke.js'
|
|
|
14
14
|
|
|
15
15
|
const TOUCH_INTERFACE = 'touch'
|
|
16
16
|
const VERTEX_TYPE = 'vertex'
|
|
17
|
-
const MOVE_VERTEX = 'commit-move'
|
|
18
|
-
const INSERT_VERTEX = 'commit-insert'
|
|
19
|
-
const DELETE_VERTEX = 'commit-delete'
|
|
20
|
-
|
|
21
|
-
// Map an undo-op type onto the geometry-change `phase` consumed by validation.
|
|
22
|
-
const OP_PHASE = {
|
|
23
|
-
move_vertex: MOVE_VERTEX,
|
|
24
|
-
insert_vertex: INSERT_VERTEX,
|
|
25
|
-
delete_vertex: DELETE_VERTEX
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Undoing an op commits the inverse change (undo of a delete re-inserts, etc.),
|
|
29
|
-
// so its re-validation reports the inverse phase.
|
|
30
|
-
const UNDO_INVERSE_PHASE = {
|
|
31
|
-
move_vertex: MOVE_VERTEX,
|
|
32
|
-
insert_vertex: DELETE_VERTEX,
|
|
33
|
-
delete_vertex: INSERT_VERTEX
|
|
34
|
-
}
|
|
35
|
-
|
|
36
17
|
// Live invalid-stroke wiring: re-validate the displayed geometry on every geometry
|
|
37
18
|
// change (Modify drag, touch drag, keyboard nudge) via the shared controller —
|
|
38
19
|
// default rules synchronously, user callback throttled. All committed vertices are
|
|
@@ -72,7 +53,7 @@ const wireLiveStroke = ({ map, manager, olFeature }) => {
|
|
|
72
53
|
feature: { type: 'Feature', geometry: { type, coordinates } },
|
|
73
54
|
context: { mode: 'edit_vertex' },
|
|
74
55
|
numVertices,
|
|
75
|
-
|
|
56
|
+
onGeometryPreview: manager._previewValidator
|
|
76
57
|
})
|
|
77
58
|
}
|
|
78
59
|
olFeature.getGeometry().on('change', updateLiveValidity)
|
|
@@ -109,7 +90,7 @@ const createVertexActions = ({ olFeature, undoStack, selection, getTouchHandler
|
|
|
109
90
|
}
|
|
110
91
|
undoStack.push({ type: 'delete_vertex', vertexIndex: result.deletedIndex, deletedCoord: result.deletedCoord })
|
|
111
92
|
syncGeom()
|
|
112
|
-
emitGeometryValidation(
|
|
93
|
+
emitGeometryValidation(result.deletedIndex)
|
|
113
94
|
setState({ selectedVertexIndex: -1, selectedVertexType: null })
|
|
114
95
|
}
|
|
115
96
|
|
|
@@ -123,7 +104,7 @@ const createVertexActions = ({ olFeature, undoStack, selection, getTouchHandler
|
|
|
123
104
|
syncGeom()
|
|
124
105
|
// An undo commits the inverse change, so it must re-validate like any other
|
|
125
106
|
// commit — otherwise the invalid stroke and the Done gate go stale.
|
|
126
|
-
emitGeometryValidation(
|
|
107
|
+
emitGeometryValidation(restoredIndex)
|
|
127
108
|
// Only re-select if a vertex was already active — undo must not create a new selection
|
|
128
109
|
const newIndex = previousIndex >= 0 ? restoredIndex : -1
|
|
129
110
|
setState({
|
|
@@ -152,7 +133,7 @@ const wireTouchHandler = ({ map, container, manager, snap, olFeature, undoStack,
|
|
|
152
133
|
onVertexMoved ({ vertexIndex, previousCoord }) {
|
|
153
134
|
undoStack.push({ type: 'move_vertex', vertexIndex, previousCoord })
|
|
154
135
|
syncGeom()
|
|
155
|
-
emitGeometryValidation(
|
|
136
|
+
emitGeometryValidation(vertexIndex)
|
|
156
137
|
selectVertex(vertexIndex)
|
|
157
138
|
touchHandler.updateTargetPosition()
|
|
158
139
|
},
|
|
@@ -173,7 +154,7 @@ const wireTouchHandler = ({ map, container, manager, snap, olFeature, undoStack,
|
|
|
173
154
|
}
|
|
174
155
|
undoStack.push({ type: 'insert_vertex', vertexIndex: result.insertedIndex })
|
|
175
156
|
syncGeom()
|
|
176
|
-
emitGeometryValidation(
|
|
157
|
+
emitGeometryValidation(result.insertedIndex)
|
|
177
158
|
selectVertex(result.insertedIndex)
|
|
178
159
|
touchHandler.updateTargetPosition()
|
|
179
160
|
}
|
|
@@ -202,13 +183,13 @@ const wireKeyboardHandler = ({ map, container, snap, undoStack, selection, touch
|
|
|
202
183
|
onVertexMoved ({ vertexIndex, previousCoord }) {
|
|
203
184
|
undoStack.push({ type: 'move_vertex', vertexIndex, previousCoord })
|
|
204
185
|
syncGeom()
|
|
205
|
-
emitGeometryValidation(
|
|
186
|
+
emitGeometryValidation(vertexIndex)
|
|
206
187
|
setState({ selectedVertexIndex: vertexIndex, selectedVertexType: VERTEX_TYPE })
|
|
207
188
|
},
|
|
208
189
|
onInserted ({ insertedIndex }) {
|
|
209
190
|
undoStack.push({ type: 'insert_vertex', vertexIndex: insertedIndex })
|
|
210
191
|
syncGeom()
|
|
211
|
-
emitGeometryValidation(
|
|
192
|
+
emitGeometryValidation(insertedIndex)
|
|
212
193
|
},
|
|
213
194
|
onDeleted: actions.doDeleteVertex,
|
|
214
195
|
onUndo: actions.doUndo,
|
|
@@ -321,11 +302,23 @@ const buildModeApi = ({ manager, store, olFeature, originalFeatureStyle, selecti
|
|
|
321
302
|
}
|
|
322
303
|
undoStack.push({ type: 'insert_vertex', vertexIndex: result.insertedIndex })
|
|
323
304
|
syncGeom()
|
|
324
|
-
emitGeometryValidation(
|
|
305
|
+
emitGeometryValidation(result.insertedIndex)
|
|
325
306
|
setState({ selectedVertexIndex: result.insertedIndex, selectedVertexType: VERTEX_TYPE })
|
|
326
307
|
touchHandler.updateTargetPosition()
|
|
327
308
|
},
|
|
328
309
|
|
|
310
|
+
// Replaces the whole shape (e.g. a corrected boundary from the consumer) as one undoable
|
|
311
|
+
// commit. Vertex indices no longer refer to the same points, so the selection is cleared.
|
|
312
|
+
setGeometry (geometry) {
|
|
313
|
+
const geom = olFeature.getGeometry()
|
|
314
|
+
undoStack.push({ type: 'replace_geometry', previousCoordinates: geom.getCoordinates() })
|
|
315
|
+
geom.setCoordinates(geometry.coordinates)
|
|
316
|
+
syncGeom()
|
|
317
|
+
emitGeometryValidation()
|
|
318
|
+
setState({ selectedVertexIndex: -1, selectedVertexType: null })
|
|
319
|
+
touchHandler.hide()
|
|
320
|
+
},
|
|
321
|
+
|
|
329
322
|
destroy () {
|
|
330
323
|
parts.live.destroy()
|
|
331
324
|
olFeature.setStyle(originalFeatureStyle)
|
|
@@ -381,7 +374,7 @@ export const createEditMode = ({ map, manager, options }) => {
|
|
|
381
374
|
return
|
|
382
375
|
}
|
|
383
376
|
undoStack.push(op)
|
|
384
|
-
emitGeometryValidation(
|
|
377
|
+
emitGeometryValidation(op.vertexIndex)
|
|
385
378
|
setState({ selectedVertexIndex: op.vertexIndex, selectedVertexType: VERTEX_TYPE })
|
|
386
379
|
}
|
|
387
380
|
})
|
|
@@ -112,7 +112,7 @@ test('a LineString edit computes numVertices directly from coordinates.length (n
|
|
|
112
112
|
|
|
113
113
|
expect(manager.emit).toHaveBeenCalledWith(ADAPTER_EVENTS.VERTEX_CHANGE, { numVertices: 3 })
|
|
114
114
|
|
|
115
|
-
//
|
|
115
|
+
// PREVIEW_RULES (self-intersect/area) only ever apply to Polygon (see rules.js's getPolygon
|
|
116
116
|
// guard) — a self-crossing LineString still drives updateLiveValidity, but never flips
|
|
117
117
|
// the stroke invalid, unlike the Polygon case above.
|
|
118
118
|
olFeature.getGeometry().setCoordinates([[0, 0], [100, 100], [100, 0], [0, 100]])
|
|
@@ -122,12 +122,12 @@ test('a LineString edit computes numVertices directly from coordinates.length (n
|
|
|
122
122
|
test('the user callback runs throttled during an edit drag', () => {
|
|
123
123
|
jest.useFakeTimers()
|
|
124
124
|
const { manager, olFeature } = setup()
|
|
125
|
-
manager.
|
|
125
|
+
manager._previewValidator = jest.fn(() => ({ valid: false, reason: 'outside region' }))
|
|
126
126
|
olFeature.getGeometry().setCoordinates([[[0, 0], [110, 0], [100, 100], [0, 100], [0, 0]]])
|
|
127
127
|
olFeature.getGeometry().setCoordinates([[[0, 0], [120, 0], [100, 100], [0, 100], [0, 0]]])
|
|
128
|
-
expect(manager.
|
|
128
|
+
expect(manager._previewValidator).not.toHaveBeenCalled() // deferred to the frame
|
|
129
129
|
jest.runAllTimers()
|
|
130
|
-
expect(manager.
|
|
130
|
+
expect(manager._previewValidator).toHaveBeenCalledTimes(1) // trailing edge only
|
|
131
131
|
expect(currentStyle(olFeature)).toBe(manager.styles.editFeatureStyleInvalid)
|
|
132
132
|
jest.useRealTimers()
|
|
133
133
|
})
|
|
@@ -215,7 +215,7 @@ test('undo re-validates with the inverse change phase (undo of a delete re-inser
|
|
|
215
215
|
mode.undo()
|
|
216
216
|
jest.runAllTimers()
|
|
217
217
|
expect(manager.emit).toHaveBeenCalledWith(ADAPTER_EVENTS.GEOMETRY_CHANGE, expect.objectContaining({
|
|
218
|
-
phase: '
|
|
218
|
+
phase: 'change',
|
|
219
219
|
vertexIndex: 1,
|
|
220
220
|
feature: expect.any(Object)
|
|
221
221
|
}))
|
|
@@ -372,3 +372,24 @@ test('destroy removes interactions, layers and listeners, and restores the featu
|
|
|
372
372
|
expect(map.layers).toHaveLength(0)
|
|
373
373
|
expect(olFeature.getStyle()).toBeNull()
|
|
374
374
|
})
|
|
375
|
+
|
|
376
|
+
test('setGeometry replaces the shape as one undoable change, clearing the selection', () => {
|
|
377
|
+
jest.useFakeTimers()
|
|
378
|
+
const { manager, mode, ring } = setup()
|
|
379
|
+
const replacement = [[0, 0], [200, 0], [200, 200], [0, 200], [0, 0]]
|
|
380
|
+
mode.selectVertex(1)
|
|
381
|
+
manager.emit.mockClear()
|
|
382
|
+
|
|
383
|
+
mode.setGeometry({ type: 'Polygon', coordinates: [replacement] })
|
|
384
|
+
expect(ring()).toEqual(replacement)
|
|
385
|
+
expect(manager.emit).toHaveBeenCalledWith(ADAPTER_EVENTS.VERTEX_SELECTION, { index: -1, numVertices: 4 })
|
|
386
|
+
jest.runAllTimers()
|
|
387
|
+
expect(manager.emit).toHaveBeenCalledWith(ADAPTER_EVENTS.GEOMETRY_CHANGE, expect.objectContaining({ phase: 'change' }))
|
|
388
|
+
|
|
389
|
+
manager.emit.mockClear()
|
|
390
|
+
mode.undo()
|
|
391
|
+
expect(ring()).toEqual(RING)
|
|
392
|
+
jest.runAllTimers()
|
|
393
|
+
expect(manager.emit).toHaveBeenCalledWith(ADAPTER_EVENTS.GEOMETRY_CHANGE, expect.objectContaining({ phase: 'change' }))
|
|
394
|
+
jest.useRealTimers()
|
|
395
|
+
})
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { getCoords, getMidpoints } from '../utils/geometryHelpers.js'
|
|
2
|
-
import { ADAPTER_EVENTS } from '../../../adapterEvents.js'
|
|
2
|
+
import { ADAPTER_EVENTS, CHANGE_PHASE } from '../../../adapterEvents.js'
|
|
3
3
|
|
|
4
4
|
// Deferred commit-level geometrychange emitter (feature + change phase + vertex index)
|
|
5
|
-
// consumed by the validation layer. Deferred a tick so
|
|
6
|
-
//
|
|
7
|
-
const createGeometryValidationEmitter = (manager, store, olFeature) => (
|
|
8
|
-
if (!phase) { return }
|
|
5
|
+
// consumed by the validation layer. Deferred a tick so it reports the shape after the
|
|
6
|
+
// current mutation's undo bookkeeping has settled.
|
|
7
|
+
const createGeometryValidationEmitter = (manager, store, olFeature) => (vertexIndex) => {
|
|
9
8
|
setTimeout(() => {
|
|
10
|
-
manager.emit(ADAPTER_EVENTS.GEOMETRY_CHANGE, { feature: store.toGeoJSON(olFeature), phase, vertexIndex })
|
|
9
|
+
manager.emit(ADAPTER_EVENTS.GEOMETRY_CHANGE, { feature: store.toGeoJSON(olFeature), phase: CHANGE_PHASE, vertexIndex })
|
|
11
10
|
}, 0)
|
|
12
11
|
}
|
|
13
12
|
|
|
@@ -75,29 +75,19 @@ test('emitGeometryValidation emits a deferred commit-level geometrychange with t
|
|
|
75
75
|
const { selection, manager, store } = setup()
|
|
76
76
|
manager.emit.mockClear()
|
|
77
77
|
|
|
78
|
-
selection.emitGeometryValidation(
|
|
78
|
+
selection.emitGeometryValidation(2)
|
|
79
79
|
// Deferred a tick to avoid re-entrancy — nothing emitted synchronously.
|
|
80
80
|
expect(manager.emit).not.toHaveBeenCalledWith(ADAPTER_EVENTS.GEOMETRY_CHANGE, expect.anything())
|
|
81
81
|
|
|
82
82
|
jest.runAllTimers()
|
|
83
83
|
expect(manager.emit).toHaveBeenCalledWith(ADAPTER_EVENTS.GEOMETRY_CHANGE, {
|
|
84
84
|
feature: store.toGeoJSON(),
|
|
85
|
-
phase: '
|
|
85
|
+
phase: 'change',
|
|
86
86
|
vertexIndex: 2
|
|
87
87
|
})
|
|
88
88
|
jest.useRealTimers()
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
test('emitGeometryValidation is a no-op without a change phase', () => {
|
|
92
|
-
jest.useFakeTimers()
|
|
93
|
-
const { selection, manager } = setup()
|
|
94
|
-
manager.emit.mockClear()
|
|
95
|
-
selection.emitGeometryValidation(undefined, 0)
|
|
96
|
-
jest.runAllTimers()
|
|
97
|
-
expect(manager.emit).not.toHaveBeenCalledWith(ADAPTER_EVENTS.GEOMETRY_CHANGE, expect.anything())
|
|
98
|
-
jest.useRealTimers()
|
|
99
|
-
})
|
|
100
|
-
|
|
101
91
|
test('geometry changes refresh the layers until destroy unbinds the listener', () => {
|
|
102
92
|
const { selection, olFeature, layers } = setup()
|
|
103
93
|
olFeature.getGeometry().setCoordinates([[[0, 0], [20, 0], [20, 20], [0, 0]]])
|
|
@@ -76,6 +76,13 @@ export const undoDeleteVertex = (olFeature, op) => {
|
|
|
76
76
|
return vertexIndex
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// Restores the whole geometry a setGeometry replaced. Vertex indices no longer refer to the
|
|
80
|
+
// same points, so there is nothing to re-select.
|
|
81
|
+
export const undoReplaceGeometry = (olFeature, op) => {
|
|
82
|
+
olFeature.getGeometry().setCoordinates(op.previousCoordinates)
|
|
83
|
+
return -1
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
/**
|
|
80
87
|
* Dispatch the correct undo handler based on operation type.
|
|
81
88
|
* @returns {number} vertex index to re-select after undo, or -1 for none
|
|
@@ -88,6 +95,8 @@ export const applyUndo = (olFeature, op) => {
|
|
|
88
95
|
return undoInsertVertex(olFeature, op)
|
|
89
96
|
case 'delete_vertex':
|
|
90
97
|
return undoDeleteVertex(olFeature, op)
|
|
98
|
+
case 'replace_geometry':
|
|
99
|
+
return undoReplaceGeometry(olFeature, op)
|
|
91
100
|
default:
|
|
92
101
|
return -1
|
|
93
102
|
}
|
|
@@ -61,4 +61,11 @@ describe('applyUndo dispatch', () => {
|
|
|
61
61
|
expect(applyUndo(feature, { type: 'insert_vertex', vertexIndex: 1 })).toBe(-1)
|
|
62
62
|
expect(applyUndo(feature, { type: 'resize' })).toBe(-1)
|
|
63
63
|
})
|
|
64
|
+
|
|
65
|
+
test('replace_geometry restores the whole previous geometry, with nothing to re-select', () => {
|
|
66
|
+
const feature = polygonFeature(SQUARE)
|
|
67
|
+
const previousCoordinates = [[[0, 0], [5, 0], [5, 5], [0, 0]]]
|
|
68
|
+
expect(applyUndo(feature, { type: 'replace_geometry', previousCoordinates })).toBe(-1)
|
|
69
|
+
expect(feature.getGeometry().getCoordinates()).toEqual(previousCoordinates)
|
|
70
|
+
})
|
|
64
71
|
})
|
|
@@ -2,7 +2,7 @@ import Draw from 'ol/interaction/Draw.js'
|
|
|
2
2
|
import { noModifierKeys } from 'ol/events/condition.js'
|
|
3
3
|
import { wireInputEvents, applyCrossHairVisibility } from '../draw/drawInput.js'
|
|
4
4
|
import { ADAPTER_EVENTS } from '../../../adapterEvents.js'
|
|
5
|
-
import { validatePlacement } from '../../../validation/validateGeometry.js'
|
|
5
|
+
import { validatePlacement, toPlacementBlocked } from '../../../validation/validateGeometry.js'
|
|
6
6
|
import { TOLERANCES } from '../defaults.js'
|
|
7
7
|
|
|
8
8
|
const MODE = 'draw_point'
|
|
@@ -11,15 +11,12 @@ const MODE = 'draw_point'
|
|
|
11
11
|
// directly rather than via validateGeometry.js's Polygon/LineString-only attemptPlacement.
|
|
12
12
|
const canPlaceVertex = (manager) => (coordinate) => {
|
|
13
13
|
const candidate = { type: 'Feature', geometry: { type: 'Point', coordinates: coordinate }, properties: {} }
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
if (!valid) {
|
|
20
|
-
manager.emit(ADAPTER_EVENTS.PLACEMENT_BLOCKED, { feature: candidate, reason: reason ?? null, phase: 'place', mode: MODE, vertexIndex: 0 })
|
|
14
|
+
const context = { mode: MODE, vertexIndex: 0 }
|
|
15
|
+
const result = validatePlacement(candidate, context, { onGeometryPreview: manager._previewValidator })
|
|
16
|
+
if (!result.valid) {
|
|
17
|
+
manager.emit(ADAPTER_EVENTS.PLACEMENT_BLOCKED, toPlacementBlocked(candidate, result, context))
|
|
21
18
|
}
|
|
22
|
-
return valid
|
|
19
|
+
return result.valid
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
// Commit a finished point to the store under the requested id and emit CREATE. Symbol
|
|
@@ -90,9 +90,9 @@ describe('createDrawPointMode', () => {
|
|
|
90
90
|
expect(nonGeometryProps).toEqual({})
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
-
test('condition vetoes placement via
|
|
93
|
+
test('condition vetoes placement via onGeometryPreview', () => {
|
|
94
94
|
const { interaction, manager, emitted } = setup()
|
|
95
|
-
manager.
|
|
95
|
+
manager._previewValidator = () => ({ valid: false, reason: 'not allowed here' })
|
|
96
96
|
const condition = interaction.condition_
|
|
97
97
|
const allowed = condition({ coordinate: [1, 2], originalEvent: {} })
|
|
98
98
|
expect(allowed).toBe(false)
|
|
@@ -154,7 +154,7 @@ describe('createDrawPointMode', () => {
|
|
|
154
154
|
test('a vetoed crosshair placement never commits', () => {
|
|
155
155
|
const { wireArgs, manager, emitted, interaction } = setup()
|
|
156
156
|
const { append, finish } = spyOnCommit(interaction)
|
|
157
|
-
manager.
|
|
157
|
+
manager._previewValidator = () => false
|
|
158
158
|
wireArgs.placeVertex()
|
|
159
159
|
expect(append).not.toHaveBeenCalled()
|
|
160
160
|
expect(finish).not.toHaveBeenCalled()
|
|
@@ -10,10 +10,6 @@ import { STYLES_CHANGED_EVENT } from '../core/internalEvents.js'
|
|
|
10
10
|
import { createLiveStroke } from '../../../validation/liveStroke.js'
|
|
11
11
|
|
|
12
12
|
const TOUCH_INTERFACE = 'touch'
|
|
13
|
-
// Shared phase name with edit_vertex's own move_vertex op — a moved point re-validates the
|
|
14
|
-
// same way (validation/rules.js has no Point-specific rule, so this only ever gates a
|
|
15
|
-
// consumer's own onGeometryChange callback).
|
|
16
|
-
const MOVE_VERTEX = 'commit-move'
|
|
17
13
|
|
|
18
14
|
// A symbol icon renders far bigger than buildModifyCondition's fixed-radius hit-test (tuned
|
|
19
15
|
// for a plain vertex dot), so this hit-tests the icon's own rendered pixels instead. No touch
|
|
@@ -43,7 +39,7 @@ const wirePointLiveValidity = ({ manager, olFeature }) => {
|
|
|
43
39
|
feature: { type: 'Feature', geometry: { type: 'Point', coordinates } },
|
|
44
40
|
context: { mode: 'edit_point' },
|
|
45
41
|
numVertices: 1,
|
|
46
|
-
|
|
42
|
+
onGeometryPreview: manager._previewValidator
|
|
47
43
|
})
|
|
48
44
|
}
|
|
49
45
|
olFeature.getGeometry().on('change', updateLiveValidity)
|
|
@@ -70,7 +66,7 @@ const wireTouchHandler = ({ map, container, manager, snap, undoStack, selection
|
|
|
70
66
|
onVertexMoved ({ vertexIndex, previousCoord }) {
|
|
71
67
|
undoStack.push({ type: 'move_vertex', vertexIndex, previousCoord })
|
|
72
68
|
syncGeom()
|
|
73
|
-
emitGeometryValidation(
|
|
69
|
+
emitGeometryValidation(vertexIndex)
|
|
74
70
|
},
|
|
75
71
|
// A stray tap never relocates the point — only the offset-target drag and the D-pad do
|
|
76
72
|
// (mirrors the ML adapter's editPointMode/touchHandlers.js onTap no-op).
|
|
@@ -99,7 +95,18 @@ const createUndoAction = ({ olFeature, undoStack, selection }) => () => {
|
|
|
99
95
|
selection.syncGeom()
|
|
100
96
|
// An undo commits the inverse change, so it must re-validate like any other commit —
|
|
101
97
|
// otherwise the Done gate could go stale. Always vertexIndex 0 — a point has only one.
|
|
102
|
-
selection.emitGeometryValidation(
|
|
98
|
+
selection.emitGeometryValidation(0)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Moves the point to the given geometry's coordinate as one undoable commit (setGeometry).
|
|
102
|
+
const createSetGeometryAction = ({ olFeature, undoStack, selection, touchHandler }) => (geometry) => {
|
|
103
|
+
undoStack.push({ type: 'replace_geometry', vertexIndex: 0, previousCoord: olFeature.getGeometry().getCoordinates() })
|
|
104
|
+
movePoint(olFeature, 0, geometry.coordinates)
|
|
105
|
+
selection.syncGeom()
|
|
106
|
+
selection.emitGeometryValidation(0)
|
|
107
|
+
if (selection.getState().interfaceType === TOUCH_INTERFACE) {
|
|
108
|
+
touchHandler.updateTargetPosition()
|
|
109
|
+
}
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
const wireKeyboardHandler = ({ map, container, snap, undoStack, selection, touchHandler, doUndo }) => {
|
|
@@ -114,7 +121,7 @@ const wireKeyboardHandler = ({ map, container, snap, undoStack, selection, touch
|
|
|
114
121
|
onVertexMoved ({ vertexIndex, previousCoord }) {
|
|
115
122
|
undoStack.push({ type: 'move_vertex', vertexIndex, previousCoord })
|
|
116
123
|
syncGeom()
|
|
117
|
-
emitGeometryValidation(
|
|
124
|
+
emitGeometryValidation(vertexIndex)
|
|
118
125
|
},
|
|
119
126
|
// No midpoint concept for a point, so this is never actually reached — required by
|
|
120
127
|
// createKeyboardHandler's interface all the same. Not reachable through this module's
|
|
@@ -204,7 +211,7 @@ export const createEditPointMode = ({ map, manager, options }) => {
|
|
|
204
211
|
return
|
|
205
212
|
}
|
|
206
213
|
undoStack.push(op)
|
|
207
|
-
selection.emitGeometryValidation(
|
|
214
|
+
selection.emitGeometryValidation(op.vertexIndex)
|
|
208
215
|
}
|
|
209
216
|
})
|
|
210
217
|
|
|
@@ -254,6 +261,8 @@ export const createEditPointMode = ({ map, manager, options }) => {
|
|
|
254
261
|
// once at construction (pointSelectionState's VERTEX_SELECTION) and held for the session.
|
|
255
262
|
nudgeSelectedVertex: keyboardHandler.nudgeByDelta,
|
|
256
263
|
|
|
264
|
+
setGeometry: createSetGeometryAction({ olFeature, undoStack, selection, touchHandler }),
|
|
265
|
+
|
|
257
266
|
destroy () {
|
|
258
267
|
live.destroy()
|
|
259
268
|
olFeature.setStyle(originalFeatureStyle)
|