@defra/interactive-map 0.0.21-alpha → 0.0.23-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/esm/index.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/button-definition.md +39 -0
- package/docs/api/context.md +4 -4
- package/docs/api/map-style-config.md +11 -2
- package/docs/api/marker-config.md +38 -7
- package/docs/api/panel-definition.md +7 -3
- package/docs/api/symbol-config.md +10 -26
- package/docs/api/symbol-registry.md +28 -13
- package/docs/api.md +65 -4
- package/docs/assets/css/{docusaurus.css → docusaurus.scss} +18 -12
- package/docs/assets/images/toggle-marker-label.jpg +0 -0
- package/docs/examples/index.mdx +12 -0
- package/docs/examples/toggle-marker-label.mdx +89 -0
- package/docs/plugins/datasets.md +39 -1
- package/docs/plugins/interact.md +4 -11
- package/docusaurus.config.cjs +2 -1
- package/package.json +10 -12
- package/plugins/beta/datasets/dist/adapters/maplibre/esm/im-datasets-ml-adapter.js +1 -0
- package/plugins/beta/datasets/dist/css/index.css +2 -2
- package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/maplibre/im-datasets-maplibre-adapter.js +2 -0
- package/plugins/beta/datasets/dist/umd/maplibre/im-datasets-plugin.js +2 -0
- package/plugins/beta/datasets/dist/umd/maplibre/index.js +2 -0
- package/plugins/beta/datasets/src/adapters/maplibre/index.js +1 -1
- package/plugins/beta/datasets/src/adapters/maplibre/layerBuilders.js +5 -5
- package/plugins/beta/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +24 -29
- package/plugins/beta/datasets/src/adapters/maplibre/patternImages.js +2 -2
- package/plugins/beta/datasets/src/adapters/maplibre/symbolImages.js +3 -3
- package/plugins/beta/datasets/src/components/KeySvg.jsx +2 -2
- package/plugins/beta/datasets/src/components/KeySvgPattern.jsx +1 -2
- package/plugins/beta/datasets/src/components/svgProperties.js +2 -2
- package/plugins/beta/datasets/src/index.maplibre.umd.js +23 -0
- package/plugins/beta/datasets/src/panels/Key.module.scss +2 -2
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- 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/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/src/manifest.js +1 -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/dist/umd/index.js +1 -1
- package/plugins/interact/src/InteractInit.jsx +23 -55
- package/plugins/interact/src/InteractInit.test.js +58 -80
- package/plugins/interact/src/defaults.js +1 -3
- package/plugins/interact/src/hooks/useAttachEvents.js +46 -0
- package/plugins/interact/src/hooks/useAttachEvents.test.js +65 -0
- package/plugins/interact/src/hooks/useCrossHairVisibility.js +47 -0
- package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +54 -0
- package/plugins/interact/src/hooks/useHighlightSync.js +30 -8
- package/plugins/interact/src/hooks/useHighlightSync.test.js +127 -80
- package/plugins/interact/src/hooks/useInteractionHandlers.js +18 -17
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +22 -61
- package/plugins/interact/src/hooks/useMapItemList.js +187 -0
- package/plugins/interact/src/hooks/useMapItemList.test.js +584 -0
- package/plugins/interact/src/index.js +0 -2
- package/plugins/interact/src/index.test.js +0 -2
- package/plugins/interact/src/manifest.js +37 -6
- package/plugins/interact/src/reducer.js +8 -4
- package/plugins/interact/src/reducer.test.js +18 -3
- package/plugins/interact/src/utils/buildStylesMap.js +21 -10
- package/plugins/interact/src/utils/buildStylesMap.test.js +29 -29
- package/plugins/interact/src/utils/spatial.js +0 -15
- package/plugins/interact/src/utils/spatial.test.js +1 -13
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/src/components/CloseButton/CloseButton.module.scss +2 -0
- package/plugins/search/src/components/OpenButton/OpenButton.jsx +1 -1
- package/plugins/search/src/components/OpenButton/OpenButton.module.scss +3 -0
- package/plugins/search/src/search.scss +1 -0
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/src/esriProvider.js +4 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +7 -1
- package/providers/maplibre/src/index.test.js +15 -2
- package/providers/maplibre/src/mapEvents.js +11 -5
- package/providers/maplibre/src/mapEvents.test.js +14 -3
- package/providers/maplibre/src/maplibreProvider.js +18 -11
- package/providers/maplibre/src/maplibreProvider.test.js +43 -36
- package/providers/maplibre/src/utils/highlightFeatures.js +102 -57
- package/providers/maplibre/src/utils/highlightFeatures.test.js +162 -51
- package/providers/maplibre/src/utils/maplibreFixes.js +10 -0
- package/providers/maplibre/src/utils/maplibreFixes.test.js +31 -0
- package/providers/maplibre/src/utils/patternImages.js +10 -12
- package/providers/maplibre/src/utils/patternImages.test.js +145 -167
- package/providers/maplibre/src/utils/rasteriseToImageData.js +1 -4
- package/providers/maplibre/src/utils/rasteriseToImageData.test.js +23 -24
- package/providers/maplibre/src/utils/symbolImages.js +23 -86
- package/providers/maplibre/src/utils/symbolImages.test.js +60 -105
- package/rollup.esm.mjs +1 -1
- package/src/App/components/Actions/Actions.module.scss +1 -0
- package/src/App/components/Actions/Actions.test.jsx +17 -4
- package/src/App/components/Hints/Hints.jsx +52 -0
- package/src/App/components/Hints/Hints.module.scss +37 -0
- package/src/App/components/Hints/Hints.test.jsx +104 -0
- package/src/App/components/KeyboardHelp/KeyboardHelp.jsx +57 -19
- package/src/App/components/KeyboardHelp/KeyboardHelp.module.scss +10 -0
- package/src/App/components/KeyboardHelp/KeyboardHelp.test.jsx +140 -31
- package/src/App/components/Markers/LabelMarker.jsx +14 -0
- package/src/App/components/Markers/LabelMarker.test.jsx +36 -0
- package/src/App/components/Markers/Markers.jsx +44 -75
- package/src/App/components/Markers/Markers.module.scss +58 -0
- package/src/App/components/Markers/Markers.test.jsx +90 -113
- package/src/App/components/Markers/SymbolLabelMarker.jsx +43 -0
- package/src/App/components/Markers/SymbolLabelMarker.test.jsx +56 -0
- package/src/App/components/Markers/SymbolMarker.jsx +31 -0
- package/src/App/components/Markers/SymbolMarker.test.jsx +72 -0
- package/src/App/components/Panel/Panel.jsx +1 -1
- package/src/App/components/Panel/Panel.module.scss +1 -0
- package/src/App/components/PopupMenu/PopupMenu.test.jsx +117 -1
- package/src/App/components/PopupMenu/usePopupMenu.js +132 -85
- package/src/App/components/Tabs/Tabs.jsx +68 -0
- package/src/App/components/Tabs/Tabs.module.scss +57 -0
- package/src/App/components/Tabs/Tabs.test.jsx +121 -0
- package/src/App/components/Tooltip/Tooltip.module.scss +1 -1
- package/src/App/components/Viewport/Features.jsx +35 -0
- package/src/App/components/Viewport/Features.module.scss +31 -0
- package/src/App/components/Viewport/Features.test.jsx +124 -0
- package/src/App/components/Viewport/MapController.jsx +1 -1
- package/src/App/components/Viewport/MapStatus.jsx +0 -4
- package/src/App/components/Viewport/Viewport.jsx +35 -29
- package/src/App/components/Viewport/Viewport.module.scss +7 -21
- package/src/App/components/Viewport/Viewport.test.jsx +108 -65
- package/src/App/controls/keyboardActions.js +9 -3
- package/src/App/controls/keyboardActions.test.js +122 -87
- package/src/App/controls/keyboardShortcuts.js +1 -14
- package/src/App/hooks/useFeatureFocus.js +199 -0
- package/src/App/hooks/useFeatureFocus.test.js +635 -0
- package/src/App/hooks/useFeatureItems.js +30 -0
- package/src/App/hooks/useFeatureItems.test.js +97 -0
- package/src/App/hooks/useFocusVisible.js +4 -7
- package/src/App/hooks/useFocusVisible.test.js +6 -6
- package/src/App/hooks/useKeyboardHint.js +9 -34
- package/src/App/hooks/useKeyboardHint.test.js +34 -84
- package/src/App/hooks/useKeyboardShortcuts.js +8 -5
- package/src/App/hooks/useKeyboardShortcuts.test.js +16 -12
- package/src/App/hooks/useLayoutMeasurements.js +10 -4
- package/src/App/hooks/useLayoutMeasurements.test.js +30 -0
- package/src/App/hooks/useMapURLSync.js +3 -3
- package/src/App/hooks/useMapURLSync.test.js +20 -3
- package/src/App/hooks/useMarkerCursor.js +33 -0
- package/src/App/hooks/useMarkerCursor.test.js +87 -0
- package/src/App/hooks/useMarkersAPI.js +32 -9
- package/src/App/hooks/useMarkersAPI.test.js +162 -94
- package/src/App/layout/Layout.jsx +2 -0
- package/src/App/layout/Layout.test.jsx +3 -0
- package/src/App/registry/keyboardShortcutRegistry.js +3 -2
- package/src/App/registry/keyboardShortcutRegistry.test.js +6 -8
- package/src/App/renderer/mapButtons.js +5 -1
- package/src/App/renderer/mapButtons.test.js +37 -1
- package/src/App/store/ServiceProvider.jsx +4 -1
- package/src/App/store/ServiceProvider.test.jsx +11 -0
- package/src/App/store/appActionsMap.js +5 -1
- package/src/App/store/appActionsMap.test.js +13 -0
- package/src/App/store/appReducer.js +1 -0
- package/src/App/store/mapActionsMap.js +2 -1
- package/src/InteractiveMap/InteractiveMap.js +13 -1
- package/src/InteractiveMap/InteractiveMap.test.js +6 -4
- package/src/InteractiveMap/behaviourController.js +1 -2
- package/src/InteractiveMap/buttonManager.js +1 -3
- package/src/InteractiveMap/buttonManager.test.js +16 -8
- package/src/InteractiveMap/domStateManager.js +2 -3
- package/src/InteractiveMap/historyManager.js +4 -3
- package/src/config/appConfig.js +3 -1
- package/src/config/appConfig.test.js +4 -0
- package/src/config/defaults.js +3 -2
- package/src/config/events.js +8 -0
- package/src/config/mapTheme.js +8 -4
- package/src/config/mergeConfig.js +8 -2
- package/src/config/mergeConfig.test.js +19 -0
- package/src/config/symbolConfig.js +23 -16
- package/src/scss/main.scss +3 -0
- package/src/scss/tools/_border-focus.scss +0 -1
- package/src/services/eventBus.js +15 -0
- package/src/services/eventBus.test.js +11 -0
- package/src/services/hints.js +47 -0
- package/src/services/hints.test.js +110 -0
- package/src/services/patternRegistry.js +69 -1
- package/src/services/patternRegistry.test.js +112 -1
- package/src/services/reverseGeocode.js +4 -0
- package/src/services/reverseGeocode.test.js +11 -1
- package/src/services/symbolRegistry.js +152 -17
- package/src/services/symbolRegistry.test.js +141 -31
- package/src/types.js +93 -16
- package/src/utils/constrainKeyboardFocus.js +5 -5
- package/src/utils/detectInterfaceType.js +27 -5
- package/src/utils/detectInterfaceType.test.js +29 -3
- package/src/utils/mapStateSync.js +2 -2
- package/src/utils/mapStateSync.test.js +18 -0
- package/src/utils/patternUtils.js +4 -67
- package/src/utils/patternUtils.test.js +1 -123
- package/src/utils/symbolUtils.js +11 -13
- package/src/utils/symbolUtils.test.js +18 -26
- package/webpack.dev.mjs +4 -0
- package/webpack.umd.mjs +9 -6
- package/plugins/beta/datasets/adapters/maplibre/dist/esm/im-datasets-ml-adapter.js +0 -1
- package/plugins/beta/datasets/adapters/maplibre/dist/umd/im-datasets-ml-adapter.js +0 -2
- package/plugins/beta/datasets/adapters/maplibre/dist/umd/index.js +0 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +0 -2
- package/plugins/beta/datasets/dist/umd/index.js +0 -2
- package/plugins/interact/dist/css/index.css +0 -1
- package/plugins/interact/src/interact.scss +0 -24
- /package/plugins/beta/datasets/{adapters/maplibre/dist → dist/adapters/maplibre}/esm/index.js +0 -0
- /package/plugins/beta/datasets/{adapters/maplibre/dist/umd/im-datasets-ml-adapter.js.LICENSE.txt → dist/umd/maplibre/im-datasets-maplibre-adapter.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/dist/umd/{im-datasets-plugin.js.LICENSE.txt → maplibre/im-datasets-plugin.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/dist/umd/{index.js.LICENSE.txt → maplibre/index.js.LICENSE.txt} +0 -0
package/docs/api.md
CHANGED
|
@@ -248,6 +248,32 @@ new InteractiveMap('map', {
|
|
|
248
248
|
})
|
|
249
249
|
```
|
|
250
250
|
|
|
251
|
+
#### MapLibre provider options
|
|
252
|
+
|
|
253
|
+
`maplibreProvider()` accepts an optional config object.
|
|
254
|
+
|
|
255
|
+
##### `workerUrl`
|
|
256
|
+
**Type:** `string`
|
|
257
|
+
**Default:** `undefined`
|
|
258
|
+
|
|
259
|
+
URL to a separately hosted MapLibre worker file (`maplibre-gl-csp-worker.js`). Required when running under a Content Security Policy that blocks `blob:` worker URLs — a common restriction on government and enterprise platforms.
|
|
260
|
+
|
|
261
|
+
When set, MapLibre loads its rendering worker from this URL instead of generating an inline blob, so your CSP only needs `worker-src 'self'` rather than `worker-src blob:`.
|
|
262
|
+
|
|
263
|
+
The worker file ships with maplibre-gl and must be served from your own origin (copy from `node_modules/maplibre-gl/dist/maplibre-gl-csp-worker.js`).
|
|
264
|
+
|
|
265
|
+
**ESM:**
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
maplibreProvider({ workerUrl: '/your-assets-path/maplibre-gl-csp-worker.js' })
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**UMD:**
|
|
272
|
+
|
|
273
|
+
```js
|
|
274
|
+
defra.maplibreProvider({ workerUrl: '/your-assets-path/maplibre-gl-csp-worker.js' })
|
|
275
|
+
```
|
|
276
|
+
|
|
251
277
|
---
|
|
252
278
|
|
|
253
279
|
### `mapSize`
|
|
@@ -277,14 +303,27 @@ See [MapStyleConfig](./api/map-style-config.md) for full details.
|
|
|
277
303
|
|
|
278
304
|
---
|
|
279
305
|
|
|
280
|
-
### `
|
|
306
|
+
### `mapViewQueryParam`
|
|
281
307
|
**Type:** `string`
|
|
282
308
|
**Default:** `'mv'`
|
|
283
309
|
|
|
284
|
-
URL query parameter
|
|
310
|
+
URL query parameter used to control fullscreen/hybrid/buttonFirst state. Override if the default value clashes with an existing parameter on your page.
|
|
285
311
|
|
|
286
312
|
---
|
|
287
313
|
|
|
314
|
+
### `urlPosition`
|
|
315
|
+
**Type:** `'sync' | 'readOnly' | 'none'`
|
|
316
|
+
**Default:** `'sync'`
|
|
317
|
+
|
|
318
|
+
Controls how map center and zoom interact with the page URL.
|
|
319
|
+
|
|
320
|
+
| Value | Behaviour |
|
|
321
|
+
|---|---|
|
|
322
|
+
| `'sync'` | Reads center/zoom from the URL on load and writes back on pan/zoom — enables bookmarking and sharing the current map view |
|
|
323
|
+
| `'readOnly'` | Seeds the initial view from the URL but never writes back |
|
|
324
|
+
| `'none'` | Ignores the URL entirely — use when you don't want the user's pan/zoom to be persisted or shared |
|
|
325
|
+
---
|
|
326
|
+
|
|
288
327
|
### `markers`
|
|
289
328
|
**Type:** `MarkerConfig[]`
|
|
290
329
|
|
|
@@ -304,8 +343,6 @@ App-wide defaults for symbol and marker appearance.
|
|
|
304
343
|
| `symbol` | `'pin'` |
|
|
305
344
|
| `backgroundColor` | `'#ca3535'` |
|
|
306
345
|
| `foregroundColor` | `'#ffffff'` |
|
|
307
|
-
| `haloWidth` | `'1'` |
|
|
308
|
-
| `selectedWidth` | `'6'` |
|
|
309
346
|
|
|
310
347
|
```js
|
|
311
348
|
new InteractiveMap('map', {
|
|
@@ -525,6 +562,30 @@ interactiveMap.addMarker('home', [-0.1276, 51.5074], { backgroundColor: '#1d70b8
|
|
|
525
562
|
|
|
526
563
|
---
|
|
527
564
|
|
|
565
|
+
### `updateMarker(id, options)`
|
|
566
|
+
|
|
567
|
+
Update an existing marker's properties. Wont do anything if the marker id is not found.
|
|
568
|
+
|
|
569
|
+
Merges the provided options into the existing marker — unspecified properties are preserved. Pass `coords` inside `options` to move the marker to new coordinates.
|
|
570
|
+
|
|
571
|
+
| Parameter | Type | Description |
|
|
572
|
+
|-----------|------|-------------|
|
|
573
|
+
| `id` | `string` | Marker identifier to update |
|
|
574
|
+
| `options` | `MarkerOptions & { coords?: [number, number] }` | Properties to merge into the marker |
|
|
575
|
+
|
|
576
|
+
```js
|
|
577
|
+
// Show the label bubble on an existing marker
|
|
578
|
+
interactiveMap.updateMarker('home', { showLabel: true })
|
|
579
|
+
|
|
580
|
+
// Move the marker to new coordinates
|
|
581
|
+
interactiveMap.updateMarker('home', { coords: [-0.1276, 51.5074] })
|
|
582
|
+
|
|
583
|
+
// Change colour and move simultaneously
|
|
584
|
+
interactiveMap.updateMarker('home', { coords: [-0.1276, 51.5074], backgroundColor: '#d4351c' })
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
---
|
|
588
|
+
|
|
528
589
|
### `removeMarker(id)`
|
|
529
590
|
|
|
530
591
|
Remove a marker from the map.
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
background-color: #f4f8fb;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
.govuk-template__body.app-homepage #main-content {
|
|
13
|
+
background-color: #ffffff;
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
.app-section--features {
|
|
13
17
|
background-color: #f4f8fb;
|
|
14
18
|
border-bottom: 1px solid #8eb8dc;
|
|
@@ -26,6 +30,19 @@
|
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
/* Override prose-scope heading sizes to match pre-theme-downgrade for homepage sections. */
|
|
34
|
+
@import 'govuk-frontend/dist/govuk/base';
|
|
35
|
+
|
|
36
|
+
.govuk-template .app-prose-scope .app-section h2 {
|
|
37
|
+
@include govuk-font($size: 36, $weight: bold);
|
|
38
|
+
@include govuk-responsive-margin(6, 'bottom');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.govuk-template .app-prose-scope .app-section h3 {
|
|
42
|
+
@include govuk-font($size: 24, $weight: bold);
|
|
43
|
+
@include govuk-responsive-margin(4, 'bottom');
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
/* Hero image */
|
|
30
47
|
.govuk-template--rebranded .app-masthead .govuk-grid-row {
|
|
31
48
|
@media (min-width: 48.125em) {
|
|
@@ -35,7 +52,7 @@
|
|
|
35
52
|
|
|
36
53
|
.govuk-template--rebranded .app-masthead .govuk-grid-column-one-third-from-desktop {
|
|
37
54
|
@media (min-width: 48.125em) {
|
|
38
|
-
background-image: url('/images/hero.png');
|
|
55
|
+
background-image: url('https://defra.github.io/interactive-map/images/hero.png');
|
|
39
56
|
background-repeat: no-repeat;
|
|
40
57
|
background-position: center bottom;
|
|
41
58
|
background-size: 220px;
|
|
@@ -103,17 +120,6 @@
|
|
|
103
120
|
inset: 0;
|
|
104
121
|
}
|
|
105
122
|
|
|
106
|
-
/* Fix sticky footer: the theme gives flex: 1 0 auto to any govuk-width-container
|
|
107
|
-
that is a direct child of govuk-template__body-inner, but the phase banner div
|
|
108
|
-
also matches that selector and grows incorrectly on short pages. Move the
|
|
109
|
-
flex-grow to <main> instead so only the content area stretches. */
|
|
110
|
-
.govuk-template--rebranded .govuk-template__body-inner > .govuk-width-container {
|
|
111
|
-
flex: none;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
.govuk-template--rebranded .govuk-main-wrapper {
|
|
115
|
-
flex: 1 0 auto;
|
|
116
|
-
}
|
|
117
123
|
|
|
118
124
|
/* GOV.UK tabs — enhanced styles for all devices; React manages active state.
|
|
119
125
|
Extra specificity via .app-prose-scope required to override the theme. */
|
|
Binary file
|
package/docs/examples/index.mdx
CHANGED
|
@@ -2,11 +2,13 @@ import useBaseUrl from '@docusaurus/useBaseUrl'
|
|
|
2
2
|
import basicMapImg from '../assets/images/basic-map.jpg'
|
|
3
3
|
import buttonFirstImg from '../assets/images/button-first.jpg'
|
|
4
4
|
import markerPanelImg from '../assets/images/marker-panel.jpg'
|
|
5
|
+
import toggleMarkerLabelImg from '../assets/images/toggle-marker-label.jpg'
|
|
5
6
|
|
|
6
7
|
export function ExampleCards() {
|
|
7
8
|
const basicHref = useBaseUrl('/examples/basic-map')
|
|
8
9
|
const buttonHref = useBaseUrl('/examples/button-map')
|
|
9
10
|
const interactHref = useBaseUrl('/examples/add-marker-with-panel')
|
|
11
|
+
const toggleMarkerLabelHref = useBaseUrl('/examples/toggle-marker-label')
|
|
10
12
|
|
|
11
13
|
return (
|
|
12
14
|
<div className='govuk-grid-row'>
|
|
@@ -40,6 +42,16 @@ export function ExampleCards() {
|
|
|
40
42
|
</div>
|
|
41
43
|
</div>
|
|
42
44
|
</div>
|
|
45
|
+
<div className='govuk-grid-column-one-half'>
|
|
46
|
+
<div className='app-example-card'>
|
|
47
|
+
<img src={toggleMarkerLabelImg} alt='' />
|
|
48
|
+
<div className='app-example-card__body'>
|
|
49
|
+
<h2 className='govuk-heading-m'>
|
|
50
|
+
<a href={toggleMarkerLabelHref}>Toggle marker label on click</a>
|
|
51
|
+
</h2>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
43
55
|
</div>
|
|
44
56
|
)
|
|
45
57
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import DemoMapToggleMarkerLabel from '../../demo/DemoMapToggleMarkerLabel.js'
|
|
2
|
+
import CodeTabs from '../../demo/js/codeTabs.js'
|
|
3
|
+
|
|
4
|
+
# Toggle marker label on click
|
|
5
|
+
|
|
6
|
+
Add a marker with a hidden label, then use the interact plugin to show the label when the marker is selected and hide it when the user clicks elsewhere.
|
|
7
|
+
|
|
8
|
+
<DemoMapToggleMarkerLabel />
|
|
9
|
+
|
|
10
|
+
<CodeTabs tabs={[
|
|
11
|
+
{
|
|
12
|
+
label: 'ESM',
|
|
13
|
+
language: 'js',
|
|
14
|
+
code: `
|
|
15
|
+
import InteractiveMap from '@defra/interactive-map'
|
|
16
|
+
import maplibreProvider from '@defra/interactive-map/providers/maplibre'
|
|
17
|
+
import createInteractPlugin from '@defra/interactive-map/plugins/interact'
|
|
18
|
+
|
|
19
|
+
const interactPlugin = createInteractPlugin({
|
|
20
|
+
deselectOnClickOutside: true
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const map = new InteractiveMap('my-map', {
|
|
24
|
+
behaviour: 'inline',
|
|
25
|
+
mapProvider: maplibreProvider(),
|
|
26
|
+
mapStyle: {
|
|
27
|
+
url: 'https://your-tile-url/style.json',
|
|
28
|
+
attribution: 'Your tile attribution'
|
|
29
|
+
},
|
|
30
|
+
center: [-2.96, 54.43],
|
|
31
|
+
zoom: 15,
|
|
32
|
+
containerHeight: '500px',
|
|
33
|
+
plugins: [interactPlugin]
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
map.on('map:ready', () => {
|
|
37
|
+
map.addMarker('my-marker', [-2.96, 54.43], {
|
|
38
|
+
label: 'My location',
|
|
39
|
+
showLabel: false
|
|
40
|
+
})
|
|
41
|
+
interactPlugin.enable()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
map.on('interact:selectionchange', ({ selectedMarkers }) => {
|
|
45
|
+
map.updateMarker('my-marker', { showLabel: selectedMarkers.includes('my-marker') })
|
|
46
|
+
})
|
|
47
|
+
`
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: 'UMD',
|
|
51
|
+
language: 'html',
|
|
52
|
+
code: `
|
|
53
|
+
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
54
|
+
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
55
|
+
<script src="/your-assets-path/interact-plugin/index.js"></script>
|
|
56
|
+
|
|
57
|
+
<script>
|
|
58
|
+
const interactPlugin = defra.interactPlugin({
|
|
59
|
+
deselectOnClickOutside: true
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const map = new defra.InteractiveMap('my-map', {
|
|
63
|
+
behaviour: 'inline',
|
|
64
|
+
mapProvider: defra.maplibreProvider(),
|
|
65
|
+
mapStyle: {
|
|
66
|
+
url: 'https://your-tile-url/style.json',
|
|
67
|
+
attribution: 'Your tile attribution'
|
|
68
|
+
},
|
|
69
|
+
center: [-2.96, 54.43],
|
|
70
|
+
zoom: 15,
|
|
71
|
+
containerHeight: '500px',
|
|
72
|
+
plugins: [interactPlugin]
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
map.on('map:ready', () => {
|
|
76
|
+
map.addMarker('my-marker', [-2.96, 54.43], {
|
|
77
|
+
label: 'My location',
|
|
78
|
+
showLabel: false
|
|
79
|
+
})
|
|
80
|
+
interactPlugin.enable()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
map.on('interact:selectionchange', ({ selectedMarkers }) => {
|
|
84
|
+
map.updateMarker('my-marker', { showLabel: selectedMarkers.includes('my-marker') })
|
|
85
|
+
})
|
|
86
|
+
</script>
|
|
87
|
+
`
|
|
88
|
+
}
|
|
89
|
+
]} />
|
package/docs/plugins/datasets.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The datasets plugin renders GeoJSON and vector tile datasets on the map, with support for polygon, line, and symbol (point) layer types, sublayer style rules, layer visibility toggling, a key panel, and runtime style and data updates.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## ESM usage
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
import createDatasetsPlugin from '@defra/interactive-map/plugins/datasets'
|
|
@@ -33,6 +33,41 @@ const interactiveMap = new InteractiveMap({
|
|
|
33
33
|
})
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## UMD usage
|
|
37
|
+
|
|
38
|
+
Copy `plugins/beta/datasets/dist/umd/maplibre/` to `/your-assets-path/plugins/beta/datasets/umd/maplibre/`, then load the script tag. The MapLibre adapter is included — no `layerAdapter` config is needed.
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<script defer src="/your-assets-path/plugins/beta/datasets/umd/maplibre/index.js"></script>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const datasetsPlugin = defra.datasetsMaplibrePlugin({
|
|
46
|
+
datasets: [
|
|
47
|
+
{
|
|
48
|
+
id: 'my-parcels',
|
|
49
|
+
label: 'My parcels',
|
|
50
|
+
geojson: 'https://example.com/api/parcels',
|
|
51
|
+
minZoom: 10,
|
|
52
|
+
maxZoom: 24,
|
|
53
|
+
showInKey: true,
|
|
54
|
+
showInMenu: true,
|
|
55
|
+
style: {
|
|
56
|
+
stroke: '#d4351c',
|
|
57
|
+
strokeWidth: 2,
|
|
58
|
+
fill: 'transparent'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
> [!NOTE]
|
|
66
|
+
> **GOV.UK Prototype Kit** — skip the copy step. The file is served automatically. Use this path instead:
|
|
67
|
+
> ```html
|
|
68
|
+
> <script defer src="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/datasets/dist/umd/maplibre/index.js"></script>
|
|
69
|
+
> ```
|
|
70
|
+
|
|
36
71
|
## Options
|
|
37
72
|
|
|
38
73
|
Options are passed to the factory function when creating the plugin.
|
|
@@ -41,6 +76,9 @@ Options are passed to the factory function when creating the plugin.
|
|
|
41
76
|
|
|
42
77
|
### `layerAdapter`
|
|
43
78
|
|
|
79
|
+
> [!NOTE]
|
|
80
|
+
> UMD users using the `datasetsMaplibrePlugin` bundle do not need to set this — the MapLibre adapter is pre-configured.
|
|
81
|
+
|
|
44
82
|
**Type:** `LayerAdapter`
|
|
45
83
|
**Required**
|
|
46
84
|
|
package/docs/plugins/interact.md
CHANGED
|
@@ -85,9 +85,11 @@ layers: [
|
|
|
85
85
|
|----------|------|-------------|
|
|
86
86
|
| `layerId` | `string` | **Required.** The map layer identifier to enable selection on |
|
|
87
87
|
| `idProperty` | `string` | Property name used as the feature's unique identifier. If omitted, features are matched by index |
|
|
88
|
+
| `labelProperty` | `string` | Property name used as the feature's display label in the keyboard-accessible listbox. **Required for features to appear in keyboard navigation** |
|
|
88
89
|
| `selectedStroke` | `string` | Overrides the selection stroke colour for this layer. Defaults to `MapStyleConfig.selectedColor` |
|
|
89
90
|
| `selectedFill` | `string` | Overrides the selection fill colour for this layer. Defaults to `transparent` |
|
|
90
91
|
| `selectedStrokeWidth` | `number` | Overrides the selection stroke width for this layer. Defaults to `3` |
|
|
92
|
+
| `activeStroke` | `string` | Overrides the keyboard cursor ring colour for this layer. Defaults to `MapStyleConfig.activeColor` |
|
|
91
93
|
|
|
92
94
|
#### Finding layer IDs
|
|
93
95
|
|
|
@@ -109,14 +111,6 @@ When `true`, clicking additional features adds them to the selection rather than
|
|
|
109
111
|
|
|
110
112
|
---
|
|
111
113
|
|
|
112
|
-
### `contiguous`
|
|
113
|
-
**Type:** `boolean`
|
|
114
|
-
**Default:** `false`
|
|
115
|
-
|
|
116
|
-
When `true`, only features that touch or overlap the existing selection can be added. Uses spatial intersection to determine contiguity. Works with polygons, lines, and points.
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
114
|
### `deselectOnClickOutside`
|
|
121
115
|
**Type:** `boolean`
|
|
122
116
|
**Default:** `false`
|
|
@@ -207,7 +201,7 @@ interactPlugin.disable()
|
|
|
207
201
|
|
|
208
202
|
### `clear()`
|
|
209
203
|
|
|
210
|
-
Clear all selected features and markers
|
|
204
|
+
Clear all selected features and markers.
|
|
211
205
|
|
|
212
206
|
```js
|
|
213
207
|
interactPlugin.clear()
|
|
@@ -350,8 +344,7 @@ Emitted whenever the selected features or selected markers change.
|
|
|
350
344
|
],
|
|
351
345
|
selectedMarkers: ['...'], // array of selected marker IDs
|
|
352
346
|
selectionBounds: [west, south, east, north] | null,
|
|
353
|
-
|
|
354
|
-
canSplit: boolean // true when exactly one Polygon or MultiPolygon is selected
|
|
347
|
+
contiguous: boolean // true when 2+ features are selected and all form a single contiguous group
|
|
355
348
|
}
|
|
356
349
|
```
|
|
357
350
|
|
package/docusaurus.config.cjs
CHANGED
|
@@ -45,7 +45,7 @@ const config = {
|
|
|
45
45
|
return {
|
|
46
46
|
name: 'custom-css',
|
|
47
47
|
getClientModules() {
|
|
48
|
-
return [require.resolve('./docs/assets/css/docusaurus.
|
|
48
|
+
return [require.resolve('./docs/assets/css/docusaurus.scss')];
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
},
|
|
@@ -92,6 +92,7 @@ const config = {
|
|
|
92
92
|
{ text: 'Basic map', href: '/examples/basic-map' },
|
|
93
93
|
{ text: 'Button-triggered map', href: '/examples/button-map' },
|
|
94
94
|
{ text: 'Add a marker with a panel', href: '/examples/add-marker-with-panel' },
|
|
95
|
+
{ text: 'Toggle marker label on click', href: '/examples/toggle-marker-label' },
|
|
95
96
|
],
|
|
96
97
|
},
|
|
97
98
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/interactive-map",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23-alpha",
|
|
4
4
|
"description": "An accessible map component",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,12 +41,10 @@
|
|
|
41
41
|
"require": "./plugins/interact/dist/umd/index.js"
|
|
42
42
|
},
|
|
43
43
|
"./plugins/datasets": {
|
|
44
|
-
"import": "./plugins/beta/datasets/dist/esm/index.js"
|
|
45
|
-
"require": "./plugins/beta/datasets/dist/umd/index.js"
|
|
44
|
+
"import": "./plugins/beta/datasets/dist/esm/index.js"
|
|
46
45
|
},
|
|
47
46
|
"./plugins/datasets/adapters/maplibre": {
|
|
48
|
-
"import": "./plugins/beta/datasets/adapters/maplibre/
|
|
49
|
-
"require": "./plugins/beta/datasets/adapters/maplibre/dist/umd/index.js"
|
|
47
|
+
"import": "./plugins/beta/datasets/dist/adapters/maplibre/esm/index.js"
|
|
50
48
|
},
|
|
51
49
|
"./plugins/map-styles": {
|
|
52
50
|
"import": "./plugins/beta/map-styles/dist/esm/index.js",
|
|
@@ -131,11 +129,13 @@
|
|
|
131
129
|
"@babel/plugin-transform-runtime": "^7.29.0",
|
|
132
130
|
"@babel/preset-env": "^7.28.0",
|
|
133
131
|
"@babel/preset-react": "^7.27.1",
|
|
134
|
-
"@defra/docusaurus-theme-govuk": "^0.0.
|
|
135
|
-
"@docusaurus/core": "^3.
|
|
136
|
-
"@docusaurus/module-type-aliases": "^3.
|
|
137
|
-
"@docusaurus/plugin-content-docs": "^3.
|
|
138
|
-
"@docusaurus/
|
|
132
|
+
"@defra/docusaurus-theme-govuk": "^0.0.22-alpha",
|
|
133
|
+
"@docusaurus/core": "^3.10.1",
|
|
134
|
+
"@docusaurus/module-type-aliases": "^3.10.1",
|
|
135
|
+
"@docusaurus/plugin-content-docs": "^3.10.1",
|
|
136
|
+
"@docusaurus/theme-common": "^3.10.1",
|
|
137
|
+
"@docusaurus/tsconfig": "^3.10.1",
|
|
138
|
+
"@easyops-cn/docusaurus-search-local": "^0.55.1",
|
|
139
139
|
"@esri/arcgis-rest-request": "^4.7.3",
|
|
140
140
|
"@mapbox/mapbox-gl-draw": "^1.5.0",
|
|
141
141
|
"@mdx-js/react": "^3.1.1",
|
|
@@ -208,8 +208,6 @@
|
|
|
208
208
|
},
|
|
209
209
|
"dependencies": {
|
|
210
210
|
"@babel/runtime": "^7.28.6",
|
|
211
|
-
"@docusaurus/theme-common": "^3.9.2",
|
|
212
|
-
"@easyops-cn/docusaurus-search-local": "^0.55.0",
|
|
213
211
|
"@turf/area": "^7.2.0",
|
|
214
212
|
"@turf/bbox": "^7.3.4",
|
|
215
213
|
"@turf/bearing": "^7.3.3",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";var r=(e,t,r,a,i)=>{if(e.getLayer(t)){var o=((e,t,r)=>{if(!r||0===r.length)return e;var a=["!",["in",t?["to-string",["get",t]]:["to-string",["id"]],["literal",r.map(String)]]];return e?["all",e,a]:a})(r,a,i);e.setFilter(t,o)}},a=e=>!(!e.fillPattern&&!e.fillPatternSvgContent),i=e=>"string"==typeof e.geojson&&!!e.idProperty&&"function"==typeof e.transformRequest,o=e=>{var t=0;for(var r of e)t=Math.trunc((t<<5)-t+r.codePointAt(0));return Math.abs(t).toString(36)},l=e=>{if(e.tiles){var t=Array.isArray(e.tiles)?e.tiles.join(","):e.tiles;return"tiles-".concat(o(t))}return e.geojson?i(e)?"geojson-dynamic-".concat(e.id):"string"==typeof e.geojson?"geojson-".concat(o(e.geojson)):"geojson-".concat(e.id):"source-".concat(e.id)},s=e=>{if((e=>!!e.symbol)(e))return{fillLayerId:null,strokeLayerId:null,symbolLayerId:e.id};var t=!!e.fill&&"transparent"!==e.fill||a(e),r=!!e.stroke,i=t?e.id:null,o=null;return r&&(o=t?"".concat(e.id,"-stroke"):e.id),{fillLayerId:i,strokeLayerId:o,symbolLayerId:null}},n=(e,t)=>({fillLayerId:"".concat(e,"-").concat(t),strokeLayerId:"".concat(e,"-").concat(t,"-stroke"),symbolLayerId:"".concat(e,"-").concat(t,"-symbol")}),y=e=>{var t;if(null!==(t=e.sublayers)&&void 0!==t&&t.length)return e.sublayers.flatMap(t=>{var{fillLayerId:r,strokeLayerId:a,symbolLayerId:i}=n(e.id,t.id);return[a,r,i]});var{fillLayerId:r,strokeLayerId:a,symbolLayerId:i}=s(e);return[a,r,i].filter(Boolean)},d=(e,t)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&e[t])return e[t];var r=Object.values(e)[0];return null!=r?r:null}return null},m=["stroke","fill","fillPattern","fillPatternSvgContent","symbol","symbolSvgContent"];function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,a)}return r}var u=(e,t)=>{return"symbolDescription"in t?t.symbolDescription:(r=t,m.some(e=>e in r)?void 0:e.symbolDescription);var r},c=(e,r)=>{var a,i,o,l,s,n,y,d,m,c,f,b,v,g,h,_,L,P=r.style||{},S=(_=e.filter,L=r.filter,_&&L?["all",_,L]:L||_||null);return function(e){for(var r=1;r<arguments.length;r++){var a=null!=arguments[r]?arguments[r]:{};r%2?p(Object(a),!0).forEach(function(r){t(e,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):p(Object(a)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}({id:r.id,label:r.label,stroke:null!==(a=P.stroke)&&void 0!==a?a:e.stroke,strokeWidth:null!==(i=P.strokeWidth)&&void 0!==i?i:e.strokeWidth,strokeDashArray:null!==(o=P.strokeDashArray)&&void 0!==o?o:e.strokeDashArray,opacity:null!==(l=P.opacity)&&void 0!==l?l:e.opacity,keySymbolShape:null!==(s=P.keySymbolShape)&&void 0!==s?s:e.keySymbolShape,symbolDescription:u(e,P),showInKey:null!==(n=r.showInKey)&&void 0!==n?n:e.showInKey,showInMenu:null!==(y=r.showInMenu)&&void 0!==y&&y,filter:S,minZoom:e.minZoom,maxZoom:e.maxZoom,symbol:null!==(d=P.symbol)&&void 0!==d?d:e.symbol,symbolSvgContent:null!==(m=P.symbolSvgContent)&&void 0!==m?m:e.symbolSvgContent,symbolViewBox:null!==(c=P.symbolViewBox)&&void 0!==c?c:e.symbolViewBox,symbolAnchor:null!==(f=P.symbolAnchor)&&void 0!==f?f:e.symbolAnchor,symbolBackgroundColor:null!==(b=P.symbolBackgroundColor)&&void 0!==b?b:e.symbolBackgroundColor,symbolForegroundColor:null!==(v=P.symbolForegroundColor)&&void 0!==v?v:e.symbolForegroundColor,symbolHaloWidth:null!==(g=P.symbolHaloWidth)&&void 0!==g?g:e.symbolHaloWidth,symbolGraphic:null!==(h=P.symbolGraphic)&&void 0!==h?h:e.symbolGraphic},((e,t)=>{var r,a;return t.fillPattern||t.fillPatternSvgContent?{fillPattern:t.fillPattern,fillPatternSvgContent:t.fillPatternSvgContent,fillPatternForegroundColor:null!==(r=t.fillPatternForegroundColor)&&void 0!==r?r:e.fillPatternForegroundColor,fillPatternBackgroundColor:null!==(a=t.fillPatternBackgroundColor)&&void 0!==a?a:e.fillPatternBackgroundColor}:"fill"in t?{fill:t.fill}:{fill:e.fill,fillPattern:e.fillPattern,fillPatternSvgContent:e.fillPatternSvgContent,fillPatternForegroundColor:e.fillPatternForegroundColor,fillPatternBackgroundColor:e.fillPatternBackgroundColor}})(e,P))},f=(e,t)=>e.flatMap(e=>{var t,r=a(e)?[e]:[];return null!==(t=e.sublayers)&&void 0!==t&&t.length&&e.sublayers.forEach(t=>{var i=c(e,t);a(i)&&r.push(i)}),r}),b=e=>!(!e.symbol&&!e.symbolSvgContent),v=e=>{var[t,r]=e,a=(e=>e<=.25?"left":e>=.75?"right":"")(t),i=(e=>e<=.25?"top":e>=.75?"bottom":"")(r);return i+(a&&i?"-":"")+a||"center"},g=e=>e.flatMap(e=>{var t,r=b(e)?[e]:[];return null!==(t=e.sublayers)&&void 0!==t&&t.length&&e.sublayers.forEach(t=>{var a=c(e,t);b(a)&&r.push(a)}),r});function h(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,a)}return r}function _(e){for(var r=1;r<arguments.length;r++){var a=null!=arguments[r]?arguments[r]:{};r%2?h(Object(a),!0).forEach(function(r){t(e,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):h(Object(a)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}var L=(e,t,r,i,o,l,s)=>{var{mapStyleId:n,patternRegistry:y,pixelRatio:m=1}=s;if(r&&!e.getLayer(r)&&(t.fill||a(t))){var p=a(t)?y.getPatternImageId(t,n,m):null,u=p?{"fill-pattern":p,"fill-opacity":t.opacity||1}:{"fill-color":d(t.fill,n),"fill-opacity":t.opacity||1};e.addLayer(_({id:r,type:"fill",source:i,"source-layer":o,minzoom:t.minZoom,maxzoom:t.maxZoom,layout:{visibility:l},paint:u},t.filter?{filter:t.filter}:{}))}},P=(e,t,r,a,i,o,l)=>{r&&t.stroke&&!e.getLayer(r)&&e.addLayer(_({id:r,type:"line",source:a,"source-layer":i,minzoom:t.minZoom,maxzoom:t.maxZoom,layout:{visibility:o},paint:_({"line-color":d(t.stroke,l),"line-width":t.strokeWidth||1,"line-opacity":t.opacity||1},t.strokeDashArray?{"line-dasharray":t.strokeDashArray}:{})},t.filter?{filter:t.filter}:{}))},S=(e,t,r,a,i,o,l)=>{var{mapStyle:s,symbolRegistry:n,pixelRatio:y}=l;if(r&&!e.getLayer(r)){var d=n.getSymbolDef(t);if(d){var m=n.getSymbolImageId(t,s,!1,y);if(m){var p=((e,t)=>{var r;return e.symbolAnchor?e.symbolAnchor:null!==(r=null==t?void 0:t.anchor)&&void 0!==r?r:[.5,.5]})(t,d);e.addLayer(_({id:r,type:"symbol",source:a,"source-layer":i,minzoom:t.minZoom,maxzoom:t.maxZoom,layout:{visibility:o,"icon-image":m,"icon-anchor":v(p),"icon-allow-overlap":!0}},t.filter?{filter:t.filter}:{}))}}}},I=(e,t,r,a,i,o)=>{var l,{mapStyle:s,symbolRegistry:y,patternRegistry:d,pixelRatio:m}=o,p=s.id,u=c(t,r),{fillLayerId:f,strokeLayerId:v,symbolLayerId:g}=n(t.id,r.id),h="hidden"===t.visibility,_="hidden"===(null===(l=t.sublayerVisibility)||void 0===l?void 0:l[r.id]),I=h||_?"none":"visible";b(u)&&y?S(e,u,g,a,i,I,{mapStyle:s,symbolRegistry:y,pixelRatio:m}):(L(e,u,f,a,i,I,{mapStyleId:p,patternRegistry:d,pixelRatio:m}),P(e,u,v,a,i,I,p))},R=(e,t,r,a,o,n)=>{var y,d,m=r.id,p=l(t);((e,t,r)=>{if(!e.getSource(r))if(t.tiles)e.addSource(r,{type:"vector",tiles:t.tiles,minzoom:t.minZoom||0,maxzoom:t.maxZoom||22});else if(t.geojson){var a=i(t)?{type:"FeatureCollection",features:[]}:t.geojson;e.addSource(r,{type:"geojson",data:a,generateId:!0})}})(e,t,p);var u=null!==(y=t.tiles)&&void 0!==y&&y.length?t.sourceLayer:void 0;if(null!==(d=t.sublayers)&&void 0!==d&&d.length)return t.sublayers.forEach(i=>{I(e,t,i,p,u,{mapStyle:r,symbolRegistry:a,patternRegistry:o,pixelRatio:n})}),p;var{fillLayerId:c,strokeLayerId:f,symbolLayerId:v}=s(t),g="hidden"===t.visibility?"none":"visible";return b(t)&&a?(S(e,t,v,p,u,g,{mapStyle:r,symbolRegistry:a,pixelRatio:n}),p):(L(e,t,c,p,u,g,{mapStyleId:m,patternRegistry:o,pixelRatio:n}),P(e,t,f,p,u,g,m),p)};class O{constructor(e,t,r){this._mapProvider=e,this._map=e.map,this._symbolRegistry=t,this._patternRegistry=r,this._datasetSourceMap=new Map,this._symbolLayerIds=new Set}init(t,r){var a=this;return e(function*(){var e=r.id;yield Promise.all([a._mapProvider.addPatternsToMap(f(t,a._patternRegistry),e,a._patternRegistry),a._mapProvider.addSymbolsToMap(g(t),r,a._symbolRegistry)]),a._symbolLayerIds.clear(),t.forEach(e=>a._addLayers(e,r)),yield new Promise(e=>a._map.once("idle",e))})()}destroy(e){var t=new Set;e.forEach(e=>{var r=l(e);this._getLayersUsingSource(r).forEach(e=>{this._map.getLayer(e)&&this._map.removeLayer(e)}),!t.has(r)&&this._map.getSource(r)&&(this._map.removeSource(r),t.add(r))}),this._datasetSourceMap.clear()}onStyleChange(t,r,a,i){var o=this;return e(function*(){yield new Promise(e=>o._map.once("idle",e));var e=r.id;yield Promise.all([o._mapProvider.addPatternsToMap(f(t,o._patternRegistry),e,o._patternRegistry),o._mapProvider.addSymbolsToMap(g(t),r,o._symbolRegistry)]),o._symbolLayerIds.clear(),t.forEach(e=>o._addLayers(e,r)),i.forEach(e=>e.reapply()),Object.entries(a).forEach(e=>{var[r,{idProperty:a,ids:i}]=e,l=t.find(e=>e.id===r);l&&o._applyFeatureFilter(l,a,i)})})()}onSizeChange(t,r){var i=this;return e(function*(){yield Promise.all([i._mapProvider.addSymbolsToMap(g(t),r,i._symbolRegistry),i._mapProvider.addPatternsToMap(f(t,i._patternRegistry),r.id,i._patternRegistry)]),t.forEach(e=>{var t;if(y(e).forEach(t=>{if(i._symbolLayerIds.has(t)&&i._map.getLayer(t)){var a=i._symbolRegistry.getSymbolImageId(e,r,!1,i._pixelRatio);a&&i._map.setLayoutProperty(t,"icon-image",a)}}),a(e)){var{fillLayerId:o}=s(e);if(i._map.getLayer(o)){var l=i._patternRegistry.getPatternImageId(e,r.id,i._pixelRatio);l&&i._map.setPaintProperty(o,"fill-pattern",l)}}null===(t=e.sublayers)||void 0===t||t.forEach(t=>{var o=c(e,t),{symbolLayerId:l,fillLayerId:s}=n(e.id,t.id);if(i._map.getLayer(l)){var y=i._symbolRegistry.getSymbolImageId(o,r,!1,i._pixelRatio);y&&i._map.setLayoutProperty(l,"icon-image",y)}if(a(o)&&i._map.getLayer(s)){var d=i._patternRegistry.getPatternImageId(o,r.id,i._pixelRatio);d&&i._map.setPaintProperty(s,"fill-pattern",d)}})})})()}addDataset(e,t){this._addLayers(e,t)}removeDataset(e,t){var r=l(e);y(e).forEach(e=>{this._map.getLayer(e)&&this._map.removeLayer(e),this._symbolLayerIds.delete(e)}),!t.some(t=>t.id!==e.id&&l(t)===r)&&this._map.getSource(r)&&this._map.removeSource(r),this._datasetSourceMap.delete(e.id)}showDataset(e){this._setDatasetVisibility(e,"visible")}hideDataset(e){this._setDatasetVisibility(e,"none")}showSublayer(e,t){var{fillLayerId:r,strokeLayerId:a,symbolLayerId:i}=n(e,t);[r,a,i].forEach(e=>{this._map.getLayer(e)&&this._map.setLayoutProperty(e,"visibility","visible")})}hideSublayer(e,t){var{fillLayerId:r,strokeLayerId:a,symbolLayerId:i}=n(e,t);[r,a,i].forEach(e=>{this._map.getLayer(e)&&this._map.setLayoutProperty(e,"visibility","none")})}showFeatures(e,t,r){this._applyFeatureFilter(e,t,r)}hideFeatures(e,t,r){this._applyFeatureFilter(e,t,r)}setStyle(t,r){var a=this;return e(function*(){var e=r.id;y(t).forEach(e=>{a._map.getLayer(e)&&a._map.removeLayer(e),a._symbolLayerIds.delete(e)}),yield Promise.all([a._mapProvider.addPatternsToMap(f([t],a._patternRegistry),e,a._patternRegistry),a._mapProvider.addSymbolsToMap(g([t]),r,a._symbolRegistry)]),a._addLayers(t,r)})()}setSublayerStyle(t,r,a){var i=this;return e(function*(){var e,o,l=a.id,s=i._pixelRatio,{fillLayerId:y,strokeLayerId:d,symbolLayerId:m}=n(t.id,r);[y,d,m].forEach(e=>{i._map.getLayer(e)&&i._map.removeLayer(e),i._symbolLayerIds.delete(e)});var p=null===(e=t.sublayers)||void 0===e?void 0:e.find(e=>e.id===r);if(p){yield Promise.all([i._mapProvider.addPatternsToMap(f([t],i._patternRegistry),l,i._patternRegistry),i._mapProvider.addSymbolsToMap(g([t]),a,i._symbolRegistry)]);var u=i._datasetSourceMap.get(t.id),c=null!==(o=t.tiles)&&void 0!==o&&o.length?t.sourceLayer:void 0;I(i._map,t,p,u,c,{mapStyle:a,symbolRegistry:i._symbolRegistry,patternRegistry:i._patternRegistry,pixelRatio:s}),i._maintainSymbolOrdering(t)}})()}setOpacity(e,t){var r=this._map.getStyle();null!=r&&r.layers&&r.layers.filter(t=>t.id===e||t.id.startsWith("".concat(e,"-"))).forEach(e=>this._setPaintOpacity(e.id,t))}setSublayerOpacity(e,t,r){var{fillLayerId:a,strokeLayerId:i}=n(e,t);this._setPaintOpacity(a,r),this._setPaintOpacity(i,r)}setData(e,t){var r=this._datasetSourceMap.get(e);if(r){var a=this._map.getSource(r);a&&"function"==typeof a.setData&&a.setData(t)}}get _pixelRatio(){return this._mapProvider.map.getPixelRatio()}_addLayers(e,t){var r=R(this._map,e,t,this._symbolRegistry,this._patternRegistry,this._pixelRatio);this._datasetSourceMap.set(e.id,r),this._maintainSymbolOrdering(e)}_getFirstSymbolLayerId(){var e,t=this._map.getStyle();if(null==t||!t.layers)return null;var r=t.layers.find(e=>this._symbolLayerIds.has(e.id));return null!==(e=null==r?void 0:r.id)&&void 0!==e?e:null}_maintainSymbolOrdering(e){var t=y(e).filter(e=>e&&this._map.getLayer(e));t.forEach(e=>{var t;"symbol"===(null===(t=this._map.getLayer(e))||void 0===t?void 0:t.type)?this._symbolLayerIds.add(e):this._symbolLayerIds.delete(e)});var r=this._getFirstSymbolLayerId();r&&t.forEach(e=>{this._symbolLayerIds.has(e)||this._map.moveLayer(e,r)})}_setDatasetVisibility(e,t){var r=this._map.getStyle();null!=r&&r.layers&&r.layers.filter(t=>t.id===e||t.id.startsWith("".concat(e,"-"))).forEach(e=>this._map.setLayoutProperty(e.id,"visibility",t))}_applyFeatureFilter(e,t,a){var i;if(null!==(i=e.sublayers)&&void 0!==i&&i.length)e.sublayers.forEach(i=>{var{fillLayerId:o,strokeLayerId:l}=n(e.id,i.id),s=e.filter&&i.filter?["all",e.filter,i.filter]:i.filter||e.filter||null;r(this._map,o,s,t,a),r(this._map,l,s,t,a)});else{var{fillLayerId:o,strokeLayerId:l,symbolLayerId:y}=s(e),d=e.filter||null;[o,l,y].filter(Boolean).forEach(e=>{r(this._map,e,d,t,a)})}}_setPaintOpacity(e,t){var r=this._map.getLayer(e);if(r){var a={line:"line-opacity",symbol:"icon-opacity"}[r.type]||"fill-opacity";this._map.setPaintProperty(e,a,t)}}_getLayersUsingSource(e){var t=this._map.getStyle();return null!=t&&t.layers?t.layers.filter(t=>t.source===e).map(e=>e.id):[]}}export{O as default};
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
.am-c-datasets-key-symbol {
|
|
55
55
|
position: relative;
|
|
56
56
|
flex-shrink: 0;
|
|
57
|
-
margin: 0 13px 0
|
|
57
|
+
margin: 0 13px 0 3px;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
.am-c-datasets-key-symbol--point {
|
|
61
|
-
margin: -
|
|
61
|
+
margin: -12px 1px -12px -9px;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
.im-c-datasets-layers--has-groups > *:not(:first-child) {
|