@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateGeometry, validatePlacement, attemptPlacement, validateDisplayedGeometry } from './validateGeometry.js'
|
|
1
|
+
import { validateGeometry, validatePlacement, attemptPlacement, validateDisplayedGeometry, normaliseResult, toPlacementBlocked } from './validateGeometry.js'
|
|
2
2
|
|
|
3
3
|
const poly = (coordinates) => ({ type: 'Feature', geometry: { type: 'Polygon', coordinates: [coordinates] } })
|
|
4
4
|
|
|
@@ -29,32 +29,32 @@ describe('validateGeometry (soft gating)', () => {
|
|
|
29
29
|
test('short-circuits on the first failing rule', () => {
|
|
30
30
|
const first = jest.fn(() => ({ valid: false, reason: 'first' }))
|
|
31
31
|
const second = jest.fn(() => ({ valid: true }))
|
|
32
|
-
expect(validateGeometry(square, {}, { rules: [first, second] })).toEqual({ valid: false, reason: 'first' })
|
|
32
|
+
expect(validateGeometry(square, {}, { rules: [first, second] })).toEqual({ valid: false, reason: 'first', source: 'rules' })
|
|
33
33
|
expect(second).not.toHaveBeenCalled()
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
test('passes the context to rules as (feature, context), and to the callback as a single flattened event object', () => {
|
|
37
37
|
const rule = jest.fn(() => ({ valid: true }))
|
|
38
|
-
const
|
|
39
|
-
const context = { phase: '
|
|
40
|
-
validateGeometry(square, context, { rules: [rule],
|
|
38
|
+
const onGeometryPreview = jest.fn(() => ({ valid: true }))
|
|
39
|
+
const context = { phase: 'change', vertexIndex: 2, mode: 'edit_vertex' }
|
|
40
|
+
validateGeometry(square, context, { rules: [rule], onGeometryPreview })
|
|
41
41
|
expect(rule).toHaveBeenCalledWith(square, context)
|
|
42
|
-
expect(
|
|
42
|
+
expect(onGeometryPreview).toHaveBeenCalledWith({ feature: square, ...context })
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
test('runs the user callback after the rules pass', () => {
|
|
46
|
-
expect(validateGeometry(square, {}, { rules: [],
|
|
47
|
-
.toEqual({ valid: false, reason: null })
|
|
48
|
-
expect(validateGeometry(square, {}, { rules: [],
|
|
46
|
+
expect(validateGeometry(square, {}, { rules: [], onGeometryPreview: () => false }))
|
|
47
|
+
.toEqual({ valid: false, reason: null, source: 'callback' })
|
|
48
|
+
expect(validateGeometry(square, {}, { rules: [], onGeometryPreview: () => true }))
|
|
49
49
|
.toEqual({ valid: true })
|
|
50
|
-
expect(validateGeometry(square, {}, { rules: [],
|
|
51
|
-
.toEqual({ valid: false, reason: 'too big' })
|
|
50
|
+
expect(validateGeometry(square, {}, { rules: [], onGeometryPreview: () => ({ valid: false, reason: 'too big' }) }))
|
|
51
|
+
.toEqual({ valid: false, reason: 'too big', source: 'callback' })
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
test('does not run the callback when a rule fails', () => {
|
|
55
|
-
const
|
|
56
|
-
validateGeometry(square, {}, { rules: [() => ({ valid: false })],
|
|
57
|
-
expect(
|
|
55
|
+
const onGeometryPreview = jest.fn()
|
|
56
|
+
validateGeometry(square, {}, { rules: [() => ({ valid: false })], onGeometryPreview })
|
|
57
|
+
expect(onGeometryPreview).not.toHaveBeenCalled()
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
test('is valid with no rules and no callback', () => {
|
|
@@ -76,6 +76,7 @@ describe('attemptPlacement (shared engine gate)', () => {
|
|
|
76
76
|
expect(result.blocked).toEqual({
|
|
77
77
|
feature: expect.objectContaining({ type: 'Feature' }),
|
|
78
78
|
reason: expect.stringMatching(/intersect/i),
|
|
79
|
+
source: 'rules',
|
|
79
80
|
phase: 'place',
|
|
80
81
|
mode: 'draw_polygon',
|
|
81
82
|
vertexIndex: 3
|
|
@@ -83,15 +84,15 @@ describe('attemptPlacement (shared engine gate)', () => {
|
|
|
83
84
|
})
|
|
84
85
|
|
|
85
86
|
test('the user callback can veto, with mode derived from the geometry type', () => {
|
|
86
|
-
const
|
|
87
|
-
const result = attemptPlacement({ placed: [[0, 0]], point: [1, 1], geometryType: 'LineString',
|
|
87
|
+
const onGeometryPreview = jest.fn(() => ({ valid: false, reason: 'outside region' }))
|
|
88
|
+
const result = attemptPlacement({ placed: [[0, 0]], point: [1, 1], geometryType: 'LineString', onGeometryPreview })
|
|
88
89
|
expect(result.blocked).toEqual(expect.objectContaining({ mode: 'draw_line', reason: 'outside region', vertexIndex: 1 }))
|
|
89
|
-
expect(
|
|
90
|
+
expect(onGeometryPreview).toHaveBeenCalledWith(expect.objectContaining({ phase: 'place', mode: 'draw_line', vertexIndex: 1 }))
|
|
90
91
|
})
|
|
91
92
|
|
|
92
93
|
test('a veto with no reason falls back to null in the PLACEMENT_BLOCKED payload', () => {
|
|
93
|
-
const
|
|
94
|
-
const result = attemptPlacement({ placed: [[0, 0]], point: [1, 1], geometryType: 'LineString',
|
|
94
|
+
const onGeometryPreview = jest.fn(() => false) // false → invalid, no reason (see normaliseResult)
|
|
95
|
+
const result = attemptPlacement({ placed: [[0, 0]], point: [1, 1], geometryType: 'LineString', onGeometryPreview })
|
|
95
96
|
expect(result.blocked.reason).toBeNull()
|
|
96
97
|
})
|
|
97
98
|
|
|
@@ -126,42 +127,42 @@ describe('validateDisplayedGeometry edge cases', () => {
|
|
|
126
127
|
expect(validateDisplayedGeometry(poly([[0, 0]]))).toEqual({ valid: true })
|
|
127
128
|
})
|
|
128
129
|
|
|
129
|
-
test('calls the caller\'s own
|
|
130
|
-
const
|
|
130
|
+
test('calls the caller\'s own onGeometryPreview once at/above the vertex threshold, with a single flattened event object', () => {
|
|
131
|
+
const onGeometryPreview = jest.fn(() => ({ valid: false, reason: 'too few for my rule' }))
|
|
131
132
|
// Polygon minimum is 3 placed vertices — this feature/numVertices pair is at it.
|
|
132
133
|
const feature = poly([[0, 0], [1, 0], [1, 1]])
|
|
133
134
|
|
|
134
|
-
const result = validateDisplayedGeometry(feature, { numVertices: 3 }, {
|
|
135
|
+
const result = validateDisplayedGeometry(feature, { numVertices: 3 }, { onGeometryPreview })
|
|
135
136
|
|
|
136
|
-
expect(
|
|
137
|
-
expect(result).toEqual({ valid: false, reason: 'too few for my rule' })
|
|
137
|
+
expect(onGeometryPreview).toHaveBeenCalledWith(expect.objectContaining({ feature, numVertices: 3, phase: 'preview' }))
|
|
138
|
+
expect(result).toEqual({ valid: false, reason: 'too few for my rule', source: 'callback' })
|
|
138
139
|
})
|
|
139
140
|
|
|
140
|
-
test('skips the built-in rules with zero committed vertices, but still runs the caller\'s
|
|
141
|
+
test('skips the built-in rules with zero committed vertices, but still runs the caller\'s onGeometryPreview — a location-based rule is meaningful against the very first candidate point', () => {
|
|
141
142
|
const failingRule = jest.fn(() => ({ valid: false, reason: 'should not run' }))
|
|
142
|
-
const
|
|
143
|
+
const onGeometryPreview = jest.fn(() => ({ valid: false, reason: 'outside region' }))
|
|
143
144
|
const feature = poly([[0, 0]])
|
|
144
145
|
|
|
145
|
-
const result = validateDisplayedGeometry(feature, { numVertices: 0 }, { rules: [failingRule],
|
|
146
|
+
const result = validateDisplayedGeometry(feature, { numVertices: 0 }, { rules: [failingRule], onGeometryPreview })
|
|
146
147
|
|
|
147
148
|
expect(failingRule).not.toHaveBeenCalled()
|
|
148
|
-
expect(
|
|
149
|
-
expect(result).toEqual({ valid: false, reason: 'outside region' })
|
|
149
|
+
expect(onGeometryPreview).toHaveBeenCalledWith(expect.objectContaining({ feature, numVertices: 0, phase: 'preview' }))
|
|
150
|
+
expect(result).toEqual({ valid: false, reason: 'outside region', source: 'callback' })
|
|
150
151
|
})
|
|
151
152
|
|
|
152
|
-
test('runs the caller\'s
|
|
153
|
+
test('runs the caller\'s onGeometryPreview from the first committed vertex, even while the built-in rules are still skipped', () => {
|
|
153
154
|
const failingRule = jest.fn(() => ({ valid: false, reason: 'should not run' }))
|
|
154
155
|
// A single committed vertex — well below the Polygon minimum of 3 — so the
|
|
155
156
|
// built-in self-intersection/area rules stay skipped, but a per-point user
|
|
156
157
|
// rule (e.g. "is this inside a region?") is meaningful and should still run.
|
|
157
|
-
const
|
|
158
|
+
const onGeometryPreview = jest.fn(() => ({ valid: false, reason: 'outside region' }))
|
|
158
159
|
const feature = poly([[0, 0], [1, 1]])
|
|
159
160
|
|
|
160
|
-
const result = validateDisplayedGeometry(feature, { numVertices: 1 }, { rules: [failingRule],
|
|
161
|
+
const result = validateDisplayedGeometry(feature, { numVertices: 1 }, { rules: [failingRule], onGeometryPreview })
|
|
161
162
|
|
|
162
163
|
expect(failingRule).not.toHaveBeenCalled()
|
|
163
|
-
expect(
|
|
164
|
-
expect(result).toEqual({ valid: false, reason: 'outside region' })
|
|
164
|
+
expect(onGeometryPreview).toHaveBeenCalledWith(expect.objectContaining({ feature, numVertices: 1, phase: 'preview' }))
|
|
165
|
+
expect(result).toEqual({ valid: false, reason: 'outside region', source: 'callback' })
|
|
165
166
|
})
|
|
166
167
|
})
|
|
167
168
|
|
|
@@ -181,20 +182,43 @@ describe('validatePlacement (hard gating)', () => {
|
|
|
181
182
|
})
|
|
182
183
|
|
|
183
184
|
test('forces phase "place" into the rule and callback context', () => {
|
|
184
|
-
const
|
|
185
|
-
validatePlacement(simplePath, { mode: 'draw_polygon', vertexIndex: 4 }, {
|
|
186
|
-
expect(
|
|
185
|
+
const onGeometryPreview = jest.fn(() => true)
|
|
186
|
+
validatePlacement(simplePath, { mode: 'draw_polygon', vertexIndex: 4 }, { onGeometryPreview })
|
|
187
|
+
expect(onGeometryPreview).toHaveBeenCalledWith({ feature: simplePath, phase: 'place', mode: 'draw_polygon', vertexIndex: 4 })
|
|
187
188
|
})
|
|
188
189
|
|
|
189
190
|
test('the user callback can veto a placement with a reason', () => {
|
|
190
|
-
const
|
|
191
|
-
expect(validatePlacement(simplePath, {}, {
|
|
192
|
-
.toEqual({ valid: false, reason: 'outside region' })
|
|
191
|
+
const onGeometryPreview = () => ({ valid: false, reason: 'outside region' })
|
|
192
|
+
expect(validatePlacement(simplePath, {}, { onGeometryPreview }))
|
|
193
|
+
.toEqual({ valid: false, reason: 'outside region', source: 'callback' })
|
|
193
194
|
})
|
|
194
195
|
|
|
195
|
-
test('
|
|
196
|
-
const
|
|
197
|
-
validatePlacement(crossingPath, {}, {
|
|
198
|
-
expect(
|
|
196
|
+
test('placement rules run before the user callback', () => {
|
|
197
|
+
const onGeometryPreview = jest.fn()
|
|
198
|
+
validatePlacement(crossingPath, {}, { onGeometryPreview })
|
|
199
|
+
expect(onGeometryPreview).not.toHaveBeenCalled()
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
// onGeometryPreview must answer synchronously; a Promise it returns can't be waited for
|
|
204
|
+
describe('normaliseResult', () => {
|
|
205
|
+
test('treats a returned Promise as valid', () => {
|
|
206
|
+
expect(normaliseResult(Promise.resolve(false)).valid).toBe(true)
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
test('keeps an announcement and recheckOnFinish, and drops anything else', () => {
|
|
210
|
+
expect(normaliseResult({ valid: true, announcement: 'Area 2 hectares', recheckOnFinish: true, other: 1 }))
|
|
211
|
+
.toEqual({ valid: true, reason: undefined, announcement: 'Area 2 hectares', recheckOnFinish: true })
|
|
212
|
+
expect(normaliseResult({ valid: false, reason: 'too big' })).not.toHaveProperty('announcement')
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
describe('toPlacementBlocked', () => {
|
|
217
|
+
test('carries the reason, source and any announcement', () => {
|
|
218
|
+
const feature = { type: 'Feature' }
|
|
219
|
+
expect(toPlacementBlocked(feature, { reason: 'outside', source: 'callback', announcement: 'Outside the area' }, { mode: 'draw_point', vertexIndex: 0 }))
|
|
220
|
+
.toEqual({ feature, reason: 'outside', source: 'callback', announcement: 'Outside the area', phase: 'place', mode: 'draw_point', vertexIndex: 0 })
|
|
221
|
+
expect(toPlacementBlocked(feature, { source: 'rules' }, { mode: 'draw_polygon', vertexIndex: 2 }))
|
|
222
|
+
.toEqual({ feature, reason: null, source: 'rules', phase: 'place', mode: 'draw_polygon', vertexIndex: 2 })
|
|
199
223
|
})
|
|
200
224
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as e,useRef as t,useEffect as r,useMemo as n}from"preact/compat";import"preact/jsx-runtime";const o={MAP_SET_SIZE:"map:setsize",MAP_SET_ACTIVE_ITEM:"map:setactiveitem",MAP_SELECT_ITEM:"map:selectitem",MAP_STYLE_CHANGE:"map:stylechange",MAP_MOVE_END:"map:moveend",MAP_DATA_CHANGE:"map:datachange",MAP_CLICK:"map:click"};function i(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function a(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!u(e[0])||!u(e[1]))throw new Error("coordinates must contain numbers");return i({type:"Point",coordinates:e},t,r)}function s(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return i({type:"LineString",coordinates:e},t,r)}function l(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return i({type:"MultiLineString",coordinates:e},t,r)}function u(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}const d=11102230246251565e-32,p=134217729,f=(3+8*d)*d;function y(e,t,r,n,o){let i,a,s,l,c=t[0],u=n[0],d=0,p=0;u>c==u>-c?(i=c,c=t[++d]):(i=u,u=n[++p]);let f=0;if(d<e&&p<r)for(u>c==u>-c?(a=c+i,s=i-(a-c),c=t[++d]):(a=u+i,s=i-(a-u),u=n[++p]),i=a,0!==s&&(o[f++]=s);d<e&&p<r;)u>c==u>-c?(a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d]):(a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p]),i=a,0!==s&&(o[f++]=s);for(;d<e;)a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d],i=a,0!==s&&(o[f++]=s);for(;p<r;)a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p],i=a,0!==s&&(o[f++]=s);return 0===i&&0!==f||(o[f++]=i),f}function g(e){return new Float64Array(e)}const m=g(4),h=g(8),E=g(12),S=g(16),v=g(4);function b(e,t,r,n,o,i){const a=(t-i)*(r-o),s=(e-o)*(n-i),l=a-s,c=Math.abs(a+s);return Math.abs(l)>=33306690738754716e-32*c?l:-function(e,t,r,n,o,i,a){let s,l,c,u,d,g,b,k,M,P,I,A,w,C,T,_,L,F;const x=e-o,R=r-o,B=t-i,D=n-i;C=x*D,g=p*x,b=g-(g-x),k=x-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=B*R,g=p*B,b=g-(g-B),k=B-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,m[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,m[1]=w-(I+d)+(d-_),F=A+I,d=F-A,m[2]=A-(F-d)+(I-d),m[3]=F;let G=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,m),O=22204460492503146e-32*a;if(G>=O||-G>=O)return G;if(d=e-x,s=e-(x+d)+(d-o),d=r-R,c=r-(R+d)+(d-o),d=t-B,l=t-(B+d)+(d-i),d=n-D,u=n-(D+d)+(d-i),0===s&&0===l&&0===c&&0===u)return G;if(O=11093356479670487e-47*a+f*Math.abs(G),G+=x*u+D*s-(B*c+R*l),G>=O||-G>=O)return G;C=s*D,g=p*s,b=g-(g-s),k=s-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=l*R,g=p*l,b=g-(g-l),k=l-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const H=y(4,m,4,v,h);C=x*u,g=p*x,b=g-(g-x),k=x-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=B*c,g=p*B,b=g-(g-B),k=B-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const N=y(H,h,4,v,E);C=s*u,g=p*s,b=g-(g-s),k=s-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=l*c,g=p*l,b=g-(g-l),k=l-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const K=y(N,E,4,v,S);return S[K-1]}(e,t,r,n,o,i,c)}function k(e,t){var r,n,o,i,a,s,l,c,u,d=0,p=e[0],f=e[1],y=t.length;for(r=0;r<y;r++){n=0;var g=t[r],m=g.length-1;if((c=g[0])[0]!==g[m][0]&&c[1]!==g[m][1])throw new Error("First and last coordinates in a ring must be the same");for(i=c[0]-p,a=c[1]-f;n<m;n++){if(s=(u=g[n+1])[0]-p,l=u[1]-f,0===a&&0===l){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(l>=0&&a<=0||l<=0&&a>=0){if(0===(o=b(i,s,a,l,0,0)))return 0;(o>0&&l>0&&a<=0||o<0&&l<=0&&a>0)&&d++}c=u,a=l,i=s}}return d%2!=0}function M(e){return"Feature"===e.type?e.geometry:e}function P(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=function(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}(e),o=M(t),i=o.type,a=t.bbox;let s=o.coordinates;if(a&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(n,a))return!1;"Polygon"===i&&(s=[s]);let l=!1;for(var c=0;c<s.length;++c){const e=k(n,s[c]);if(0===e)return!r.ignoreBoundary;e&&(l=!0)}return l}class I{constructor(e=[],t=A){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,n=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(n,i)>=0)break;t[e]=i,e=o}t[e]=n}_down(e){const{data:t,compare:r}=this,n=this.length>>1,o=t[e];for(;e<n;){let n=1+(e<<1),i=t[n];const a=n+1;if(a<this.length&&r(t[a],i)<0&&(n=a,i=t[a]),r(i,o)>=0)break;t[e]=i,e=n}t[e]=o}}function A(e,t){return e<t?-1:e>t?1:0}function w(e,t){return e.p.x>t.p.x?1:e.p.x<t.p.x?-1:e.p.y!==t.p.y?e.p.y>t.p.y?1:-1:1}function C(e,t){return e.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:e.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:e.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?e.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}class T{constructor(e,t,r,n){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=r,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let _=0,L=0,F=0;function x(e,t){const r="Feature"===e.type?e.geometry:e;let n=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(n=[n]),"LineString"===r.type&&(n=[[n]]);for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length;r++){let o=n[e][r][0],i=null;L+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new T(o,_,L,F),l=new T(i,_,L,F+1);s.otherEvent=l,l.otherEvent=s,w(s,l)>0?(l.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,l.isLeftEndpoint=!1),t.push(s),t.push(l),o=i,F+=1}}_+=1}class R{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function B(e,t){if(null===e||null===t)return!1;if(e.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.rightSweepEvent)||e.leftSweepEvent.isSamePoint(t.leftSweepEvent)||e.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;const r=e.leftSweepEvent.p.x,n=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,a=t.leftSweepEvent.p.x,s=t.leftSweepEvent.p.y,l=t.rightSweepEvent.p.x,c=t.rightSweepEvent.p.y,u=(c-s)*(o-r)-(l-a)*(i-n),d=(l-a)*(n-s)-(c-s)*(r-a),p=(o-r)*(n-s)-(i-n)*(r-a);if(0===u)return!1;const f=d/u,y=p/u;if(f>=0&&f<=1&&y>=0&&y<=1){return[r+f*(o-r),n+f*(i-n)]}return!1}var D=function(e,t){const r=new I([],w);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)x(r[e],t)}else x(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new I([],C);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new R(o);for(let i=0;i<n.data.length;i++){const a=n.data[i];if(t&&a.leftSweepEvent.featureId===o.featureId)continue;const s=B(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function G(e,t,r={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:o=!0}=r;let s=[];"FeatureCollection"===e.type?s=s.concat(e.features):"Feature"===e.type?s.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||s.push(i(e)),"FeatureCollection"===t.type?s=s.concat(t.features):"Feature"===t.type?s.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||s.push(i(t));const c=D(l(s),o);let u=[];if(n){const e={};c.forEach(t=>{const r=t.join(",");e[r]||(e[r]=!0,u.push(t))})}else u=c;return l(u.map(e=>a(e)))}function O(e,t,r){if(null!==e)for(var n,o,i,a,s,l,c,u,d=0,p=0,f=e.type,y="FeatureCollection"===f,g="Feature"===f,m=y?e.features.length:1,h=0;h<m;h++){s=(u=!!(c=y?e.features[h].geometry:g?e.geometry:e)&&"GeometryCollection"===c.type)?c.geometries.length:1;for(var E=0;E<s;E++){var S=0,v=0;if(null!==(a=u?c.geometries[E]:c)){l=a.coordinates;var b=a.type;switch(d=0,b){case null:break;case"Point":if(!1===t(l,p,h,S,v))return!1;p++,S++;break;case"LineString":case"MultiPoint":for(n=0;n<l.length;n++){if(!1===t(l[n],p,h,S,v))return!1;p++,"MultiPoint"===b&&S++}"LineString"===b&&S++;break;case"Polygon":case"MultiLineString":for(n=0;n<l.length;n++){for(o=0;o<l[n].length-d;o++){if(!1===t(l[n][o],p,h,S,v))return!1;p++}"MultiLineString"===b&&S++,"Polygon"===b&&v++}"Polygon"===b&&S++;break;case"MultiPolygon":for(n=0;n<l.length;n++){for(v=0,o=0;o<l[n].length;o++){for(i=0;i<l[n][o].length-d;i++){if(!1===t(l[n][o][i],p,h,S,v))return!1;p++}v++}S++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===O(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function H(e,t){!function(e,t){var r,n,o,i,a,s,l,c,u,d,p=0,f="FeatureCollection"===e.type,y="Feature"===e.type,g=f?e.features.length:1;for(r=0;r<g;r++){for(s=f?e.features[r].geometry:y?e.geometry:e,c=f?e.features[r].properties:y?e.properties:{},u=f?e.features[r].bbox:y?e.bbox:void 0,d=f?e.features[r].id:y?e.id:void 0,a=(l=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=l?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,c,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,c,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,c,u,d))return!1;p++}}(e,function(e,r,n,o,a){var s,l=null===e?null:e.type;switch(l){case null:case"Point":case"LineString":case"Polygon":return!1!==t(i(e,n,{bbox:o,id:a}),r,0)&&void 0}switch(l){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var c=0;c<e.coordinates.length;c++){var u=e.coordinates[c];if(!1===t(i({type:s,coordinates:u},n),r,c))return!1}})}function N(e,t={}){const r=M(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return K(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(K(e,o))}),l(i)}(r,t);default:throw new Error("invalid poly")}}function K(e,t){return e.length>1?c(e,t):s(e[0],t)}function U(e,t){for(let r=0;r<e.coordinates.length-1;r++)if($(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function V(e,t,r){for(const r of t.coordinates)if(P(r,e))return!0;return G(t,N(e),{ignoreSelfIntersections:r}).features.length>0}function $(e,t,r){const n=r[0]-e[0],o=r[1]-e[1],i=t[0]-e[0],a=t[1]-e[1];return 0===n*a-o*i&&(Math.abs(i)>=Math.abs(a)?i>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:a>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1])}var j=function(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return H(e,e=>{H(t,t=>{if(!1===n)return!1;n=function(e,t,r){switch(e.type){case"Point":switch(t.type){case"Point":return n=e.coordinates,o=t.coordinates,!(n[0]===o[0]&&n[1]===o[1]);case"LineString":return!U(t,e);case"Polygon":return!P(e,t)}break;case"LineString":switch(t.type){case"Point":return!U(e,t);case"LineString":return!function(e,t,r){const n=G(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!V(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!P(t,e);case"LineString":return!V(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(P(r,t))return!0;for(const r of t.coordinates[0])if(P(r,e))return!0;const n=G(N(e),N(t),{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(t,e,r)}}var n,o;return!1}(e.geometry,t.geometry,r)})}),n};var q=function(e,t={}){if(null!=e.bbox&&!0!==t.recompute)return e.bbox;const r=[1/0,1/0,-1/0,-1/0];return O(e,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r};function z(e){const t=e.geometry||e;switch(t.type){case"Polygon":return function(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return i({type:"Polygon",coordinates:e},t,r)}(t.coordinates);case"MultiPolygon":return function(e,t,r={}){return i({type:"MultiPolygon",coordinates:e},t,r)}(t.coordinates);case"LineString":return s(t.coordinates);case"MultiLineString":return c(t.coordinates);case"Point":return a(t.coordinates);case"MultiPoint":return function(e,t,r={}){return i({type:"MultiPoint",coordinates:e},t,r)}(t.coordinates);default:throw new Error(`Unsupported geometry type: ${t.type}`)}}function X(e,t){return t.some(t=>!j(z(t),z(e)))}function W(e){if(e.length<2)return!1;if(e.some(e=>{return t=e.geometry?.type,!("Polygon"===t||"MultiPolygon"===t);var t}))return!1;const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length}const Y={".cold":".hot",".hot":".cold"},Z=e=>{for(const[t,r]of Object.entries(Y))if(e.endsWith(t))return`${e.slice(0,-t.length)}${r}`;return null},J=e=>{const t={};for(const r of e){t[r.layerId]=r;const e=Z(r.layerId);e&&(t[e]=r)}return t},Q=(e,t,r)=>{try{return e?.getFeaturesAtPoint(t,r)||[]}catch(e){return console.warn("Feature query failed:",e),[]}},ee=e=>{const t=e.geometry?.type;return"Point"===t||"MultiPoint"===t},te=(e,t)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&e[t])return e[t];return Object.values(e)[0]??null}return null},re=e=>!!e.label&&(!e.symbol&&!e.svgContent&&(null===e.symbol||null===e.svgContent)),ne={light:{haloColor:"#ffffff",selectedColor:"#0b0c0c",activeColor:"#ffdd00",foregroundColor:"#0b0c0c"},dark:{haloColor:"#0b0c0c",selectedColor:"#ffffff",activeColor:"#ffdd00",foregroundColor:"#ffffff"}},oe={small:1,medium:1.5,large:2},ie=(e,t,r,n)=>({featureId:e,multiSelect:t,layerId:r.layerId,idProperty:r.idProperty,properties:n.properties,geometry:n.geometry}),ae=({featureId:e,feature:t,config:r,selectedFeatures:n,dispatch:o,multiSelect:i})=>{if(!n.length)return!1;const a=n.findIndex(t=>t.featureId===e&&t.layerId===r.layerId);if(-1!==a){if(n.length<3)return!1;const e=(e=>{const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);e[n].geometry?.type&&X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length?null:[...t].map(t=>e[t])})(n.filter((e,t)=>t!==a));return!!e&&(o({type:"SET_SELECTED_FEATURES",payload:e}),!0)}const s=n.filter(e=>e.geometry?.type);return!(!t.geometry?.type||!s.length)&&(!X(t,s)&&(o({type:"TOGGLE_SELECTED_FEATURES",payload:{...ie(e,i,r,t),replaceAll:!0}}),!0))},se=({mapProvider:t,layers:r,interactionModes:n,multiSelect:o,dispatch:i,markers:a,layerConfigMap:s,debug:l,tolerance:c,processFeatureMatch:u,processFallback:d,scale:p})=>e(({point:e,coords:f})=>{const y=l?Q(t,e,{radius:c}):null;if(y&&((e,t)=>{const[r,n]=e;console.groupCollapsed(`[interact] click (${r.toFixed(4)}, ${n.toFixed(4)}) — ${t.length} feature${1!==t.length?"s":""}`),t.forEach(e=>{console.log({layer:e.layer.id,type:e.layer.type,id:e.id??"—",sourceLayer:e.sourceLayer??"—",properties:e.properties})}),console.groupEnd()})(f,y),n.includes("selectMarker")){const t=((e,t,r)=>{for(const n of e.items){const o=e.markerRefs?.get(n.id);if(!o||re(n))continue;const i=o.closest(".im-c-viewport__markers")||o.parentElement,a=i?i.getBoundingClientRect():{left:0,top:0},{left:s,top:l,right:c,bottom:u}=o.getBoundingClientRect(),d=t.x*r,p=t.y*r;if(d>=s-a.left&&d<=c-a.left&&p>=l-a.top&&p<=u-a.top)return n.id}return null})(a,e,p);if(t)return void i({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:t,multiSelect:o}})}if(n.includes("selectFeature")&&r.length>0){const r=((e,t)=>{const r=e.filter(e=>t[e.layer?.id]),n=r.find(ee);if(n)return{feature:n,config:t[n.layer.id]};const o=r[0];return o?{feature:o,config:t[o.layer.id]}:null})(y??Q(t,e,{radius:c}),s);if(r)return void u(r)}d({coords:f})},[t,r,n,o,i,a,s,l,c,u,d,p]),le=({mapState:n,pluginState:o,services:i,mapProvider:a})=>{const{markers:s,mapSize:l}=n,{dispatch:c,layers:u,interactionModes:d,multiSelect:p,contiguous:f,marker:y,tolerance:g,selectedFeatures:m,selectedMarkers:h,deselectOnClickOutside:E}=o,{eventBus:S}=i,v=J(u),b=oe[l]??1,k=e(({feature:e,config:t})=>{s.remove("location");const r=e.properties?.[t.idProperty]??e.id;if(null==r)return;const n=a.getFeatureGeometry?.(t.layerId,r,t.idProperty),o=n?{...e,geometry:n}:e;if(f&&p){if(ae({featureId:r,feature:o,config:t,selectedFeatures:m,dispatch:c,multiSelect:p}))return}c({type:"TOGGLE_SELECTED_FEATURES",payload:ie(r,p,t,o)})},[s,c,p,f,m,a]),M=e(({coords:e})=>{const t=d.includes("placeMarker");(t||E)&&(c({type:"CLEAR_SELECTED_FEATURES"}),t&&(s.add("location",e,y),S.emit("interact:markerchange",{coords:e})))},[d,c,s,y,S,E]),P=se({mapProvider:a,layers:u,interactionModes:d,multiSelect:p,dispatch:c,markers:s,layerConfigMap:v,debug:o?.debug,tolerance:g,processFeatureMatch:k,processFallback:M,scale:b});return((e,n,o)=>{const i=t(null);r(()=>{const t=i.current;(null===t||0===t.features.length&&0===t.markers.length)&&0===n.length&&0===o.length||(e.emit("interact:selectionchange",{selectedFeatures:n.map(({featureId:e,layerId:t,idProperty:r,properties:n,geometry:o})=>({featureId:e,layerId:t,idProperty:r,properties:n,geometryType:o?.type})),selectedMarkers:o,contiguous:W(n)}),i.current={features:n,markers:o})},[n,o])})(S,m,h),{handleInteraction:P}},ce=e=>{const t=e.closest(".im-c-viewport__markers");if(!t)return!1;const r=t.getBoundingClientRect(),{left:n,right:o,top:i,bottom:a}=e.getBoundingClientRect();return o>r.left&&n<r.right&&a>r.top&&i<r.bottom},ue=(e,t,r)=>{const{x:n,y:o}=e.mapToScreen(r);return{x:n*oe[t],y:o*oe[t]}},de=(e,t,r,n,o)=>{const i=t[e.layer?.id];if(!i?.labelProperty)return null;const a=((e,t)=>e.properties?.[t.idProperty]??e.id)(e,i),s=null==a?null:String(a);if(null==s||r.has(s))return null;r.add(s);const l={id:s,label:e.properties?.[i.labelProperty]??s,isMarker:!1,featureId:a,layerId:i.layerId,idProperty:i.idProperty,geometry:e.geometry,properties:e.properties},c=function(e){try{const[t,r,n,o]=q(z(e));return[(t+n)/2,(r+o)/2]}catch{return null}}(e);return c&&Object.assign(l,ue(n,o,c)),l};function pe({markers:e,mapSize:n,interactionModes:i,layers:a,mapProvider:s,multiSelect:l,spatialListRegistry:c,eventBus:u,itemsRef:d}){const p=t(l);p.current=l,r(()=>{const t=()=>{const t=[];i?.includes("selectMarker")&&t.push(...((e,t,r)=>{const n=[];for(const o of e.items){if(!o.label)continue;const i=e.markerRefs?.get(o.id);if(!re(o)&&i&&ce(i)){const e={id:o.id,label:o.label,isMarker:!0};o.coords&&Object.assign(e,ue(t,r,o.coords)),n.push(e)}}return n})(e,s,n)),i?.includes("selectFeature")&&a.length>0&&t.push(...((e,t,r)=>{const n=[],o=new Set,i=t.map(e=>e.layerId),a=J(t),s=e.getVisibleFeatures(i);for(const t of s){const i=de(t,a,o,e,r);i&&n.push(i)}return n})(s,a,n)),d.current=t,c.notifyItemsChanged("interact")};return t(),u.on(o.MAP_MOVE_END,t),u.on(o.MAP_DATA_CHANGE,t),()=>{u.off(o.MAP_MOVE_END,t),u.off(o.MAP_DATA_CHANGE,t)}},[e,n,i,a,s,l,c,u,d]),r(()=>(c.registerItemProvider("interact",{getItems:()=>({items:d.current,multiselectable:p.current,label:"Map features"})}),()=>{c.unregisterItemProvider("interact")}),[c,d])}function fe({mapState:e,pluginState:n,services:i,mapProvider:a,spatialListRegistry:s}){const{markers:l,mapSize:c}=e,{dispatch:u,interactionModes:d,layers:p,multiSelect:f}=n,{eventBus:y}=i,g=t(null),m=t([]);pe({markers:l,mapSize:c,interactionModes:d,layers:p,mapProvider:a,multiSelect:f,spatialListRegistry:s,eventBus:y,itemsRef:m}),function({itemsRef:e,eventBus:t,dispatch:n,listboxActiveItemRef:i}){r(()=>{const r=({id:t})=>{if(null===t)return i.current=null,void n({type:"SET_LISTBOX_ACTIVE",payload:null});const r=e.current.find(e=>e.id===t);if(!r)return;if(r.isMarker)return i.current={id:t,isMarker:!0},void n({type:"SET_LISTBOX_ACTIVE",payload:null});const o={featureId:r.featureId,layerId:r.layerId,idProperty:r.idProperty,geometry:r.geometry};i.current={id:t,isMarker:!1,...o,properties:r.properties},n({type:"SET_LISTBOX_ACTIVE",payload:o})};return t.on(o.MAP_SET_ACTIVE_ITEM,r),()=>{t.off(o.MAP_SET_ACTIVE_ITEM,r)}},[e,t,n,i])}({itemsRef:m,eventBus:y,dispatch:u,listboxActiveItemRef:g}),function({eventBus:e,dispatch:t,listboxActiveItemRef:n,multiSelect:i}){r(()=>{const r=()=>{const e=n.current;if(e)if(e.isMarker)t({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:e.id,multiSelect:i}});else{const{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s}=e;t({type:"TOGGLE_SELECTED_FEATURES",payload:{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s,multiSelect:i,replaceAll:!i}})}};return e.on(o.MAP_SELECT_ITEM,r),()=>{e.off(o.MAP_SELECT_ITEM,r)}},[e,t,n,i])}({eventBus:y,dispatch:u,listboxActiveItemRef:g,multiSelect:f})}const ye=({mapProvider:e,mapStyle:t,pluginState:o,selectedFeatures:i,events:a,eventBus:s})=>{const{layers:l,listboxActiveItem:c}=o,u=n(()=>t?((e,t)=>{const r={};if(!t)return console.warn("[interact] buildStylesMap: mapStyle is null/undefined, cannot build styles"),r;const n=ne[t.mapColorScheme]??ne.light,o=t.activeColor??n.activeColor,i=t.selectedColor??n.selectedColor;return e.forEach(e=>{const n=e.activeStroke||o,a=e.selectedStroke||i,s=e.selectedFill||"transparent",l=e.selectedStrokeWidth||3,c=l+6;r[e.layerId]={stroke:te(n,t.id),selectionStroke:te(a,t.id),fill:te(s,t.id),strokeWidth:l,activeStrokeWidth:c}}),r})(l,t):null,[l,t]),d=()=>{const t=c?[{featureId:c.featureId,layerId:c.layerId,idProperty:c.idProperty,geometry:c.geometry}]:[];e.updateHighlightedFeatures?.(i,t,u)};r(()=>{if(!e||!u)return;d();let t=0,r=!1;const n=()=>{d(),Date.now()>=t&&(s.off(a.MAP_DATA_CHANGE,n),r=!1)},o=()=>{t=Date.now()+3e3,r||(r=!0,s.on(a.MAP_DATA_CHANGE,n))};return s.on(a.MAP_STYLE_CHANGE,o),s.on(a.MAP_SET_SIZE,o),()=>{s.off(a.MAP_STYLE_CHANGE,o),s.off(a.MAP_SET_SIZE,o),s.off(a.MAP_DATA_CHANGE,n)}},[i,c,e,u,s])},ge='[role="listbox"], [role="option"]';const me=e=>!("Enter"!==e.key||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey);function he({getAppState:e,mapState:t,getPluginState:r,buttonConfig:n,events:o,eventBus:i,handleInteraction:a,clickReadyRef:s}){const{selectAtTarget:l}=n,c=()=>a(t.crossHair.getDetail()),u=e=>{s.current&&a(e)},{handleKeydown:d,handleKeyup:p}=((e,t)=>{let r=!1;return{handleKeydown:t=>{r=me(t)&&e.current===t.target},handleKeyup:e=>{me(e)&&r&&(e.preventDefault(),t())}}})(e().layoutRefs.viewportRef,c),f=((e,t)=>(r,n)=>{const o=t();e.markers.remove("location"),o.dispatch({type:"TOGGLE_SELECTED_FEATURES",payload:{multiSelect:o.multiSelect,addToExisting:n,...r}})})(t,r),y=e=>f(e,!0),g=e=>f(e,!1);return document.addEventListener("keydown",d),document.addEventListener("keyup",p),i.on(o.MAP_CLICK,u),i.on("interact:selectFeature",y),i.on("interact:unselectFeature",g),l.onClick=c,()=>{l.onClick=null,document.removeEventListener("keydown",d),document.removeEventListener("keyup",p),i.off(o.MAP_CLICK,u),i.off("interact:selectFeature",y),i.off("interact:unselectFeature",g)}}const Ee=({appState:e,pluginState:t})=>{return!!e.expandedButtons?.has("mapControls")||"touch"===e.interfaceType&&!1!==t.touchTarget&&(r=t.interactionModes,!(1===r?.length&&r.includes("selectMarker")));var r};const Se={ENABLE:(e,t)=>({...e,...t,enabled:!0}),DISABLE:e=>({...e,enabled:!1,selectedFeatures:[],selectedMarkers:[],listboxActiveItem:null}),TOGGLE_SELECTED_FEATURES:(e,t)=>{const{featureId:r,multiSelect:n,layerId:o,idProperty:i,addToExisting:a=!0,replaceAll:s=!1,properties:l,geometry:c}=t,u=Array.isArray(e.selectedFeatures)?e.selectedFeatures:[],d=u.findIndex(e=>e.featureId===r&&e.layerId===o);if(!1===a){const t=u.filter((e,t)=>t!==d);return{...e,selectedFeatures:t}}const p={featureId:r,layerId:o,idProperty:i,properties:l,geometry:c};let f;if(n&&!s){const e=[...u];-1===d?e.push(p):e.splice(d,1),f=e}else{f=-1!==d&&1===u.length?[]:[p]}return{...e,selectedFeatures:f,selectedMarkers:n&&!s?e.selectedMarkers:[]}},TOGGLE_SELECTED_MARKERS:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers,o=n.includes(t);if(r){const r=o?n.filter(e=>e!==t):[...n,t];return{...e,selectedMarkers:r}}return{...e,selectedFeatures:[],selectedMarkers:o&&1===n.length?[]:[t]}},CLEAR_SELECTED_FEATURES:e=>({...e,selectedFeatures:[],selectedMarkers:[]}),SET_SELECTED_FEATURES:(e,t)=>({...e,selectedFeatures:t}),SELECT_MARKER:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers;if(n.includes(t))return e;const o=r?[...n,t]:[t];return{...e,selectedFeatures:r?e.selectedFeatures:[],selectedMarkers:o}},UNSELECT_MARKER:(e,{markerId:t})=>{const r=e.selectedMarkers;return r.includes(t)?{...e,selectedMarkers:r.filter(e=>e!==t)}:e},SET_LISTBOX_ACTIVE:(e,t)=>({...e,listboxActiveItem:t??null}),SET_LISTBOX_FOCUSED:(e,t)=>({...e,listboxFocused:!!t})},ve={tolerance:10,interactionModes:["selectMarker"],multiSelect:!1,contiguous:!1,deselectOnClickOutside:!1,touchTarget:!0,marker:{}},be="Select",ke={InitComponent:({appState:n,mapState:i,services:a,buttonConfig:s,mapProvider:l,pluginState:c})=>{const{enabled:u,selectedFeatures:d,interactionModes:p,layers:f}=c,{eventBus:y}=a,{crossHair:g,mapStyle:m,markers:h}=i,E=Ee({appState:n,pluginState:c});fe({mapState:i,pluginState:c,services:a,mapProvider:l,spatialListRegistry:n.spatialListRegistry});const{handleInteraction:S}=le({mapState:i,pluginState:c,services:a,mapProvider:l});return ye({mapProvider:l,mapStyle:m,pluginState:c,selectedFeatures:d,events:o,eventBus:y}),r(()=>{y.emit("interact:active",{active:u,interactionModes:p})},[u,p]),function({enabled:e,interactionModes:t,markers:n,layers:o,eventBus:i}){r(()=>{if(!e)return;const r=t?.includes("selectMarker")&&n.items.some(e=>e.label),a=t?.includes("selectFeature")&&o.some(e=>e.labelProperty);(r||a)&&i.emit("interact:listboxcapable")},[e,t,n,o,i])}({enabled:u,interactionModes:p,markers:h,layers:f,eventBus:y}),((e,t,n,o)=>{r(()=>{const r=t&&n?.includes("selectFeature")?o.map(e=>e.layerId):[];return e.setHoverCursor?.(r),()=>e.setHoverCursor?.([])},[t,n,o])})(l,u,p,f),function({crossHair:n,enabled:o,targetNeeded:i,appState:a,dispatch:s}){const l=t(o);l.current=o;const c=t(i);c.current=i;const u=t(n);u.current=n;const d=t(s);d.current=s;const p=t(!1),f=t(!1),y=t(a.interfaceType);y.current=a.interfaceType;const g=e(()=>{const e="keyboard"===y.current&&f.current,t=c.current&&!p.current;l.current&&(e||t)?u.current.fixAtCenter():u.current.hide()},[]);r(()=>{g()},[o,i,a.interfaceType,g]),r(()=>{const e=a.layoutRefs?.appContainerRef?.current;if(!e)return;const t=e=>{p.current=e,d.current?.({type:"SET_LISTBOX_FOCUSED",payload:e})};f.current=!!document.activeElement?.closest("[data-map-keyboard-scope]"),document.activeElement?.closest(ge)&&t(!0);const r=e=>{const r=!!e.target.closest(ge),n=!!e.target.closest("[data-map-keyboard-scope]"),o=p.current!==r,i=o||f.current!==n;o&&t(r),f.current=n,i&&l.current&&g()};return e.addEventListener("focusin",r),()=>{e.removeEventListener("focusin",r)}},[a.layoutRefs,g])}({crossHair:g,enabled:u,targetNeeded:E,appState:n,dispatch:c.dispatch}),function({pluginState:e,appState:n,mapState:i,buttonConfig:a,eventBus:s,handleInteraction:l}){const c=t(l);c.current=l;const u=t(e);u.current=e;const d=t(n);d.current=n;const p=t(!1);r(()=>{p.current=!1;const e=setTimeout(()=>{p.current=!0},0);return()=>clearTimeout(e)},[e.enabled]),r(()=>{if(e.enabled)return he({getAppState:()=>d.current,mapState:i,getPluginState:()=>u.current,buttonConfig:a,events:o,eventBus:s,handleInteraction:e=>c.current(e),clickReadyRef:p})},[e.enabled,a,s]),r(()=>{if(!e.enabled)return;const t=()=>c.current(i.crossHair.getDetail());return i.crossHair.activate=t,()=>{i.crossHair.activate===t&&(i.crossHair.activate=null)}},[e.enabled,i.crossHair])}({pluginState:c,appState:n,mapState:i,buttonConfig:s,eventBus:y,handleInteraction:S}),null},reducer:{initialState:{enabled:!1,layers:[],marker:null,interactionModes:null,multiSelect:!1,deselectOnClickOutside:!1,touchTarget:!0,selectedFeatures:[],selectedMarkers:[],closeOnAction:!0,listboxActiveItem:null,listboxFocused:!1},actions:Se},buttons:[{id:"selectAtTarget",label:"Select",variant:"primary",hiddenWhen:({appState:e,pluginState:t})=>!t.enabled||t.listboxFocused||!Ee({appState:e,pluginState:t}),mobile:{slot:"actions"},tablet:{slot:"actions"},desktop:{slot:"actions"}}],keyboardShortcuts:[{id:"clickAtTarget",title:"Click at target",command:"<kbd>Enter</kbd>"},{id:"selectFeatures",group:be,context:"listbox",title:"Select features",command:"<kbd>Tab</kbd>"},{id:"navigateFeatures",group:be,context:"listbox",title:"Highlight next feature",command:"<kbd>↑</kbd> or <kbd>↓</kbd>"},{id:"navigateFeaturesSpatially",group:be,context:"listbox",title:"Highlight nearby feature",command:`${"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||"")?"<kbd>Option</kbd>":"<kbd>Alt</kbd>"} + <kbd>↑</kbd>, <kbd>↓</kbd>, <kbd>←</kbd> or <kbd>→</kbd>`},{id:"selectFeature",group:be,context:"listbox",title:"Select a feature",command:"<kbd>Enter</kbd> or <kbd>Space</kbd>"},{id:"dismissHintOrReturn",group:be,context:"listbox",title:"Dismiss hint / return to map",command:"<kbd>Escape</kbd>"}],icons:[{id:"select",svgContent:'<path d="M22 14a8 8 0 0 1-8 8"/><path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/><path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1"/><path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10"/><path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>'}],api:{enable:({pluginState:e,pluginConfig:t},r)=>{e.dispatch({type:"ENABLE",payload:{...ve,...t,...r}})},disable:({pluginState:e})=>{e.dispatch({type:"DISABLE"})},clear:({pluginState:e,mapState:t})=>{e.dispatch({type:"CLEAR_SELECTED_FEATURES"}),t.markers.remove("location")},selectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:selectFeature",{featureId:t,layerId:r,idProperty:n})},unselectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:unselectFeature",{featureId:t,layerId:r,idProperty:n})},selectMarker:({pluginState:e},t)=>{e.dispatch({type:"SELECT_MARKER",payload:{markerId:t,multiSelect:e.multiSelect}})},unselectMarker:({pluginState:e},t)=>{e.dispatch({type:"UNSELECT_MARKER",payload:{markerId:t}})}}};export{ke as manifest};
|
|
1
|
+
import{useCallback as e,useRef as t,useEffect as r,useMemo as n}from"preact/compat";const o={MAP_SET_SIZE:"map:setsize",MAP_SET_ACTIVE_ITEM:"map:setactiveitem",MAP_SELECT_ITEM:"map:selectitem",MAP_STYLE_CHANGE:"map:stylechange",MAP_MOVE_END:"map:moveend",MAP_DATA_CHANGE:"map:datachange",MAP_CLICK:"map:click"};function i(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function a(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!u(e[0])||!u(e[1]))throw new Error("coordinates must contain numbers");return i({type:"Point",coordinates:e},t,r)}function s(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return i({type:"LineString",coordinates:e},t,r)}function l(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return i({type:"MultiLineString",coordinates:e},t,r)}function u(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}const d=11102230246251565e-32,p=134217729,f=(3+8*d)*d;function y(e,t,r,n,o){let i,a,s,l,c=t[0],u=n[0],d=0,p=0;u>c==u>-c?(i=c,c=t[++d]):(i=u,u=n[++p]);let f=0;if(d<e&&p<r)for(u>c==u>-c?(a=c+i,s=i-(a-c),c=t[++d]):(a=u+i,s=i-(a-u),u=n[++p]),i=a,0!==s&&(o[f++]=s);d<e&&p<r;)u>c==u>-c?(a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d]):(a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p]),i=a,0!==s&&(o[f++]=s);for(;d<e;)a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d],i=a,0!==s&&(o[f++]=s);for(;p<r;)a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p],i=a,0!==s&&(o[f++]=s);return 0===i&&0!==f||(o[f++]=i),f}function g(e){return new Float64Array(e)}const h=g(4),m=g(8),E=g(12),S=g(16),v=g(4);function b(e,t,r,n,o,i){const a=(t-i)*(r-o),s=(e-o)*(n-i),l=a-s,c=Math.abs(a+s);return Math.abs(l)>=33306690738754716e-32*c?l:-function(e,t,r,n,o,i,a){let s,l,c,u,d,g,b,k,M,P,I,A,w,C,T,_,L,F;const x=e-o,R=r-o,B=t-i,D=n-i;C=x*D,g=p*x,b=g-(g-x),k=x-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=B*R,g=p*B,b=g-(g-B),k=B-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,h[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,h[1]=w-(I+d)+(d-_),F=A+I,d=F-A,h[2]=A-(F-d)+(I-d),h[3]=F;let G=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,h),O=22204460492503146e-32*a;if(G>=O||-G>=O)return G;if(d=e-x,s=e-(x+d)+(d-o),d=r-R,c=r-(R+d)+(d-o),d=t-B,l=t-(B+d)+(d-i),d=n-D,u=n-(D+d)+(d-i),0===s&&0===l&&0===c&&0===u)return G;if(O=11093356479670487e-47*a+f*Math.abs(G),G+=x*u+D*s-(B*c+R*l),G>=O||-G>=O)return G;C=s*D,g=p*s,b=g-(g-s),k=s-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=l*R,g=p*l,b=g-(g-l),k=l-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const H=y(4,h,4,v,m);C=x*u,g=p*x,b=g-(g-x),k=x-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=B*c,g=p*B,b=g-(g-B),k=B-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const N=y(H,m,4,v,E);C=s*u,g=p*s,b=g-(g-s),k=s-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=l*c,g=p*l,b=g-(g-l),k=l-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const K=y(N,E,4,v,S);return S[K-1]}(e,t,r,n,o,i,c)}function k(e,t){var r,n,o,i,a,s,l,c,u,d=0,p=e[0],f=e[1],y=t.length;for(r=0;r<y;r++){n=0;var g=t[r],h=g.length-1;if((c=g[0])[0]!==g[h][0]&&c[1]!==g[h][1])throw new Error("First and last coordinates in a ring must be the same");for(i=c[0]-p,a=c[1]-f;n<h;n++){if(s=(u=g[n+1])[0]-p,l=u[1]-f,0===a&&0===l){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(l>=0&&a<=0||l<=0&&a>=0){if(0===(o=b(i,s,a,l,0,0)))return 0;(o>0&&l>0&&a<=0||o<0&&l<=0&&a>0)&&d++}c=u,a=l,i=s}}return d%2!=0}function M(e){return"Feature"===e.type?e.geometry:e}function P(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=function(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}(e),o=M(t),i=o.type,a=t.bbox;let s=o.coordinates;if(a&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(n,a))return!1;"Polygon"===i&&(s=[s]);let l=!1;for(var c=0;c<s.length;++c){const e=k(n,s[c]);if(0===e)return!r.ignoreBoundary;e&&(l=!0)}return l}class I{constructor(e=[],t=A){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,n=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(n,i)>=0)break;t[e]=i,e=o}t[e]=n}_down(e){const{data:t,compare:r}=this,n=this.length>>1,o=t[e];for(;e<n;){let n=1+(e<<1),i=t[n];const a=n+1;if(a<this.length&&r(t[a],i)<0&&(n=a,i=t[a]),r(i,o)>=0)break;t[e]=i,e=n}t[e]=o}}function A(e,t){return e<t?-1:e>t?1:0}function w(e,t){return e.p.x>t.p.x?1:e.p.x<t.p.x?-1:e.p.y!==t.p.y?e.p.y>t.p.y?1:-1:1}function C(e,t){return e.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:e.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:e.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?e.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}class T{constructor(e,t,r,n){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=r,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let _=0,L=0,F=0;function x(e,t){const r="Feature"===e.type?e.geometry:e;let n=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(n=[n]),"LineString"===r.type&&(n=[[n]]);for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length;r++){let o=n[e][r][0],i=null;L+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new T(o,_,L,F),l=new T(i,_,L,F+1);s.otherEvent=l,l.otherEvent=s,w(s,l)>0?(l.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,l.isLeftEndpoint=!1),t.push(s),t.push(l),o=i,F+=1}}_+=1}class R{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function B(e,t){if(null===e||null===t)return!1;if(e.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.rightSweepEvent)||e.leftSweepEvent.isSamePoint(t.leftSweepEvent)||e.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;const r=e.leftSweepEvent.p.x,n=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,a=t.leftSweepEvent.p.x,s=t.leftSweepEvent.p.y,l=t.rightSweepEvent.p.x,c=t.rightSweepEvent.p.y,u=(c-s)*(o-r)-(l-a)*(i-n),d=(l-a)*(n-s)-(c-s)*(r-a),p=(o-r)*(n-s)-(i-n)*(r-a);if(0===u)return!1;const f=d/u,y=p/u;if(f>=0&&f<=1&&y>=0&&y<=1){return[r+f*(o-r),n+f*(i-n)]}return!1}var D=function(e,t){const r=new I([],w);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)x(r[e],t)}else x(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new I([],C);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new R(o);for(let i=0;i<n.data.length;i++){const a=n.data[i];if(t&&a.leftSweepEvent.featureId===o.featureId)continue;const s=B(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function G(e,t,r={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:o=!0}=r;let s=[];"FeatureCollection"===e.type?s=s.concat(e.features):"Feature"===e.type?s.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||s.push(i(e)),"FeatureCollection"===t.type?s=s.concat(t.features):"Feature"===t.type?s.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||s.push(i(t));const c=D(l(s),o);let u=[];if(n){const e={};c.forEach(t=>{const r=t.join(",");e[r]||(e[r]=!0,u.push(t))})}else u=c;return l(u.map(e=>a(e)))}function O(e,t,r){if(null!==e)for(var n,o,i,a,s,l,c,u,d=0,p=0,f=e.type,y="FeatureCollection"===f,g="Feature"===f,h=y?e.features.length:1,m=0;m<h;m++){s=(u=!!(c=y?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===c.type)?c.geometries.length:1;for(var E=0;E<s;E++){var S=0,v=0;if(null!==(a=u?c.geometries[E]:c)){l=a.coordinates;var b=a.type;switch(d=0,b){case null:break;case"Point":if(!1===t(l,p,m,S,v))return!1;p++,S++;break;case"LineString":case"MultiPoint":for(n=0;n<l.length;n++){if(!1===t(l[n],p,m,S,v))return!1;p++,"MultiPoint"===b&&S++}"LineString"===b&&S++;break;case"Polygon":case"MultiLineString":for(n=0;n<l.length;n++){for(o=0;o<l[n].length-d;o++){if(!1===t(l[n][o],p,m,S,v))return!1;p++}"MultiLineString"===b&&S++,"Polygon"===b&&v++}"Polygon"===b&&S++;break;case"MultiPolygon":for(n=0;n<l.length;n++){for(v=0,o=0;o<l[n].length;o++){for(i=0;i<l[n][o].length-d;i++){if(!1===t(l[n][o][i],p,m,S,v))return!1;p++}v++}S++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===O(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function H(e,t){!function(e,t){var r,n,o,i,a,s,l,c,u,d,p=0,f="FeatureCollection"===e.type,y="Feature"===e.type,g=f?e.features.length:1;for(r=0;r<g;r++){for(s=f?e.features[r].geometry:y?e.geometry:e,c=f?e.features[r].properties:y?e.properties:{},u=f?e.features[r].bbox:y?e.bbox:void 0,d=f?e.features[r].id:y?e.id:void 0,a=(l=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=l?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,c,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,c,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,c,u,d))return!1;p++}}(e,function(e,r,n,o,a){var s,l=null===e?null:e.type;switch(l){case null:case"Point":case"LineString":case"Polygon":return!1!==t(i(e,n,{bbox:o,id:a}),r,0)&&void 0}switch(l){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var c=0;c<e.coordinates.length;c++){var u=e.coordinates[c];if(!1===t(i({type:s,coordinates:u},n),r,c))return!1}})}function N(e,t={}){const r=M(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return K(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(K(e,o))}),l(i)}(r,t);default:throw new Error("invalid poly")}}function K(e,t){return e.length>1?c(e,t):s(e[0],t)}function U(e,t){for(let r=0;r<e.coordinates.length-1;r++)if($(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function V(e,t,r){for(const r of t.coordinates)if(P(r,e))return!0;return G(t,N(e),{ignoreSelfIntersections:r}).features.length>0}function $(e,t,r){const n=r[0]-e[0],o=r[1]-e[1],i=t[0]-e[0],a=t[1]-e[1];return 0===n*a-o*i&&(Math.abs(i)>=Math.abs(a)?i>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:a>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1])}var q=function(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return H(e,e=>{H(t,t=>{if(!1===n)return!1;n=function(e,t,r){switch(e.type){case"Point":switch(t.type){case"Point":return n=e.coordinates,o=t.coordinates,!(n[0]===o[0]&&n[1]===o[1]);case"LineString":return!U(t,e);case"Polygon":return!P(e,t)}break;case"LineString":switch(t.type){case"Point":return!U(e,t);case"LineString":return!function(e,t,r){const n=G(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!V(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!P(t,e);case"LineString":return!V(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(P(r,t))return!0;for(const r of t.coordinates[0])if(P(r,e))return!0;const n=G(N(e),N(t),{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(t,e,r)}}var n,o;return!1}(e.geometry,t.geometry,r)})}),n};var z=function(e,t={}){if(null!=e.bbox&&!0!==t.recompute)return e.bbox;const r=[1/0,1/0,-1/0,-1/0];return O(e,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r};function j(e){const t=e.geometry||e;switch(t.type){case"Polygon":return function(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return i({type:"Polygon",coordinates:e},t,r)}(t.coordinates);case"MultiPolygon":return function(e,t,r={}){return i({type:"MultiPolygon",coordinates:e},t,r)}(t.coordinates);case"LineString":return s(t.coordinates);case"MultiLineString":return c(t.coordinates);case"Point":return a(t.coordinates);case"MultiPoint":return function(e,t,r={}){return i({type:"MultiPoint",coordinates:e},t,r)}(t.coordinates);default:throw new Error(`Unsupported geometry type: ${t.type}`)}}function X(e,t){return t.some(t=>!q(j(t),j(e)))}function W(e){if(e.length<2)return!1;if(e.some(e=>{return t=e.geometry?.type,!("Polygon"===t||"MultiPolygon"===t);var t}))return!1;const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length}const Y={".cold":".hot",".hot":".cold"},Z=e=>{for(const[t,r]of Object.entries(Y))if(e.endsWith(t))return`${e.slice(0,-t.length)}${r}`;return null},J=e=>{const t={};for(const r of e){t[r.layerId]=r;const e=Z(r.layerId);e&&(t[e]=r)}return t},Q=(e,t,r)=>{try{return e?.getFeaturesAtPoint(t,r)||[]}catch(e){return console.warn("Feature query failed:",e),[]}},ee=e=>{const t=e.geometry?.type;return"Point"===t||"MultiPoint"===t},te=e=>!!e.label&&(!e.symbol&&!e.svgContent&&(null===e.symbol||null===e.svgContent)),re=(e,t,r,n)=>({featureId:e,multiSelect:t,layerId:r.layerId,idProperty:r.idProperty,properties:n.properties,geometry:n.geometry}),ne=({featureId:e,feature:t,config:r,selectedFeatures:n,dispatch:o,multiSelect:i})=>{if(!n.length)return!1;const a=n.findIndex(t=>t.featureId===e&&t.layerId===r.layerId);if(-1!==a){if(n.length<3)return!1;const e=(e=>{const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);e[n].geometry?.type&&X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length?null:[...t].map(t=>e[t])})(n.filter((e,t)=>t!==a));return!!e&&(o({type:"SET_SELECTED_FEATURES",payload:e}),!0)}const s=n.filter(e=>e.geometry?.type);return!(!t.geometry?.type||!s.length)&&(!X(t,s)&&(o({type:"TOGGLE_SELECTED_FEATURES",payload:{...re(e,i,r,t),replaceAll:!0}}),!0))},oe=({mapProvider:t,layers:r,interactionModes:n,multiSelect:o,dispatch:i,markers:a,layerConfigMap:s,debug:l,tolerance:c,processFeatureMatch:u,processFallback:d,scale:p})=>e(({point:e,coords:f})=>{const y=l?Q(t,e,{radius:c}):null;if(y&&((e,t)=>{const[r,n]=e;console.groupCollapsed(`[interact] click (${r.toFixed(4)}, ${n.toFixed(4)}) — ${t.length} feature${1!==t.length?"s":""}`),t.forEach(e=>{console.log({layer:e.layer.id,type:e.layer.type,id:e.id??"—",sourceLayer:e.sourceLayer??"—",properties:e.properties})}),console.groupEnd()})(f,y),n.includes("selectMarker")){const t=((e,t,r)=>{for(const n of e.items){const o=e.markerRefs?.get(n.id);if(!o||te(n))continue;const i=o.closest(".im-c-viewport__markers")||o.parentElement,a=i?i.getBoundingClientRect():{left:0,top:0},{left:s,top:l,right:c,bottom:u}=o.getBoundingClientRect(),d=t.x*r,p=t.y*r;if(d>=s-a.left&&d<=c-a.left&&p>=l-a.top&&p<=u-a.top)return n.id}return null})(a,e,p);if(t)return void i({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:t,multiSelect:o}})}if(n.includes("selectFeature")&&r.length>0){const r=((e,t)=>{const r=e.filter(e=>t[e.layer?.id]),n=r.find(ee);if(n)return{feature:n,config:t[n.layer.id]};const o=r[0];return o?{feature:o,config:t[o.layer.id]}:null})(y??Q(t,e,{radius:c}),s);if(r)return void u(r)}d({coords:f})},[t,r,n,o,i,a,s,l,c,u,d,p]),ie=({mapState:n,pluginState:o,services:i,mapProvider:a})=>{const{markers:s,mapSizeScale:l}=n,{dispatch:c,layers:u,interactionModes:d,multiSelect:p,contiguous:f,marker:y,tolerance:g,selectedFeatures:h,selectedMarkers:m,deselectOnClickOutside:E}=o,{eventBus:S}=i,v=J(u),b=e(({feature:e,config:t})=>{s.remove("location");const r=e.properties?.[t.idProperty]??e.id;if(null==r)return;const n=a.getFeatureGeometry?.(t.layerId,r,t.idProperty),o=n?{...e,geometry:n}:e;if(f&&p){if(ne({featureId:r,feature:o,config:t,selectedFeatures:h,dispatch:c,multiSelect:p}))return}c({type:"TOGGLE_SELECTED_FEATURES",payload:re(r,p,t,o)})},[s,c,p,f,h,a]),k=e(({coords:e})=>{const t=d.includes("placeMarker");(t||E)&&(c({type:"CLEAR_SELECTED_FEATURES"}),t&&(s.add("location",e,y),S.emit("interact:markerchange",{coords:e})))},[d,c,s,y,S,E]),M=oe({mapProvider:a,layers:u,interactionModes:d,multiSelect:p,dispatch:c,markers:s,layerConfigMap:v,debug:o?.debug,tolerance:g,processFeatureMatch:b,processFallback:k,scale:l});return((e,n,o)=>{const i=t(null);r(()=>{const t=i.current;(null===t||0===t.features.length&&0===t.markers.length)&&0===n.length&&0===o.length||(e.emit("interact:selectionchange",{selectedFeatures:n.map(({featureId:e,layerId:t,idProperty:r,properties:n,geometry:o})=>({featureId:e,layerId:t,idProperty:r,properties:n,geometryType:o?.type})),selectedMarkers:o,contiguous:W(n)}),i.current={features:n,markers:o})},[n,o])})(S,h,m),{handleInteraction:M}},ae=e=>{const t=e.closest(".im-c-viewport__markers");if(!t)return!1;const r=t.getBoundingClientRect(),{left:n,right:o,top:i,bottom:a}=e.getBoundingClientRect();return o>r.left&&n<r.right&&a>r.top&&i<r.bottom},se=(e,t,r)=>{const{x:n,y:o}=e.mapToScreen(r);return{x:n*t,y:o*t}},le=(e,t,r,n,o)=>{const i=t[e.layer?.id];if(!i?.labelProperty)return null;const a=((e,t)=>e.properties?.[t.idProperty]??e.id)(e,i),s=null==a?null:String(a);if(null==s||r.has(s))return null;r.add(s);const l={id:s,label:e.properties?.[i.labelProperty]??s,isMarker:!1,featureId:a,layerId:i.layerId,idProperty:i.idProperty,geometry:e.geometry,properties:e.properties},c=function(e){try{const[t,r,n,o]=z(j(e));return[(t+n)/2,(r+o)/2]}catch{return null}}(e);return c&&Object.assign(l,se(n,o,c)),l};function ce({markers:e,mapSizeScale:n,interactionModes:i,layers:a,mapProvider:s,multiSelect:l,spatialListRegistry:c,eventBus:u,itemsRef:d}){const p=t(l);p.current=l,r(()=>{const t=()=>{const t=[];i?.includes("selectMarker")&&t.push(...((e,t,r)=>{const n=[];for(const o of e.items){if(!o.label)continue;const i=e.markerRefs?.get(o.id);if(!te(o)&&i&&ae(i)){const e={id:o.id,label:o.label,isMarker:!0};o.coords&&Object.assign(e,se(t,r,o.coords)),n.push(e)}}return n})(e,s,n)),i?.includes("selectFeature")&&a.length>0&&t.push(...((e,t,r)=>{const n=[],o=new Set,i=t.map(e=>e.layerId),a=J(t),s=e.getVisibleFeatures(i);for(const t of s){const i=le(t,a,o,e,r);i&&n.push(i)}return n})(s,a,n)),d.current=t,c.notifyItemsChanged("interact")};return t(),u.on(o.MAP_MOVE_END,t),u.on(o.MAP_DATA_CHANGE,t),()=>{u.off(o.MAP_MOVE_END,t),u.off(o.MAP_DATA_CHANGE,t)}},[e,n,i,a,s,l,c,u,d]),r(()=>(c.registerItemProvider("interact",{getItems:()=>({items:d.current,multiselectable:p.current,label:"Map features"})}),()=>{c.unregisterItemProvider("interact")}),[c,d])}function ue({mapState:e,pluginState:n,services:i,mapProvider:a,spatialListRegistry:s}){const{markers:l,mapSizeScale:c}=e,{dispatch:u,interactionModes:d,layers:p,multiSelect:f}=n,{eventBus:y}=i,g=t(null),h=t([]);ce({markers:l,mapSizeScale:c,interactionModes:d,layers:p,mapProvider:a,multiSelect:f,spatialListRegistry:s,eventBus:y,itemsRef:h}),function({itemsRef:e,eventBus:t,dispatch:n,listboxActiveItemRef:i}){r(()=>{const r=({id:t})=>{if(null===t)return i.current=null,void n({type:"SET_LISTBOX_ACTIVE",payload:null});const r=e.current.find(e=>e.id===t);if(!r)return;if(r.isMarker)return i.current={id:t,isMarker:!0},void n({type:"SET_LISTBOX_ACTIVE",payload:null});const o={featureId:r.featureId,layerId:r.layerId,idProperty:r.idProperty,geometry:r.geometry};i.current={id:t,isMarker:!1,...o,properties:r.properties},n({type:"SET_LISTBOX_ACTIVE",payload:o})};return t.on(o.MAP_SET_ACTIVE_ITEM,r),()=>{t.off(o.MAP_SET_ACTIVE_ITEM,r)}},[e,t,n,i])}({itemsRef:h,eventBus:y,dispatch:u,listboxActiveItemRef:g}),function({eventBus:e,dispatch:t,listboxActiveItemRef:n,multiSelect:i}){r(()=>{const r=()=>{const e=n.current;if(e)if(e.isMarker)t({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:e.id,multiSelect:i}});else{const{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s}=e;t({type:"TOGGLE_SELECTED_FEATURES",payload:{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s,multiSelect:i,replaceAll:!i}})}};return e.on(o.MAP_SELECT_ITEM,r),()=>{e.off(o.MAP_SELECT_ITEM,r)}},[e,t,n,i])}({eventBus:y,dispatch:u,listboxActiveItemRef:g,multiSelect:f})}const de=(e,t)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&e[t])return e[t];return Object.values(e)[0]??null}return null},pe={light:{haloColor:"#ffffff",selectedColor:"#0b0c0c",activeColor:"#ffdd00",foregroundColor:"#0b0c0c"},dark:{haloColor:"#0b0c0c",selectedColor:"#ffffff",activeColor:"#ffdd00",foregroundColor:"#ffffff"}},fe=({mapProvider:e,mapStyle:t,pluginState:o,selectedFeatures:i,events:a,eventBus:s})=>{const{layers:l,listboxActiveItem:c}=o,u=n(()=>t?((e,t)=>{const r={};if(!t)return console.warn("[interact] buildStylesMap: mapStyle is null/undefined, cannot build styles"),r;const n=pe[t.mapColorScheme]??pe.light,o=t.activeColor??n.activeColor,i=t.selectedColor??n.selectedColor;return e.forEach(e=>{const n=e.activeStroke||o,a=e.selectedStroke||i,s=e.selectedFill||"transparent",l=e.selectedStrokeWidth||3,c=l+6;r[e.layerId]={stroke:de(n,t.id),selectionStroke:de(a,t.id),fill:de(s,t.id),strokeWidth:l,activeStrokeWidth:c}}),r})(l,t):null,[l,t]),d=()=>{const t=c?[{featureId:c.featureId,layerId:c.layerId,idProperty:c.idProperty,geometry:c.geometry}]:[];e.updateHighlightedFeatures?.(i,t,u)};r(()=>{if(!e||!u)return;d();let t=0,r=!1;const n=()=>{d(),Date.now()>=t&&(s.off(a.MAP_DATA_CHANGE,n),r=!1)},o=()=>{t=Date.now()+3e3,r||(r=!0,s.on(a.MAP_DATA_CHANGE,n))};return s.on(a.MAP_STYLE_CHANGE,o),s.on(a.MAP_SET_SIZE,o),()=>{s.off(a.MAP_STYLE_CHANGE,o),s.off(a.MAP_SET_SIZE,o),s.off(a.MAP_DATA_CHANGE,n)}},[i,c,e,u,s])},ye='[role="listbox"], [role="option"]';const ge=e=>!("Enter"!==e.key||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey);function he({getAppState:e,mapState:t,getPluginState:r,buttonConfig:n,events:o,eventBus:i,handleInteraction:a,clickReadyRef:s}){const{selectAtTarget:l}=n,c=()=>a(t.crossHair.getDetail()),u=e=>{s.current&&a(e)},{handleKeydown:d,handleKeyup:p}=((e,t)=>{let r=!1;return{handleKeydown:t=>{r=ge(t)&&e.current===t.target},handleKeyup:e=>{ge(e)&&r&&(e.preventDefault(),t())}}})(e().layoutRefs.viewportRef,c),f=((e,t)=>(r,n)=>{const o=t();e.markers.remove("location"),o.dispatch({type:"TOGGLE_SELECTED_FEATURES",payload:{multiSelect:o.multiSelect,addToExisting:n,...r}})})(t,r),y=e=>f(e,!0),g=e=>f(e,!1);return document.addEventListener("keydown",d),document.addEventListener("keyup",p),i.on(o.MAP_CLICK,u),i.on("interact:selectFeature",y),i.on("interact:unselectFeature",g),l.onClick=c,()=>{l.onClick=null,document.removeEventListener("keydown",d),document.removeEventListener("keyup",p),i.off(o.MAP_CLICK,u),i.off("interact:selectFeature",y),i.off("interact:unselectFeature",g)}}const me=({appState:e,pluginState:t})=>{return!!e.expandedButtons?.has("mapControls")||"touch"===e.interfaceType&&!1!==t.touchTarget&&(r=t.interactionModes,!(1===r?.length&&r.includes("selectMarker")));var r};const Ee={ENABLE:(e,t)=>({...e,...t,enabled:!0}),DISABLE:e=>({...e,enabled:!1,selectedFeatures:[],selectedMarkers:[],listboxActiveItem:null}),TOGGLE_SELECTED_FEATURES:(e,t)=>{const{featureId:r,multiSelect:n,layerId:o,idProperty:i,addToExisting:a=!0,replaceAll:s=!1,properties:l,geometry:c}=t,u=Array.isArray(e.selectedFeatures)?e.selectedFeatures:[],d=u.findIndex(e=>e.featureId===r&&e.layerId===o);if(!1===a){const t=u.filter((e,t)=>t!==d);return{...e,selectedFeatures:t}}const p={featureId:r,layerId:o,idProperty:i,properties:l,geometry:c};let f;if(n&&!s){const e=[...u];-1===d?e.push(p):e.splice(d,1),f=e}else{f=-1!==d&&1===u.length?[]:[p]}return{...e,selectedFeatures:f,selectedMarkers:n&&!s?e.selectedMarkers:[]}},TOGGLE_SELECTED_MARKERS:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers,o=n.includes(t);if(r){const r=o?n.filter(e=>e!==t):[...n,t];return{...e,selectedMarkers:r}}return{...e,selectedFeatures:[],selectedMarkers:o&&1===n.length?[]:[t]}},CLEAR_SELECTED_FEATURES:e=>({...e,selectedFeatures:[],selectedMarkers:[]}),SET_SELECTED_FEATURES:(e,t)=>({...e,selectedFeatures:t}),SELECT_MARKER:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers;if(n.includes(t))return e;const o=r?[...n,t]:[t];return{...e,selectedFeatures:r?e.selectedFeatures:[],selectedMarkers:o}},UNSELECT_MARKER:(e,{markerId:t})=>{const r=e.selectedMarkers;return r.includes(t)?{...e,selectedMarkers:r.filter(e=>e!==t)}:e},SET_LISTBOX_ACTIVE:(e,t)=>({...e,listboxActiveItem:t??null}),SET_LISTBOX_FOCUSED:(e,t)=>({...e,listboxFocused:!!t})},Se={tolerance:10,interactionModes:["selectMarker"],multiSelect:!1,contiguous:!1,deselectOnClickOutside:!1,touchTarget:!0,marker:{}},ve="Select",be={InitComponent:({appState:n,mapState:i,services:a,buttonConfig:s,mapProvider:l,pluginState:c})=>{const{enabled:u,selectedFeatures:d,interactionModes:p,layers:f}=c,{eventBus:y}=a,{crossHair:g,mapStyle:h,markers:m}=i,E=me({appState:n,pluginState:c});ue({mapState:i,pluginState:c,services:a,mapProvider:l,spatialListRegistry:n.spatialListRegistry});const{handleInteraction:S}=ie({mapState:i,pluginState:c,services:a,mapProvider:l});return fe({mapProvider:l,mapStyle:h,pluginState:c,selectedFeatures:d,events:o,eventBus:y}),r(()=>{y.emit("interact:active",{active:u,interactionModes:p})},[u,p]),function({enabled:e,interactionModes:t,markers:n,layers:o,eventBus:i}){r(()=>{if(!e)return;const r=t?.includes("selectMarker")&&n.items.some(e=>e.label),a=t?.includes("selectFeature")&&o.some(e=>e.labelProperty);(r||a)&&i.emit("interact:listboxcapable")},[e,t,n,o,i])}({enabled:u,interactionModes:p,markers:m,layers:f,eventBus:y}),((e,t,n,o)=>{r(()=>{const r=t&&n?.includes("selectFeature")?o.map(e=>e.layerId):[];return e.setHoverCursor?.(r),()=>e.setHoverCursor?.([])},[t,n,o])})(l,u,p,f),function({crossHair:n,enabled:o,targetNeeded:i,appState:a,dispatch:s}){const l=t(o);l.current=o;const c=t(i);c.current=i;const u=t(n);u.current=n;const d=t(s);d.current=s;const p=t(!1),f=t(!1),y=t(a.interfaceType);y.current=a.interfaceType;const g=e(()=>{const e="keyboard"===y.current&&f.current,t=c.current&&!p.current;l.current&&(e||t)?u.current.fixAtCenter():u.current.hide()},[]);r(()=>{g()},[o,i,a.interfaceType,g]),r(()=>{const e=a.layoutRefs?.appContainerRef?.current;if(!e)return;const t=e=>{p.current=e,d.current?.({type:"SET_LISTBOX_FOCUSED",payload:e})};f.current=!!document.activeElement?.closest("[data-map-keyboard-scope]"),document.activeElement?.closest(ye)&&t(!0);const r=e=>{const r=!!e.target.closest(ye),n=!!e.target.closest("[data-map-keyboard-scope]"),o=p.current!==r,i=o||f.current!==n;o&&t(r),f.current=n,i&&l.current&&g()};return e.addEventListener("focusin",r),()=>{e.removeEventListener("focusin",r)}},[a.layoutRefs,g])}({crossHair:g,enabled:u,targetNeeded:E,appState:n,dispatch:c.dispatch}),function({pluginState:e,appState:n,mapState:i,buttonConfig:a,eventBus:s,handleInteraction:l}){const c=t(l);c.current=l;const u=t(e);u.current=e;const d=t(n);d.current=n;const p=t(!1);r(()=>{p.current=!1;const e=setTimeout(()=>{p.current=!0},0);return()=>clearTimeout(e)},[e.enabled]),r(()=>{if(e.enabled)return he({getAppState:()=>d.current,mapState:i,getPluginState:()=>u.current,buttonConfig:a,events:o,eventBus:s,handleInteraction:e=>c.current(e),clickReadyRef:p})},[e.enabled,a,s]),r(()=>{if(!e.enabled)return;const t=()=>c.current(i.crossHair.getDetail());return i.crossHair.activate=t,()=>{i.crossHair.activate===t&&(i.crossHair.activate=null)}},[e.enabled,i.crossHair])}({pluginState:c,appState:n,mapState:i,buttonConfig:s,eventBus:y,handleInteraction:S}),null},reducer:{initialState:{enabled:!1,layers:[],marker:null,interactionModes:null,multiSelect:!1,deselectOnClickOutside:!1,touchTarget:!0,selectedFeatures:[],selectedMarkers:[],closeOnAction:!0,listboxActiveItem:null,listboxFocused:!1},actions:Ee},buttons:[{id:"selectAtTarget",label:"Select",variant:"primary",hiddenWhen:({appState:e,pluginState:t})=>!t.enabled||t.listboxFocused||!me({appState:e,pluginState:t}),mobile:{slot:"actions"},tablet:{slot:"actions"},desktop:{slot:"actions"}}],keyboardShortcuts:[{id:"clickAtTarget",title:"Click at target",command:"<kbd>Enter</kbd>"},{id:"selectFeatures",group:ve,context:"listbox",title:"Select features",command:"<kbd>Tab</kbd>"},{id:"navigateFeatures",group:ve,context:"listbox",title:"Highlight next feature",command:"<kbd>↑</kbd> or <kbd>↓</kbd>"},{id:"navigateFeaturesSpatially",group:ve,context:"listbox",title:"Highlight nearby feature",command:`${"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||"")?"<kbd>Option</kbd>":"<kbd>Alt</kbd>"} + <kbd>↑</kbd>, <kbd>↓</kbd>, <kbd>←</kbd> or <kbd>→</kbd>`},{id:"selectFeature",group:ve,context:"listbox",title:"Select a feature",command:"<kbd>Enter</kbd> or <kbd>Space</kbd>"},{id:"dismissHintOrReturn",group:ve,context:"listbox",title:"Dismiss hint / return to map",command:"<kbd>Escape</kbd>"}],icons:[{id:"select",svgContent:'<path d="M22 14a8 8 0 0 1-8 8"/><path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/><path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1"/><path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10"/><path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>'}],api:{enable:({pluginState:e,pluginConfig:t},r)=>{e.dispatch({type:"ENABLE",payload:{...Se,...t,...r}})},disable:({pluginState:e})=>{e.dispatch({type:"DISABLE"})},clear:({pluginState:e,mapState:t})=>{e.dispatch({type:"CLEAR_SELECTED_FEATURES"}),t.markers.remove("location")},selectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:selectFeature",{featureId:t,layerId:r,idProperty:n})},unselectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:unselectFeature",{featureId:t,layerId:r,idProperty:n})},selectMarker:({pluginState:e},t)=>{e.dispatch({type:"SELECT_MARKER",payload:{markerId:t,multiSelect:e.multiSelect}})},unselectMarker:({pluginState:e},t)=>{e.dispatch({type:"UNSELECT_MARKER",payload:{markerId:t}})}}};export{be as manifest};
|