@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
|
@@ -87,7 +87,7 @@ describe('undo via draw.undo event and reinitialisation', () => {
|
|
|
87
87
|
expect(state.polygon.coordinates[0]).toHaveLength(3)
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
test('undo re-validates the committed shape (deferred, phase
|
|
90
|
+
test('undo re-validates the committed shape (deferred, phase change)', () => {
|
|
91
91
|
jest.useFakeTimers()
|
|
92
92
|
const { ctx, state } = setup(DrawPolygonMode)
|
|
93
93
|
clickAt(ctx, state, 0, 0)
|
|
@@ -98,7 +98,7 @@ describe('undo via draw.undo event and reinitialisation', () => {
|
|
|
98
98
|
ctx.onUndo(state)
|
|
99
99
|
jest.runAllTimers()
|
|
100
100
|
expect(firedWith(ctx.map, 'draw.geometrychange').pop()).toEqual(expect.objectContaining({
|
|
101
|
-
phase: '
|
|
101
|
+
phase: 'change',
|
|
102
102
|
feature: expect.any(Object)
|
|
103
103
|
}))
|
|
104
104
|
jest.useRealTimers()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import MapboxDraw from '@mapbox/mapbox-gl-draw'
|
|
2
2
|
import { createLifecycle } from './drawMode/lifecycle.js'
|
|
3
|
-
import { validatePlacement } from '../../../validation/validateGeometry.js'
|
|
3
|
+
import { validatePlacement, toPlacementBlocked } from '../../../validation/validateGeometry.js'
|
|
4
4
|
import {
|
|
5
5
|
getSnapInstance, isSnapEnabled, isSnapActive, getSnapLngLat, triggerSnapAtPoint, triggerSnapAtCenter
|
|
6
6
|
} from '../utils/snapHelpers.js'
|
|
@@ -16,15 +16,12 @@ const INTERFACE_KEYS = new Set(['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown
|
|
|
16
16
|
// Polygon/LineString via MODE_BY_GEOMETRY, so a Point candidate is built and validated directly.
|
|
17
17
|
const canPlace = (map, coord) => {
|
|
18
18
|
const candidate = { type: 'Feature', geometry: { type: 'Point', coordinates: coord }, properties: {} }
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
if (!valid) {
|
|
25
|
-
map.fire('draw.placementblocked', { feature: candidate, reason: reason ?? null, phase: 'place', mode: MODE, vertexIndex: 0 })
|
|
19
|
+
const context = { mode: MODE, vertexIndex: 0 }
|
|
20
|
+
const result = validatePlacement(candidate, context, { onGeometryPreview: map._drawPreviewValidator })
|
|
21
|
+
if (!result.valid) {
|
|
22
|
+
map.fire('draw.placementblocked', toPlacementBlocked(candidate, result, context))
|
|
26
23
|
}
|
|
27
|
-
return valid
|
|
24
|
+
return result.valid
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
const ParentMode = MapboxDraw.modes.draw_point
|
|
@@ -11,7 +11,7 @@ const createMap = () => {
|
|
|
11
11
|
_undoInProgress: false,
|
|
12
12
|
_undoStack: null,
|
|
13
13
|
_snapInstance: null,
|
|
14
|
-
|
|
14
|
+
_drawPreviewValidator: undefined,
|
|
15
15
|
getCanvas: () => canvas,
|
|
16
16
|
getCenter: () => ({ ...CENTER }),
|
|
17
17
|
project: jest.fn(() => ({ x: 50, y: 50 })),
|
|
@@ -179,9 +179,9 @@ describe('DrawPointMode', () => {
|
|
|
179
179
|
expect(state.point.coordinates).toEqual([])
|
|
180
180
|
})
|
|
181
181
|
|
|
182
|
-
it('vetoes placement via
|
|
182
|
+
it('vetoes placement via onGeometryPreview and never commits', () => {
|
|
183
183
|
const { ctx, state } = setup()
|
|
184
|
-
ctx.map.
|
|
184
|
+
ctx.map._drawPreviewValidator = () => ({ valid: false, reason: 'not allowed here' })
|
|
185
185
|
ctx.onClick(state, clickEvent(ctx, 1, 2))
|
|
186
186
|
expect(state.point.coordinates).toEqual([])
|
|
187
187
|
const blocked = firedWith(ctx.map, 'draw.placementblocked')
|
|
@@ -192,7 +192,7 @@ describe('DrawPointMode', () => {
|
|
|
192
192
|
|
|
193
193
|
it('defaults the blocked reason to null when the veto gives none', () => {
|
|
194
194
|
const { ctx, state } = setup()
|
|
195
|
-
ctx.map.
|
|
195
|
+
ctx.map._drawPreviewValidator = () => false // no {reason} shape
|
|
196
196
|
ctx.onClick(state, clickEvent(ctx, 1, 2))
|
|
197
197
|
const blocked = firedWith(ctx.map, 'draw.placementblocked')
|
|
198
198
|
expect(blocked[0].reason).toBeNull()
|
|
@@ -3,7 +3,7 @@ import { isActiveFeature } from '../../../../../../../node_modules/@mapbox/mapbo
|
|
|
3
3
|
import {
|
|
4
4
|
getSnapInstance, isSnapEnabled, getSnapLngLat, triggerSnapAtPoint, clearSnapState, setAutoSnapSuspended
|
|
5
5
|
} from '../../utils/snapHelpers.js'
|
|
6
|
-
import { validatePlacement } from '../../../../validation/validateGeometry.js'
|
|
6
|
+
import { validatePlacement, toPlacementBlocked } from '../../../../validation/validateGeometry.js'
|
|
7
7
|
|
|
8
8
|
const MODE = 'edit_point'
|
|
9
9
|
|
|
@@ -13,15 +13,12 @@ const MODE = 'edit_point'
|
|
|
13
13
|
// Point candidate is built and validated directly instead.
|
|
14
14
|
const canPlaceAt = (map, coord) => {
|
|
15
15
|
const candidate = { type: 'Feature', geometry: { type: 'Point', coordinates: coord }, properties: {} }
|
|
16
|
-
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
if (!valid) {
|
|
22
|
-
map.fire('draw.placementblocked', { feature: candidate, reason: reason ?? null, phase: 'place', mode: MODE, vertexIndex: 0 })
|
|
16
|
+
const context = { mode: MODE, vertexIndex: 0 }
|
|
17
|
+
const result = validatePlacement(candidate, context, { onGeometryPreview: map._drawPreviewValidator })
|
|
18
|
+
if (!result.valid) {
|
|
19
|
+
map.fire('draw.placementblocked', toPlacementBlocked(candidate, result, context))
|
|
23
20
|
}
|
|
24
|
-
return valid
|
|
21
|
+
return result.valid
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
/**
|
|
@@ -77,7 +77,7 @@ describe('pointerHandlers', () => {
|
|
|
77
77
|
|
|
78
78
|
test('onClick is vetoed by a rejecting geometry validator, firing draw.placementblocked with a fallback null reason, and leaving the point untouched', () => {
|
|
79
79
|
const { ctx, state, map } = createHarness()
|
|
80
|
-
map.
|
|
80
|
+
map._drawPreviewValidator = () => false // no {reason} shape
|
|
81
81
|
ctx.onClick(state, { featureTarget: undefined, lngLat: { lng: 9, lat: 9 }, point: { x: 90, y: 90 } })
|
|
82
82
|
expect(state.feature.coordinates).toEqual([5, 5])
|
|
83
83
|
expect(map.fire).toHaveBeenCalledWith('draw.placementblocked', expect.objectContaining({ reason: null }))
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { scalePoint } from '../editVertexMode/helpers.js'
|
|
2
2
|
import { sharedUndoHandlers } from '../../utils/geometryValidation.js'
|
|
3
3
|
|
|
4
|
-
// Map an undo-stack op type onto the geometry-change `phase` consumed by validation. Read off
|
|
5
|
-
// `this` by the shared pushUndo mixin (utils/geometryValidation.js) — see that file's comment.
|
|
6
|
-
const UNDO_OP_PHASE = { move_point: 'commit-move' }
|
|
7
|
-
|
|
8
|
-
// Undoing a move commits the inverse move, so it re-validates with the same phase.
|
|
9
|
-
const UNDO_INVERSE_PHASE = { move_point: 'commit-move' }
|
|
10
|
-
|
|
11
4
|
// Same dispatch-by-op-type pattern as editVertexMode/undoHandlers.js, but with a single op
|
|
12
5
|
// type — there's no insert/delete concept for a Point's one coordinate — so undoMovePoint
|
|
13
6
|
// writes the coordinate directly, with no getRingSegments/getSegmentForIndex/
|
|
14
7
|
// getModifiableCoords lookup needed at all.
|
|
15
8
|
export const undoHandlers = {
|
|
16
9
|
...sharedUndoHandlers,
|
|
17
|
-
UNDO_OP_PHASE,
|
|
18
|
-
UNDO_INVERSE_PHASE,
|
|
19
10
|
|
|
20
11
|
handleUndo (state) {
|
|
21
12
|
const undoStack = this.map._undoStack
|
|
@@ -25,22 +16,25 @@ export const undoHandlers = {
|
|
|
25
16
|
|
|
26
17
|
const op = undoStack.pop()
|
|
27
18
|
|
|
28
|
-
if (op.type === 'move_point') {
|
|
19
|
+
if (op.type === 'move_point' || op.type === 'replace_geometry') {
|
|
29
20
|
this.undoMovePoint(state, op)
|
|
30
21
|
}
|
|
31
22
|
// An undo commits the inverse change, so it must re-validate like any other
|
|
32
23
|
// commit — otherwise the invalid stroke and the Done gate go stale.
|
|
33
|
-
this.emitGeometryValidation(
|
|
24
|
+
this.emitGeometryValidation(op.vertexIndex, op.featureId)
|
|
34
25
|
},
|
|
35
26
|
|
|
36
27
|
undoMovePoint (state, op) {
|
|
37
|
-
|
|
28
|
+
this.setPointPosition(state, op.featureId, op.previousPosition)
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
setPointPosition (state, featureId, position) {
|
|
38
32
|
const feature = this.getFeature(featureId)
|
|
39
33
|
if (!feature) { return }
|
|
40
34
|
|
|
41
|
-
feature.updateCoordinate('',
|
|
35
|
+
feature.updateCoordinate('', position[0], position[1])
|
|
42
36
|
this._ctx.store.render()
|
|
43
37
|
this.fireGeometryChange(state)
|
|
44
|
-
this.updateTouchPointTarget(state, scalePoint(this.map.project(
|
|
38
|
+
this.updateTouchPointTarget(state, scalePoint(this.map.project(position), state.scale))
|
|
45
39
|
}
|
|
46
40
|
}
|
|
@@ -3,16 +3,16 @@ import { createHarness } from './__helpers__/harness.js'
|
|
|
3
3
|
// fireGeometryChange/emitGeometryValidation/pushUndo are the shared mixin from
|
|
4
4
|
// utils/geometryValidation.js — their own behaviour is covered by
|
|
5
5
|
// utils/geometryValidation.test.js. This file only tests what's specific to editPointMode:
|
|
6
|
-
// pushUndo's
|
|
6
|
+
// pushUndo's validation for 'move_point', handleUndo's single-op-type dispatch,
|
|
7
7
|
// and undoMovePoint itself.
|
|
8
8
|
describe('undoHandlers', () => {
|
|
9
|
-
test('pushUndo maps move_point to the
|
|
9
|
+
test('pushUndo maps move_point to the change phase', () => {
|
|
10
10
|
jest.useFakeTimers()
|
|
11
11
|
const { ctx, map } = createHarness()
|
|
12
12
|
map.fire.mockClear()
|
|
13
13
|
ctx.pushUndo({ type: 'move_point', featureId: 'feat-1', vertexIndex: 0 })
|
|
14
14
|
jest.runAllTimers()
|
|
15
|
-
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: '
|
|
15
|
+
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: 'change' }))
|
|
16
16
|
jest.useRealTimers()
|
|
17
17
|
})
|
|
18
18
|
|
|
@@ -28,15 +28,44 @@ describe('undoHandlers', () => {
|
|
|
28
28
|
expect(() => ctx.handleUndo(state)).not.toThrow()
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
// handleUndo's own call to emitGeometryValidation
|
|
32
|
-
//
|
|
33
|
-
// single-entry map, so it would just re-confirm the 'commit-move' phase already checked
|
|
34
|
-
// above via pushUndo. (editVertexMode's equivalent op/inverse maps genuinely differ —
|
|
35
|
-
// see its own undoHandlers.test.js.)
|
|
31
|
+
// handleUndo's own call to emitGeometryValidation isn't re-asserted here — it reports the
|
|
32
|
+
// same 'change' phase already checked above via pushUndo.
|
|
36
33
|
test('undoMovePoint restores the previous position directly, guarding a missing feature', () => {
|
|
37
34
|
const { ctx, state } = createHarness()
|
|
38
35
|
ctx.undoMovePoint({ ...state, featureId: 'missing' }, { previousPosition: [0, 0], featureId: 'missing' })
|
|
39
36
|
ctx.undoMovePoint(state, { previousPosition: [3, 4], featureId: 'feat-1' })
|
|
40
37
|
expect(ctx.getFeature('feat-1').coordinates).toEqual([3, 4])
|
|
41
38
|
})
|
|
39
|
+
|
|
40
|
+
describe('setGeometry', () => {
|
|
41
|
+
test('moves the point on draw.setgeometry and re-validates as a change', () => {
|
|
42
|
+
jest.useFakeTimers()
|
|
43
|
+
const { ctx, map } = createHarness()
|
|
44
|
+
map.fire.mockClear()
|
|
45
|
+
map.fire('draw.setgeometry', { geometry: { type: 'Point', coordinates: [7, 8] } })
|
|
46
|
+
expect(ctx.getFeature('feat-1').coordinates).toEqual([7, 8])
|
|
47
|
+
jest.runAllTimers()
|
|
48
|
+
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: 'change' }))
|
|
49
|
+
jest.useRealTimers()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('undo moves the point back and re-validates as a change', () => {
|
|
53
|
+
jest.useFakeTimers()
|
|
54
|
+
const { ctx, state, map } = createHarness()
|
|
55
|
+
const original = [...ctx.getFeature('feat-1').coordinates]
|
|
56
|
+
map.fire('draw.setgeometry', { geometry: { type: 'Point', coordinates: [7, 8] } })
|
|
57
|
+
jest.runAllTimers()
|
|
58
|
+
map.fire.mockClear()
|
|
59
|
+
ctx.handleUndo(state)
|
|
60
|
+
expect(ctx.getFeature('feat-1').coordinates).toEqual(original)
|
|
61
|
+
jest.runAllTimers()
|
|
62
|
+
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: 'change' }))
|
|
63
|
+
jest.useRealTimers()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('guards a missing feature', () => {
|
|
67
|
+
const { ctx, state } = createHarness()
|
|
68
|
+
expect(() => ctx.onSetGeometry({ ...state, featureId: 'missing' }, { geometry: { type: 'Point', coordinates: [1, 1] } })).not.toThrow()
|
|
69
|
+
})
|
|
70
|
+
})
|
|
42
71
|
})
|
|
@@ -98,7 +98,7 @@ export const EditPointMode = {
|
|
|
98
98
|
},
|
|
99
99
|
|
|
100
100
|
setupEventListeners (state) {
|
|
101
|
-
const handlers = this.handlers = buildEditModeHandlers(this, state, { nudge: this.onNudgePoint })
|
|
101
|
+
const handlers = this.handlers = buildEditModeHandlers(this, state, { nudge: this.onNudgePoint, setgeometry: this.onSetGeometry })
|
|
102
102
|
bindEditModeListeners(state, this.map, handlers)
|
|
103
103
|
},
|
|
104
104
|
|
|
@@ -136,6 +136,16 @@ export const EditPointMode = {
|
|
|
136
136
|
this.updateTouchPointTarget(state, scalePoint(this.map.project(state.feature.coordinates), state.scale))
|
|
137
137
|
},
|
|
138
138
|
|
|
139
|
+
// Inbound signal from MaplibreDrawAdapter.setGeometry — moves the point to the given
|
|
140
|
+
// geometry's coordinate as one undoable commit.
|
|
141
|
+
onSetGeometry (state, event) {
|
|
142
|
+
const feature = this.getFeature(state.featureId)
|
|
143
|
+
if (!feature) { return }
|
|
144
|
+
const previousPosition = feature.getCoordinates()
|
|
145
|
+
this.setPointPosition(state, state.featureId, event.geometry.coordinates)
|
|
146
|
+
this.pushUndo({ type: 'replace_geometry', featureId: state.featureId, previousPosition })
|
|
147
|
+
},
|
|
148
|
+
|
|
139
149
|
onButtonClick (state, event) {
|
|
140
150
|
if (event.target.closest(`#${state.undoButtonId}`)) {
|
|
141
151
|
this.handleUndo(state)
|
|
@@ -6,26 +6,8 @@ import {
|
|
|
6
6
|
import { scalePoint } from './helpers.js'
|
|
7
7
|
import { sharedUndoHandlers } from '../../utils/geometryValidation.js'
|
|
8
8
|
|
|
9
|
-
// Map an undo-stack op type onto the geometry-change `phase` consumed by validation. Read off
|
|
10
|
-
// `this` by the shared pushUndo mixin (utils/geometryValidation.js) — see that file's comment.
|
|
11
|
-
const UNDO_OP_PHASE = {
|
|
12
|
-
move_vertex: 'commit-move',
|
|
13
|
-
insert_vertex: 'commit-insert',
|
|
14
|
-
delete_vertex: 'commit-delete'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Undoing an op commits the inverse change (undo of a delete re-inserts, etc.),
|
|
18
|
-
// so its re-validation reports the inverse phase.
|
|
19
|
-
const UNDO_INVERSE_PHASE = {
|
|
20
|
-
move_vertex: 'commit-move',
|
|
21
|
-
insert_vertex: 'commit-delete',
|
|
22
|
-
delete_vertex: 'commit-insert'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
9
|
export const undoHandlers = {
|
|
26
10
|
...sharedUndoHandlers,
|
|
27
|
-
UNDO_OP_PHASE,
|
|
28
|
-
UNDO_INVERSE_PHASE,
|
|
29
11
|
|
|
30
12
|
handleUndo (state) {
|
|
31
13
|
const undoStack = this.map._undoStack
|
|
@@ -41,12 +23,14 @@ export const undoHandlers = {
|
|
|
41
23
|
this.undoInsertVertex(state, op)
|
|
42
24
|
} else if (op.type === 'delete_vertex') {
|
|
43
25
|
this.undoDeleteVertex(state, op)
|
|
26
|
+
} else if (op.type === 'replace_geometry') {
|
|
27
|
+
this.replaceGeometry(state, op.featureId, op.previousGeometry)
|
|
44
28
|
} else {
|
|
45
29
|
// No action
|
|
46
30
|
}
|
|
47
31
|
// An undo commits the inverse change, so it must re-validate like any other
|
|
48
32
|
// commit — otherwise the invalid stroke and the Done gate go stale.
|
|
49
|
-
this.emitGeometryValidation(
|
|
33
|
+
this.emitGeometryValidation(op.vertexIndex, op.featureId)
|
|
50
34
|
},
|
|
51
35
|
|
|
52
36
|
undoMoveVertex (state, op) {
|
|
@@ -126,6 +110,17 @@ export const undoHandlers = {
|
|
|
126
110
|
this.changeMode(state, { selectedVertexIndex: vertexIndex, selectedVertexType: 'vertex', coordPath: this.getCoordPath(state, vertexIndex) })
|
|
127
111
|
},
|
|
128
112
|
|
|
113
|
+
// Swaps in a whole new geometry (setGeometry, or undoing one) and clears the selection,
|
|
114
|
+
// since vertex indices no longer refer to the same points.
|
|
115
|
+
replaceGeometry (state, featureId, geometry) {
|
|
116
|
+
const feature = this.getFeature(featureId)
|
|
117
|
+
if (!feature) { return }
|
|
118
|
+
this._applyUndoAndSync(state, { ...feature.toGeoJSON(), geometry }, featureId)
|
|
119
|
+
this.clearSelectedCoordinates()
|
|
120
|
+
this.hideTouchVertexIndicator(state)
|
|
121
|
+
this.changeMode(state, { selectedVertexIndex: -1, selectedVertexType: null })
|
|
122
|
+
},
|
|
123
|
+
|
|
129
124
|
_applyUndoAndSync (state, geojson, featureId) {
|
|
130
125
|
this._ctx.api.add(geojson)
|
|
131
126
|
state.vertices = this.getVertices(featureId)
|
|
@@ -4,16 +4,16 @@ import { getRingSegments } from './geometryHelpers.js'
|
|
|
4
4
|
// fireGeometryChange/emitGeometryValidation/pushUndo are the shared mixin from
|
|
5
5
|
// utils/geometryValidation.js — their own behaviour is covered by
|
|
6
6
|
// utils/geometryValidation.test.js. This file only tests what's specific to editVertexMode:
|
|
7
|
-
// pushUndo's
|
|
7
|
+
// pushUndo's validation, handleUndo's per-op-type dispatch, and the
|
|
8
8
|
// undoMoveVertex/undoInsertVertex/undoDeleteVertex ring operations themselves.
|
|
9
9
|
describe('undoHandlers', () => {
|
|
10
|
-
test('pushUndo
|
|
10
|
+
test('pushUndo validates each op type as a change', () => {
|
|
11
11
|
jest.useFakeTimers()
|
|
12
12
|
const { ctx, map } = createHarness()
|
|
13
13
|
map.fire.mockClear()
|
|
14
14
|
ctx.pushUndo({ type: 'move_vertex', featureId: 'feat-1', vertexIndex: 2 })
|
|
15
15
|
jest.runAllTimers()
|
|
16
|
-
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: '
|
|
16
|
+
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: 'change', vertexIndex: 2 }))
|
|
17
17
|
jest.useRealTimers()
|
|
18
18
|
})
|
|
19
19
|
|
|
@@ -42,7 +42,7 @@ describe('undoHandlers', () => {
|
|
|
42
42
|
ctx.handleUndo(state)
|
|
43
43
|
jest.runAllTimers()
|
|
44
44
|
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({
|
|
45
|
-
phase: '
|
|
45
|
+
phase: 'change',
|
|
46
46
|
vertexIndex: 1,
|
|
47
47
|
feature: expect.any(Object)
|
|
48
48
|
}))
|
|
@@ -88,4 +88,41 @@ describe('undoHandlers', () => {
|
|
|
88
88
|
ctx.undoDeleteVertex(state, { vertexIndex: seg.start + seg.length, position: [2, 2], featureId: 'feat-1' })
|
|
89
89
|
expect(ctx.getVertices('feat-1')).toHaveLength(6)
|
|
90
90
|
})
|
|
91
|
+
|
|
92
|
+
describe('setGeometry', () => {
|
|
93
|
+
const replacement = { type: 'Polygon', coordinates: [[[0, 0], [20, 0], [20, 20], [0, 20], [0, 0]]] }
|
|
94
|
+
|
|
95
|
+
test('replaces the shape on draw.setgeometry, clears the selection and re-validates as a change', () => {
|
|
96
|
+
jest.useFakeTimers()
|
|
97
|
+
const { ctx, map } = createHarness()
|
|
98
|
+
const changeMode = jest.spyOn(ctx, 'changeMode')
|
|
99
|
+
map.fire.mockClear()
|
|
100
|
+
map.fire('draw.setgeometry', { geometry: replacement })
|
|
101
|
+
expect(ctx.getFeature('feat-1').toGeoJSON().geometry).toEqual(replacement)
|
|
102
|
+
expect(changeMode).toHaveBeenCalledWith(expect.anything(), { selectedVertexIndex: -1, selectedVertexType: null })
|
|
103
|
+
jest.runAllTimers()
|
|
104
|
+
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: 'change' }))
|
|
105
|
+
jest.useRealTimers()
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('undo restores the previous shape and re-validates as a change', () => {
|
|
109
|
+
jest.useFakeTimers()
|
|
110
|
+
const { ctx, state, map } = createHarness()
|
|
111
|
+
const original = ctx.getFeature('feat-1').toGeoJSON().geometry
|
|
112
|
+
map.fire('draw.setgeometry', { geometry: replacement })
|
|
113
|
+
jest.runAllTimers()
|
|
114
|
+
map.fire.mockClear()
|
|
115
|
+
ctx.handleUndo(state)
|
|
116
|
+
expect(ctx.getFeature('feat-1').toGeoJSON().geometry).toEqual(original)
|
|
117
|
+
jest.runAllTimers()
|
|
118
|
+
expect(map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: 'change' }))
|
|
119
|
+
jest.useRealTimers()
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('guards a missing feature', () => {
|
|
123
|
+
const { ctx, state } = createHarness()
|
|
124
|
+
expect(() => ctx.onSetGeometry({ ...state, featureId: 'missing' }, { geometry: replacement })).not.toThrow()
|
|
125
|
+
expect(() => ctx.replaceGeometry(state, 'missing', replacement)).not.toThrow()
|
|
126
|
+
})
|
|
127
|
+
})
|
|
91
128
|
})
|
|
@@ -79,7 +79,8 @@ export const EditVertexMode = {
|
|
|
79
79
|
selectionchange: this.onSelectionChange,
|
|
80
80
|
update: this.onUpdate,
|
|
81
81
|
selectvertex: this.onSelectVertex,
|
|
82
|
-
insertvertexatmidpoint: this.onInsertVertexAtMidpoint
|
|
82
|
+
insertvertexatmidpoint: this.onInsertVertexAtMidpoint,
|
|
83
|
+
setgeometry: this.onSetGeometry
|
|
83
84
|
})
|
|
84
85
|
|
|
85
86
|
bindEditModeListeners(state, this.map, handlers)
|
|
@@ -197,6 +198,16 @@ export const EditVertexMode = {
|
|
|
197
198
|
this.insertVertex({ ...state, selectedVertexIndex: event.index, selectedVertexType: 'midpoint' })
|
|
198
199
|
},
|
|
199
200
|
|
|
201
|
+
// Inbound signal from MaplibreDrawAdapter.setGeometry — replaces the whole shape (e.g. a
|
|
202
|
+
// corrected boundary from the consumer) as one undoable commit.
|
|
203
|
+
onSetGeometry (state, event) {
|
|
204
|
+
const feature = this.getFeature(state.featureId)
|
|
205
|
+
if (!feature) { return }
|
|
206
|
+
const previousGeometry = feature.toGeoJSON().geometry
|
|
207
|
+
this.replaceGeometry(state, state.featureId, event.geometry)
|
|
208
|
+
this.pushUndo({ type: 'replace_geometry', featureId: state.featureId, previousGeometry })
|
|
209
|
+
},
|
|
210
|
+
|
|
200
211
|
onButtonClick (state, event) {
|
|
201
212
|
if (event.target.closest(`#${state.deleteVertexButtonId}`) && state.selectedVertexType === 'vertex') {
|
|
202
213
|
this.deleteVertex(state)
|
|
@@ -4,7 +4,7 @@ import { getSnapInstance, clearSnapIndicator } from './snapHelpers.js'
|
|
|
4
4
|
// Builds the `handlers` map both modes' setupEventListeners bind to bindEditModeListeners —
|
|
5
5
|
// the base set of window/container/scale/move/interface-type-change handlers is identical
|
|
6
6
|
// in both, bound to whichever mode instance is passed in; `extra` supplies the handlers that
|
|
7
|
-
// differ per mode (nudge, plus edit_vertex's own selectionchange/update).
|
|
7
|
+
// differ per mode (nudge and setgeometry, plus edit_vertex's own selectionchange/update).
|
|
8
8
|
export const buildEditModeHandlers = (mode, state, extra = {}) => {
|
|
9
9
|
const bind = (handler) => (event) => handler.call(mode, state, event)
|
|
10
10
|
const handlers = {
|
|
@@ -48,6 +48,7 @@ export const bindEditModeListeners = (state, map, handlers) => {
|
|
|
48
48
|
map.on('move', handlers.move)
|
|
49
49
|
map.on(CUSTOM_DRAW_EVENTS.INTERFACE_TYPE_CHANGE, handlers.interfacetypechange)
|
|
50
50
|
map.on(CUSTOM_DRAW_EVENTS.NUDGE_VERTEX, handlers.nudge)
|
|
51
|
+
map.on(CUSTOM_DRAW_EVENTS.SET_GEOMETRY, handlers.setgeometry)
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
// Mirrors bindEditModeListeners, plus the dragPan re-enable both modes' onStop does right
|
|
@@ -63,6 +64,7 @@ export const unbindEditModeListeners = (state, map, handlers) => {
|
|
|
63
64
|
map.off('move', handlers.move)
|
|
64
65
|
map.off(CUSTOM_DRAW_EVENTS.INTERFACE_TYPE_CHANGE, handlers.interfacetypechange)
|
|
65
66
|
map.off(CUSTOM_DRAW_EVENTS.NUDGE_VERTEX, handlers.nudge)
|
|
67
|
+
map.off(CUSTOM_DRAW_EVENTS.SET_GEOMETRY, handlers.setgeometry)
|
|
66
68
|
map.dragPan.enable()
|
|
67
69
|
window.removeEventListener('click', handlers.click)
|
|
68
70
|
window.removeEventListener('keydown', handlers.keydown, { capture: true })
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CHANGE_PHASE } from '../../../adapterEvents.js'
|
|
2
|
+
|
|
1
3
|
// Shared by editPointMode/undoHandlers.js and editVertexMode/undoHandlers.js — recording an
|
|
2
4
|
// undo op and feeding it to commit-level validation is identical plumbing for both modes; only
|
|
3
5
|
// the op types themselves differ (a Point only ever moves, a ring vertex can also be inserted
|
|
4
|
-
// or deleted)
|
|
5
|
-
// UNDO_INVERSE_PHASE maps (read here off `this`, since pushUndo is mixed into both modes).
|
|
6
|
+
// or deleted).
|
|
6
7
|
export const sharedUndoHandlers = {
|
|
7
8
|
// Fire geometry change event (for external listeners)
|
|
8
9
|
fireGeometryChange (state) {
|
|
@@ -15,16 +16,14 @@ export const sharedUndoHandlers = {
|
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
|
|
18
|
-
// Emit a commit-level geometrychange (feature + change phase + vertex index) so the
|
|
19
|
-
// validation layer can
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
emitGeometryValidation (phase, vertexIndex, featureId) {
|
|
23
|
-
if (!phase) { return }
|
|
19
|
+
// Emit a commit-level geometrychange (feature + 'change' phase + vertex index) so the
|
|
20
|
+
// validation layer can gate the Done button. Deferred a tick so it reports the shape
|
|
21
|
+
// after the current mutation (and its undo bookkeeping) has fully settled.
|
|
22
|
+
emitGeometryValidation (vertexIndex, featureId) {
|
|
24
23
|
setTimeout(() => {
|
|
25
24
|
const feature = this.getFeature(featureId)
|
|
26
25
|
if (!feature) { return }
|
|
27
|
-
this.map.fire('draw.geometrychange', { feature: feature.toGeoJSON(), phase, vertexIndex })
|
|
26
|
+
this.map.fire('draw.geometrychange', { feature: feature.toGeoJSON(), phase: CHANGE_PHASE, vertexIndex })
|
|
28
27
|
}, 0)
|
|
29
28
|
},
|
|
30
29
|
|
|
@@ -37,6 +36,6 @@ export const sharedUndoHandlers = {
|
|
|
37
36
|
undoStack.push(operation)
|
|
38
37
|
// Every edit commit (move/insert/delete, via mouse/touch/keyboard/D-pad) records an undo
|
|
39
38
|
// op here, so this is the single point that feeds commit-level validation.
|
|
40
|
-
this.emitGeometryValidation(
|
|
39
|
+
this.emitGeometryValidation(operation.vertexIndex, operation.featureId)
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -3,7 +3,6 @@ import { createUndoStack } from '../../../utils/undoStack.js'
|
|
|
3
3
|
|
|
4
4
|
const makeCtx = (overrides = {}) => ({
|
|
5
5
|
...sharedUndoHandlers,
|
|
6
|
-
UNDO_OP_PHASE: { move: 'commit-move' },
|
|
7
6
|
map: { fire: jest.fn(), _undoStack: createUndoStack(() => {}) },
|
|
8
7
|
getFeature: jest.fn((id) => (id === 'missing' ? undefined : { toGeoJSON: () => ({ type: 'Feature', id }) })),
|
|
9
8
|
...overrides
|
|
@@ -22,25 +21,16 @@ describe('fireGeometryChange', () => {
|
|
|
22
21
|
})
|
|
23
22
|
|
|
24
23
|
describe('emitGeometryValidation', () => {
|
|
25
|
-
test('does nothing without a phase', () => {
|
|
26
|
-
jest.useFakeTimers()
|
|
27
|
-
const ctx = makeCtx()
|
|
28
|
-
ctx.emitGeometryValidation(undefined, 0, 'feat-1')
|
|
29
|
-
jest.runAllTimers()
|
|
30
|
-
expect(ctx.map.fire).not.toHaveBeenCalled()
|
|
31
|
-
jest.useRealTimers()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
24
|
test('fires a deferred draw.geometrychange with the phase, vertexIndex and feature', () => {
|
|
35
25
|
jest.useFakeTimers()
|
|
36
26
|
const ctx = makeCtx()
|
|
37
|
-
ctx.emitGeometryValidation(
|
|
27
|
+
ctx.emitGeometryValidation(2, 'feat-1')
|
|
38
28
|
// Deferred a tick to avoid re-entrancy — nothing fired synchronously.
|
|
39
29
|
expect(ctx.map.fire).not.toHaveBeenCalled()
|
|
40
30
|
|
|
41
31
|
jest.runAllTimers()
|
|
42
32
|
expect(ctx.map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({
|
|
43
|
-
phase: '
|
|
33
|
+
phase: 'change',
|
|
44
34
|
vertexIndex: 2,
|
|
45
35
|
feature: expect.any(Object)
|
|
46
36
|
}))
|
|
@@ -50,7 +40,7 @@ describe('emitGeometryValidation', () => {
|
|
|
50
40
|
test('does not fire once the feature is gone', () => {
|
|
51
41
|
jest.useFakeTimers()
|
|
52
42
|
const ctx = makeCtx()
|
|
53
|
-
ctx.emitGeometryValidation(
|
|
43
|
+
ctx.emitGeometryValidation(0, 'missing')
|
|
54
44
|
jest.runAllTimers()
|
|
55
45
|
expect(ctx.map.fire).not.toHaveBeenCalled()
|
|
56
46
|
jest.useRealTimers()
|
|
@@ -63,23 +53,14 @@ describe('pushUndo', () => {
|
|
|
63
53
|
expect(() => ctx.pushUndo({ type: 'move' })).not.toThrow()
|
|
64
54
|
})
|
|
65
55
|
|
|
66
|
-
test('pushes the operation and emits validation
|
|
56
|
+
test('pushes the operation and emits validation as a change', () => {
|
|
67
57
|
jest.useFakeTimers()
|
|
68
58
|
const ctx = makeCtx()
|
|
69
59
|
ctx.pushUndo({ type: 'move', featureId: 'feat-1', vertexIndex: 0 })
|
|
70
60
|
expect(ctx.map._undoStack.length).toBe(1)
|
|
71
61
|
|
|
72
62
|
jest.runAllTimers()
|
|
73
|
-
expect(ctx.map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: '
|
|
74
|
-
jest.useRealTimers()
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
test('does not emit validation for an unmapped op type', () => {
|
|
78
|
-
jest.useFakeTimers()
|
|
79
|
-
const ctx = makeCtx()
|
|
80
|
-
ctx.pushUndo({ type: 'unmapped', featureId: 'feat-1' })
|
|
81
|
-
jest.runAllTimers()
|
|
82
|
-
expect(ctx.map.fire).not.toHaveBeenCalled()
|
|
63
|
+
expect(ctx.map.fire).toHaveBeenCalledWith('draw.geometrychange', expect.objectContaining({ phase: 'change' }))
|
|
83
64
|
jest.useRealTimers()
|
|
84
65
|
})
|
|
85
66
|
})
|
|
@@ -27,6 +27,7 @@ const DRAW_OUTLINE_STYLE_LAYER = 'stroke-inactive.cold'
|
|
|
27
27
|
* done() / cancel() / undo() / deleteVertex()
|
|
28
28
|
* nudgeSelectedVertex(dx, dy, isLargeStep)
|
|
29
29
|
* getVertexItems() / selectVertex(index) / insertVertexAtMidpoint(index)
|
|
30
|
+
* setGeometry(geometry)
|
|
30
31
|
* get(id) / add(feature) / setStyle(id, properties) / delete(id) / deleteAll()
|
|
31
32
|
* setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
|
|
32
33
|
* setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
|
|
@@ -83,15 +84,17 @@ export class OLDrawAdapter {
|
|
|
83
84
|
getVertexItems () { return this._manager.getVertexItems() }
|
|
84
85
|
selectVertex (index) { this._manager.selectVertex(index) }
|
|
85
86
|
insertVertexAtMidpoint (index) { this._manager.insertVertexAtMidpoint(index) }
|
|
87
|
+
setGeometry (geometry) { this._manager.setGeometry(geometry) }
|
|
86
88
|
|
|
87
|
-
// Record the
|
|
88
|
-
// (double-click / click-to-close) while
|
|
89
|
-
|
|
89
|
+
// Record whether the in-progress shape can be finished, so the draw mode can block finish
|
|
90
|
+
// gestures (double-click / click-to-close) while its latest check has failed.
|
|
91
|
+
setCanFinish (canFinish) { this._manager._canFinish = canFinish }
|
|
90
92
|
|
|
91
|
-
// The api entry points assign the
|
|
92
|
-
// on the manager so the
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
// The api entry points assign the session's onGeometryPreview callback to the adapter
|
|
94
|
+
// (see validation/commitChecks.js's startCheckSession); store it on the manager so the
|
|
95
|
+
// draw mode can veto placements synchronously.
|
|
96
|
+
set _previewValidator (fn) { this._manager._previewValidator = fn }
|
|
97
|
+
get _previewValidator () { return this._manager._previewValidator }
|
|
95
98
|
|
|
96
99
|
// Show/hide the dashed invalid stroke on the active sketch or edit feature.
|
|
97
100
|
setInvalid (invalid) { this._manager.setInvalid(invalid) }
|
|
@@ -19,6 +19,7 @@ const fakeManager = () => ({
|
|
|
19
19
|
getVertexItems: jest.fn(() => ({ vertices: [[0, 0]], midpoints: [] })),
|
|
20
20
|
selectVertex: jest.fn(),
|
|
21
21
|
insertVertexAtMidpoint: jest.fn(),
|
|
22
|
+
setGeometry: jest.fn(),
|
|
22
23
|
setInvalid: jest.fn(),
|
|
23
24
|
setDrawingPreviewProperty: jest.fn(),
|
|
24
25
|
get: jest.fn(() => 'feature'),
|
|
@@ -147,6 +148,10 @@ test('remaining calls delegate straight through; setFeatureProperty is a deliber
|
|
|
147
148
|
adapter.insertVertexAtMidpoint(3)
|
|
148
149
|
expect(manager.selectVertex).toHaveBeenCalledWith(2)
|
|
149
150
|
expect(manager.insertVertexAtMidpoint).toHaveBeenCalledWith(3)
|
|
151
|
+
|
|
152
|
+
const geometry = { type: 'Polygon', coordinates: [] }
|
|
153
|
+
adapter.setGeometry(geometry)
|
|
154
|
+
expect(manager.setGeometry).toHaveBeenCalledWith(geometry)
|
|
150
155
|
})
|
|
151
156
|
|
|
152
157
|
// A directly-added Point skips draw_point's own icon-resolving drawend handler.
|
|
@@ -231,18 +236,18 @@ describe('setStyle()', () => {
|
|
|
231
236
|
})
|
|
232
237
|
})
|
|
233
238
|
|
|
234
|
-
test('
|
|
239
|
+
test('setCanFinish records validity on the manager for finish gating', () => {
|
|
235
240
|
const { adapter, manager } = setup()
|
|
236
|
-
adapter.
|
|
237
|
-
expect(manager.
|
|
241
|
+
adapter.setCanFinish(false)
|
|
242
|
+
expect(manager._canFinish).toBe(false)
|
|
238
243
|
})
|
|
239
244
|
|
|
240
|
-
test('
|
|
245
|
+
test('_previewValidator accessor stores and retrieves the preview callback on the manager', () => {
|
|
241
246
|
const { adapter, manager } = setup()
|
|
242
247
|
const validator = jest.fn(() => ({ valid: true }))
|
|
243
|
-
adapter.
|
|
244
|
-
expect(manager.
|
|
245
|
-
expect(adapter.
|
|
248
|
+
adapter._previewValidator = validator
|
|
249
|
+
expect(manager._previewValidator).toBe(validator)
|
|
250
|
+
expect(adapter._previewValidator).toBe(validator)
|
|
246
251
|
})
|
|
247
252
|
|
|
248
253
|
test('setInvalid delegates to the manager to toggle the dashed stroke', () => {
|