@defra/interactive-map 0.0.59-alpha → 0.0.60-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/assets/templates/add-polygons.njk +2 -2
- package/assets/templates/add-symbols.njk +2 -2
- 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/panel-definition.md +30 -0
- package/docs/api/symbol-config.md +12 -0
- package/docs/api.md +21 -2
- package/docs/assets/images/slot-map.svg +3 -3
- package/docs/plugins/datasets.md +11 -1
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.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/index.js +0 -1
- package/plugins/datasets/src/index.test.js +2 -8
- package/plugins/datasets/src/registry/dataset.test.js +9 -0
- 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/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/src/components/Form/Form.module.scss +1 -0
- package/providers/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/esri/src/esriProvider.js +10 -21
- package/providers/esri/src/utils/coords.js +37 -7
- package/providers/esri/src/utils/coords.test.js +22 -1
- package/providers/esri/src/utils/spatial.js +1 -47
- 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 +5 -14
- package/providers/maplibre/src/maplibreProvider.test.js +143 -146
- package/providers/maplibre/src/utils/spatial.js +0 -40
- package/providers/maplibre/src/utils/spatial.test.js +0 -35
- package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/openlayers/src/openlayersProvider.js +5 -14
- package/providers/openlayers/src/openlayersProvider.test.js +12 -10
- package/providers/openlayers/src/utils/spatial.js +0 -39
- package/providers/openlayers/src/utils/spatial.test.js +1 -26
- package/src/App/components/Hints/Hints.jsx +9 -21
- package/src/App/components/Hints/Hints.test.jsx +20 -33
- package/src/App/components/Panel/Panel.jsx +16 -1
- package/src/App/components/Panel/Panel.test.jsx +44 -0
- package/src/App/hooks/useCrossHairAPI.js +27 -28
- package/src/App/hooks/useCrossHairAPI.test.js +64 -7
- package/src/App/hooks/useLayoutMeasurements.js +175 -131
- package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
- package/src/App/hooks/useMapProviderOverrides.js +114 -35
- package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
- package/src/App/hooks/useModalPanelBehaviour.js +18 -32
- package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
- package/src/App/hooks/useVisibleGeometry.js +35 -45
- package/src/App/hooks/useVisibleGeometry.test.js +149 -121
- package/src/App/layout/Layout.jsx +4 -4
- package/src/App/layout/layout.module.scss +124 -61
- package/src/App/store/AppProvider.jsx +3 -0
- package/src/App/store/appDispatchMiddleware.js +18 -10
- package/src/App/store/appDispatchMiddleware.test.js +42 -4
- package/src/InteractiveMap/InteractiveMap.js +3 -2
- package/src/InteractiveMap/InteractiveMap.test.js +2 -2
- package/src/config/events.js +1 -1
- package/src/config/mapPanelSlots.js +8 -0
- package/src/config/symbolConfig.js +1 -1
- package/src/services/symbolRegistry.js +1 -1
- package/src/services/symbolRegistry.test.js +19 -0
- package/src/types.js +29 -8
- package/src/utils/getFitMove.js +73 -0
- package/src/utils/getFitMove.test.js +114 -0
- package/src/utils/getSafeZoneInset.js +122 -77
- package/src/utils/getSafeZoneInset.test.js +241 -54
- package/src/utils/getValueForStyle.js +10 -5
- package/src/utils/getValueForStyle.test.js +13 -2
- package/src/utils/renderedBoxes.js +25 -0
- package/src/utils/renderedBoxes.test.js +61 -0
- package/src/utils/screenBox.js +70 -0
- package/src/utils/screenBox.test.js +69 -0
- package/src/utils/symbolUtils.js +9 -9
- package/src/utils/symbolUtils.test.js +21 -0
- package/providers/esri/src/utils/spatial.test.js +0 -58
|
@@ -38,9 +38,8 @@ describe('useModalPanelBehaviour', () => {
|
|
|
38
38
|
|
|
39
39
|
handleClose = jest.fn()
|
|
40
40
|
jest.clearAllMocks()
|
|
41
|
-
document.
|
|
42
|
-
|
|
43
|
-
useApp.mockReturnValue({ layoutRefs: {} })
|
|
41
|
+
elements.appContainer = document.createElement('div')
|
|
42
|
+
useApp.mockReturnValue({ layoutRefs: { appContainerRef: { current: elements.appContainer } } })
|
|
44
43
|
})
|
|
45
44
|
|
|
46
45
|
afterEach(() => {
|
|
@@ -104,22 +103,11 @@ describe('useModalPanelBehaviour', () => {
|
|
|
104
103
|
jest.restoreAllMocks()
|
|
105
104
|
})
|
|
106
105
|
|
|
107
|
-
it('
|
|
106
|
+
it('leaves left and right slot modals to their own CSS', () => {
|
|
108
107
|
refs.panel.current.dataset.slot = 'left-top'
|
|
109
108
|
render(<TestComponent />)
|
|
110
|
-
expect(
|
|
111
|
-
|
|
112
|
-
expect(document.documentElement.style.getPropertyValue(MODAL_MAX_HEIGHT))
|
|
113
|
-
.toBe('var(--left-top-max-height)')
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('sets --modal-inset via SLOT_MODAL_VARS for bottom slot', () => {
|
|
117
|
-
refs.panel.current.dataset.slot = 'left-bottom'
|
|
118
|
-
render(<TestComponent />)
|
|
119
|
-
expect(document.documentElement.style.getPropertyValue(MODAL_INSET))
|
|
120
|
-
.toBe('auto auto var(--left-offset-bottom) var(--primary-gap)')
|
|
121
|
-
expect(document.documentElement.style.getPropertyValue(MODAL_MAX_HEIGHT))
|
|
122
|
-
.toBe('var(--left-top-max-height)')
|
|
109
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('')
|
|
110
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_MAX_HEIGHT)).toBe('')
|
|
123
111
|
})
|
|
124
112
|
|
|
125
113
|
it('sets --modal-inset and --modal-max-height from slot container when no buttonContainerEl', () => {
|
|
@@ -129,19 +117,29 @@ describe('useModalPanelBehaviour', () => {
|
|
|
129
117
|
configurable: true
|
|
130
118
|
})
|
|
131
119
|
Object.defineProperty(insetEl, 'offsetWidth', { value: 192, configurable: true })
|
|
132
|
-
useApp.mockReturnValue({ layoutRefs: { insetRef: { current: insetEl }, mainRef: refs.main } })
|
|
120
|
+
useApp.mockReturnValue({ layoutRefs: { appContainerRef: { current: elements.appContainer }, insetRef: { current: insetEl }, mainRef: refs.main } })
|
|
133
121
|
|
|
134
122
|
render(<TestComponent />)
|
|
135
123
|
|
|
136
|
-
expect(
|
|
137
|
-
expect(
|
|
124
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('60px auto auto 8px')
|
|
125
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_MAX_HEIGHT)).toContain('px')
|
|
138
126
|
})
|
|
139
127
|
|
|
140
|
-
it('leaves --modal-inset unset when
|
|
128
|
+
it('leaves --modal-inset unset when there is no app container to set it on', () => {
|
|
129
|
+
refs.panel.current.dataset.slot = buttonSlot
|
|
130
|
+
elements.buttonContainer.dataset.buttonSlot = buttonSlot
|
|
131
|
+
document.body.appendChild(elements.buttonContainer)
|
|
132
|
+
useApp.mockReturnValue({ layoutRefs: {} })
|
|
141
133
|
render(<TestComponent />)
|
|
134
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('')
|
|
142
135
|
expect(document.documentElement.style.getPropertyValue(MODAL_INSET)).toBe('')
|
|
143
136
|
})
|
|
144
137
|
|
|
138
|
+
it('leaves --modal-inset unset when slot ref cannot be resolved', () => {
|
|
139
|
+
render(<TestComponent />)
|
|
140
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('')
|
|
141
|
+
})
|
|
142
|
+
|
|
145
143
|
it('updates --modal-inset and --modal-max-height via aria-controls when buttonContainerEl is stale', () => {
|
|
146
144
|
refs.panel.current.dataset.slot = buttonSlot
|
|
147
145
|
|
|
@@ -153,8 +151,22 @@ describe('useModalPanelBehaviour', () => {
|
|
|
153
151
|
const staleEl = document.createElement('div') // detached
|
|
154
152
|
render(<TestComponent buttonContainerEl={staleEl} />)
|
|
155
153
|
|
|
156
|
-
expect(
|
|
157
|
-
expect(
|
|
154
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toContain('10px')
|
|
155
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_MAX_HEIGHT)).toContain('px')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('stops a button panel a primary gap short of the far edge, with a divider gap beside its button', () => {
|
|
159
|
+
const gaps = { '--divider-gap': '8', '--primary-gap': '15' }
|
|
160
|
+
globalThis.getComputedStyle.mockReturnValue({ getPropertyValue: (name) => gaps[name] })
|
|
161
|
+
refs.panel.current.dataset.slot = buttonSlot
|
|
162
|
+
elements.buttonContainer.dataset.buttonSlot = buttonSlot
|
|
163
|
+
document.body.appendChild(elements.buttonContainer)
|
|
164
|
+
|
|
165
|
+
render(<TestComponent />)
|
|
166
|
+
|
|
167
|
+
// Button top 10 in a main 50 high: 50 - 10 - 15. Beside the button: 100 - 20 + 8
|
|
168
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_MAX_HEIGHT)).toBe('25px')
|
|
169
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('10px 88px auto auto')
|
|
158
170
|
})
|
|
159
171
|
|
|
160
172
|
it('uses data-button-slot fallback when no aria-controls button and no buttonContainerEl', () => {
|
|
@@ -164,8 +176,8 @@ describe('useModalPanelBehaviour', () => {
|
|
|
164
176
|
|
|
165
177
|
render(<TestComponent buttonContainerEl={undefined} />)
|
|
166
178
|
|
|
167
|
-
expect(
|
|
168
|
-
expect(
|
|
179
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toContain('10px')
|
|
180
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_MAX_HEIGHT)).toContain('px')
|
|
169
181
|
})
|
|
170
182
|
|
|
171
183
|
it('uses connected buttonContainerEl when panel has no ID', () => {
|
|
@@ -175,13 +187,13 @@ describe('useModalPanelBehaviour', () => {
|
|
|
175
187
|
|
|
176
188
|
render(<TestComponent buttonContainerEl={elements.buttonContainer} />)
|
|
177
189
|
|
|
178
|
-
expect(
|
|
190
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toContain('10px')
|
|
179
191
|
})
|
|
180
192
|
|
|
181
193
|
it('skips update when effectiveContainer cannot be resolved', () => {
|
|
182
194
|
refs.panel.current.dataset.slot = buttonSlot
|
|
183
195
|
render(<TestComponent buttonContainerEl={null} />)
|
|
184
|
-
expect(
|
|
196
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('')
|
|
185
197
|
})
|
|
186
198
|
|
|
187
199
|
it('anchors to bottom when button is in a bottom sub-slot', () => {
|
|
@@ -197,8 +209,8 @@ describe('useModalPanelBehaviour', () => {
|
|
|
197
209
|
render(<TestComponent />)
|
|
198
210
|
|
|
199
211
|
// Bottom slot: insetTop='auto', insetBottom = mainRect.bottom - buttonRect.bottom = 50 - 40 = 10px
|
|
200
|
-
expect(
|
|
201
|
-
expect(
|
|
212
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toMatch(/^auto/)
|
|
213
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toContain('10px')
|
|
202
214
|
})
|
|
203
215
|
|
|
204
216
|
it('uses left inset when button is in a left sub-slot', () => {
|
|
@@ -214,7 +226,7 @@ describe('useModalPanelBehaviour', () => {
|
|
|
214
226
|
render(<TestComponent />)
|
|
215
227
|
|
|
216
228
|
// Left slot: insetTop = buttonRect.top - mainRect.top = 10, insetLeft = buttonRect.right - mainRect.left + dividerGap = 80 + 8 = 88
|
|
217
|
-
expect(
|
|
229
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('10px auto auto 88px')
|
|
218
230
|
})
|
|
219
231
|
})
|
|
220
232
|
|
|
@@ -266,14 +278,14 @@ describe('useModalPanelBehaviour', () => {
|
|
|
266
278
|
// Mounted closed, as it would be permanently — mainRef's size gets recorded but the
|
|
267
279
|
// calc no-ops on the isModal guard.
|
|
268
280
|
const { rerender } = render(<TestComponent isModal={false} />)
|
|
269
|
-
expect(
|
|
281
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toBe('')
|
|
270
282
|
|
|
271
283
|
// Open it. mainRef hasn't resized, so the resize observer's own delivery is deduped
|
|
272
284
|
// away — only the open-triggered layout effect can position it here.
|
|
273
285
|
rerender(<TestComponent isModal />)
|
|
274
286
|
|
|
275
|
-
expect(
|
|
276
|
-
expect(
|
|
287
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_INSET)).toContain('10px')
|
|
288
|
+
expect(elements.appContainer.style.getPropertyValue(MODAL_MAX_HEIGHT)).toContain('px')
|
|
277
289
|
})
|
|
278
290
|
})
|
|
279
291
|
|
|
@@ -1,63 +1,56 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react'
|
|
2
2
|
import { useConfig } from '../store/configContext.js'
|
|
3
3
|
import { useApp } from '../store/appContext.js'
|
|
4
|
+
import { useMap } from '../store/mapContext.js'
|
|
5
|
+
import { useEvaluateProp } from './useEvaluateProp.js'
|
|
4
6
|
import { EVENTS as events } from '../../config/events.js'
|
|
7
|
+
import { getMapSizeScale } from '../../config/mapSizeScales.js'
|
|
8
|
+
import { MAP_PANEL_SLOT_REFS } from '../../config/mapPanelSlots.js'
|
|
9
|
+
import { getPanelElementId } from '../../utils/getPanelElementId.js'
|
|
10
|
+
import { getScreenBox, getRelativeBox, isOverlapping } from '../../utils/screenBox.js'
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return null
|
|
9
|
-
}
|
|
10
|
-
if (geojson.type === 'Feature') {
|
|
11
|
-
return geojson.geometry?.type
|
|
12
|
-
}
|
|
13
|
-
return geojson.type
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const isPointGeometry = (geojson) => {
|
|
17
|
-
const type = getGeometryType(geojson)
|
|
18
|
-
return type === 'Point' || type === 'MultiPoint'
|
|
19
|
-
}
|
|
12
|
+
// Only panels over the map can hide the geometry
|
|
13
|
+
const isOverMap = (panel, layoutRefs) => MAP_PANEL_SLOT_REFS.some(refName => layoutRefs[refName]?.current?.contains(panel))
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
// Whether any of the geometry's bounding box is under the panel, both measured relative to the viewport
|
|
16
|
+
const isUnderPanel = ({ visibleGeometry, panelRect, mapProvider, viewport, mapSize }) => {
|
|
17
|
+
if (!viewport) {
|
|
18
|
+
return false
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
if (geojson.type === 'MultiPoint') {
|
|
29
|
-
return geojson.coordinates[0]
|
|
30
|
-
}
|
|
31
|
-
return null
|
|
20
|
+
const box = getScreenBox(visibleGeometry, (coords) => mapProvider.mapToScreen(coords), getMapSizeScale(mapSize))
|
|
21
|
+
return isOverlapping(box, getRelativeBox(panelRect, viewport.getBoundingClientRect()))
|
|
32
22
|
}
|
|
33
23
|
|
|
34
24
|
export const useVisibleGeometry = () => {
|
|
35
25
|
const { id, mapProvider, eventBus } = useConfig()
|
|
36
|
-
const { layoutRefs, panelConfig, panelRegistry
|
|
26
|
+
const { layoutRefs, panelConfig, panelRegistry } = useApp()
|
|
27
|
+
const { mapSize } = useMap()
|
|
28
|
+
const evaluateProp = useEvaluateProp()
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
latestRef
|
|
30
|
+
// Read in the event handler, so it uses the latest of each, not the first render's
|
|
31
|
+
const latestRef = useRef({ panelConfig, panelRegistry, mapSize, evaluateProp })
|
|
32
|
+
latestRef.current = { panelConfig, panelRegistry, mapSize, evaluateProp }
|
|
40
33
|
|
|
41
34
|
useEffect(() => {
|
|
42
35
|
if (!mapProvider || !eventBus) {
|
|
43
36
|
return undefined
|
|
44
37
|
}
|
|
45
38
|
|
|
46
|
-
const handlePanelOpened = ({ panelId,
|
|
47
|
-
const { panelConfig: config, panelRegistry: registry } = latestRef.current
|
|
39
|
+
const handlePanelOpened = ({ panelId, ...openedOptions }) => {
|
|
40
|
+
const { panelConfig: config, panelRegistry: registry, evaluateProp: evaluate } = latestRef.current
|
|
48
41
|
const resolvedConfig = config?.[panelId] ? config : (registry?.getPanelConfig() ?? config)
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
// A panel that opens as it's added sends its options with the event, as the registry may not
|
|
43
|
+
// have them yet. visibleGeometry can be a function of the context, like a panel's label
|
|
44
|
+
const { visibleGeometry: geometryOption, preferPan = true, paddingPercent, pluginId } = { ...resolvedConfig?.[panelId], ...openedOptions }
|
|
45
|
+
const visibleGeometry = evaluate(geometryOption, pluginId)
|
|
46
|
+
const panel = layoutRefs.appContainerRef.current?.querySelector(`#${getPanelElementId(id, panelId)}`)
|
|
51
47
|
|
|
52
48
|
if (!visibleGeometry) {
|
|
53
49
|
return
|
|
54
50
|
}
|
|
55
|
-
if (typeof mapProvider.isGeometryObscured !== 'function') {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
51
|
|
|
59
52
|
const waitForPanel = () => {
|
|
60
|
-
if (!panel) { return }
|
|
53
|
+
if (!panel || !isOverMap(panel, layoutRefs)) { return }
|
|
61
54
|
const panelRect = panel.getBoundingClientRect()
|
|
62
55
|
|
|
63
56
|
if (!panelRect || panelRect.width === 0 || panelRect.height === 0) {
|
|
@@ -66,19 +59,16 @@ export const useVisibleGeometry = () => {
|
|
|
66
59
|
return
|
|
67
60
|
}
|
|
68
61
|
|
|
69
|
-
//
|
|
70
|
-
|
|
62
|
+
// Only move the map when the panel opens over the geometry. Once the user has moved the
|
|
63
|
+
// map, a geometry elsewhere or off screen is theirs to come back to.
|
|
64
|
+
const viewport = layoutRefs.viewportRef?.current
|
|
65
|
+
if (!isUnderPanel({ visibleGeometry, panelRect, mapProvider, viewport, mapSize: latestRef.current.mapSize })) {
|
|
71
66
|
return
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
mapProvider.setView({ center })
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
mapProvider.fitToBounds(visibleGeometry)
|
|
81
|
-
}
|
|
69
|
+
// The panel has a size, so the safe zone now allows for it. With preferPan, the map pans
|
|
70
|
+
// to centre the geometry in the safe zone, only zooming out if it doesn't fit.
|
|
71
|
+
mapProvider.fitToBounds(visibleGeometry, { preferPan, paddingPercent })
|
|
82
72
|
}
|
|
83
73
|
|
|
84
74
|
// Start waiting for panel to exist with a measurable size
|