@defra/interactive-map 0.0.22-alpha → 0.0.24-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/images/light-raster-thumb.jpg +0 -0
- package/assets/images/outdoor-raster-thumb.jpg +0 -0
- package/assets/images/road-raster-thumb.jpg +0 -0
- 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 +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 +24 -2
- 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/interact.md +4 -11
- package/docs/plugins/search.md +70 -0
- package/docusaurus.config.cjs +2 -1
- package/package.json +23 -9
- package/plugins/beta/datasets/dist/adapters/maplibre/esm/im-datasets-ml-adapter.js +1 -1
- 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 +1 -1
- package/plugins/beta/datasets/dist/umd/maplibre/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/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/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/css/index.css +1 -21
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/src/api/editFeature.js +9 -4
- package/plugins/beta/draw-ml/src/modes/createDrawMode.js +11 -3
- 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 +68 -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/esm/index.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/plugins/search/src/Search.jsx +2 -1
- package/plugins/search/src/components/CloseButton/CloseButton.module.scss +2 -0
- package/plugins/search/src/components/Form/Form.jsx +11 -7
- package/plugins/search/src/components/Form/Form.test.jsx +23 -1
- 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/datasets.js +2 -2
- package/plugins/search/src/datasets.test.js +1 -1
- package/plugins/search/src/defaults.js +7 -1
- package/plugins/search/src/events/fetchSuggestions.js +13 -10
- package/plugins/search/src/events/fetchSuggestions.test.js +14 -1
- package/plugins/search/src/events/formHandlers.js +2 -4
- package/plugins/search/src/events/formHandlers.test.js +3 -3
- package/plugins/search/src/events/inputHandlers.js +1 -1
- package/plugins/search/src/events/inputHandlers.test.js +1 -1
- package/plugins/search/src/events/suggestionHandlers.js +2 -1
- package/plugins/search/src/events/suggestionHandlers.test.js +7 -1
- package/plugins/search/src/index.js +3 -7
- package/plugins/search/src/reducer.js +10 -5
- package/plugins/search/src/reducer.test.js +2 -1
- package/plugins/search/src/search.scss +1 -0
- package/plugins/search/src/utils/parseOsNamesResults.js +3 -3
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/src/esriProvider.js +4 -0
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -0
- package/providers/beta/openlayers/dist/esm/index.js +1 -0
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +2 -0
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js.LICENSE.txt +1 -0
- package/providers/beta/openlayers/dist/umd/index.js +2 -0
- package/providers/beta/openlayers/dist/umd/index.js.LICENSE.txt +1 -0
- package/providers/beta/openlayers/src/appEvents.js +50 -0
- package/providers/beta/openlayers/src/appEvents.test.js +140 -0
- package/providers/beta/openlayers/src/defaults.js +36 -0
- package/providers/beta/openlayers/src/index.js +21 -0
- package/providers/beta/openlayers/src/mapEvents.js +132 -0
- package/providers/beta/openlayers/src/mapEvents.test.js +197 -0
- package/providers/beta/openlayers/src/openlayersProvider.js +234 -0
- package/providers/beta/openlayers/src/openlayersProvider.test.js +331 -0
- package/providers/beta/openlayers/src/utils/spatial.js +142 -0
- package/providers/beta/openlayers/src/utils/spatial.test.js +117 -0
- package/providers/beta/openlayers/src/utils/zoom.js +26 -0
- package/providers/beta/openlayers/src/utils/zoom.test.js +23 -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 +1 -1
- package/providers/maplibre/src/index.test.js +9 -14
- 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 +112 -57
- package/providers/maplibre/src/utils/highlightFeatures.test.js +179 -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 +22 -19
- package/providers/maplibre/src/utils/patternImages.test.js +146 -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 +14 -3
- 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/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 +98 -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 -1
- 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 +163 -94
- package/src/App/hooks/useModalPanelBehaviour.test.js +2 -1
- 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/AppProvider.test.jsx +5 -0
- package/src/App/store/MapProvider.test.jsx +8 -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 +12 -0
- package/src/InteractiveMap/InteractiveMap.test.js +2 -0
- package/src/config/appConfig.js +3 -1
- package/src/config/appConfig.test.js +4 -0
- package/src/config/defaults.js +1 -1
- package/src/config/events.js +8 -0
- package/src/config/mapTheme.js +8 -4
- 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/announcer.test.js +5 -7
- 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 +71 -14
- 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/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 +6 -1
- package/webpack.umd.mjs +1 -0
- package/plugins/interact/dist/css/index.css +0 -1
- package/plugins/interact/src/interact.scss +0 -24
package/docs/api.md
CHANGED
|
@@ -343,8 +343,6 @@ App-wide defaults for symbol and marker appearance.
|
|
|
343
343
|
| `symbol` | `'pin'` |
|
|
344
344
|
| `backgroundColor` | `'#ca3535'` |
|
|
345
345
|
| `foregroundColor` | `'#ffffff'` |
|
|
346
|
-
| `haloWidth` | `'1'` |
|
|
347
|
-
| `selectedWidth` | `'6'` |
|
|
348
346
|
|
|
349
347
|
```js
|
|
350
348
|
new InteractiveMap('map', {
|
|
@@ -564,6 +562,30 @@ interactiveMap.addMarker('home', [-0.1276, 51.5074], { backgroundColor: '#1d70b8
|
|
|
564
562
|
|
|
565
563
|
---
|
|
566
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
|
+
|
|
567
589
|
### `removeMarker(id)`
|
|
568
590
|
|
|
569
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/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/docs/plugins/search.md
CHANGED
|
@@ -116,6 +116,20 @@ CSS width of the search input on tablet and desktop. For example `'300px'`.
|
|
|
116
116
|
|
|
117
117
|
---
|
|
118
118
|
|
|
119
|
+
### `placeholder`
|
|
120
|
+
**Type:** `string`
|
|
121
|
+
**Default:** `'Search'`
|
|
122
|
+
|
|
123
|
+
Placeholder text shown in the search input when it is empty.
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
searchPlugin({
|
|
127
|
+
placeholder: 'Search for a location'
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
119
133
|
### `expanded`
|
|
120
134
|
**Type:** `boolean`
|
|
121
135
|
**Default:** `false`
|
|
@@ -127,6 +141,62 @@ Controls whether the search input is always visible or hidden behind an open but
|
|
|
127
141
|
|
|
128
142
|
---
|
|
129
143
|
|
|
144
|
+
### `minSearchLength`
|
|
145
|
+
**Type:** `number`
|
|
146
|
+
**Default:** `3`
|
|
147
|
+
|
|
148
|
+
Minimum number of characters the user must type before a search is triggered.
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
searchPlugin({
|
|
152
|
+
minSearchLength: 4
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
### `maxSuggestions`
|
|
159
|
+
**Type:** `number`
|
|
160
|
+
**Default:** `8`
|
|
161
|
+
|
|
162
|
+
Maximum number of suggestions shown in the autocomplete list. Applies to OS Names results; custom datasets control their own result counts via `parseResults`.
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
searchPlugin({
|
|
166
|
+
maxSuggestions: 5
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### `noResultsMessage`
|
|
173
|
+
**Type:** `string`
|
|
174
|
+
**Default:** `'No results available'`
|
|
175
|
+
|
|
176
|
+
Message shown below the search input when a query returns no results.
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
searchPlugin({
|
|
180
|
+
noResultsMessage: 'No matching locations found'
|
|
181
|
+
})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
### `searchErrorMessage`
|
|
187
|
+
**Type:** `string`
|
|
188
|
+
**Default:** `'Sorry, there was a problem with search'`
|
|
189
|
+
|
|
190
|
+
Message shown below the search input when one or more datasets returns an error response. Shown in place of `noResultsMessage` when an error occurs.
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
searchPlugin({
|
|
194
|
+
searchErrorMessage: 'Search is temporarily unavailable'
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
130
200
|
### `includeModes`
|
|
131
201
|
**Type:** `string[]`
|
|
132
202
|
|
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.24-alpha",
|
|
4
4
|
"description": "An accessible map component",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"./providers/esri": {
|
|
25
25
|
"import": "./providers/beta/esri/dist/esm/index.js"
|
|
26
26
|
},
|
|
27
|
+
"./providers/openlayers": {
|
|
28
|
+
"import": "./providers/beta/openlayers/dist/esm/index.js",
|
|
29
|
+
"require": "./providers/beta/openlayers/dist/umd/index.js"
|
|
30
|
+
},
|
|
27
31
|
"./plugins/scale-bar": {
|
|
28
32
|
"import": "./plugins/beta/scale-bar/dist/esm/index.js",
|
|
29
33
|
"require": "./plugins/beta/scale-bar/dist/umd/index.js"
|
|
@@ -116,24 +120,36 @@
|
|
|
116
120
|
]
|
|
117
121
|
},
|
|
118
122
|
"peerDependencies": {
|
|
119
|
-
"@arcgis/core": "^5.0.9"
|
|
123
|
+
"@arcgis/core": "^5.0.9",
|
|
124
|
+
"ol": "^10.9.0",
|
|
125
|
+
"proj4": "^2.20.8"
|
|
120
126
|
},
|
|
121
127
|
"peerDependenciesMeta": {
|
|
122
128
|
"@arcgis/core": {
|
|
123
129
|
"optional": true
|
|
130
|
+
},
|
|
131
|
+
"ol": {
|
|
132
|
+
"optional": true
|
|
133
|
+
},
|
|
134
|
+
"proj4": {
|
|
135
|
+
"optional": true
|
|
124
136
|
}
|
|
125
137
|
},
|
|
126
138
|
"devDependencies": {
|
|
127
139
|
"@arcgis/core": "^5.0.9",
|
|
140
|
+
"ol": "^10.9.0",
|
|
141
|
+
"proj4": "^2.20.8",
|
|
128
142
|
"@babel/core": "^7.28.0",
|
|
129
143
|
"@babel/plugin-transform-runtime": "^7.29.0",
|
|
130
144
|
"@babel/preset-env": "^7.28.0",
|
|
131
145
|
"@babel/preset-react": "^7.27.1",
|
|
132
|
-
"@defra/docusaurus-theme-govuk": "^0.0.
|
|
133
|
-
"@docusaurus/core": "^3.
|
|
134
|
-
"@docusaurus/module-type-aliases": "^3.
|
|
135
|
-
"@docusaurus/plugin-content-docs": "^3.
|
|
136
|
-
"@docusaurus/
|
|
146
|
+
"@defra/docusaurus-theme-govuk": "^0.0.22-alpha",
|
|
147
|
+
"@docusaurus/core": "^3.10.1",
|
|
148
|
+
"@docusaurus/module-type-aliases": "^3.10.1",
|
|
149
|
+
"@docusaurus/plugin-content-docs": "^3.10.1",
|
|
150
|
+
"@docusaurus/theme-common": "^3.10.1",
|
|
151
|
+
"@docusaurus/tsconfig": "^3.10.1",
|
|
152
|
+
"@easyops-cn/docusaurus-search-local": "^0.55.1",
|
|
137
153
|
"@esri/arcgis-rest-request": "^4.7.3",
|
|
138
154
|
"@mapbox/mapbox-gl-draw": "^1.5.0",
|
|
139
155
|
"@mdx-js/react": "^3.1.1",
|
|
@@ -206,8 +222,6 @@
|
|
|
206
222
|
},
|
|
207
223
|
"dependencies": {
|
|
208
224
|
"@babel/runtime": "^7.28.6",
|
|
209
|
-
"@docusaurus/theme-common": "^3.9.2",
|
|
210
|
-
"@easyops-cn/docusaurus-search-local": "^0.55.0",
|
|
211
225
|
"@turf/area": "^7.2.0",
|
|
212
226
|
"@turf/bbox": "^7.3.4",
|
|
213
227
|
"@turf/bearing": "^7.3.3",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useContext as e,createContext as r}from"preact/compat";import{jsx as t,jsxs as i}from"preact/jsx-runtime";import o from"@babel/runtime/helpers/asyncToGenerator";import a from"@babel/runtime/helpers/defineProperty";var l=(e,r,t,i,o)=>{if(e.getLayer(r)){var a=((e,r,t)=>{if(!t||0===t.length)return e;var i=["!",["in",r?["to-string",["get",r]]:["to-string",["id"]],["literal",t.map(String)]]];return e?["all",e,i]:i})(t,i,o);e.setFilter(r,a)}},s=(e,r)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(r&&e[r])return e[r];var t=Object.values(e)[0];return null!=t?t:null}return null},n=e=>!(!e.fillPattern&&!e.fillPatternSvgContent),y=function(e,r,t){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,o=((e,r)=>{return e.fillPatternSvgContent?e.fillPatternSvgContent:e.fillPattern&&null!==(t=null==r||null===(i=r.get(e.fillPattern))||void 0===i?void 0:i.svgContent)&&void 0!==t?t:null;var t,i})(e,t);if(!o)return null;var a=s(e.fillPatternForegroundColor,r)||"black",l=s(e.fillPatternBackgroundColor,r)||"transparent",n=Math.max(2,i);return"pattern-".concat((e=>{var r=0;for(var t of e)r=(r<<5)-r+t.codePointAt(0),r&=r;return Math.abs(r).toString(36)})(o+a+l),"-").concat(n,"x")},d=e=>"string"==typeof e.geojson&&!!e.idProperty&&"function"==typeof e.transformRequest,m=e=>{var r=0;for(var t of e)r=Math.trunc((r<<5)-r+t.codePointAt(0));return Math.abs(r).toString(36)},p=e=>{if(e.tiles){var r=Array.isArray(e.tiles)?e.tiles.join(","):e.tiles;return"tiles-".concat(m(r))}return e.geojson?d(e)?"geojson-dynamic-".concat(e.id):"string"==typeof e.geojson?"geojson-".concat(m(e.geojson)):"geojson-".concat(e.id):"source-".concat(e.id)},c=e=>{if((e=>!!e.symbol)(e))return{fillLayerId:null,strokeLayerId:null,symbolLayerId:e.id};var r=!!e.fill&&"transparent"!==e.fill||n(e),t=!!e.stroke,i=r?e.id:null,o=null;return t&&(o=r?"".concat(e.id,"-stroke"):e.id),{fillLayerId:i,strokeLayerId:o,symbolLayerId:null}},u=(e,r)=>({fillLayerId:"".concat(e,"-").concat(r),strokeLayerId:"".concat(e,"-").concat(r,"-stroke"),symbolLayerId:"".concat(e,"-").concat(r,"-symbol")}),f=e=>{var r;if(null!==(r=e.sublayers)&&void 0!==r&&r.length)return e.sublayers.flatMap(r=>{var{fillLayerId:t,strokeLayerId:i,symbolLayerId:o}=u(e.id,r.id);return[i,t,o]});var{fillLayerId:t,strokeLayerId:i,symbolLayerId:o}=c(e);return[i,t,o].filter(Boolean)},v=["stroke","fill","fillPattern","fillPatternSvgContent","symbol","symbolSvgContent"];function b(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,i)}return t}var g=(e,r)=>{return"symbolDescription"in r?r.symbolDescription:(t=r,v.some(e=>e in t)?void 0:e.symbolDescription);var t},h=(e,r)=>{var t,i,o,l,s,n,y,d,m,p,c,u,f,v,h,_,P,L=r.style||{},S=(_=e.filter,P=r.filter,_&&P?["all",_,P]:P||_||null);return function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?b(Object(t),!0).forEach(function(r){a(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):b(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}({id:r.id,label:r.label,stroke:null!==(t=L.stroke)&&void 0!==t?t:e.stroke,strokeWidth:null!==(i=L.strokeWidth)&&void 0!==i?i:e.strokeWidth,strokeDashArray:null!==(o=L.strokeDashArray)&&void 0!==o?o:e.strokeDashArray,opacity:null!==(l=L.opacity)&&void 0!==l?l:e.opacity,keySymbolShape:null!==(s=L.keySymbolShape)&&void 0!==s?s:e.keySymbolShape,symbolDescription:g(e,L),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=L.symbol)&&void 0!==d?d:e.symbol,symbolSvgContent:null!==(m=L.symbolSvgContent)&&void 0!==m?m:e.symbolSvgContent,symbolViewBox:null!==(p=L.symbolViewBox)&&void 0!==p?p:e.symbolViewBox,symbolAnchor:null!==(c=L.symbolAnchor)&&void 0!==c?c:e.symbolAnchor,symbolBackgroundColor:null!==(u=L.symbolBackgroundColor)&&void 0!==u?u:e.symbolBackgroundColor,symbolForegroundColor:null!==(f=L.symbolForegroundColor)&&void 0!==f?f:e.symbolForegroundColor,symbolHaloWidth:null!==(v=L.symbolHaloWidth)&&void 0!==v?v:e.symbolHaloWidth,symbolGraphic:null!==(h=L.symbolGraphic)&&void 0!==h?h:e.symbolGraphic},((e,r)=>{var t,i;return r.fillPattern||r.fillPatternSvgContent?{fillPattern:r.fillPattern,fillPatternSvgContent:r.fillPatternSvgContent,fillPatternForegroundColor:null!==(t=r.fillPatternForegroundColor)&&void 0!==t?t:e.fillPatternForegroundColor,fillPatternBackgroundColor:null!==(i=r.fillPatternBackgroundColor)&&void 0!==i?i:e.fillPatternBackgroundColor}:"fill"in r?{fill:r.fill}:{fill:e.fill,fillPattern:e.fillPattern,fillPatternSvgContent:e.fillPatternSvgContent,fillPatternForegroundColor:e.fillPatternForegroundColor,fillPatternBackgroundColor:e.fillPatternBackgroundColor}})(e,L))},_=(e,r)=>e.flatMap(e=>{var r,t=n(e)?[e]:[];return null!==(r=e.sublayers)&&void 0!==r&&r.length&&e.sublayers.forEach(r=>{var i=h(e,r);n(i)&&t.push(i)}),t}),P=new Set(["symbolBackgroundColor","symbolForegroundColor","symbolHaloWidth","symbolGraphic"]),L=e=>!(!e.symbol&&!e.symbolSvgContent),S=(e,r)=>e.symbolSvgContent?{svg:e.symbolSvgContent}:e.symbol?r.get(e.symbol):void 0,I=e=>{var[r,t]=e,i=(e=>e<=.25?"left":e>=.75?"right":"")(r),o=(e=>e<=.25?"top":e>=.75?"bottom":"")(t);return o+(i&&o?"-":"")+i||"center"},O=function(e,r,t){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:2,a=S(e,t);if(!a)return null;var l=(e=>{if(!L(e))return{};var r={};return P.forEach(t=>{if(null!=e[t]){var i=t.charAt(6).toLowerCase()+t.slice(7);r[i]=e[t]}}),r})(e),s=i?t.resolveSelected(a,l,r):t.resolve(a,l,r);return"symbol-".concat(i?"sel-":"").concat((e=>{var r=0;for(var t of e)r=Math.trunc((r<<5)-r+t.codePointAt(0));return Math.abs(r).toString(36)})(s),"-").concat(o,"x")},R=e=>e.flatMap(e=>{var r,t=L(e)?[e]:[];return null!==(r=e.sublayers)&&void 0!==r&&r.length&&e.sublayers.forEach(r=>{var i=h(e,r);L(i)&&t.push(i)}),t});function j(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,i)}return t}function k(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?j(Object(t),!0).forEach(function(r){a(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):j(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var w=(e,r,t,i,o,a,l)=>{var{mapStyleId:d,patternRegistry:m,pixelRatio:p=1}=l;if(t&&!e.getLayer(t)&&(r.fill||n(r))){var c=n(r)?y(r,d,m,p):null,u=c?{"fill-pattern":c,"fill-opacity":r.opacity||1}:{"fill-color":s(r.fill,d),"fill-opacity":r.opacity||1};e.addLayer(k({id:t,type:"fill",source:i,"source-layer":o,minzoom:r.minZoom,maxzoom:r.maxZoom,layout:{visibility:a},paint:u},r.filter?{filter:r.filter}:{}))}},C=(e,r,t,i,o,a,l)=>{t&&r.stroke&&!e.getLayer(t)&&e.addLayer(k({id:t,type:"line",source:i,"source-layer":o,minzoom:r.minZoom,maxzoom:r.maxZoom,layout:{visibility:a},paint:k({"line-color":s(r.stroke,l),"line-width":r.strokeWidth||1,"line-opacity":r.opacity||1},r.strokeDashArray?{"line-dasharray":r.strokeDashArray}:{})},r.filter?{filter:r.filter}:{}))},x=(e,r,t,i,o,a,l)=>{var{mapStyle:s,symbolRegistry:n,pixelRatio:y}=l;if(t&&!e.getLayer(t)){var d=S(r,n);if(d){var m=O(r,s,n,!1,y);if(m){var p=((e,r)=>{var t;return e.symbolAnchor?e.symbolAnchor:null!==(t=null==r?void 0:r.anchor)&&void 0!==t?t:[.5,.5]})(r,d);e.addLayer(k({id:t,type:"symbol",source:i,"source-layer":o,minzoom:r.minZoom,maxzoom:r.maxZoom,layout:{visibility:a,"icon-image":m,"icon-anchor":I(p),"icon-allow-overlap":!0}},r.filter?{filter:r.filter}:{}))}}}},D=(e,r,t,i,o,a)=>{var l,{mapStyle:s,symbolRegistry:n,patternRegistry:y,pixelRatio:d}=a,m=s.id,p=h(r,t),{fillLayerId:c,strokeLayerId:f,symbolLayerId:v}=u(r.id,t.id),b="hidden"===r.visibility,g="hidden"===(null===(l=r.sublayerVisibility)||void 0===l?void 0:l[t.id]),_=b||g?"none":"visible";L(p)&&n?x(e,p,v,i,o,_,{mapStyle:s,symbolRegistry:n,pixelRatio:d}):(w(e,p,c,i,o,_,{mapStyleId:m,patternRegistry:y,pixelRatio:d}),C(e,p,f,i,o,_,m))},E=(e,r,t,i,o,a)=>{var l,s,n=t.id,y=p(r);((e,r,t)=>{if(!e.getSource(t))if(r.tiles)e.addSource(t,{type:"vector",tiles:r.tiles,minzoom:r.minZoom||0,maxzoom:r.maxZoom||22});else if(r.geojson){var i=d(r)?{type:"FeatureCollection",features:[]}:r.geojson;e.addSource(t,{type:"geojson",data:i,generateId:!0})}})(e,r,y);var m=null!==(l=r.tiles)&&void 0!==l&&l.length?r.sourceLayer:void 0;if(null!==(s=r.sublayers)&&void 0!==s&&s.length)return r.sublayers.forEach(l=>{D(e,r,l,y,m,{mapStyle:t,symbolRegistry:i,patternRegistry:o,pixelRatio:a})}),y;var{fillLayerId:u,strokeLayerId:f,symbolLayerId:v}=c(r),b="hidden"===r.visibility?"none":"visible";return L(r)&&i?(x(e,r,v,y,m,b,{mapStyle:t,symbolRegistry:i,pixelRatio:a}),y):(w(e,r,u,y,m,b,{mapStyleId:n,patternRegistry:o,pixelRatio:a}),C(e,r,f,y,m,b,n),y)};new Set;function F(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,i)}return t}function M(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?F(Object(t),!0).forEach(function(r){a(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):F(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var A={slot:"middle",open:!1,dismissible:!0,modal:!0};M({},A),M(M({},A),{},{width:"500px"}),M(M({},A),{},{width:"500px"});var B={small:1,medium:1.5,large:2};class Z{constructor(e,r,t){this._mapProvider=e,this._map=e.map,this._symbolRegistry=r,this._patternRegistry=t,this._datasetSourceMap=new Map,this._symbolLayerIds=new Set}init(e,r){var t=this;return o(function*(){var i=r.id,o=t._pixelRatio;yield Promise.all([t._mapProvider.registerPatterns(_(e,t._patternRegistry),i,t._patternRegistry),t._mapProvider.registerSymbols(R(e),r,t._symbolRegistry)]),t._symbolLayerIds.clear(),e.forEach(e=>t._addLayers(e,r,o)),yield new Promise(e=>t._map.once("idle",e))})()}destroy(e){var r=new Set;e.forEach(e=>{var t=p(e);this._getLayersUsingSource(t).forEach(e=>{this._map.getLayer(e)&&this._map.removeLayer(e)}),!r.has(t)&&this._map.getSource(t)&&(this._map.removeSource(t),r.add(t))}),this._datasetSourceMap.clear()}onStyleChange(e,r,t,i){var a=this;return o(function*(){yield new Promise(e=>a._map.once("idle",e));var o=r.id,l=a._pixelRatio;yield Promise.all([a._mapProvider.registerPatterns(_(e,a._patternRegistry),o,a._patternRegistry),a._mapProvider.registerSymbols(R(e),r,a._symbolRegistry)]),a._symbolLayerIds.clear(),e.forEach(e=>a._addLayers(e,r,l)),i.forEach(e=>e.reapply()),Object.entries(t).forEach(r=>{var[t,{idProperty:i,ids:o}]=r,l=e.find(e=>e.id===t);l&&a._applyFeatureFilter(l,i,o)})})()}onSizeChange(e,r){var t=this;return o(function*(){var i=t._pixelRatio;yield Promise.all([t._mapProvider.registerSymbols(R(e),r,t._symbolRegistry),t._mapProvider.registerPatterns(_(e,t._patternRegistry),r.id,t._patternRegistry)]),e.forEach(e=>{var o;if(f(e).forEach(o=>{if(t._symbolLayerIds.has(o)&&t._map.getLayer(o)){var a=O(e,r,t._symbolRegistry,!1,i);a&&t._map.setLayoutProperty(o,"icon-image",a)}}),n(e)){var{fillLayerId:a}=c(e);if(t._map.getLayer(a)){var l=y(e,r.id,t._patternRegistry,i);l&&t._map.setPaintProperty(a,"fill-pattern",l)}}null===(o=e.sublayers)||void 0===o||o.forEach(o=>{var a=h(e,o),{symbolLayerId:l,fillLayerId:s}=u(e.id,o.id);if(t._map.getLayer(l)){var d=O(a,r,t._symbolRegistry,!1,i);d&&t._map.setLayoutProperty(l,"icon-image",d)}if(n(a)&&t._map.getLayer(s)){var m=y(a,r.id,t._patternRegistry,i);m&&t._map.setPaintProperty(s,"fill-pattern",m)}})})})()}addDataset(e,r){this._addLayers(e,r,this._pixelRatio)}removeDataset(e,r){var t=p(e);f(e).forEach(e=>{this._map.getLayer(e)&&this._map.removeLayer(e),this._symbolLayerIds.delete(e)}),!r.some(r=>r.id!==e.id&&p(r)===t)&&this._map.getSource(t)&&this._map.removeSource(t),this._datasetSourceMap.delete(e.id)}showDataset(e){this._setDatasetVisibility(e,"visible")}hideDataset(e){this._setDatasetVisibility(e,"none")}showSublayer(e,r){var{fillLayerId:t,strokeLayerId:i,symbolLayerId:o}=u(e,r);[t,i,o].forEach(e=>{this._map.getLayer(e)&&this._map.setLayoutProperty(e,"visibility","visible")})}hideSublayer(e,r){var{fillLayerId:t,strokeLayerId:i,symbolLayerId:o}=u(e,r);[t,i,o].forEach(e=>{this._map.getLayer(e)&&this._map.setLayoutProperty(e,"visibility","none")})}showFeatures(e,r,t){this._applyFeatureFilter(e,r,t)}hideFeatures(e,r,t){this._applyFeatureFilter(e,r,t)}setStyle(e,r){var t=this;return o(function*(){var i=r.id,o=t._pixelRatio;f(e).forEach(e=>{t._map.getLayer(e)&&t._map.removeLayer(e),t._symbolLayerIds.delete(e)}),yield Promise.all([t._mapProvider.registerPatterns(_([e],t._patternRegistry),i,t._patternRegistry),t._mapProvider.registerSymbols(R([e]),r,t._symbolRegistry)]),t._addLayers(e,r,o)})()}setSublayerStyle(e,r,t){var i=this;return o(function*(){var o,a,l=t.id,s=i._pixelRatio,{fillLayerId:n,strokeLayerId:y,symbolLayerId:d}=u(e.id,r);[n,y,d].forEach(e=>{i._map.getLayer(e)&&i._map.removeLayer(e),i._symbolLayerIds.delete(e)});var m=null===(o=e.sublayers)||void 0===o?void 0:o.find(e=>e.id===r);if(m){yield Promise.all([i._mapProvider.registerPatterns(_([e],i._patternRegistry),l,i._patternRegistry),i._mapProvider.registerSymbols(R([e]),t,i._symbolRegistry)]);var p=i._datasetSourceMap.get(e.id),c=null!==(a=e.tiles)&&void 0!==a&&a.length?e.sourceLayer:void 0;D(i._map,e,m,p,c,{mapStyle:t,symbolRegistry:i._symbolRegistry,patternRegistry:i._patternRegistry,pixelRatio:s}),i._maintainSymbolOrdering(e)}})()}setOpacity(e,r){var t=this._map.getStyle();null!=t&&t.layers&&t.layers.filter(r=>r.id===e||r.id.startsWith("".concat(e,"-"))).forEach(e=>this._setPaintOpacity(e.id,r))}setSublayerOpacity(e,r,t){var{fillLayerId:i,strokeLayerId:o}=u(e,r);this._setPaintOpacity(i,t),this._setPaintOpacity(o,t)}setData(e,r){var t=this._datasetSourceMap.get(e);if(t){var i=this._map.getSource(t);i&&"function"==typeof i.setData&&i.setData(r)}}get _pixelRatio(){return this._mapProvider.map.getPixelRatio()*(B[this._mapProvider.mapSize]||1)}_addLayers(e,r,t){var i=E(this._map,e,r,this._symbolRegistry,this._patternRegistry,t);this._datasetSourceMap.set(e.id,i),this._maintainSymbolOrdering(e)}_getFirstSymbolLayerId(){var e,r=this._map.getStyle();if(null==r||!r.layers)return null;var t=r.layers.find(e=>this._symbolLayerIds.has(e.id));return null!==(e=null==t?void 0:t.id)&&void 0!==e?e:null}_maintainSymbolOrdering(e){var r=f(e).filter(e=>e&&this._map.getLayer(e));r.forEach(e=>{var r;"symbol"===(null===(r=this._map.getLayer(e))||void 0===r?void 0:r.type)?this._symbolLayerIds.add(e):this._symbolLayerIds.delete(e)});var t=this._getFirstSymbolLayerId();t&&r.forEach(e=>{this._symbolLayerIds.has(e)||this._map.moveLayer(e,t)})}_setDatasetVisibility(e,r){var t=this._map.getStyle();null!=t&&t.layers&&t.layers.filter(r=>r.id===e||r.id.startsWith("".concat(e,"-"))).forEach(e=>this._map.setLayoutProperty(e.id,"visibility",r))}_applyFeatureFilter(e,r,t){var i;if(null!==(i=e.sublayers)&&void 0!==i&&i.length)e.sublayers.forEach(i=>{var{fillLayerId:o,strokeLayerId:a}=u(e.id,i.id),s=e.filter&&i.filter?["all",e.filter,i.filter]:i.filter||e.filter||null;l(this._map,o,s,r,t),l(this._map,a,s,r,t)});else{var{fillLayerId:o,strokeLayerId:a,symbolLayerId:s}=c(e),n=e.filter||null;[o,a,s].filter(Boolean).forEach(e=>{l(this._map,e,n,r,t)})}}_setPaintOpacity(e,r){var t=this._map.getLayer(e);if(t){var i={line:"line-opacity",symbol:"icon-opacity"}[t.type]||"fill-opacity";this._map.setPaintProperty(e,i,r)}}_getLayersUsingSource(e){var r=this._map.getStyle();return null!=r&&r.layers?r.layers.filter(r=>r.source===e).map(e=>e.id):[]}}export{Z as default};
|
|
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) {
|