@defra/interactive-map 0.0.30-alpha → 0.0.31-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/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/context.md +4 -4
- package/docs/api.md +111 -37
- package/docs/assets/css/docusaurus.scss +20 -4
- package/docs/assets/images/basic-map.jpg +0 -0
- package/docs/assets/images/button-first.jpg +0 -0
- package/docs/assets/images/deuteranopia-ozs-map-thumb.jpg +0 -0
- package/docs/assets/images/draw.jpg +0 -0
- package/docs/assets/images/marker-panel.jpg +0 -0
- package/docs/assets/images/night-ozs-map-thumb.jpg +0 -0
- package/docs/assets/images/outdoor-ozs-map-thumb.jpg +0 -0
- package/docs/assets/images/search.jpg +0 -0
- package/docs/assets/images/select-feature.jpg +0 -0
- package/docs/assets/images/style-switcher.jpg +0 -0
- package/docs/assets/images/toggle-marker-label.jpg +0 -0
- package/docs/assets/images/tritanopia-ozs-map-thumb.jpg +0 -0
- package/docs/examples/add-marker-with-panel.mdx +2 -2
- package/docs/examples/basic-map.mdx +2 -2
- package/docs/examples/draw.mdx +271 -0
- package/docs/examples/index.mdx +58 -10
- package/docs/examples/search-control.mdx +71 -0
- package/docs/examples/select-feature.mdx +146 -0
- package/docs/examples/style-switcher.mdx +135 -0
- package/docs/examples/toggle-marker-label.mdx +3 -3
- package/docs/plugins/datasets.md +15 -28
- package/docusaurus.config.cjs +5 -1
- package/package.json +1 -1
- package/plugins/beta/datasets/dist/css/index.css +4 -0
- package/plugins/beta/datasets/dist/esm/im-datasets-ml-adapter.js +1 -0
- package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/esm/index.js +1 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-ml-adapter.js +2 -0
- package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +2 -0
- package/plugins/beta/datasets/dist/umd/index.js +2 -0
- package/plugins/beta/datasets/src/adapters/loadLayerAdapter.js +33 -0
- package/plugins/beta/datasets/src/adapters/maplibre/layerBuilders.js +44 -120
- package/plugins/beta/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +145 -245
- package/plugins/beta/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +516 -0
- package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +191 -0
- package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +441 -0
- package/plugins/beta/datasets/src/api/addDataset.js +2 -5
- package/plugins/beta/datasets/src/api/addDataset.test.js +16 -0
- package/plugins/beta/datasets/src/api/getOpacity.js +14 -14
- package/plugins/beta/datasets/src/api/getOpacity.test.js +72 -0
- package/plugins/beta/datasets/src/api/getStyle.js +8 -9
- package/plugins/beta/datasets/src/api/getStyle.test.js +42 -0
- package/plugins/beta/datasets/src/api/removeDataset.js +7 -7
- package/plugins/beta/datasets/src/api/removeDataset.test.js +45 -0
- package/plugins/beta/datasets/src/api/setData.js +9 -3
- package/plugins/beta/datasets/src/api/setData.test.js +62 -0
- package/plugins/beta/datasets/src/api/setDatasetVisibility.js +5 -30
- package/plugins/beta/datasets/src/api/setDatasetVisibility.test.js +31 -0
- package/plugins/beta/datasets/src/api/setFeatureVisibility.js +3 -21
- package/plugins/beta/datasets/src/api/setFeatureVisibility.test.js +32 -0
- package/plugins/beta/datasets/src/api/setGlobals.js +20 -0
- package/plugins/beta/datasets/src/api/setGlobals.test.js +63 -0
- package/plugins/beta/datasets/src/api/setOpacity.js +8 -27
- package/plugins/beta/datasets/src/api/setOpacity.test.js +31 -0
- package/plugins/beta/datasets/src/api/setStyle.js +5 -21
- package/plugins/beta/datasets/src/api/setStyle.test.js +53 -0
- package/plugins/beta/datasets/src/components/Key/Key.jsx +51 -0
- package/plugins/beta/datasets/src/components/Key/KeyGroupItem.jsx +18 -0
- package/plugins/beta/datasets/src/components/Key/KeyItem.jsx +20 -0
- package/plugins/beta/datasets/src/components/Key/KeySvg.jsx +22 -0
- package/plugins/beta/datasets/src/components/Key/KeySvg.test.jsx +87 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgLine.jsx +19 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgLine.test.jsx +71 -0
- package/plugins/beta/datasets/src/components/{KeySvgPattern.jsx → Key/KeySvgPattern.jsx} +3 -4
- package/plugins/beta/datasets/src/components/Key/KeySvgPattern.test.jsx +55 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgRect.jsx +22 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgRect.test.jsx +85 -0
- package/plugins/beta/datasets/src/components/{KeySvgSymbol.jsx → Key/KeySvgSymbol.jsx} +5 -5
- package/plugins/beta/datasets/src/components/Key/KeySvgSymbol.test.jsx +80 -0
- package/plugins/beta/datasets/src/components/Key/svgProperties.test.js +61 -0
- package/plugins/beta/datasets/src/{panels → components/LayersMenu}/Layers.module.scss +4 -0
- package/plugins/beta/datasets/src/components/LayersMenu/LayersMenu.jsx +33 -0
- package/plugins/beta/datasets/src/components/LayersMenu/LayersMenuCheckbox.jsx +31 -0
- package/plugins/beta/datasets/src/components/LayersMenu/LayersMenuGroupWrapper.jsx +19 -0
- package/plugins/beta/datasets/src/datasets.scss +2 -2
- package/plugins/beta/datasets/src/fetch/createDynamicSource.js +8 -8
- package/plugins/beta/datasets/src/{DatasetsInit.jsx → initialise/DatasetsInit.jsx} +19 -21
- package/plugins/beta/datasets/src/{defaults.js → initialise/defaults.js} +17 -2
- package/plugins/beta/datasets/src/initialise/defaults.test.js +127 -0
- package/plugins/beta/datasets/src/{datasets.js → initialise/initialiseDatasets.js} +30 -26
- package/plugins/beta/datasets/src/initialise/initialiseDatasets.test.js +273 -0
- package/plugins/beta/datasets/src/manifest.js +8 -6
- package/plugins/beta/datasets/src/reducers/__data__/demoDatasets.js +253 -0
- package/plugins/beta/datasets/src/reducers/datasetsToMenu.js +78 -0
- package/plugins/beta/datasets/src/reducers/datasetsToMenu.test.js +35 -0
- package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.js +34 -0
- package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.test.js +117 -0
- package/plugins/beta/datasets/src/reducers/pluginState.js +206 -0
- package/plugins/beta/datasets/src/reducers/pluginState.test.js +386 -0
- package/plugins/beta/datasets/src/registry/__mocks__/datasetRegistry.js +29 -0
- package/plugins/beta/datasets/src/registry/createDataset.js +5 -0
- package/plugins/beta/datasets/src/registry/dataset.js +172 -0
- package/plugins/beta/datasets/src/registry/dataset.test.js +483 -0
- package/plugins/beta/datasets/src/registry/datasetDefinitionCache.js +35 -0
- package/plugins/beta/datasets/src/registry/datasetRegistry.js +116 -0
- package/plugins/beta/datasets/src/registry/datasetRegistry.test.js +335 -0
- package/plugins/beta/datasets/src/registry/dynamicGeoJson.js +17 -0
- package/plugins/beta/datasets/src/registry/globalDataset.js +36 -0
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/src/events.js +13 -1
- package/plugins/beta/draw-ml/src/index.js +1 -1
- package/plugins/beta/draw-ml/src/manifest.js +3 -0
- 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/src/InteractInit.jsx +2 -2
- package/plugins/interact/src/InteractInit.test.js +1 -1
- package/plugins/interact/src/events.js +2 -29
- package/plugins/interact/src/events.test.js +4 -102
- package/plugins/interact/src/hooks/useAttachEvents.js +3 -4
- package/plugins/interact/src/hooks/useAttachEvents.test.js +1 -3
- package/plugins/interact/src/hooks/useInteractionHandlers.js +10 -1
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +23 -4
- package/plugins/interact/src/manifest.js +0 -35
- package/plugins/interact/src/manifest.test.js +3 -43
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/src/esriProvider.js +4 -0
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/src/openlayersProvider.js +4 -0
- package/providers/beta/openlayers/src/openlayersProvider.test.js +5 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +6 -4
- package/providers/maplibre/src/maplibreProvider.test.js +5 -0
- package/providers/maplibre/src/utils/highlightFeatures.js +74 -25
- package/providers/maplibre/src/utils/highlightFeatures.test.js +132 -0
- package/providers/maplibre/src/utils/patternImages.js +2 -4
- package/providers/maplibre/src/utils/symbolImages.js +1 -4
- package/rollup.esm.mjs +2 -8
- package/src/App/components/MapButton/MapButton.jsx +16 -1
- package/src/App/components/MapButton/MapButton.module.scss +12 -1
- package/src/App/components/MapButton/MapButton.test.jsx +40 -1
- package/src/App/hooks/useContinueEnabledEvaluator.js +31 -0
- package/src/App/hooks/useContinueEnabledEvaluator.test.js +118 -0
- package/src/App/hooks/useEvaluateProp.js +15 -15
- package/src/App/hooks/useEvaluateProp.test.js +80 -76
- package/src/App/hooks/useLayoutMeasurements.js +1 -3
- package/src/App/hooks/useResizeObserver.js +12 -1
- package/src/App/hooks/useResizeObserver.test.js +1 -0
- package/src/App/renderer/PluginInits.jsx +2 -0
- package/src/App/renderer/mapButtons.js +21 -1
- package/src/App/renderer/mapButtons.test.js +46 -1
- package/src/App/store/appReducer.js +1 -1
- package/src/App/store/appReducer.test.js +37 -0
- package/src/InteractiveMap/InteractiveMap.js +10 -0
- package/src/InteractiveMap/InteractiveMap.test.js +8 -0
- package/src/config/appConfig.js +25 -0
- package/src/config/appConfig.test.js +50 -0
- package/src/config/defaults.js +1 -0
- package/src/scss/settings/_dimensions.scss +1 -0
- package/src/services/patternRegistry.js +8 -4
- package/src/types.js +7 -0
- package/src/utils/patternUtils.js +1 -2
- package/src/utils/patternUtils.test.js +9 -0
- package/webpack.dev.mjs +10 -0
- package/webpack.umd.mjs +1 -1
- package/plugins/beta/datasets/dist/adapters/maplibre/esm/im-datasets-ml-adapter.js +0 -1
- package/plugins/beta/datasets/dist/adapters/maplibre/esm/index.js +0 -1
- package/plugins/beta/datasets/dist/umd/maplibre/im-datasets-maplibre-adapter.js +0 -2
- package/plugins/beta/datasets/dist/umd/maplibre/im-datasets-plugin.js +0 -2
- package/plugins/beta/datasets/dist/umd/maplibre/index.js +0 -2
- package/plugins/beta/datasets/src/adapters/maplibre/index.js +0 -18
- package/plugins/beta/datasets/src/adapters/maplibre/layerIds.js +0 -75
- package/plugins/beta/datasets/src/adapters/maplibre/patternImages.js +0 -27
- package/plugins/beta/datasets/src/adapters/maplibre/symbolImages.js +0 -31
- package/plugins/beta/datasets/src/components/KeySvg.jsx +0 -24
- package/plugins/beta/datasets/src/components/KeySvgLine.jsx +0 -19
- package/plugins/beta/datasets/src/components/KeySvgRect.jsx +0 -22
- package/plugins/beta/datasets/src/index.maplibre.umd.js +0 -23
- package/plugins/beta/datasets/src/panels/Key.jsx +0 -62
- package/plugins/beta/datasets/src/panels/Layers.jsx +0 -141
- package/plugins/beta/datasets/src/reducer.js +0 -219
- package/plugins/beta/datasets/src/reducers/keyReducer.js +0 -34
- package/plugins/beta/datasets/src/utils/filters.js +0 -34
- package/plugins/beta/datasets/src/utils/mergeSublayer.js +0 -86
- package/plugins/beta/draw-ml/dist/css/index.css +0 -21
- /package/plugins/beta/datasets/dist/umd/{maplibre/im-datasets-maplibre-adapter.js.LICENSE.txt → im-datasets-ml-adapter.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/dist/umd/{maplibre/im-datasets-plugin.js.LICENSE.txt → im-datasets-plugin.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/dist/umd/{maplibre/index.js.LICENSE.txt → index.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/src/components/{EmptyKey.jsx → Key/EmptyKey.jsx} +0 -0
- /package/plugins/beta/datasets/src/components/{EmptyKey.test.jsx → Key/EmptyKey.test.jsx} +0 -0
- /package/plugins/beta/datasets/src/{panels → components/Key}/Key.module.scss +0 -0
- /package/plugins/beta/datasets/src/components/{svgProperties.js → Key/svgProperties.js} +0 -0
|
@@ -2,11 +2,10 @@ import { attachEvents } from './events.js'
|
|
|
2
2
|
|
|
3
3
|
const MOCK_POINT = { x: 1, y: 2 }
|
|
4
4
|
const MOCK_COORDS = [1, 2]
|
|
5
|
-
const INTERACT_DONE = 'interact:done'
|
|
6
5
|
|
|
7
6
|
const createParams = () => {
|
|
8
7
|
const appState = { layoutRefs: { viewportRef: { current: document.body } }, disabledButtons: new Set() }
|
|
9
|
-
const pluginState = { dispatch: jest.fn(), selectionBounds: null, selectedFeatures: [], selectedMarkers: [],
|
|
8
|
+
const pluginState = { dispatch: jest.fn(), selectionBounds: null, selectedFeatures: [], selectedMarkers: [], multiSelect: false }
|
|
10
9
|
const clickReadyRef = { current: false }
|
|
11
10
|
return {
|
|
12
11
|
appState,
|
|
@@ -18,11 +17,10 @@ const createParams = () => {
|
|
|
18
17
|
markers: { remove: jest.fn(), getMarker: jest.fn(() => null) },
|
|
19
18
|
crossHair: { getDetail: jest.fn(() => ({ point: { x: 0, y: 0 }, coords: [0, 0] })) }
|
|
20
19
|
},
|
|
21
|
-
buttonConfig: {
|
|
20
|
+
buttonConfig: { selectAtTarget: {} },
|
|
22
21
|
events: { MAP_CLICK: 'map:click' },
|
|
23
22
|
eventBus: { on: jest.fn(), off: jest.fn(), emit: jest.fn() },
|
|
24
|
-
handleInteraction: jest.fn()
|
|
25
|
-
closeApp: jest.fn()
|
|
23
|
+
handleInteraction: jest.fn()
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
|
|
@@ -109,102 +107,6 @@ describe('attachEvents — click handling', () => {
|
|
|
109
107
|
})
|
|
110
108
|
})
|
|
111
109
|
|
|
112
|
-
describe('attachEvents — button actions', () => {
|
|
113
|
-
let cleanup = null
|
|
114
|
-
|
|
115
|
-
beforeEach(() => { jest.useFakeTimers() })
|
|
116
|
-
afterEach(() => { cleanup?.(); jest.useRealTimers() })
|
|
117
|
-
|
|
118
|
-
it('selectDone emits correct payload and respects closeOnAction', () => {
|
|
119
|
-
const params = createParams()
|
|
120
|
-
cleanup = attachEvents(params)
|
|
121
|
-
|
|
122
|
-
params.mapState.markers.getMarker.mockReturnValue({ coords: MOCK_COORDS })
|
|
123
|
-
params.buttonConfig.selectDone.onClick()
|
|
124
|
-
expect(params.closeApp).toHaveBeenCalled()
|
|
125
|
-
|
|
126
|
-
params.closeApp.mockClear()
|
|
127
|
-
params.pluginState.closeOnAction = false
|
|
128
|
-
params.buttonConfig.selectDone.onClick()
|
|
129
|
-
expect(params.closeApp).not.toHaveBeenCalled()
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('selectDone emits selectedFeatures and selectionBounds when no marker', () => {
|
|
133
|
-
const params = createParams()
|
|
134
|
-
cleanup = attachEvents(params)
|
|
135
|
-
|
|
136
|
-
params.pluginState.selectedFeatures = [{ id: 'f1' }]
|
|
137
|
-
params.pluginState.selectionBounds = { sw: [0, 0], ne: [1, 1] }
|
|
138
|
-
params.buttonConfig.selectDone.onClick()
|
|
139
|
-
|
|
140
|
-
expect(params.eventBus.emit).toHaveBeenCalledWith(INTERACT_DONE, {
|
|
141
|
-
selectedFeatures: [{ id: 'f1' }],
|
|
142
|
-
selectionBounds: { sw: [0, 0], ne: [1, 1] }
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('selectDone includes selectedMarkers in payload when present', () => {
|
|
147
|
-
const params = createParams()
|
|
148
|
-
cleanup = attachEvents(params)
|
|
149
|
-
|
|
150
|
-
params.pluginState.selectedMarkers = ['m1', 'm2']
|
|
151
|
-
params.buttonConfig.selectDone.onClick()
|
|
152
|
-
|
|
153
|
-
expect(params.eventBus.emit).toHaveBeenCalledWith(INTERACT_DONE,
|
|
154
|
-
expect.objectContaining({ selectedMarkers: ['m1', 'm2'] })
|
|
155
|
-
)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
it('selectDone omits selectedMarkers from payload when empty', () => {
|
|
159
|
-
const params = createParams()
|
|
160
|
-
cleanup = attachEvents(params)
|
|
161
|
-
|
|
162
|
-
params.buttonConfig.selectDone.onClick()
|
|
163
|
-
|
|
164
|
-
const payload = params.eventBus.emit.mock.calls.find(c => c[0] === INTERACT_DONE)[1]
|
|
165
|
-
expect(payload).not.toHaveProperty('selectedMarkers')
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
it('does not emit or closeApp if selectDone button is disabled', () => {
|
|
169
|
-
const params = createParams()
|
|
170
|
-
cleanup = attachEvents(params)
|
|
171
|
-
|
|
172
|
-
params.appState.disabledButtons.add('selectDone')
|
|
173
|
-
params.buttonConfig.selectDone.onClick()
|
|
174
|
-
|
|
175
|
-
expect(params.eventBus.emit).not.toHaveBeenCalled()
|
|
176
|
-
expect(params.closeApp).not.toHaveBeenCalled()
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('selectCancel emits cancel and respects closeOnAction', () => {
|
|
180
|
-
const params = createParams()
|
|
181
|
-
cleanup = attachEvents(params)
|
|
182
|
-
|
|
183
|
-
params.buttonConfig.selectCancel.onClick()
|
|
184
|
-
expect(params.closeApp).toHaveBeenCalled()
|
|
185
|
-
|
|
186
|
-
cleanup()
|
|
187
|
-
const params2 = createParams()
|
|
188
|
-
cleanup = attachEvents(params2)
|
|
189
|
-
params2.pluginState.closeOnAction = false
|
|
190
|
-
params2.buttonConfig.selectCancel.onClick()
|
|
191
|
-
expect(params2.closeApp).not.toHaveBeenCalled()
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('respects default closeOnAction when value is nullish', () => {
|
|
195
|
-
const params = createParams()
|
|
196
|
-
params.pluginState.closeOnAction = null
|
|
197
|
-
cleanup = attachEvents(params)
|
|
198
|
-
|
|
199
|
-
params.buttonConfig.selectDone.onClick()
|
|
200
|
-
expect(params.closeApp).toHaveBeenCalledTimes(1)
|
|
201
|
-
|
|
202
|
-
params.closeApp.mockClear()
|
|
203
|
-
params.buttonConfig.selectCancel.onClick()
|
|
204
|
-
expect(params.closeApp).toHaveBeenCalledTimes(1)
|
|
205
|
-
})
|
|
206
|
-
})
|
|
207
|
-
|
|
208
110
|
describe('attachEvents — programmatic selection', () => {
|
|
209
111
|
let cleanup = null
|
|
210
112
|
|
|
@@ -232,7 +134,7 @@ describe('attachEvents — cleanup', () => {
|
|
|
232
134
|
const params = createParams()
|
|
233
135
|
const cleanup = attachEvents(params)
|
|
234
136
|
cleanup()
|
|
235
|
-
|
|
137
|
+
expect(params.buttonConfig.selectAtTarget.onClick).toBeNull()
|
|
236
138
|
jest.useRealTimers()
|
|
237
139
|
})
|
|
238
140
|
})
|
|
@@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react'
|
|
|
2
2
|
import { EVENTS } from '../../../../src/config/events.js'
|
|
3
3
|
import { attachEvents } from '../events.js'
|
|
4
4
|
|
|
5
|
-
export function useAttachEvents ({ pluginState, appState, mapState, buttonConfig, eventBus, handleInteraction
|
|
5
|
+
export function useAttachEvents ({ pluginState, appState, mapState, buttonConfig, eventBus, handleInteraction }) {
|
|
6
6
|
// Refs updated synchronously each render — keeps callbacks fresh without re-attaching events
|
|
7
7
|
const handleInteractionRef = useRef(handleInteraction)
|
|
8
8
|
handleInteractionRef.current = handleInteraction
|
|
@@ -37,10 +37,9 @@ export function useAttachEvents ({ pluginState, appState, mapState, buttonConfig
|
|
|
37
37
|
events: EVENTS,
|
|
38
38
|
eventBus,
|
|
39
39
|
handleInteraction: (event) => handleInteractionRef.current(event),
|
|
40
|
-
clickReadyRef
|
|
41
|
-
closeApp
|
|
40
|
+
clickReadyRef
|
|
42
41
|
})
|
|
43
42
|
|
|
44
43
|
return cleanupEvents
|
|
45
|
-
}, [pluginState.enabled, buttonConfig, eventBus
|
|
44
|
+
}, [pluginState.enabled, buttonConfig, eventBus])
|
|
46
45
|
}
|
|
@@ -21,7 +21,6 @@ beforeEach(() => {
|
|
|
21
21
|
mapState: { mapStyle: {} },
|
|
22
22
|
buttonConfig: {},
|
|
23
23
|
eventBus: { emit: jest.fn() },
|
|
24
|
-
closeApp: jest.fn(),
|
|
25
24
|
handleInteraction: handleInteractionMock
|
|
26
25
|
}
|
|
27
26
|
})
|
|
@@ -36,8 +35,7 @@ describe('useAttachEvents', () => {
|
|
|
36
35
|
mapState: props.mapState,
|
|
37
36
|
buttonConfig: props.buttonConfig,
|
|
38
37
|
events: EVENTS,
|
|
39
|
-
eventBus: props.eventBus
|
|
40
|
-
closeApp: props.closeApp
|
|
38
|
+
eventBus: props.eventBus
|
|
41
39
|
}))
|
|
42
40
|
|
|
43
41
|
const { getAppState, getPluginState, handleInteraction } = attachEvents.mock.calls.at(-1)[0]
|
|
@@ -166,6 +166,15 @@ const resolveContiguousDispatch = ({ featureId, feature, config, selectedFeature
|
|
|
166
166
|
return true
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
const logDebugFeatures = (coords, features) => {
|
|
170
|
+
const [lng, lat] = coords
|
|
171
|
+
console.groupCollapsed(`[interact] click (${lng.toFixed(4)}, ${lat.toFixed(4)}) — ${features.length} feature${features.length !== 1 ? 's' : ''}`) // NOSONAR
|
|
172
|
+
features.forEach(f => { // NOSONAR
|
|
173
|
+
console.log({ layer: f.layer.id, type: f.layer.type, id: f.id ?? '—', sourceLayer: f.sourceLayer ?? '—', properties: f.properties }) // NOSONAR
|
|
174
|
+
})
|
|
175
|
+
console.groupEnd() // NOSONAR
|
|
176
|
+
}
|
|
177
|
+
|
|
169
178
|
/**
|
|
170
179
|
* Core interaction hook. Processes map clicks in fixed priority order:
|
|
171
180
|
* selectMarker → selectFeature → placeMarker (fallback).
|
|
@@ -185,7 +194,7 @@ const useHandleInteraction = ({ mapProvider, layers, interactionModes, multiSele
|
|
|
185
194
|
return useCallback(({ point, coords }) => {
|
|
186
195
|
const debugFeatures = debug ? getFeaturesAtPoint(mapProvider, point, { radius: tolerance }) : null
|
|
187
196
|
if (debugFeatures) {
|
|
188
|
-
|
|
197
|
+
logDebugFeatures(coords, debugFeatures)
|
|
189
198
|
}
|
|
190
199
|
if (interactionModes.includes('selectMarker')) {
|
|
191
200
|
const markerHit = findMarkerAtPoint(markers, point, scale)
|
|
@@ -423,18 +423,37 @@ it('skips emission when selection remains empty after being cleared', () => {
|
|
|
423
423
|
/* ------------------------------------------------------------------ */
|
|
424
424
|
|
|
425
425
|
it('logs features when debug mode is enabled', () => {
|
|
426
|
+
const groupSpy = jest.spyOn(console, 'groupCollapsed').mockImplementation(() => {})
|
|
426
427
|
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {})
|
|
428
|
+
const groupEndSpy = jest.spyOn(console, 'groupEnd').mockImplementation(() => {})
|
|
427
429
|
|
|
428
430
|
const { result } = setup({ debug: true })
|
|
429
431
|
|
|
430
432
|
click(result)
|
|
431
433
|
|
|
432
|
-
expect(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
)
|
|
434
|
+
expect(groupSpy).toHaveBeenCalledWith(expect.stringContaining('[interact] click ('))
|
|
435
|
+
expect(groupSpy).toHaveBeenCalledWith(expect.stringContaining('1 feature'))
|
|
436
|
+
expect(logSpy).toHaveBeenCalledWith(expect.objectContaining({ layer: 'parcels' }))
|
|
437
|
+
expect(groupEndSpy).toHaveBeenCalled()
|
|
436
438
|
|
|
439
|
+
groupSpy.mockRestore()
|
|
437
440
|
logSpy.mockRestore()
|
|
441
|
+
groupEndSpy.mockRestore()
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
it('uses plural label when multiple features are found', () => {
|
|
445
|
+
const groupSpy = jest.spyOn(console, 'groupCollapsed').mockImplementation(() => {})
|
|
446
|
+
jest.spyOn(console, 'log').mockImplementation(() => {})
|
|
447
|
+
jest.spyOn(console, 'groupEnd').mockImplementation(() => {})
|
|
448
|
+
|
|
449
|
+
featureQueries.getFeaturesAtPoint.mockReturnValue([baseFeature, baseFeature])
|
|
450
|
+
|
|
451
|
+
const { result } = setup({ debug: true })
|
|
452
|
+
click(result)
|
|
453
|
+
|
|
454
|
+
expect(groupSpy).toHaveBeenCalledWith(expect.stringContaining('2 features'))
|
|
455
|
+
|
|
456
|
+
jest.restoreAllMocks()
|
|
438
457
|
})
|
|
439
458
|
|
|
440
459
|
/* ------------------------------------------------------------------ */
|
|
@@ -21,23 +21,6 @@ export const manifest = {
|
|
|
21
21
|
},
|
|
22
22
|
|
|
23
23
|
buttons: [{
|
|
24
|
-
id: 'selectCancel',
|
|
25
|
-
label: 'Back',
|
|
26
|
-
variant: 'tertiary',
|
|
27
|
-
hiddenWhen: ({ appConfig, appState, pluginState }) => !pluginState.enabled || !(['hybrid', 'buttonFirst'].includes(appConfig.behaviour) && appState.isFullscreen),
|
|
28
|
-
mobile: {
|
|
29
|
-
slot: 'actions',
|
|
30
|
-
showLabel: true
|
|
31
|
-
},
|
|
32
|
-
tablet: {
|
|
33
|
-
slot: 'actions',
|
|
34
|
-
showLabel: true
|
|
35
|
-
},
|
|
36
|
-
desktop: {
|
|
37
|
-
slot: 'actions',
|
|
38
|
-
showLabel: true
|
|
39
|
-
}
|
|
40
|
-
}, {
|
|
41
24
|
id: 'selectAtTarget',
|
|
42
25
|
label: 'Select',
|
|
43
26
|
variant: 'primary',
|
|
@@ -54,24 +37,6 @@ export const manifest = {
|
|
|
54
37
|
desktop: {
|
|
55
38
|
slot: 'actions'
|
|
56
39
|
}
|
|
57
|
-
}, {
|
|
58
|
-
id: 'selectDone',
|
|
59
|
-
label: 'Continue',
|
|
60
|
-
variant: 'primary',
|
|
61
|
-
excludeWhen: ({ appState, pluginState }) => !pluginState.enabled || !appState.isFullscreen,
|
|
62
|
-
enableWhen: ({ mapState, pluginState }) => !!mapState.markers.items.some(m => m.id === 'location') || !!pluginState.selectionBounds,
|
|
63
|
-
mobile: {
|
|
64
|
-
slot: 'actions',
|
|
65
|
-
showLabel: true
|
|
66
|
-
},
|
|
67
|
-
tablet: {
|
|
68
|
-
slot: 'actions',
|
|
69
|
-
showLabel: true
|
|
70
|
-
},
|
|
71
|
-
desktop: {
|
|
72
|
-
slot: 'actions',
|
|
73
|
-
showLabel: true
|
|
74
|
-
}
|
|
75
40
|
}],
|
|
76
41
|
|
|
77
42
|
keyboardShortcuts: [
|
|
@@ -18,7 +18,9 @@ describe('manifest', () => {
|
|
|
18
18
|
|
|
19
19
|
it('defines buttons with correct ids', () => {
|
|
20
20
|
const ids = manifest.buttons.map(b => b.id)
|
|
21
|
-
expect(ids).toEqual(expect.arrayContaining(['
|
|
21
|
+
expect(ids).toEqual(expect.arrayContaining(['selectAtTarget']))
|
|
22
|
+
expect(ids).not.toContain('selectDone')
|
|
23
|
+
expect(ids).not.toContain('selectCancel')
|
|
22
24
|
})
|
|
23
25
|
|
|
24
26
|
it('buttons have slots and showLabel', () => {
|
|
@@ -33,54 +35,12 @@ describe('manifest', () => {
|
|
|
33
35
|
})
|
|
34
36
|
|
|
35
37
|
it('button logic functions cover all branches', () => {
|
|
36
|
-
const done = manifest.buttons.find(b => b.id === 'selectDone')
|
|
37
38
|
const atTarget = manifest.buttons.find(b => b.id === 'selectAtTarget')
|
|
38
|
-
const cancel = manifest.buttons.find(b => b.id === 'selectCancel')
|
|
39
|
-
|
|
40
|
-
// selectDone.excludeWhen
|
|
41
|
-
expect(done.excludeWhen({ appState: { isFullscreen: false }, pluginState: { enabled: true } })).toBe(true)
|
|
42
|
-
expect(done.excludeWhen({ appState: { isFullscreen: true }, pluginState: { enabled: true } })).toBe(false)
|
|
43
|
-
|
|
44
|
-
// selectDone.enableWhen
|
|
45
|
-
expect(done.enableWhen({
|
|
46
|
-
mapState: { markers: { items: [{ id: 'location' }] } },
|
|
47
|
-
pluginState: { selectionBounds: null }
|
|
48
|
-
})).toBe(true)
|
|
49
|
-
expect(done.enableWhen({
|
|
50
|
-
mapState: { markers: { items: [] } },
|
|
51
|
-
pluginState: { selectionBounds: null }
|
|
52
|
-
})).toBe(false)
|
|
53
|
-
expect(done.enableWhen({
|
|
54
|
-
mapState: { markers: { items: [] } },
|
|
55
|
-
pluginState: { selectionBounds: { sw: [0, 0], ne: [1, 1] } }
|
|
56
|
-
})).toBe(true)
|
|
57
39
|
|
|
58
40
|
// selectAtTarget.hiddenWhen
|
|
59
41
|
expect(atTarget.hiddenWhen({ appState: { interfaceType: 'pointer' }, pluginState: { enabled: true } })).toBe(true)
|
|
60
42
|
expect(atTarget.hiddenWhen({ appState: { interfaceType: 'touch' }, pluginState: { enabled: true } })).toBe(false)
|
|
61
43
|
expect(atTarget.hiddenWhen({ appState: { interfaceType: 'touch' }, pluginState: { enabled: false } })).toBe(true)
|
|
62
|
-
|
|
63
|
-
// selectCancel.hiddenWhen
|
|
64
|
-
expect(cancel.hiddenWhen({
|
|
65
|
-
appConfig: { behaviour: 'always' },
|
|
66
|
-
appState: { isFullscreen: true },
|
|
67
|
-
pluginState: { enabled: true }
|
|
68
|
-
})).toBe(true)
|
|
69
|
-
expect(cancel.hiddenWhen({
|
|
70
|
-
appConfig: { behaviour: 'hybrid' },
|
|
71
|
-
appState: { isFullscreen: true },
|
|
72
|
-
pluginState: { enabled: true }
|
|
73
|
-
})).toBe(false)
|
|
74
|
-
expect(cancel.hiddenWhen({
|
|
75
|
-
appConfig: { behaviour: 'hybrid' },
|
|
76
|
-
appState: { isFullscreen: false },
|
|
77
|
-
pluginState: { enabled: true }
|
|
78
|
-
})).toBe(true)
|
|
79
|
-
expect(cancel.hiddenWhen({
|
|
80
|
-
appConfig: { behaviour: 'hybrid' },
|
|
81
|
-
appState: { isFullscreen: true },
|
|
82
|
-
pluginState: { enabled: false }
|
|
83
|
-
})).toBe(true)
|
|
84
44
|
})
|
|
85
45
|
|
|
86
46
|
it('keyboardShortcuts array exists', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"@arcgis/core/config.js";import n from"@arcgis/core/layers/support/TileInfo.js";import i from"@arcgis/core/Map.js";import o from"@arcgis/core/views/MapView.js";import a from"@arcgis/core/layers/VectorTileLayer.js";import s from"@arcgis/core/geometry/Point.js";import{when as m,once as l,watch as u}from"@arcgis/core/core/reactiveUtils.js";import c from"@arcgis/core/geometry/Extent.js";var p={animationDuration:200},v=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom"];var y=(e,t)=>{var r=null,n=function(){for(var n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];clearTimeout(r),r=setTimeout(()=>{e(...i)},t)};return n.cancel=()=>{r&&(clearTimeout(r),r=null)},n};function h(e){var{mapProvider:t,view:r,baseTileLayer:n,events:i,eventBus:o,getZoom:a,getCenter:s,getBounds:c,getResolution:p}=e,v=!1,h=[],d=[],f=e=>{var t=(()=>{if(v||!r||r.destroyed||!r.extent)return null;var{maxZoom:e,minZoom:t}=r.constraints;return{center:s(),bounds:c(),resolution:p(),zoom:a(),isAtMaxZoom:r.zoom+.01>=e,isAtMinZoom:r.zoom-.01<=t}})();t&&o.emit(e,t)};m(()=>n.loaded&&r.resolution>0,()=>f(i.MAP_LOADED)),l(()=>r.ready).then(()=>{v||o.emit(i.MAP_READY,{map:t.map,view:t.view,mapStyleId:t.mapStyleId,mapSize:t.mapSize,crs:t.crs})}),l(()=>r.stationary).then(()=>f(i.MAP_FIRST_IDLE));var g=y(()=>f(i.MAP_MOVE_END),500);d.push(g),h.push(u(()=>[r.interacting,r.animation],e=>{var[t,r]=e;(t||r)&&o.emit(i.MAP_MOVE_START),t||r||g()}));var w,x,b,M=(w=()=>f(i.MAP_MOVE),x=10,b=0,function(){var e=Date.now();e-b>=x&&(b=e,w(...arguments))});d.push(M),h.push(u(()=>r.zoom,M)),h.push(u(()=>r.extent,()=>o.emit(i.MAP_RENDER),{initial:!1}));var E=y(()=>f(i.MAP_DATA_CHANGE),500);d.push(E),h.push(u(()=>r.updating,e=>!e&&E()));var A=null,T=null;return h.push(r.on("pointer-down",e=>{A=e.x,T=e.y})),h.push(r.on("pointer-up",e=>{var n;if(0===e.button&&!(Math.hypot(e.x-A,e.y-T)>6)&&"active"!==(null===(n=t.sketchViewModel)||void 0===n?void 0:n.state)){var a={x:e.x,y:e.y},s=r.toMap(a);s&&o.emit(i.MAP_CLICK,{point:a,coords:[s.x,s.y]})}})),{remove(){v=!0,d.forEach(e=>e.cancel()),h.forEach(e=>e.remove())}}}var d=e=>e?new c({xmin:e[0],ymin:e[1],xmax:e[2],ymax:e[3],spatialReference:{wkid:27700}}):void 0,f=e=>e?new s({x:e[0],y:e[1],spatialReference:{wkid:27700}}):void 0,g=(e,t)=>{if(e)if("FeatureCollection"===e.type)e.features.forEach(e=>g(e,t));else if("Feature"===e.type)g(e.geometry,t);else if("GeometryCollection"===e.type)e.geometries.forEach(e=>g(e,t));else{var r=e=>{Array.isArray(e)&&("number"==typeof e[0]?t.push(e):e.forEach(r))};r(e.coordinates)}},w=e=>{var t=[];g(e,t);var r=t.map(e=>e[0]),n=t.map(e=>e[1]);return d([Math.min(...r),Math.min(...n),Math.max(...r),Math.max(...n)])},x=e=>{var t=1609.344,r=e/t;if(r<.5/t)return"".concat(Math.round(e),"m");if(r<10){var n=Number.parseFloat(r.toFixed(1)),i=1===n?"mile":"miles";return"".concat(n," ").concat(i)}var o=Math.round(r),a=1===o?"mile":"miles";return"".concat(o," ").concat(a)};var b={top:0,right:0,bottom:0,left:0};function M(){return(M=t(function*(e,t){if(!e||!t)return[];var r=e.map.layers.filter(e=>e instanceof a);return r.length?(yield e.hitTest(t,{include:r.toArray()})).results.map(e=>({layerId:e.layer.id,layerTitle:e.layer.title||e.layer.id,type:e.layer.type,geometry:e.graphic.geometry,symbol:e.graphic.symbol})):[]})).apply(this,arguments)}function E(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function A(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?E(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):E(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}class T{constructor(e){var{mapProviderConfig:t={},events:r,eventBus:n}=e;this.events=r,this.eventBus=n,this.capabilities={supportedShortcuts:v,supportsMapSizes:!1},Object.assign(this,t),this.mapEventHandles=[],this.appEventHandles=[]}initMap(e){var s=this;return t(function*(){var{container:t,padding:m,mapStyle:l,mapSize:u,maxExtent:c}=e;s.mapStyleId=null==l?void 0:l.id,s.mapSize=u;var{events:p,eventBus:v}=s;s.setupConfig&&(yield s.setupConfig(r));var y=new a({id:"baselayer",url:l.url,visible:!0}),g=new i({layers:[y]}),w=c?d(c):null,x=new o({spatialReference:27700,container:t,map:g,zoom:e.zoom,center:f(e.center),maxExtent:c,constraints:{lods:n.create({spatialReference:{wkid:27700}}).lods,snapToZoom:!1,minZoom:e.minZoom,maxZoom:e.maxZoom,maxScale:0,geometry:w,rotationEnabled:!1},ui:{components:[]},popupEnabled:!1});(e=>{if(e){var t=e.querySelector(".esri-view-surface");t.removeAttribute("role"),t.tabIndex=-1,t.style["outline-color"]="transparent",t.style.touchAction="none"}})(x.container),x.padding=m,e.bounds&&x.when(()=>x.goTo(d(e.bounds),{duration:0})),s.mapEventHandles=h({mapProvider:s,view:x,baseTileLayer:y,events:p,eventBus:v,getZoom:s.getZoom.bind(s),getCenter:s.getCenter.bind(s),getBounds:s.getBounds.bind(s),getResolution:s.getResolution.bind(s)}),s.appEventHandles=function(e){var{baseTileLayer:t,events:r,eventBus:n}=e,i=e=>{t.loadStyle(e.url).then(()=>{n.emit(r.MAP_STYLE_CHANGE,{mapStyleId:e.id})})};return n.on(r.MAP_SET_STYLE,i),{remove(){n.off(r.MAP_SET_STYLE,i)}}}({baseTileLayer:y,events:p,eventBus:v})||[],s.map=g,s.view=x,s.baseTileLayer=y})()}destroyMap(){var e,t;null===(e=this.mapEvents)||void 0===e||e.remove(),null===(t=this.appEvents)||void 0===t||t.remove(),this.mapEvents=null,this.appEvents=null,this.view&&(this.view.container=null,this.view.destroy(),this.view=null),this.map&&(this.map.removeAll(),this.map=null)}setView(e){var t,{center:r,zoom:n}=e;null===(t=this.view.animation)||void 0===t||t.destroy();var i={center:r?new s({x:r[0],y:r[1],spatialReference:{wkid:27700}}):this.view.center,zoom:null!=n?n:this.view.zoom};this.view.goTo(A(A({},i),{},{duration:p.animationDuration}))}zoomIn(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom+e,duration:p.animationDuration})}zoomOut(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom-e,duration:p.animationDuration})}panBy(e){var{x:t,y:r}=this.view.toScreen(this.view.center),n={x:t+e[0],y:r+e[1]},i=this.view.toMap(n);this.view.goTo({center:i,duration:p.animationDuration})}fitToBounds(e){var t=Array.isArray(e)?d(e):w(e);this.view.goTo(t,{duration:p.DELAY})}setPadding(e){this.view.padding=e}getCenter(){var e=this.view.center;return[e.x,e.y].map(e=>Math.round(100*e)/100)}getZoom(){return this.view.zoom}getBounds(){var{xmin:e,ymin:t,xmax:r,ymax:n}=this.view.extent;return[e,t,r,n].map(e=>Math.round(100*e)/100)}getFeaturesAtPoint(e,t){return function(e,t){return M.apply(this,arguments)}(this.view,e)}getVisibleFeatures(e){return[]}getAreaDimensions(){return(e=>{if(!(e&&e instanceof c))return"";var t=e.xmin,r=e.ymin,n=e.xmax,i=e.ymax-r,o=x(n-t),a=x(i);return"".concat(a," by ").concat(o)})(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:b;if(!e.container)return null;var{width:r,height:n}=e.container.getBoundingClientRect(),i={x:t.left,y:n-t.bottom},o={x:r-t.right,y:t.top},a=e.toMap(i),s=e.toMap(o);return new c({xmin:a.x,ymin:a.y,xmax:s.x,ymax:s.y,spatialReference:a.spatialReference})}(this.view))}getCardinalMove(e,t){return function(e,t){var[r,n]=e,[i,o]=t,a=i-r,s=o-n,m=[];return Math.abs(s)>.1&&m.push("".concat(s>0?"north":"south"," ").concat(x(Math.abs(s)))),Math.abs(a)>.1&&m.push("".concat(a>0?"east":"west"," ").concat(x(Math.abs(a)))),m.join(", ")}(e,t)}getResolution(){return this.view.resolution}mapToScreen(e){var t=f(e),r=this.view.toScreen(t);return{x:r.x,y:r.y}}screenToMap(e){var t=this.view.toMap(e);return[t.x,t.y]}isGeometryObscured(e,t){return((e,t,r)=>{if(null==r||!r.container)return!1;var n=r.container.getBoundingClientRect(),i=w(e),o=[r.toScreen(new s({x:i.xmin,y:i.ymin,spatialReference:i.spatialReference})),r.toScreen(new s({x:i.xmin,y:i.ymax,spatialReference:i.spatialReference})),r.toScreen(new s({x:i.xmax,y:i.ymin,spatialReference:i.spatialReference})),r.toScreen(new s({x:i.xmax,y:i.ymax,spatialReference:i.spatialReference}))],a=Math.min(...o.map(e=>e.x)),m=Math.max(...o.map(e=>e.x)),l=Math.min(...o.map(e=>e.y)),u=Math.max(...o.map(e=>e.y)),c=t.left-n.left,p=t.top-n.top,v=t.right-n.left,y=t.bottom-n.top;return a<v&&m>c&&l<y&&u>p})(e,t,this.view)}}export{T as default};
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"@arcgis/core/config.js";import n from"@arcgis/core/layers/support/TileInfo.js";import i from"@arcgis/core/Map.js";import o from"@arcgis/core/views/MapView.js";import a from"@arcgis/core/layers/VectorTileLayer.js";import s from"@arcgis/core/geometry/Point.js";import{when as m,once as l,watch as u}from"@arcgis/core/core/reactiveUtils.js";import c from"@arcgis/core/geometry/Extent.js";var p={animationDuration:200},v=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom"];var y=(e,t)=>{var r=null,n=function(){for(var n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];clearTimeout(r),r=setTimeout(()=>{e(...i)},t)};return n.cancel=()=>{r&&(clearTimeout(r),r=null)},n};function h(e){var{mapProvider:t,view:r,baseTileLayer:n,events:i,eventBus:o,getZoom:a,getCenter:s,getBounds:c,getResolution:p}=e,v=!1,h=[],d=[],f=e=>{var t=(()=>{if(v||!r||r.destroyed||!r.extent)return null;var{maxZoom:e,minZoom:t}=r.constraints;return{center:s(),bounds:c(),resolution:p(),zoom:a(),isAtMaxZoom:r.zoom+.01>=e,isAtMinZoom:r.zoom-.01<=t}})();t&&o.emit(e,t)};m(()=>n.loaded&&r.resolution>0,()=>f(i.MAP_LOADED)),l(()=>r.ready).then(()=>{v||o.emit(i.MAP_READY,{map:t.map,view:t.view,mapStyleId:t.mapStyleId,mapSize:t.mapSize,crs:t.crs})}),l(()=>r.stationary).then(()=>f(i.MAP_FIRST_IDLE));var g=y(()=>f(i.MAP_MOVE_END),500);d.push(g),h.push(u(()=>[r.interacting,r.animation],e=>{var[t,r]=e;(t||r)&&o.emit(i.MAP_MOVE_START),t||r||g()}));var w,x,b,M=(w=()=>f(i.MAP_MOVE),x=10,b=0,function(){var e=Date.now();e-b>=x&&(b=e,w(...arguments))});d.push(M),h.push(u(()=>r.zoom,M)),h.push(u(()=>r.extent,()=>o.emit(i.MAP_RENDER),{initial:!1}));var E=y(()=>f(i.MAP_DATA_CHANGE),500);d.push(E),h.push(u(()=>r.updating,e=>!e&&E()));var A=null,T=null;return h.push(r.on("pointer-down",e=>{A=e.x,T=e.y})),h.push(r.on("pointer-up",e=>{var n;if(0===e.button&&!(Math.hypot(e.x-A,e.y-T)>6)&&"active"!==(null===(n=t.sketchViewModel)||void 0===n?void 0:n.state)){var a={x:e.x,y:e.y},s=r.toMap(a);s&&o.emit(i.MAP_CLICK,{point:a,coords:[s.x,s.y]})}})),{remove(){v=!0,d.forEach(e=>e.cancel()),h.forEach(e=>e.remove())}}}var d=e=>e?new c({xmin:e[0],ymin:e[1],xmax:e[2],ymax:e[3],spatialReference:{wkid:27700}}):void 0,f=e=>e?new s({x:e[0],y:e[1],spatialReference:{wkid:27700}}):void 0,g=(e,t)=>{if(e)if("FeatureCollection"===e.type)e.features.forEach(e=>g(e,t));else if("Feature"===e.type)g(e.geometry,t);else if("GeometryCollection"===e.type)e.geometries.forEach(e=>g(e,t));else{var r=e=>{Array.isArray(e)&&("number"==typeof e[0]?t.push(e):e.forEach(r))};r(e.coordinates)}},w=e=>{var t=[];g(e,t);var r=t.map(e=>e[0]),n=t.map(e=>e[1]);return d([Math.min(...r),Math.min(...n),Math.max(...r),Math.max(...n)])},x=e=>{var t=1609.344,r=e/t;if(r<.5/t)return"".concat(Math.round(e),"m");if(r<10){var n=Number.parseFloat(r.toFixed(1)),i=1===n?"mile":"miles";return"".concat(n," ").concat(i)}var o=Math.round(r),a=1===o?"mile":"miles";return"".concat(o," ").concat(a)};var b={top:0,right:0,bottom:0,left:0};function M(){return(M=t(function*(e,t){if(!e||!t)return[];var r=e.map.layers.filter(e=>e instanceof a);return r.length?(yield e.hitTest(t,{include:r.toArray()})).results.map(e=>({layerId:e.layer.id,layerTitle:e.layer.title||e.layer.id,type:e.layer.type,geometry:e.graphic.geometry,symbol:e.graphic.symbol})):[]})).apply(this,arguments)}function E(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function A(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?E(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):E(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}class T{constructor(e){var{mapProviderConfig:t={},events:r,eventBus:n}=e;this.events=r,this.eventBus=n,this.capabilities={supportedShortcuts:v,supportsMapSizes:!1},Object.assign(this,t),this.mapEventHandles=[],this.appEventHandles=[]}get name(){return"EsriProvider"}initMap(e){var s=this;return t(function*(){var{container:t,padding:m,mapStyle:l,mapSize:u,maxExtent:c}=e;s.mapStyleId=null==l?void 0:l.id,s.mapSize=u;var{events:p,eventBus:v}=s;s.setupConfig&&(yield s.setupConfig(r));var y=new a({id:"baselayer",url:l.url,visible:!0}),g=new i({layers:[y]}),w=c?d(c):null,x=new o({spatialReference:27700,container:t,map:g,zoom:e.zoom,center:f(e.center),maxExtent:c,constraints:{lods:n.create({spatialReference:{wkid:27700}}).lods,snapToZoom:!1,minZoom:e.minZoom,maxZoom:e.maxZoom,maxScale:0,geometry:w,rotationEnabled:!1},ui:{components:[]},popupEnabled:!1});(e=>{if(e){var t=e.querySelector(".esri-view-surface");t.removeAttribute("role"),t.tabIndex=-1,t.style["outline-color"]="transparent",t.style.touchAction="none"}})(x.container),x.padding=m,e.bounds&&x.when(()=>x.goTo(d(e.bounds),{duration:0})),s.mapEventHandles=h({mapProvider:s,view:x,baseTileLayer:y,events:p,eventBus:v,getZoom:s.getZoom.bind(s),getCenter:s.getCenter.bind(s),getBounds:s.getBounds.bind(s),getResolution:s.getResolution.bind(s)}),s.appEventHandles=function(e){var{baseTileLayer:t,events:r,eventBus:n}=e,i=e=>{t.loadStyle(e.url).then(()=>{n.emit(r.MAP_STYLE_CHANGE,{mapStyleId:e.id})})};return n.on(r.MAP_SET_STYLE,i),{remove(){n.off(r.MAP_SET_STYLE,i)}}}({baseTileLayer:y,events:p,eventBus:v})||[],s.map=g,s.view=x,s.baseTileLayer=y})()}destroyMap(){var e,t;null===(e=this.mapEvents)||void 0===e||e.remove(),null===(t=this.appEvents)||void 0===t||t.remove(),this.mapEvents=null,this.appEvents=null,this.view&&(this.view.container=null,this.view.destroy(),this.view=null),this.map&&(this.map.removeAll(),this.map=null)}setView(e){var t,{center:r,zoom:n}=e;null===(t=this.view.animation)||void 0===t||t.destroy();var i={center:r?new s({x:r[0],y:r[1],spatialReference:{wkid:27700}}):this.view.center,zoom:null!=n?n:this.view.zoom};this.view.goTo(A(A({},i),{},{duration:p.animationDuration}))}zoomIn(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom+e,duration:p.animationDuration})}zoomOut(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom-e,duration:p.animationDuration})}panBy(e){var{x:t,y:r}=this.view.toScreen(this.view.center),n={x:t+e[0],y:r+e[1]},i=this.view.toMap(n);this.view.goTo({center:i,duration:p.animationDuration})}fitToBounds(e){var t=Array.isArray(e)?d(e):w(e);this.view.goTo(t,{duration:p.DELAY})}setPadding(e){this.view.padding=e}getCenter(){var e=this.view.center;return[e.x,e.y].map(e=>Math.round(100*e)/100)}getZoom(){return this.view.zoom}getBounds(){var{xmin:e,ymin:t,xmax:r,ymax:n}=this.view.extent;return[e,t,r,n].map(e=>Math.round(100*e)/100)}getFeaturesAtPoint(e,t){return function(e,t){return M.apply(this,arguments)}(this.view,e)}getVisibleFeatures(e){return[]}getAreaDimensions(){return(e=>{if(!(e&&e instanceof c))return"";var t=e.xmin,r=e.ymin,n=e.xmax,i=e.ymax-r,o=x(n-t),a=x(i);return"".concat(a," by ").concat(o)})(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:b;if(!e.container)return null;var{width:r,height:n}=e.container.getBoundingClientRect(),i={x:t.left,y:n-t.bottom},o={x:r-t.right,y:t.top},a=e.toMap(i),s=e.toMap(o);return new c({xmin:a.x,ymin:a.y,xmax:s.x,ymax:s.y,spatialReference:a.spatialReference})}(this.view))}getCardinalMove(e,t){return function(e,t){var[r,n]=e,[i,o]=t,a=i-r,s=o-n,m=[];return Math.abs(s)>.1&&m.push("".concat(s>0?"north":"south"," ").concat(x(Math.abs(s)))),Math.abs(a)>.1&&m.push("".concat(a>0?"east":"west"," ").concat(x(Math.abs(a)))),m.join(", ")}(e,t)}getResolution(){return this.view.resolution}mapToScreen(e){var t=f(e),r=this.view.toScreen(t);return{x:r.x,y:r.y}}screenToMap(e){var t=this.view.toMap(e);return[t.x,t.y]}isGeometryObscured(e,t){return((e,t,r)=>{if(null==r||!r.container)return!1;var n=r.container.getBoundingClientRect(),i=w(e),o=[r.toScreen(new s({x:i.xmin,y:i.ymin,spatialReference:i.spatialReference})),r.toScreen(new s({x:i.xmin,y:i.ymax,spatialReference:i.spatialReference})),r.toScreen(new s({x:i.xmax,y:i.ymin,spatialReference:i.spatialReference})),r.toScreen(new s({x:i.xmax,y:i.ymax,spatialReference:i.spatialReference}))],a=Math.min(...o.map(e=>e.x)),m=Math.max(...o.map(e=>e.x)),l=Math.min(...o.map(e=>e.y)),u=Math.max(...o.map(e=>e.y)),c=t.left-n.left,p=t.top-n.top,v=t.right-n.left,y=t.bottom-n.top;return a<v&&m>c&&l<y&&u>p})(e,t,this.view)}}export{T as default};
|
|
@@ -29,6 +29,10 @@ export default class EsriProvider {
|
|
|
29
29
|
this.appEventHandles = []
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
get name () {
|
|
33
|
+
return 'EsriProvider'
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
async initMap (config) {
|
|
33
37
|
const { container, padding, mapStyle, mapSize, maxExtent } = config
|
|
34
38
|
this.mapStyleId = mapStyle?.id
|