@defra/interactive-map 0.0.58-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/docs/plugins/draw.md +95 -13
- 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/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/adapterEvents.js +2 -0
- package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
- package/plugins/draw/src/api/addFeature.js +9 -6
- package/plugins/draw/src/api/addFeature.test.js +37 -10
- package/plugins/draw/src/api/editFeature.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
- package/plugins/draw/src/api/setProperties.js +39 -0
- package/plugins/draw/src/api/setProperties.test.js +74 -0
- package/plugins/draw/src/api/setStyle.js +16 -19
- package/plugins/draw/src/api/setStyle.test.js +17 -2
- package/plugins/draw/src/api/split.js +7 -4
- package/plugins/draw/src/api/split.test.js +25 -2
- package/plugins/draw/src/events.js +95 -53
- package/plugins/draw/src/events.test.js +425 -6
- package/plugins/draw/src/manifest.js +6 -4
- package/plugins/draw/src/manifest.test.js +20 -26
- package/plugins/draw/src/reducer.js +7 -0
- package/plugins/draw/src/reducer.test.js +11 -0
- package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
- package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
- package/plugins/draw/src/utils/isPlainObject.js +14 -0
- package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
- package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
- package/plugins/draw/src/validation/commitChecks.js +29 -11
- package/plugins/draw/src/validation/commitChecks.test.js +67 -11
- package/plugins/draw/src/validation/validateGeometry.js +12 -5
- package/plugins/draw/src/validation/validateGeometry.test.js +18 -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/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/MapProvider.jsx +1 -0
- package/src/App/store/MapProvider.test.jsx +25 -0
- package/src/App/store/appDispatchMiddleware.js +18 -10
- package/src/App/store/appDispatchMiddleware.test.js +42 -4
- package/src/App/store/mapActionsMap.js +6 -0
- package/src/App/store/mapActionsMap.test.js +7 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +2 -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/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
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
height: 100%;
|
|
12
12
|
min-height: 0;
|
|
13
13
|
overflow: hidden;
|
|
14
|
+
overflow: clip; // Can't be scrolled, so focusing something wider than a narrow map can't shift it
|
|
14
15
|
|
|
15
16
|
touch-action: none;
|
|
16
17
|
}
|
|
@@ -119,19 +120,33 @@
|
|
|
119
120
|
// Top: Includes a panel and buttons in colums
|
|
120
121
|
// ---------------------------------------------------
|
|
121
122
|
|
|
122
|
-
//
|
|
123
|
+
// The side columns share the row by their content, so one only wraps when the row is really full.
|
|
124
|
+
// A column is never narrower than its widest item, so items keep their size and wrap between them.
|
|
123
125
|
.im-o-app__top {
|
|
124
126
|
z-index: 10;
|
|
125
127
|
display: grid;
|
|
126
|
-
grid-template-columns:
|
|
128
|
+
grid-template-columns: minmax(min-content, auto) auto minmax(min-content, auto);
|
|
127
129
|
margin-bottom: auto;
|
|
128
130
|
align-items: start;
|
|
129
131
|
width: 100%;
|
|
130
132
|
gap: var(--divider-gap);
|
|
131
133
|
}
|
|
132
134
|
|
|
135
|
+
// With something in the middle, equal side columns keep it centred while there's room. It then moves
|
|
136
|
+
// off-centre as the gaps close, and nothing wraps until they have.
|
|
137
|
+
.im-o-app__top:has(> .im-o-app__top-col:nth-child(2) > :not([hidden])) {
|
|
138
|
+
grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Once the columns no longer fit on one line (set in useLayoutMeasurements), they can narrow and
|
|
142
|
+
// wrap, and the middle wraps past a third of the row.
|
|
143
|
+
.im-o-app__top--wrapped:has(> .im-o-app__top-col:nth-child(2) > :not([hidden])) {
|
|
144
|
+
grid-template-columns: minmax(min-content, 1fr) fit-content(34%) minmax(min-content, 1fr);
|
|
145
|
+
}
|
|
146
|
+
|
|
133
147
|
.im-o-app__top-col {
|
|
134
148
|
display: flex;
|
|
149
|
+
flex-wrap: wrap;
|
|
135
150
|
gap: var(--divider-gap);
|
|
136
151
|
}
|
|
137
152
|
|
|
@@ -164,41 +179,101 @@
|
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
// ---------------------------------------------------
|
|
167
|
-
// Left: Buttons and panels
|
|
182
|
+
// Left and right: Buttons and panels
|
|
168
183
|
// ---------------------------------------------------
|
|
169
184
|
|
|
170
|
-
|
|
185
|
+
// The top sub-slot, a spacer, then the bottom sub-slot, which sits at the bottom of the column.
|
|
186
|
+
// Each sub-slot grows to its content until the two meet. Grid shares the room out equally, so a
|
|
187
|
+
// sub-slot that needs less than half keeps its full height and the other gets the rest, or each
|
|
188
|
+
// gets half. A panel squeezed this way scrolls its own content. The auto minimums keep buttons and
|
|
189
|
+
// controls at their full height, at this level and in the sub-slots: only panels give way.
|
|
190
|
+
.im-o-app__left,
|
|
191
|
+
.im-o-app__right {
|
|
171
192
|
position: absolute;
|
|
172
|
-
display:
|
|
173
|
-
|
|
193
|
+
display: grid;
|
|
194
|
+
grid-template-columns: minmax(0, 1fr);
|
|
195
|
+
max-width: calc(100% - (var(--primary-gap) * 2));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// With panels open on both sides, each column is at most half the map, so they come no closer than
|
|
199
|
+
// a divider gap. Closed panels have the hidden attribute, or display: none for HTML panels
|
|
200
|
+
$open-panel: '.im-c-panel:not([hidden]):not([style*="display: none"])';
|
|
201
|
+
|
|
202
|
+
.im-o-app__main:has(> .im-o-app__left > * > #{$open-panel}):has(> .im-o-app__right > * > #{$open-panel}) {
|
|
203
|
+
> .im-o-app__left,
|
|
204
|
+
> .im-o-app__right {
|
|
205
|
+
max-width: calc(50% - var(--primary-gap) - (var(--divider-gap) / 2));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.im-o-app__left {
|
|
210
|
+
grid-template-rows: minmax(auto, max-content) minmax(var(--left-slot-gap, var(--divider-gap)), 1fr) minmax(auto, max-content);
|
|
174
211
|
left: var(--primary-gap);
|
|
175
212
|
top: var(--left-offset-top);
|
|
176
213
|
bottom: var(--left-offset-bottom);
|
|
177
|
-
|
|
214
|
+
}
|
|
178
215
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
216
|
+
.im-o-app__right {
|
|
217
|
+
grid-template-rows: minmax(auto, max-content) minmax(var(--right-slot-gap, var(--divider-gap)), 1fr) minmax(auto, max-content);
|
|
218
|
+
right: var(--primary-gap);
|
|
219
|
+
top: var(--right-offset-top);
|
|
220
|
+
bottom: var(--right-offset-bottom);
|
|
182
221
|
}
|
|
183
222
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
223
|
+
// Each panel or button in a sub-slot shares its room the same way, so two panels in one sub-slot
|
|
224
|
+
// split it rather than one squeezing the other below its own heading
|
|
225
|
+
.im-o-app__left-top,
|
|
226
|
+
.im-o-app__left-bottom,
|
|
227
|
+
.im-o-app__right-top,
|
|
228
|
+
.im-o-app__right-bottom {
|
|
189
229
|
position: relative;
|
|
230
|
+
display: grid;
|
|
231
|
+
// A track no wider than the column, so a wide panel narrows to fit rather than widening the track
|
|
232
|
+
grid-template-columns: minmax(0, 1fr);
|
|
233
|
+
grid-auto-rows: minmax(auto, max-content);
|
|
190
234
|
gap: var(--divider-gap);
|
|
191
235
|
}
|
|
192
236
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
align-items: flex-start;
|
|
197
|
-
justify-content: flex-end;
|
|
237
|
+
// Only a sub-slot with an open panel can shrink, so the buttons and controls in the other keep their
|
|
238
|
+
// size and the mobile drawer cap can reserve room for them
|
|
239
|
+
:is(.im-o-app__left-top, .im-o-app__left-bottom, .im-o-app__right-top, .im-o-app__right-bottom):has(> #{$open-panel}) {
|
|
198
240
|
min-height: 0;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// A panel's set and minimum widths give way to its column's (a panel beside a button sits inside the button)
|
|
244
|
+
:is(.im-o-app__left-top, .im-o-app__left-bottom, .im-o-app__right-top, .im-o-app__right-bottom) > .im-c-panel {
|
|
245
|
+
min-width: min(var(--min-panel-width), 100%);
|
|
246
|
+
max-width: 100%;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.im-o-app__left-top,
|
|
250
|
+
.im-o-app__right-top {
|
|
251
|
+
grid-row: 1;
|
|
252
|
+
align-content: start;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.im-o-app__left-bottom,
|
|
256
|
+
.im-o-app__right-bottom {
|
|
257
|
+
grid-row: 3;
|
|
258
|
+
align-content: end;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.im-o-app__left-top,
|
|
262
|
+
.im-o-app__left-bottom {
|
|
263
|
+
justify-items: start;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.im-o-app__right-top,
|
|
267
|
+
.im-o-app__right-bottom {
|
|
268
|
+
justify-items: end;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.im-o-app__left-top {
|
|
272
|
+
max-height: var(--left-top-slot-max-height, none);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.im-o-app__right-top {
|
|
276
|
+
max-height: var(--right-top-slot-max-height, none);
|
|
202
277
|
}
|
|
203
278
|
|
|
204
279
|
// ---------------------------------------------------
|
|
@@ -217,39 +292,6 @@
|
|
|
217
292
|
z-index: -1; // Support masking the viewport
|
|
218
293
|
}
|
|
219
294
|
|
|
220
|
-
// ---------------------------------------------------
|
|
221
|
-
// Right: Buttons and panels
|
|
222
|
-
// ---------------------------------------------------
|
|
223
|
-
|
|
224
|
-
.im-o-app__right {
|
|
225
|
-
position: absolute;
|
|
226
|
-
display: flex;
|
|
227
|
-
flex-direction: column;
|
|
228
|
-
right: var(--primary-gap);
|
|
229
|
-
top: var(--right-offset-top);
|
|
230
|
-
bottom: var(--right-offset-bottom);
|
|
231
|
-
gap: var(--divider-gap);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
.im-o-app__right-top {
|
|
235
|
-
display: flex;
|
|
236
|
-
flex-direction: column;
|
|
237
|
-
flex: 0 0 auto;
|
|
238
|
-
align-items: flex-end;
|
|
239
|
-
position: relative;
|
|
240
|
-
gap: var(--divider-gap);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
.im-o-app__right-bottom {
|
|
244
|
-
display: flex;
|
|
245
|
-
flex-direction: column;
|
|
246
|
-
flex: 0 0 auto;
|
|
247
|
-
margin-top: auto;
|
|
248
|
-
align-items: flex-end;
|
|
249
|
-
position: relative;
|
|
250
|
-
gap: var(--divider-gap);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
295
|
// ---------------------------------------------------
|
|
254
296
|
// Bottom: Logo, scalebar, copyright etc
|
|
255
297
|
// ---------------------------------------------------
|
|
@@ -334,11 +376,19 @@
|
|
|
334
376
|
// Drawer:
|
|
335
377
|
// ---------------------------------------------------
|
|
336
378
|
|
|
379
|
+
// Capped in useLayoutMeasurements so it never covers the side columns or runs off main
|
|
337
380
|
.im-o-app__drawer {
|
|
381
|
+
display: flex;
|
|
382
|
+
flex-direction: column;
|
|
383
|
+
min-height: 0;
|
|
384
|
+
max-height: var(--drawer-max-height, none);
|
|
338
385
|
z-index: 1;
|
|
339
386
|
}
|
|
340
387
|
|
|
341
388
|
.im-o-app__drawer .im-c-panel {
|
|
389
|
+
min-height: 0;
|
|
390
|
+
max-height: 100%;
|
|
391
|
+
|
|
342
392
|
@include tools.border-focus-corner-override(
|
|
343
393
|
$corners: 'top'
|
|
344
394
|
);
|
|
@@ -468,6 +518,11 @@
|
|
|
468
518
|
|
|
469
519
|
}
|
|
470
520
|
|
|
521
|
+
// Leaves a gap above and below, so a long banner scrolls instead of running off the map
|
|
522
|
+
.im-o-app .im-o-app__modal .im-c-panel--banner {
|
|
523
|
+
max-height: calc(100% - (var(--primary-gap) * 2));
|
|
524
|
+
}
|
|
525
|
+
|
|
471
526
|
// Mobile and tablet
|
|
472
527
|
.im-o-app--mobile, .im-o-app--tablet {
|
|
473
528
|
.im-o-app__modal .im-c-panel--banner {
|
|
@@ -497,15 +552,15 @@
|
|
|
497
552
|
|
|
498
553
|
// Actions inset when width is greater
|
|
499
554
|
.im-o-app--tablet, .im-o-app--desktop {
|
|
555
|
+
// As wide as the bar, so its size changes when the bar's does and the layout is measured again
|
|
500
556
|
.im-o-app__actions {
|
|
501
557
|
position: absolute;
|
|
502
|
-
width: 100%;
|
|
503
558
|
left: 0;
|
|
559
|
+
right: 0;
|
|
504
560
|
bottom: calc(var(--primary-gap) * 2);
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
561
|
+
width: fit-content;
|
|
562
|
+
max-width: var(--action-bar-max-width);
|
|
563
|
+
margin-inline: auto;
|
|
509
564
|
|
|
510
565
|
// Opacity-only so it fades in instead of visually sliding up.
|
|
511
566
|
@media (prefers-reduced-motion: no-preference) {
|
|
@@ -527,6 +582,7 @@
|
|
|
527
582
|
|
|
528
583
|
.im-c-panel {
|
|
529
584
|
width: 100%;
|
|
585
|
+
min-width: 0;
|
|
530
586
|
|
|
531
587
|
@include tools.border-focus-corner-override(
|
|
532
588
|
$corners: 'none'
|
|
@@ -538,6 +594,13 @@
|
|
|
538
594
|
clip-path: inset(-20px 0 0 0);
|
|
539
595
|
}
|
|
540
596
|
|
|
597
|
+
// Only the top panel in the drawer casts a shadow over the map. Panels below it are separated by a
|
|
598
|
+
// border instead, as the actions bar is (see Actions.jsx)
|
|
599
|
+
.im-o-app--mobile .im-o-app__drawer .im-c-panel:not([hidden]):not([style*="display: none"]) ~ .im-c-panel {
|
|
600
|
+
clip-path: inset(0);
|
|
601
|
+
border-top: 1px solid var(--app-border-color);
|
|
602
|
+
}
|
|
603
|
+
|
|
541
604
|
// Inset the focus ring so it isn't clipped by the parent's overflow:hidden.
|
|
542
605
|
.im-o-app--mobile .im-o-app__drawer .im-c-panel::after,
|
|
543
606
|
.im-o-app--mobile .im-o-app__actions .im-c-panel::after,
|
|
@@ -30,6 +30,7 @@ export const AppProvider = ({ options, children }) => {
|
|
|
30
30
|
headerRef: useRef(null),
|
|
31
31
|
topRef: useRef(null),
|
|
32
32
|
topLeftColRef: useRef(null),
|
|
33
|
+
topMiddleColRef: useRef(null),
|
|
33
34
|
topRightColRef: useRef(null),
|
|
34
35
|
leftRef: useRef(null),
|
|
35
36
|
leftTopRef: useRef(null),
|
|
@@ -40,6 +41,8 @@ export const AppProvider = ({ options, children }) => {
|
|
|
40
41
|
rightBottomRef: useRef(null),
|
|
41
42
|
drawerRef: useRef(null),
|
|
42
43
|
bottomRef: useRef(null),
|
|
44
|
+
bottomLeftColRef: useRef(null),
|
|
45
|
+
bottomRightColRef: useRef(null),
|
|
43
46
|
bottomRightRef: useRef(null),
|
|
44
47
|
attributionsRef: useRef(null),
|
|
45
48
|
actionsRef: useRef(null),
|
|
@@ -21,6 +21,7 @@ export const MapProvider = ({ options, children }) => {
|
|
|
21
21
|
const mapStyle = mapStyles.find(s => s.id === savedMapStyleId) || mapStyles[0]
|
|
22
22
|
const savedMapSize = localStorage.getItem(`${options.id}:mapSize`)
|
|
23
23
|
const mapSize = savedMapSize || options.mapSize
|
|
24
|
+
dispatch({ type: 'SET_MAP_STYLES', payload: mapStyles })
|
|
24
25
|
dispatch({ type: 'SET_MAP_STYLE', payload: mapStyle })
|
|
25
26
|
dispatch({ type: 'SET_MAP_SIZE', payload: mapSize })
|
|
26
27
|
}
|
|
@@ -13,12 +13,14 @@ jest.mock('./mapReducer.js', () => {
|
|
|
13
13
|
|
|
14
14
|
const setMapReady = jest.fn((state) => ({ ...state, isMapReady: true }))
|
|
15
15
|
const setMapStyle = jest.fn((state, payload) => ({ ...state, mapStyle: payload }))
|
|
16
|
+
const setMapStyles = jest.fn((state, payload) => ({ ...state, mapStyles: payload }))
|
|
16
17
|
const setMapSize = jest.fn((state, payload) => ({ ...state, mapSize: payload }))
|
|
17
18
|
const updateCrossHair = jest.fn((state, payload) => ({ ...state, crossHair: payload }))
|
|
18
19
|
|
|
19
20
|
const actionsMap = {
|
|
20
21
|
SET_MAP_READY: setMapReady,
|
|
21
22
|
SET_MAP_STYLE: setMapStyle,
|
|
23
|
+
SET_MAP_STYLES: setMapStyles,
|
|
22
24
|
SET_MAP_SIZE: setMapSize,
|
|
23
25
|
UPDATE_CROSS_HAIR: updateCrossHair
|
|
24
26
|
}
|
|
@@ -103,6 +105,29 @@ describe('MapProvider', () => {
|
|
|
103
105
|
})
|
|
104
106
|
})
|
|
105
107
|
|
|
108
|
+
test('keeps every announced map style, and selects the saved one', () => {
|
|
109
|
+
let contextValue
|
|
110
|
+
const Child = () => {
|
|
111
|
+
contextValue = React.useContext(MapContext)
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
localStorage.setItem('map1:mapStyleId', 'dark')
|
|
115
|
+
|
|
116
|
+
render(
|
|
117
|
+
<MapProvider options={{ id: 'map1', mapSize: '100x100', eventBus: mockEventBus }}>
|
|
118
|
+
<Child />
|
|
119
|
+
</MapProvider>
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const mapStyles = [{ id: 'outdoor' }, { id: 'dark' }]
|
|
123
|
+
act(() => {
|
|
124
|
+
capturedHandlers['map:initmapstyles'](mapStyles)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
expect(contextValue.mapStyles).toBe(mapStyles)
|
|
128
|
+
expect(contextValue.mapStyle).toEqual({ id: 'dark' })
|
|
129
|
+
})
|
|
130
|
+
|
|
106
131
|
test('dispatches SET_MAP_READY when MAP_READY fires', () => {
|
|
107
132
|
let contextValue
|
|
108
133
|
const Child = () => {
|
|
@@ -7,6 +7,16 @@ import { logger } from '../../services/logger.js'
|
|
|
7
7
|
|
|
8
8
|
const BREAKPOINTS = ['mobile', 'tablet', 'desktop']
|
|
9
9
|
|
|
10
|
+
const VISIBLE_GEOMETRY_KEYS = ['visibleGeometry', 'preferPan', 'paddingPercent']
|
|
11
|
+
|
|
12
|
+
// The panel's visibleGeometry options that are set. Sent with the opened event for a panel that
|
|
13
|
+
// opens as it's added, as the panel registry may not have its config yet
|
|
14
|
+
const getVisibleGeometryOptions = (source) => Object.fromEntries(
|
|
15
|
+
VISIBLE_GEOMETRY_KEYS.filter(key => source[key] !== undefined).map(key => [key, source[key]])
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const isOpen = (panelId, state) => Boolean(state.openPanels?.[panelId])
|
|
19
|
+
|
|
10
20
|
/**
|
|
11
21
|
* Determines which panels were implicitly closed when opening a new panel
|
|
12
22
|
*/
|
|
@@ -60,6 +70,7 @@ function emitOpenPanelEvents ({ panelId, props }, previousState, panelConfig, ev
|
|
|
60
70
|
previousState.breakpoint,
|
|
61
71
|
panelConfig
|
|
62
72
|
)
|
|
73
|
+
const wasOpen = isOpen(panelId, previousState)
|
|
63
74
|
|
|
64
75
|
queueMicrotask(() => {
|
|
65
76
|
// Emit close events for implicitly closed panels
|
|
@@ -67,8 +78,10 @@ function emitOpenPanelEvents ({ panelId, props }, previousState, panelConfig, ev
|
|
|
67
78
|
eventBus.emit(events.APP_PANEL_CLOSED, { panelId: closedPanelId })
|
|
68
79
|
})
|
|
69
80
|
|
|
70
|
-
// Emit open event for the new panel
|
|
71
|
-
|
|
81
|
+
// Emit open event for the new panel. Showing a panel that's already open doesn't open it
|
|
82
|
+
if (!wasOpen) {
|
|
83
|
+
eventBus.emit(events.APP_PANEL_OPENED, { panelId, props })
|
|
84
|
+
}
|
|
72
85
|
})
|
|
73
86
|
}
|
|
74
87
|
|
|
@@ -129,15 +142,10 @@ export function handleActionSideEffects (action, previousState, panelConfig, eve
|
|
|
129
142
|
}
|
|
130
143
|
})
|
|
131
144
|
const bpConfig = mergedConfig[previousState.breakpoint]
|
|
132
|
-
|
|
145
|
+
// Adding a panel again while it's open doesn't open it
|
|
146
|
+
if (bpConfig?.open && !isOpen(id, previousState)) {
|
|
133
147
|
queueMicrotask(() => {
|
|
134
|
-
|
|
135
|
-
const { visibleGeometry } = mergedConfig
|
|
136
|
-
const eventPayload = { panelId: id, slot }
|
|
137
|
-
if (visibleGeometry) {
|
|
138
|
-
eventPayload.visibleGeometry = visibleGeometry
|
|
139
|
-
}
|
|
140
|
-
eventBus.emit(events.APP_PANEL_OPENED, eventPayload)
|
|
148
|
+
eventBus.emit(events.APP_PANEL_OPENED, { panelId: id, slot: bpConfig.slot, ...getVisibleGeometryOptions(mergedConfig) })
|
|
141
149
|
})
|
|
142
150
|
}
|
|
143
151
|
}
|
|
@@ -74,6 +74,33 @@ describe('OPEN_PANEL — regular panel', () => {
|
|
|
74
74
|
})
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
+
describe('OPEN_PANEL — panel already open', () => {
|
|
78
|
+
it('doesn\'t emit panel opened again', async () => {
|
|
79
|
+
run(
|
|
80
|
+
{ type: 'OPEN_PANEL', payload: { panelId: 'openPanel', props: {} } },
|
|
81
|
+
{ openPanels: { openPanel: {} }, breakpoint: 'md' },
|
|
82
|
+
{ openPanel: { md: {} } }
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
await flushMicrotasks()
|
|
86
|
+
|
|
87
|
+
expect(eventBus.emit).not.toHaveBeenCalledWith(events.APP_PANEL_OPENED, expect.anything())
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('still emits panel closed for the panels it closes', async () => {
|
|
91
|
+
run(
|
|
92
|
+
{ type: 'OPEN_PANEL', payload: { panelId: 'openPanel', props: {} } },
|
|
93
|
+
{ openPanels: { openPanel: {}, exclusivePanel: {} }, breakpoint: 'md' },
|
|
94
|
+
{ openPanel: { md: {} }, exclusivePanel: { md: { exclusive: true } } }
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
await flushMicrotasks()
|
|
98
|
+
|
|
99
|
+
expect(eventBus.emit).toHaveBeenCalledWith(events.APP_PANEL_CLOSED, { panelId: 'exclusivePanel' })
|
|
100
|
+
expect(eventBus.emit).not.toHaveBeenCalledWith(events.APP_PANEL_OPENED, expect.anything())
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
77
104
|
const CLOSED_PLUS_OPENED = 3
|
|
78
105
|
|
|
79
106
|
describe('OPEN_PANEL — opening exclusive closes non-exclusive', () => {
|
|
@@ -241,10 +268,10 @@ describe('ADD_PANEL', () => {
|
|
|
241
268
|
)
|
|
242
269
|
})
|
|
243
270
|
|
|
244
|
-
it('emits APP_PANEL_OPENED with
|
|
245
|
-
const visibleGeometry = { type: '
|
|
271
|
+
it('emits APP_PANEL_OPENED with preferPan and paddingPercent when provided in config', async () => {
|
|
272
|
+
const visibleGeometry = { type: 'Point', coordinates: [1, 2] }
|
|
246
273
|
run(
|
|
247
|
-
{ type: 'ADD_PANEL', payload: { id: 'geoPanel', config: { visibleGeometry } } },
|
|
274
|
+
{ type: 'ADD_PANEL', payload: { id: 'geoPanel', config: { visibleGeometry, preferPan: false, paddingPercent: 10 } } },
|
|
248
275
|
{ breakpoint: 'desktop' }
|
|
249
276
|
)
|
|
250
277
|
|
|
@@ -252,10 +279,21 @@ describe('ADD_PANEL', () => {
|
|
|
252
279
|
|
|
253
280
|
expect(eventBus.emit).toHaveBeenCalledWith(
|
|
254
281
|
events.APP_PANEL_OPENED,
|
|
255
|
-
{ panelId: 'geoPanel', slot: 'left-top', visibleGeometry }
|
|
282
|
+
{ panelId: 'geoPanel', slot: 'left-top', visibleGeometry, preferPan: false, paddingPercent: 10 }
|
|
256
283
|
)
|
|
257
284
|
})
|
|
258
285
|
|
|
286
|
+
it('does not emit APP_PANEL_OPENED when the panel is added again while it\'s open', async () => {
|
|
287
|
+
run(
|
|
288
|
+
{ type: 'ADD_PANEL', payload: { id: 'openPanel', config: {} } },
|
|
289
|
+
{ breakpoint: 'desktop', openPanels: { openPanel: {} } }
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
await flushMicrotasks()
|
|
293
|
+
|
|
294
|
+
expect(eventBus.emit).not.toHaveBeenCalledWith(events.APP_PANEL_OPENED, expect.anything())
|
|
295
|
+
})
|
|
296
|
+
|
|
259
297
|
it('does not emit APP_PANEL_OPENED when breakpoint config sets open: false', async () => {
|
|
260
298
|
run(
|
|
261
299
|
{ type: 'ADD_PANEL', payload: { id: 'hiddenPanel', config: { desktop: { open: false } } } },
|
|
@@ -17,6 +17,11 @@ const setMapStyle = (state, payload) => ({
|
|
|
17
17
|
mapStyle: payload
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
+
const setMapStyles = (state, payload) => ({
|
|
21
|
+
...state,
|
|
22
|
+
mapStyles: payload
|
|
23
|
+
})
|
|
24
|
+
|
|
20
25
|
const setMapSize = (state, payload) => {
|
|
21
26
|
return {
|
|
22
27
|
...state,
|
|
@@ -67,6 +72,7 @@ export const actionsMap = {
|
|
|
67
72
|
MAP_MOVE_END: mergePayload,
|
|
68
73
|
MAP_FIRST_IDLE: mergePayload,
|
|
69
74
|
SET_MAP_STYLE: setMapStyle,
|
|
75
|
+
SET_MAP_STYLES: setMapStyles,
|
|
70
76
|
SET_MAP_SIZE: setMapSize,
|
|
71
77
|
UPDATE_CROSS_HAIR: updateCrossHair,
|
|
72
78
|
UPSERT_LOCATION_MARKER: upsertMarker,
|
|
@@ -52,6 +52,13 @@ describe('actionsMap', () => {
|
|
|
52
52
|
expect(result.otherProp).toBe(state.otherProp)
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
+
test('SET_MAP_STYLES sets mapStyles', () => {
|
|
56
|
+
const mapStyles = [{ id: 'outdoor' }, { id: 'dark' }]
|
|
57
|
+
const result = actionsMap.SET_MAP_STYLES(state, mapStyles)
|
|
58
|
+
expect(result.mapStyles).toBe(mapStyles)
|
|
59
|
+
expect(result.otherProp).toBe(state.otherProp)
|
|
60
|
+
})
|
|
61
|
+
|
|
55
62
|
test('SET_MAP_SIZE sets mapSize', () => {
|
|
56
63
|
const newSize = { width: 200, height: 200 }
|
|
57
64
|
const result = actionsMap.SET_MAP_SIZE(state, newSize)
|
|
@@ -22,6 +22,8 @@ export const initialState = (config) => {
|
|
|
22
22
|
isMapReady: false,
|
|
23
23
|
mapProvider: null,
|
|
24
24
|
mapStyle: initialMapStyle,
|
|
25
|
+
// Every map style the user can switch to — set by a plugin that handles map styles
|
|
26
|
+
mapStyles: initialMapStyle ? [initialMapStyle] : [],
|
|
25
27
|
mapSize,
|
|
26
28
|
center,
|
|
27
29
|
zoom,
|
|
@@ -39,6 +39,7 @@ describe('mapReducer', () => {
|
|
|
39
39
|
expect(state).toMatchObject({
|
|
40
40
|
isMapReady: false,
|
|
41
41
|
mapStyle: { id: 'style1' },
|
|
42
|
+
mapStyles: [{ id: 'style1' }],
|
|
42
43
|
mapSize: '100x100',
|
|
43
44
|
center: [0, 0],
|
|
44
45
|
zoom: 5,
|
|
@@ -63,6 +64,7 @@ describe('mapReducer', () => {
|
|
|
63
64
|
const state = initialState(getConfig({ mapStyle: { id: 'custom' }, center: [10, 20], zoom: 12 }))
|
|
64
65
|
|
|
65
66
|
expect(state.mapStyle).toBeNull()
|
|
67
|
+
expect(state.mapStyles).toEqual([])
|
|
66
68
|
expect(state.center).toEqual([10, 20])
|
|
67
69
|
expect(state.zoom).toBe(12)
|
|
68
70
|
})
|
|
@@ -539,9 +539,10 @@ export default class InteractiveMap {
|
|
|
539
539
|
* Fit the map view to a bounding box or GeoJSON geometry, respecting the safe zone padding.
|
|
540
540
|
*
|
|
541
541
|
* @param {[number, number, number, number] | object} target - Bounds as [west, south, east, north] or [minX, minY, maxX, maxY] depending on the crs, or a GeoJSON Feature, FeatureCollection, or geometry.
|
|
542
|
+
* @param {import('../types.js').FitToBoundsOptions} [options]
|
|
542
543
|
*/
|
|
543
|
-
fitToBounds (target) {
|
|
544
|
-
this.eventBus.emitWhenReady(events.MAP_FIT_TO_BOUNDS, target)
|
|
544
|
+
fitToBounds (target, options) {
|
|
545
|
+
this.eventBus.emitWhenReady(events.MAP_FIT_TO_BOUNDS, target, options)
|
|
545
546
|
}
|
|
546
547
|
|
|
547
548
|
/**
|
|
@@ -635,9 +635,9 @@ describe('InteractiveMap — Public API Methods', () => {
|
|
|
635
635
|
it('fitToBounds and setView emit correct events', () => {
|
|
636
636
|
const bbox = [-0.489, 51.28, 0.236, 51.686]
|
|
637
637
|
const center = [-0.1276, 51.5074]
|
|
638
|
-
map.fitToBounds(bbox)
|
|
638
|
+
map.fitToBounds(bbox, { preferPan: true })
|
|
639
639
|
map.setView({ center, zoom: 12 })
|
|
640
|
-
expect(map.eventBus.emitWhenReady).toHaveBeenCalledWith('map:fittobounds', bbox)
|
|
640
|
+
expect(map.eventBus.emitWhenReady).toHaveBeenCalledWith('map:fittobounds', bbox, { preferPan: true })
|
|
641
641
|
expect(map.eventBus.emitWhenReady).toHaveBeenCalledWith('map:setview', { center, zoom: 12 })
|
|
642
642
|
})
|
|
643
643
|
|
package/src/config/events.js
CHANGED
|
@@ -116,7 +116,7 @@ export const EVENTS = {
|
|
|
116
116
|
APP_FULLSCREEN_CHANGE: 'app:fullscreenchange',
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* Emitted when a panel
|
|
119
|
+
* Emitted when a closed panel opens. Showing or adding a panel that's already open doesn't emit it again.
|
|
120
120
|
* Payload: { panelId: string }
|
|
121
121
|
*
|
|
122
122
|
* @example
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Layout refs of the slots whose panels sit over the map. Panels in other slots are modal, beside
|
|
2
|
+
// the map, or hold buttons or little content.
|
|
3
|
+
|
|
4
|
+
// The side columns. The safe zone leaves out a panel here that's too small to narrow it.
|
|
5
|
+
export const SIDE_PANEL_SLOT_REFS = ['leftTopRef', 'leftBottomRef', 'rightTopRef', 'rightBottomRef']
|
|
6
|
+
|
|
7
|
+
// The side columns and the drawer, which is always within the safe zone's bottom inset
|
|
8
|
+
export const MAP_PANEL_SLOT_REFS = [...SIDE_PANEL_SLOT_REFS, 'drawerRef']
|
|
@@ -11,7 +11,7 @@ export const symbolDefaults = {
|
|
|
11
11
|
foregroundColor: '#ffffff'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/** The symbol style keys a dataset or draw style can set (see docs/plugins/datasets.md) */
|
|
14
|
+
/** The named symbol style keys a dataset or draw style can set (see docs/plugins/datasets.md) */
|
|
15
15
|
export const SYMBOL_STYLE_KEYS = [
|
|
16
16
|
'symbol', 'symbolSvgContent', 'symbolViewBox', 'symbolAnchor', 'symbolSize',
|
|
17
17
|
'symbolBackgroundColor', 'symbolForegroundColor', 'symbolHaloWidth', 'symbolGraphic'
|
|
@@ -105,7 +105,7 @@ function resolveValues (symbolDef, markerValues, mapStyle, constructorDefaults)
|
|
|
105
105
|
merged.graphic = graphics[merged.graphic]
|
|
106
106
|
}
|
|
107
107
|
return Object.fromEntries(
|
|
108
|
-
Object.entries(merged).map(([token, value]) => [token, getValueForStyle(value, mapStyleId)
|
|
108
|
+
Object.entries(merged).map(([token, value]) => [token, getValueForStyle(value, mapStyleId) ?? ''])
|
|
109
109
|
)
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -81,6 +81,17 @@ describe('getKeySymbol', () => {
|
|
|
81
81
|
expect(svg).toBe(symbolRegistry.getKeySymbol(style, { ...mapStyle, mapColorScheme: 'light', appColorScheme: 'light' }).svg)
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
+
it('fills number tokens, including zero', () => {
|
|
85
|
+
const style = { symbolSvgContent: '<path stroke-width="{{ringWidth}}" opacity="{{bandOpacity}}"/>', symbolRingWidth: 3, symbolBandOpacity: { [mapStyle.id]: 0 } }
|
|
86
|
+
expect(symbolRegistry.getKeySymbol(style, mapStyle).svg).toContain('stroke-width="3" opacity="0"')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('fills custom tokens from the style', () => {
|
|
90
|
+
const style = { symbolSvgContent: '<path fill="{{accentColor}}"/>', symbolAccentColor: { outdoor: '#ffdd00', dark: '#f47738' } }
|
|
91
|
+
const { svg } = symbolRegistry.getKeySymbol(style, { ...mapStyle, id: 'dark' })
|
|
92
|
+
expect(svg).toContain('fill="#f47738"')
|
|
93
|
+
})
|
|
94
|
+
|
|
84
95
|
it('is null for a style with no known symbol', () => {
|
|
85
96
|
expect(symbolRegistry.getKeySymbol({ symbol: 'does-not-exist' }, mapStyle)).toBeNull()
|
|
86
97
|
})
|
|
@@ -269,6 +280,14 @@ describe('symbolRegistry — image ids and rasterising', () => {
|
|
|
269
280
|
expect(small).not.toBe(big)
|
|
270
281
|
})
|
|
271
282
|
|
|
283
|
+
it('gives a different image id when a custom token changes, or differs by map style', () => {
|
|
284
|
+
const style = { symbolSvgContent: '<circle r="4" fill="{{accentColor}}"/>' }
|
|
285
|
+
const imageIdFor = (symbolAccentColor, id) => symbolRegistry.getSymbolImageId({ ...style, symbolAccentColor }, { ...mapStyle, id }, 'normal', 2)
|
|
286
|
+
const perStyle = { outdoor: '#ffdd00', dark: '#f47738' }
|
|
287
|
+
expect(imageIdFor('#ffdd00', 'outdoor')).not.toBe(imageIdFor('#f47738', 'outdoor'))
|
|
288
|
+
expect(imageIdFor(perStyle, 'outdoor')).not.toBe(imageIdFor(perStyle, 'dark'))
|
|
289
|
+
})
|
|
290
|
+
|
|
272
291
|
it('rasterises at the sized viewBox × pixelRatio, under the same id getSymbolImageId gives', async () => {
|
|
273
292
|
const style = { symbol: 'circle', symbolSize: 'large' }
|
|
274
293
|
const { imageId, imageData } = await symbolRegistry.rasteriseSymbolImage(style, mapStyle, 'normal', 2)
|