@defra/interactive-map 0.0.59-alpha → 0.0.61-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/button-definition.md +11 -0
- package/docs/api/context.md +2 -0
- 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/docs/plugins/draw.md +26 -0
- 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/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/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 +3 -0
- package/plugins/draw/src/DrawInit.test.jsx +16 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
- package/plugins/draw/src/defaults.js +4 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
- package/plugins/draw/src/manifest.js +4 -1
- package/plugins/draw/src/manifest.test.js +15 -2
- package/plugins/draw/src/utils/snapMinZoom.js +8 -0
- package/plugins/draw/src/utils/snapMinZoom.test.js +22 -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/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/map-key/src/manifest.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/MapButton/MapButton.jsx +20 -2
- package/src/App/components/MapButton/MapButton.module.scss +15 -1
- package/src/App/components/MapButton/MapButton.test.jsx +21 -3
- package/src/App/components/Panel/Panel.jsx +16 -1
- package/src/App/components/Panel/Panel.test.jsx +44 -0
- package/src/App/components/Tooltip/Tooltip.jsx +29 -11
- package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
- package/src/App/components/Viewport/MapController.jsx +2 -0
- package/src/App/components/Viewport/MapController.test.jsx +3 -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/useUserMoveTracking.js +65 -0
- package/src/App/hooks/useUserMoveTracking.test.js +99 -0
- 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/renderer/mapButtons.js +1 -0
- package/src/App/renderer/mapButtons.test.js +8 -0
- 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/App/store/mapActionsMap.js +2 -1
- package/src/App/store/mapActionsMap.test.js +6 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +1 -0
- 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/scss/settings/_colors.scss +4 -0
- package/src/services/symbolRegistry.js +1 -1
- package/src/services/symbolRegistry.test.js +19 -0
- package/src/types.js +33 -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
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import { renderHook } from '@testing-library/react'
|
|
2
|
-
import { useVisibleGeometry
|
|
2
|
+
import { useVisibleGeometry } from './useVisibleGeometry'
|
|
3
3
|
import { useConfig } from '../store/configContext.js'
|
|
4
4
|
import { useApp } from '../store/appContext.js'
|
|
5
|
+
import { useMap } from '../store/mapContext.js'
|
|
6
|
+
import { getPanelElementId } from '../../utils/getPanelElementId.js'
|
|
5
7
|
|
|
6
8
|
jest.mock('../store/configContext.js')
|
|
7
9
|
jest.mock('../store/appContext.js')
|
|
10
|
+
jest.mock('../store/mapContext.js')
|
|
11
|
+
// Like the real one: a value is returned as it is, a function is called with the context
|
|
12
|
+
jest.mock('./useEvaluateProp.js', () => ({
|
|
13
|
+
useEvaluateProp: () => (prop, pluginId) => typeof prop === 'function' ? prop({ pluginId, pluginState: { feature: 'from plugin state' } }) : prop
|
|
14
|
+
}))
|
|
8
15
|
|
|
9
16
|
const pointFeature = { type: 'Feature', geometry: { type: 'Point', coordinates: [1, 51] }, properties: {} }
|
|
10
|
-
const multiPointFeature = { type: 'Feature', geometry: { type: 'MultiPoint', coordinates: [[1, 51], [2, 52]] }, properties: {} }
|
|
11
17
|
const polygonFeature = { type: 'Feature', geometry: { type: 'Polygon', coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]] }, properties: {} }
|
|
12
18
|
|
|
13
19
|
const APP_ID = 'test'
|
|
14
20
|
const panelRect = { left: 600, top: 0, right: 1000, bottom: 800, width: 400, height: 800 }
|
|
15
21
|
|
|
22
|
+
// Every coordinate lands at (700, 100), under the panel
|
|
23
|
+
const underPanel = () => ({ x: 700, y: 100 })
|
|
24
|
+
|
|
16
25
|
// Creates a panel DOM element with id matching what useVisibleGeometry queries.
|
|
17
26
|
const makePanelEl = (panelId, rect = panelRect) => {
|
|
18
27
|
const el = document.createElement('div')
|
|
19
|
-
el.id =
|
|
28
|
+
el.id = getPanelElementId(APP_ID, panelId)
|
|
20
29
|
el.getBoundingClientRect = jest.fn(() => rect)
|
|
21
30
|
return el
|
|
22
31
|
}
|
|
@@ -24,9 +33,8 @@ const makePanelEl = (panelId, rect = panelRect) => {
|
|
|
24
33
|
const setup = (overrides = {}) => {
|
|
25
34
|
const capturedHandlers = {}
|
|
26
35
|
const mapProvider = {
|
|
27
|
-
isGeometryObscured: jest.fn(() => true),
|
|
28
36
|
fitToBounds: jest.fn(),
|
|
29
|
-
|
|
37
|
+
mapToScreen: jest.fn(underPanel),
|
|
30
38
|
...overrides.mapProvider
|
|
31
39
|
}
|
|
32
40
|
const eventBus = {
|
|
@@ -35,14 +43,20 @@ const setup = (overrides = {}) => {
|
|
|
35
43
|
...overrides.eventBus
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
// appContainerRef holds panel elements that the hook queries by id
|
|
46
|
+
// appContainerRef holds panel elements that the hook queries by id, in a slot over the map
|
|
39
47
|
const appContainer = document.createElement('div')
|
|
40
48
|
const myPanelEl = makePanelEl('myPanel')
|
|
41
49
|
appContainer.appendChild(myPanelEl)
|
|
42
50
|
|
|
51
|
+
const viewport = document.createElement('div')
|
|
52
|
+
viewport.getBoundingClientRect = () => ({ left: 0, top: 0 })
|
|
53
|
+
|
|
43
54
|
const layoutRefs = {
|
|
44
55
|
mainRef: { current: document.createElement('div') },
|
|
45
56
|
appContainerRef: { current: appContainer },
|
|
57
|
+
viewportRef: { current: viewport },
|
|
58
|
+
// Tests that pass their own container keep it in the slot
|
|
59
|
+
rightTopRef: overrides.layoutRefs?.appContainerRef ?? { current: appContainer },
|
|
46
60
|
...overrides.layoutRefs
|
|
47
61
|
}
|
|
48
62
|
const panelConfig = {
|
|
@@ -57,6 +71,7 @@ const setup = (overrides = {}) => {
|
|
|
57
71
|
|
|
58
72
|
useConfig.mockReturnValue({ id: APP_ID, mapProvider, eventBus, ...overrides.config })
|
|
59
73
|
useApp.mockReturnValue({ layoutRefs, panelConfig, panelRegistry, breakpoint: 'desktop', ...overrides.app })
|
|
74
|
+
useMap.mockReturnValue({ mapSize: 'small', ...overrides.map })
|
|
60
75
|
|
|
61
76
|
return { mapProvider, eventBus, capturedHandlers, layoutRefs, panelConfig, myPanelEl, appContainer }
|
|
62
77
|
}
|
|
@@ -99,14 +114,14 @@ describe('useVisibleGeometry', () => {
|
|
|
99
114
|
const { mapProvider, capturedHandlers } = setup()
|
|
100
115
|
renderHook(() => useVisibleGeometry())
|
|
101
116
|
capturedHandlers['app:panelopened']({ panelId: 'emptyPanel' })
|
|
102
|
-
expect(mapProvider.
|
|
117
|
+
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
103
118
|
})
|
|
104
119
|
|
|
105
120
|
test('does nothing when panel does not exist in config', () => {
|
|
106
121
|
const { mapProvider, capturedHandlers } = setup()
|
|
107
122
|
renderHook(() => useVisibleGeometry())
|
|
108
123
|
capturedHandlers['app:panelopened']({ panelId: 'unknownPanel' })
|
|
109
|
-
expect(mapProvider.
|
|
124
|
+
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
110
125
|
})
|
|
111
126
|
|
|
112
127
|
test('does nothing when panel element is not in the DOM', () => {
|
|
@@ -117,130 +132,193 @@ describe('useVisibleGeometry', () => {
|
|
|
117
132
|
renderHook(() => useVisibleGeometry())
|
|
118
133
|
capturedHandlers['app:panelopened']({ panelId: 'noElPanel' })
|
|
119
134
|
jest.runAllTimers()
|
|
120
|
-
expect(mapProvider.
|
|
135
|
+
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
121
136
|
})
|
|
122
137
|
|
|
123
|
-
test('
|
|
124
|
-
const {
|
|
138
|
+
test('calls fitToBounds with preferPan once the panel has a size', () => {
|
|
139
|
+
const { mapProvider, capturedHandlers } = setup()
|
|
125
140
|
renderHook(() => useVisibleGeometry())
|
|
126
141
|
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
127
|
-
|
|
142
|
+
jest.runAllTimers()
|
|
143
|
+
|
|
144
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature, { preferPan: true })
|
|
128
145
|
})
|
|
129
146
|
|
|
130
|
-
test('
|
|
147
|
+
test('waits for the panel to have a size before calling fitToBounds', () => {
|
|
131
148
|
const zeroRect = { left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 }
|
|
149
|
+
const panelEl = makePanelEl('myPanel', zeroRect)
|
|
132
150
|
const appContainer = document.createElement('div')
|
|
133
|
-
appContainer.appendChild(
|
|
151
|
+
appContainer.appendChild(panelEl)
|
|
134
152
|
const { mapProvider, capturedHandlers } = setup({
|
|
135
|
-
layoutRefs: {
|
|
136
|
-
mainRef: { current: document.createElement('div') },
|
|
137
|
-
appContainerRef: { current: appContainer }
|
|
138
|
-
}
|
|
153
|
+
layoutRefs: { mainRef: { current: document.createElement('div') }, appContainerRef: { current: appContainer } }
|
|
139
154
|
})
|
|
140
155
|
renderHook(() => useVisibleGeometry())
|
|
141
156
|
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
157
|
+
jest.runOnlyPendingTimers()
|
|
158
|
+
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
142
159
|
|
|
143
|
-
|
|
160
|
+
panelEl.getBoundingClientRect.mockReturnValue(panelRect)
|
|
144
161
|
jest.runOnlyPendingTimers()
|
|
162
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature, { preferPan: true })
|
|
163
|
+
})
|
|
145
164
|
|
|
146
|
-
|
|
165
|
+
test('passes a bare geometry, not just a Feature, to fitToBounds', () => {
|
|
166
|
+
const rawPolygon = { type: 'Polygon', coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]] }
|
|
167
|
+
const appContainer = document.createElement('div')
|
|
168
|
+
appContainer.appendChild(makePanelEl('geoPanel'))
|
|
169
|
+
const { mapProvider, capturedHandlers } = setup({
|
|
170
|
+
panelConfig: { geoPanel: { visibleGeometry: rawPolygon, desktop: { slot: 'left-top' } } },
|
|
171
|
+
layoutRefs: { mainRef: { current: document.createElement('div') }, appContainerRef: { current: appContainer } }
|
|
172
|
+
})
|
|
173
|
+
renderHook(() => useVisibleGeometry())
|
|
174
|
+
capturedHandlers['app:panelopened']({ panelId: 'geoPanel' })
|
|
175
|
+
jest.runAllTimers()
|
|
176
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(rawPolygon, { preferPan: true })
|
|
147
177
|
})
|
|
148
178
|
|
|
149
|
-
test('
|
|
150
|
-
const { mapProvider, capturedHandlers } = setup({ mapProvider: {
|
|
179
|
+
test('leaves the map alone when the geometry isn\'t under the panel', () => {
|
|
180
|
+
const { mapProvider, capturedHandlers } = setup({ mapProvider: { mapToScreen: jest.fn(() => ({ x: 100, y: 100 })) } })
|
|
151
181
|
renderHook(() => useVisibleGeometry())
|
|
152
182
|
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
153
183
|
jest.runAllTimers()
|
|
154
184
|
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
155
|
-
expect(mapProvider.setView).not.toHaveBeenCalled()
|
|
156
185
|
})
|
|
157
186
|
|
|
158
|
-
test('
|
|
159
|
-
const { mapProvider, capturedHandlers } = setup()
|
|
187
|
+
test('leaves the map alone when the geometry is off screen', () => {
|
|
188
|
+
const { mapProvider, capturedHandlers } = setup({ mapProvider: { mapToScreen: jest.fn(() => ({ x: -500, y: 100 })) } })
|
|
160
189
|
renderHook(() => useVisibleGeometry())
|
|
161
190
|
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
162
191
|
jest.runAllTimers()
|
|
192
|
+
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
193
|
+
})
|
|
163
194
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
195
|
+
test('moves the map when only part of the geometry is under the panel', () => {
|
|
196
|
+
// West corners at x 500, east corners at x 650, across the panel's left edge at 600
|
|
197
|
+
const mapToScreen = jest.fn(([x]) => ({ x: x === 0 ? 500 : 650, y: 100 }))
|
|
198
|
+
const { mapProvider, capturedHandlers } = setup({ mapProvider: { mapToScreen } })
|
|
199
|
+
renderHook(() => useVisibleGeometry())
|
|
200
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
201
|
+
jest.runAllTimers()
|
|
202
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature, { preferPan: true })
|
|
167
203
|
})
|
|
168
204
|
|
|
169
|
-
test('
|
|
170
|
-
|
|
171
|
-
appContainer.appendChild(makePanelEl('pointPanel'))
|
|
205
|
+
test('measures the geometry in CSS pixels at larger map sizes', () => {
|
|
206
|
+
// Map pixel 350 is CSS pixel 700 at the large size, under the panel
|
|
172
207
|
const { mapProvider, capturedHandlers } = setup({
|
|
173
|
-
|
|
174
|
-
|
|
208
|
+
mapProvider: { mapToScreen: jest.fn(() => ({ x: 350, y: 50 })) },
|
|
209
|
+
map: { mapSize: 'large' }
|
|
175
210
|
})
|
|
176
211
|
renderHook(() => useVisibleGeometry())
|
|
177
|
-
capturedHandlers['app:panelopened']({ panelId: '
|
|
212
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
178
213
|
jest.runAllTimers()
|
|
214
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalled()
|
|
215
|
+
})
|
|
179
216
|
|
|
180
|
-
|
|
217
|
+
test('measures the panel relative to the viewport', () => {
|
|
218
|
+
// The geometry at x 700 is under a panel at 600–1000 on the page, but the viewport starts
|
|
219
|
+
// at 300, so the panel covers 300–700 of the map and only touches the geometry's edge
|
|
220
|
+
const { mapProvider, capturedHandlers, layoutRefs } = setup()
|
|
221
|
+
layoutRefs.viewportRef.current.getBoundingClientRect = () => ({ left: 300, top: 0 })
|
|
222
|
+
renderHook(() => useVisibleGeometry())
|
|
223
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
224
|
+
jest.runAllTimers()
|
|
181
225
|
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
182
226
|
})
|
|
183
227
|
|
|
184
|
-
test('
|
|
185
|
-
const
|
|
186
|
-
|
|
228
|
+
test('leaves the map alone for a panel that isn\'t in a slot over the map, like a modal', () => {
|
|
229
|
+
const { mapProvider, capturedHandlers } = setup({ layoutRefs: { rightTopRef: { current: document.createElement('div') } } })
|
|
230
|
+
renderHook(() => useVisibleGeometry())
|
|
231
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
232
|
+
jest.runAllTimers()
|
|
233
|
+
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('moves the map for a panel in the drawer', () => {
|
|
237
|
+
const drawer = document.createElement('div')
|
|
238
|
+
drawer.appendChild(makePanelEl('myPanel'))
|
|
187
239
|
const { mapProvider, capturedHandlers } = setup({
|
|
188
|
-
|
|
189
|
-
layoutRefs: { mainRef: { current: document.createElement('div') }, appContainerRef: { current: appContainer } }
|
|
240
|
+
layoutRefs: { appContainerRef: { current: drawer }, rightTopRef: { current: null }, drawerRef: { current: drawer } }
|
|
190
241
|
})
|
|
191
242
|
renderHook(() => useVisibleGeometry())
|
|
192
|
-
capturedHandlers['app:panelopened']({ panelId: '
|
|
243
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
193
244
|
jest.runAllTimers()
|
|
245
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalled()
|
|
246
|
+
})
|
|
194
247
|
|
|
195
|
-
|
|
248
|
+
test('leaves the map alone when there is no viewport to measure against', () => {
|
|
249
|
+
const { mapProvider, capturedHandlers } = setup({ layoutRefs: { viewportRef: { current: null } } })
|
|
250
|
+
renderHook(() => useVisibleGeometry())
|
|
251
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
252
|
+
jest.runAllTimers()
|
|
196
253
|
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
197
254
|
})
|
|
198
255
|
|
|
199
|
-
test('
|
|
200
|
-
|
|
256
|
+
test('finds a panel whose id is in camelCase', () => {
|
|
257
|
+
// The panel's element id is in kebab case: test-panel-draw-rules-issues
|
|
201
258
|
const appContainer = document.createElement('div')
|
|
202
|
-
appContainer.appendChild(makePanelEl('
|
|
259
|
+
appContainer.appendChild(makePanelEl('drawRulesIssues'))
|
|
203
260
|
const { mapProvider, capturedHandlers } = setup({
|
|
204
|
-
panelConfig: {
|
|
205
|
-
layoutRefs: {
|
|
261
|
+
panelConfig: { drawRulesIssues: { visibleGeometry: polygonFeature } },
|
|
262
|
+
layoutRefs: { appContainerRef: { current: appContainer } }
|
|
206
263
|
})
|
|
207
264
|
renderHook(() => useVisibleGeometry())
|
|
208
|
-
capturedHandlers['app:panelopened']({ panelId: '
|
|
265
|
+
capturedHandlers['app:panelopened']({ panelId: 'drawRulesIssues' })
|
|
209
266
|
jest.runAllTimers()
|
|
210
|
-
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(
|
|
211
|
-
expect(mapProvider.setView).not.toHaveBeenCalled()
|
|
267
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature, { preferPan: true })
|
|
212
268
|
})
|
|
213
269
|
|
|
214
|
-
test('calls
|
|
215
|
-
const
|
|
216
|
-
const appContainer = document.createElement('div')
|
|
217
|
-
appContainer.appendChild(makePanelEl('rawPointPanel'))
|
|
270
|
+
test('calls a visibleGeometry function as the panel opens, with its plugin\'s context', () => {
|
|
271
|
+
const visibleGeometry = jest.fn(({ pluginState }) => pluginState.feature === 'from plugin state' ? pointFeature : null)
|
|
218
272
|
const { mapProvider, capturedHandlers } = setup({
|
|
219
|
-
panelConfig: {
|
|
220
|
-
layoutRefs: { mainRef: { current: document.createElement('div') }, appContainerRef: { current: appContainer } }
|
|
273
|
+
panelConfig: { myPanel: { visibleGeometry, pluginId: 'drawRules' } }
|
|
221
274
|
})
|
|
222
275
|
renderHook(() => useVisibleGeometry())
|
|
223
|
-
capturedHandlers['app:panelopened']({ panelId: '
|
|
276
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
224
277
|
jest.runAllTimers()
|
|
225
|
-
expect(
|
|
226
|
-
expect(mapProvider.fitToBounds).
|
|
278
|
+
expect(visibleGeometry).toHaveBeenCalledWith(expect.objectContaining({ pluginId: 'drawRules' }))
|
|
279
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(pointFeature, { preferPan: true })
|
|
227
280
|
})
|
|
228
281
|
|
|
229
|
-
test('
|
|
230
|
-
const nullCoordsFeature = { type: 'Feature', geometry: { type: 'Point', coordinates: null }, properties: {} }
|
|
231
|
-
const appContainer = document.createElement('div')
|
|
232
|
-
appContainer.appendChild(makePanelEl('nullPanel'))
|
|
282
|
+
test('leaves the map alone when a visibleGeometry function returns nothing', () => {
|
|
233
283
|
const { mapProvider, capturedHandlers } = setup({
|
|
234
|
-
panelConfig: {
|
|
235
|
-
layoutRefs: { mainRef: { current: document.createElement('div') }, appContainerRef: { current: appContainer } }
|
|
284
|
+
panelConfig: { myPanel: { visibleGeometry: () => null } }
|
|
236
285
|
})
|
|
237
286
|
renderHook(() => useVisibleGeometry())
|
|
238
|
-
capturedHandlers['app:panelopened']({ panelId: '
|
|
287
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
239
288
|
jest.runAllTimers()
|
|
240
|
-
expect(mapProvider.setView).not.toHaveBeenCalled()
|
|
241
289
|
expect(mapProvider.fitToBounds).not.toHaveBeenCalled()
|
|
242
290
|
})
|
|
243
291
|
|
|
292
|
+
test('passes the panel\'s own preferPan and paddingPercent to fitToBounds', () => {
|
|
293
|
+
const { mapProvider, capturedHandlers } = setup({
|
|
294
|
+
panelConfig: { myPanel: { visibleGeometry: polygonFeature, preferPan: false, paddingPercent: 10 } }
|
|
295
|
+
})
|
|
296
|
+
renderHook(() => useVisibleGeometry())
|
|
297
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
298
|
+
jest.runAllTimers()
|
|
299
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature, { preferPan: false, paddingPercent: 10 })
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
test('uses the options sent with the opened event, for a panel opening as it\'s added', () => {
|
|
303
|
+
const { mapProvider, capturedHandlers } = setup({
|
|
304
|
+
panelConfig: { myPanel: { visibleGeometry: polygonFeature, preferPan: false, paddingPercent: 10 } }
|
|
305
|
+
})
|
|
306
|
+
renderHook(() => useVisibleGeometry())
|
|
307
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel', visibleGeometry: pointFeature, preferPan: true, paddingPercent: 20 })
|
|
308
|
+
jest.runAllTimers()
|
|
309
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(pointFeature, { preferPan: true, paddingPercent: 20 })
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
test('uses the panel\'s own value for each option the opened event leaves out', () => {
|
|
313
|
+
const { mapProvider, capturedHandlers } = setup({
|
|
314
|
+
panelConfig: { myPanel: { visibleGeometry: polygonFeature, preferPan: false, paddingPercent: 10 } }
|
|
315
|
+
})
|
|
316
|
+
renderHook(() => useVisibleGeometry())
|
|
317
|
+
capturedHandlers['app:panelopened']({ panelId: 'myPanel', visibleGeometry: pointFeature })
|
|
318
|
+
jest.runAllTimers()
|
|
319
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(pointFeature, { preferPan: false, paddingPercent: 10 })
|
|
320
|
+
})
|
|
321
|
+
|
|
244
322
|
test('uses latest panelConfig via ref when it changes between renders', () => {
|
|
245
323
|
const { mapProvider, capturedHandlers, appContainer } = setup()
|
|
246
324
|
const { rerender } = renderHook(() => useVisibleGeometry())
|
|
@@ -257,22 +335,7 @@ describe('useVisibleGeometry', () => {
|
|
|
257
335
|
|
|
258
336
|
capturedHandlers['app:panelopened']({ panelId: 'myPanel' })
|
|
259
337
|
jest.runAllTimers()
|
|
260
|
-
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(updatedGeometry)
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
test('uses slot from event payload when registry config lacks slot info', () => {
|
|
264
|
-
const freshGeometry = { type: 'Feature', geometry: { type: 'Polygon', coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]] }, properties: {} }
|
|
265
|
-
const appContainer = document.createElement('div')
|
|
266
|
-
appContainer.appendChild(makePanelEl('freshPanel'))
|
|
267
|
-
const { mapProvider, capturedHandlers } = setup({
|
|
268
|
-
panelRegistry: { getPanelConfig: jest.fn(() => ({ freshPanel: { visibleGeometry: freshGeometry } })) },
|
|
269
|
-
layoutRefs: { mainRef: { current: document.createElement('div') }, appContainerRef: { current: appContainer } }
|
|
270
|
-
})
|
|
271
|
-
renderHook(() => useVisibleGeometry())
|
|
272
|
-
// Event includes slot (as middleware provides for ADD_PANEL); registry config has no slot info
|
|
273
|
-
capturedHandlers['app:panelopened']({ panelId: 'freshPanel', slot: 'left-top' })
|
|
274
|
-
jest.runAllTimers()
|
|
275
|
-
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(freshGeometry)
|
|
338
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(updatedGeometry, { preferPan: true })
|
|
276
339
|
})
|
|
277
340
|
|
|
278
341
|
test('falls back to panelRegistry for panels not yet in stale panelConfig', () => {
|
|
@@ -286,7 +349,7 @@ describe('useVisibleGeometry', () => {
|
|
|
286
349
|
renderHook(() => useVisibleGeometry())
|
|
287
350
|
capturedHandlers['app:panelopened']({ panelId: 'freshPanel' })
|
|
288
351
|
jest.runAllTimers()
|
|
289
|
-
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(freshGeometry)
|
|
352
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(freshGeometry, { preferPan: true })
|
|
290
353
|
})
|
|
291
354
|
|
|
292
355
|
test('falls back to config when panel not in panelConfig and registry returns null', () => {
|
|
@@ -302,7 +365,7 @@ describe('useVisibleGeometry', () => {
|
|
|
302
365
|
capturedHandlers['app:panelopened']({ panelId: 'missingPanel', visibleGeometry: polygonFeature, slot: 'left-top' })
|
|
303
366
|
jest.runAllTimers()
|
|
304
367
|
// Should still call fitToBounds using visibleGeometry from event payload
|
|
305
|
-
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature)
|
|
368
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature, { preferPan: true })
|
|
306
369
|
})
|
|
307
370
|
|
|
308
371
|
test('uses visibleGeometry from event payload directly, bypassing registry (ADD_PANEL first-click case)', () => {
|
|
@@ -316,41 +379,6 @@ describe('useVisibleGeometry', () => {
|
|
|
316
379
|
renderHook(() => useVisibleGeometry())
|
|
317
380
|
capturedHandlers['app:panelopened']({ panelId: 'newPanel', slot: 'left-top', visibleGeometry: polygonFeature })
|
|
318
381
|
jest.runAllTimers()
|
|
319
|
-
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature)
|
|
320
|
-
})
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
describe('getGeometryType', () => {
|
|
324
|
-
test('returns null for falsy input', () => {
|
|
325
|
-
expect(getGeometryType(null)).toBeNull()
|
|
326
|
-
expect(getGeometryType(undefined)).toBeNull()
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
test('returns geometry type for a Feature', () => {
|
|
330
|
-
expect(getGeometryType({ type: 'Feature', geometry: { type: 'Polygon' } })).toBe('Polygon')
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
test('returns type directly for a raw geometry', () => {
|
|
334
|
-
expect(getGeometryType({ type: 'Point' })).toBe('Point')
|
|
335
|
-
expect(getGeometryType({ type: 'FeatureCollection' })).toBe('FeatureCollection')
|
|
336
|
-
})
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
describe('getPointCoordinates', () => {
|
|
340
|
-
test('returns null for unrecognised geometry type', () => {
|
|
341
|
-
expect(getPointCoordinates({ type: 'Polygon', coordinates: [] })).toBeNull()
|
|
342
|
-
expect(getPointCoordinates({ type: 'LineString', coordinates: [] })).toBeNull()
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
test('returns coordinates for a Point', () => {
|
|
346
|
-
expect(getPointCoordinates(pointFeature.geometry)).toEqual(pointFeature.geometry.coordinates)
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
test('returns first coordinate for a MultiPoint', () => {
|
|
350
|
-
expect(getPointCoordinates(multiPointFeature.geometry)).toEqual(multiPointFeature.geometry.coordinates[0])
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
test('recurses into Feature geometry', () => {
|
|
354
|
-
expect(getPointCoordinates(pointFeature)).toEqual(pointFeature.geometry.coordinates)
|
|
382
|
+
expect(mapProvider.fitToBounds).toHaveBeenCalledWith(polygonFeature, { preferPan: true })
|
|
355
383
|
})
|
|
356
384
|
})
|
|
@@ -61,7 +61,7 @@ export const Layout = () => {
|
|
|
61
61
|
<div className='im-o-app__top-col' ref={layoutRefs.topLeftColRef}>
|
|
62
62
|
<SlotRenderer slot={layoutSlots.TOP_LEFT} />
|
|
63
63
|
</div>
|
|
64
|
-
<div className='im-o-app__top-col'>
|
|
64
|
+
<div className='im-o-app__top-col' ref={layoutRefs.topMiddleColRef}>
|
|
65
65
|
<SlotRenderer slot={layoutSlots.TOP_MIDDLE} />
|
|
66
66
|
</div>
|
|
67
67
|
<div className='im-o-app__top-col' ref={layoutRefs.topRightColRef}>
|
|
@@ -93,14 +93,15 @@ export const Layout = () => {
|
|
|
93
93
|
<SlotRenderer slot={layoutSlots.RIGHT_BOTTOM} />
|
|
94
94
|
</div>
|
|
95
95
|
</div>
|
|
96
|
+
<Hints />
|
|
96
97
|
<div className='im-o-app__bottom' ref={layoutRefs.bottomRef}>
|
|
97
|
-
<div className='im-o-app__bottom-col'>
|
|
98
|
+
<div className='im-o-app__bottom-col' ref={layoutRefs.bottomLeftColRef}>
|
|
98
99
|
<Logo />
|
|
99
100
|
<div className='im-o-app__bottom-left'>
|
|
100
101
|
<SlotRenderer slot={layoutSlots.BOTTOM_LEFT} />
|
|
101
102
|
</div>
|
|
102
103
|
</div>
|
|
103
|
-
<div className='im-o-app__bottom-col'>
|
|
104
|
+
<div className='im-o-app__bottom-col' ref={layoutRefs.bottomRightColRef}>
|
|
104
105
|
<div className='im-o-app__bottom-right' ref={layoutRefs.bottomRightRef}>
|
|
105
106
|
<SlotRenderer slot={layoutSlots.BOTTOM_RIGHT} />
|
|
106
107
|
</div>
|
|
@@ -125,7 +126,6 @@ export const Layout = () => {
|
|
|
125
126
|
</div>
|
|
126
127
|
</div>
|
|
127
128
|
</div>
|
|
128
|
-
<Hints />
|
|
129
129
|
<HtmlElementHost />
|
|
130
130
|
</div>
|
|
131
131
|
)
|