@defra/interactive-map 0.0.30-alpha → 0.0.32-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/README.md +2 -2
- package/assets/images/bright-ofm-thumb.jpg +0 -0
- package/assets/images/dark-ofm-thumb.jpg +0 -0
- package/assets/images/road-ofm-thumb.jpg +0 -0
- package/assets/templates/add-polygons.njk +143 -0
- package/assets/templates/add-symbols.njk +119 -0
- package/assets/templates/{map.njk → basic-map.njk} +9 -17
- package/assets/templates/button-map.njk +56 -0
- package/assets/templates/draw-tools.njk +161 -0
- package/assets/templates/marker-panel.njk +91 -0
- package/assets/templates/place-marker.njk +104 -0
- package/assets/templates/search-control.njk +98 -0
- package/assets/templates/select-feature.njk +101 -0
- package/assets/templates/style-switcher.njk +87 -0
- package/assets/templates/toggle-marker-label.njk +74 -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/context.md +4 -4
- package/docs/api.md +166 -37
- package/docs/assets/css/docusaurus.scss +36 -4
- package/docs/assets/images/add-polygons.jpg +0 -0
- package/docs/assets/images/add-symbols.jpg +0 -0
- package/docs/assets/images/basic-map.jpg +0 -0
- package/docs/assets/images/button-first.jpg +0 -0
- package/docs/assets/images/deuteranopia-ozs-map-thumb.jpg +0 -0
- package/docs/assets/images/draw.jpg +0 -0
- package/docs/assets/images/marker-panel.jpg +0 -0
- package/docs/assets/images/night-ozs-map-thumb.jpg +0 -0
- package/docs/assets/images/outdoor-ozs-map-thumb.jpg +0 -0
- package/docs/assets/images/place-marker.jpg +0 -0
- package/docs/assets/images/screenshot.jpg +0 -0
- package/docs/assets/images/search.jpg +0 -0
- package/docs/assets/images/select-feature.jpg +0 -0
- package/docs/assets/images/style-switcher.jpg +0 -0
- package/docs/assets/images/toggle-marker-label.jpg +0 -0
- package/docs/assets/images/tritanopia-ozs-map-thumb.jpg +0 -0
- package/docs/examples/add-marker-with-panel.mdx +3 -3
- package/docs/examples/add-polygons.mdx +225 -0
- package/docs/examples/add-symbols.mdx +177 -0
- package/docs/examples/basic-map.mdx +2 -2
- package/docs/examples/draw-tools.mdx +271 -0
- package/docs/examples/index.mdx +95 -11
- package/docs/examples/place-marker.mdx +151 -0
- package/docs/examples/search-control.mdx +71 -0
- package/docs/examples/select-feature.mdx +146 -0
- package/docs/examples/style-switcher.mdx +135 -0
- package/docs/examples/toggle-marker-label.mdx +3 -3
- package/docs/plugins/datasets.md +157 -122
- package/docs/plugins/interact.md +1 -4
- package/docusaurus.config.cjs +9 -2
- package/govuk-prototype-kit.config.json +52 -2
- package/package.json +1 -1
- package/plugins/beta/datasets/dist/css/index.css +5 -2
- package/plugins/beta/datasets/dist/esm/im-datasets-ml-adapter.js +1 -0
- package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/esm/index.js +1 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-ml-adapter.js +2 -0
- package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +2 -0
- package/plugins/beta/datasets/dist/umd/index.js +2 -0
- package/plugins/beta/datasets/src/adapters/loadLayerAdapter.js +33 -0
- package/plugins/beta/datasets/src/adapters/maplibre/layerBuilders.js +44 -120
- package/plugins/beta/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +145 -245
- package/plugins/beta/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +516 -0
- package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +209 -0
- package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +483 -0
- package/plugins/beta/datasets/src/api/addDataset.js +2 -5
- package/plugins/beta/datasets/src/api/addDataset.test.js +16 -0
- package/plugins/beta/datasets/src/api/getOpacity.js +14 -14
- package/plugins/beta/datasets/src/api/getOpacity.test.js +72 -0
- package/plugins/beta/datasets/src/api/getStyle.js +8 -9
- package/plugins/beta/datasets/src/api/getStyle.test.js +42 -0
- package/plugins/beta/datasets/src/api/removeDataset.js +7 -7
- package/plugins/beta/datasets/src/api/removeDataset.test.js +45 -0
- package/plugins/beta/datasets/src/api/setData.js +9 -3
- package/plugins/beta/datasets/src/api/setData.test.js +62 -0
- package/plugins/beta/datasets/src/api/setDatasetVisibility.js +5 -30
- package/plugins/beta/datasets/src/api/setDatasetVisibility.test.js +31 -0
- package/plugins/beta/datasets/src/api/setFeatureVisibility.js +9 -18
- package/plugins/beta/datasets/src/api/setFeatureVisibility.test.js +74 -0
- package/plugins/beta/datasets/src/api/setGlobals.js +20 -0
- package/plugins/beta/datasets/src/api/setGlobals.test.js +63 -0
- package/plugins/beta/datasets/src/api/setOpacity.js +8 -27
- package/plugins/beta/datasets/src/api/setOpacity.test.js +31 -0
- package/plugins/beta/datasets/src/api/setStyle.js +5 -21
- package/plugins/beta/datasets/src/api/setStyle.test.js +53 -0
- package/plugins/beta/datasets/src/components/Key/Key.jsx +51 -0
- package/plugins/beta/datasets/src/components/Key/KeyGroupItem.jsx +18 -0
- package/plugins/beta/datasets/src/components/Key/KeyItem.jsx +20 -0
- package/plugins/beta/datasets/src/components/Key/KeySvg.jsx +22 -0
- package/plugins/beta/datasets/src/components/Key/KeySvg.test.jsx +87 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgLine.jsx +19 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgLine.test.jsx +71 -0
- package/plugins/beta/datasets/src/components/{KeySvgPattern.jsx → Key/KeySvgPattern.jsx} +3 -4
- package/plugins/beta/datasets/src/components/Key/KeySvgPattern.test.jsx +55 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgRect.jsx +22 -0
- package/plugins/beta/datasets/src/components/Key/KeySvgRect.test.jsx +85 -0
- package/plugins/beta/datasets/src/components/{KeySvgSymbol.jsx → Key/KeySvgSymbol.jsx} +5 -5
- package/plugins/beta/datasets/src/components/Key/KeySvgSymbol.test.jsx +80 -0
- package/plugins/beta/datasets/src/components/Key/svgProperties.test.js +61 -0
- package/plugins/beta/datasets/src/{panels → components/LayersMenu}/Layers.module.scss +15 -11
- package/plugins/beta/datasets/src/components/LayersMenu/LayersMenu.jsx +33 -0
- package/plugins/beta/datasets/src/components/LayersMenu/LayersMenuCheckbox.jsx +31 -0
- package/plugins/beta/datasets/src/components/LayersMenu/LayersMenuGroupWrapper.jsx +19 -0
- package/plugins/beta/datasets/src/datasets.scss +2 -2
- package/plugins/beta/datasets/src/fetch/createDynamicSource.js +8 -8
- package/plugins/beta/datasets/src/{DatasetsInit.jsx → initialise/DatasetsInit.jsx} +19 -21
- package/plugins/beta/datasets/src/{defaults.js → initialise/defaults.js} +17 -2
- package/plugins/beta/datasets/src/initialise/defaults.test.js +127 -0
- package/plugins/beta/datasets/src/{datasets.js → initialise/initialiseDatasets.js} +30 -26
- package/plugins/beta/datasets/src/initialise/initialiseDatasets.test.js +273 -0
- package/plugins/beta/datasets/src/manifest.js +8 -6
- package/plugins/beta/datasets/src/reducers/__data__/demoDatasets.js +253 -0
- package/plugins/beta/datasets/src/reducers/datasetsToMenu.js +83 -0
- package/plugins/beta/datasets/src/reducers/datasetsToMenu.test.js +84 -0
- package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.js +41 -0
- package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.test.js +117 -0
- package/plugins/beta/datasets/src/reducers/pluginState.js +206 -0
- package/plugins/beta/datasets/src/reducers/pluginState.test.js +386 -0
- package/plugins/beta/datasets/src/registry/__mocks__/datasetRegistry.js +29 -0
- package/plugins/beta/datasets/src/registry/createDataset.js +5 -0
- package/plugins/beta/datasets/src/registry/dataset.js +176 -0
- package/plugins/beta/datasets/src/registry/dataset.test.js +497 -0
- package/plugins/beta/datasets/src/registry/datasetDefinitionCache.js +35 -0
- package/plugins/beta/datasets/src/registry/datasetRegistry.js +116 -0
- package/plugins/beta/datasets/src/registry/datasetRegistry.test.js +335 -0
- package/plugins/beta/datasets/src/registry/dynamicGeoJson.js +17 -0
- package/plugins/beta/datasets/src/registry/globalDataset.js +36 -0
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/src/api/addFeature.js +12 -3
- package/plugins/beta/draw-es/src/events.js +8 -3
- package/plugins/beta/draw-es/src/events.test.js +2 -0
- package/plugins/beta/draw-es/src/graphic.js +26 -2
- 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/DrawInit.jsx +8 -0
- package/plugins/beta/draw-ml/src/api/newLine.js +1 -0
- package/plugins/beta/draw-ml/src/api/newPolygon.js +1 -0
- package/plugins/beta/draw-ml/src/events.js +13 -1
- package/plugins/beta/draw-ml/src/index.js +1 -1
- package/plugins/beta/draw-ml/src/manifest.js +3 -0
- package/plugins/beta/draw-ml/src/modes/createDrawMode.js +21 -12
- package/plugins/beta/draw-ml/src/modes/editVertexMode.js +4 -0
- package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +4 -2
- package/plugins/beta/map-styles/src/mapStyles.scss +41 -41
- 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 +3 -5
- package/plugins/interact/src/InteractInit.test.js +1 -3
- package/plugins/interact/src/events.js +2 -29
- package/plugins/interact/src/events.test.js +4 -102
- package/plugins/interact/src/hooks/useAttachEvents.js +3 -4
- package/plugins/interact/src/hooks/useAttachEvents.test.js +1 -3
- package/plugins/interact/src/hooks/useCrossHairVisibility.js +4 -10
- package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +5 -10
- package/plugins/interact/src/hooks/useHighlightSync.js +1 -10
- package/plugins/interact/src/hooks/useHighlightSync.test.js +2 -21
- package/plugins/interact/src/hooks/useInteractionHandlers.js +15 -12
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +28 -29
- package/plugins/interact/src/manifest.js +0 -35
- package/plugins/interact/src/manifest.test.js +3 -43
- package/plugins/interact/src/reducer.js +4 -22
- package/plugins/interact/src/reducer.test.js +11 -39
- package/plugins/search/dist/css/index.css +5 -2
- package/plugins/search/src/components/Form/Form.module.scss +5 -2
- package/plugins/search/src/search.scss +4 -4
- 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 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/src/openlayersProvider.js +4 -0
- package/providers/beta/openlayers/src/openlayersProvider.test.js +5 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +6 -4
- package/providers/maplibre/src/maplibreProvider.test.js +5 -0
- package/providers/maplibre/src/utils/highlightFeatures.js +74 -25
- package/providers/maplibre/src/utils/highlightFeatures.test.js +132 -0
- package/providers/maplibre/src/utils/patternImages.js +2 -4
- package/providers/maplibre/src/utils/symbolImages.js +1 -4
- package/rollup.esm.mjs +2 -8
- package/src/App/components/CrossHair/CrossHair.module.scss +8 -8
- package/src/App/components/MapButton/MapButton.jsx +16 -1
- package/src/App/components/MapButton/MapButton.module.scss +12 -1
- package/src/App/components/MapButton/MapButton.test.jsx +40 -1
- package/src/App/hooks/useContinueEnabledEvaluator.js +31 -0
- package/src/App/hooks/useContinueEnabledEvaluator.test.js +118 -0
- package/src/App/hooks/useEvaluateProp.js +15 -15
- package/src/App/hooks/useEvaluateProp.test.js +80 -76
- package/src/App/hooks/useLayoutMeasurements.js +11 -5
- package/src/App/hooks/useResizeObserver.js +15 -2
- package/src/App/hooks/useResizeObserver.test.js +1 -0
- package/src/App/renderer/PluginInits.jsx +2 -0
- package/src/App/renderer/mapButtons.js +21 -1
- package/src/App/renderer/mapButtons.test.js +46 -1
- package/src/App/store/appReducer.js +1 -1
- package/src/App/store/appReducer.test.js +37 -0
- package/src/InteractiveMap/InteractiveMap.js +14 -4
- package/src/InteractiveMap/InteractiveMap.test.js +11 -3
- package/src/InteractiveMap/behaviourController.js +3 -1
- package/src/InteractiveMap/behaviourController.test.js +6 -3
- package/src/InteractiveMap/domStateManager.js +2 -0
- package/src/config/appConfig.js +25 -0
- package/src/config/appConfig.test.js +50 -0
- package/src/config/defaults.js +1 -0
- package/src/config/events.js +21 -3
- package/src/scss/settings/_dimensions.scss +1 -0
- package/src/services/patternRegistry.js +8 -4
- package/src/types.js +7 -0
- package/src/utils/patternUtils.js +1 -2
- package/src/utils/patternUtils.test.js +9 -0
- package/webpack.dev.mjs +10 -0
- package/webpack.umd.mjs +1 -1
- package/docs/assets/images/screens-blue.jpg +0 -0
- package/docs/assets/images/screens-white.jpg +0 -0
- package/plugins/beta/datasets/dist/adapters/maplibre/esm/im-datasets-ml-adapter.js +0 -1
- package/plugins/beta/datasets/dist/adapters/maplibre/esm/index.js +0 -1
- package/plugins/beta/datasets/dist/umd/maplibre/im-datasets-maplibre-adapter.js +0 -2
- package/plugins/beta/datasets/dist/umd/maplibre/im-datasets-plugin.js +0 -2
- package/plugins/beta/datasets/dist/umd/maplibre/index.js +0 -2
- package/plugins/beta/datasets/src/adapters/maplibre/index.js +0 -18
- package/plugins/beta/datasets/src/adapters/maplibre/layerIds.js +0 -75
- package/plugins/beta/datasets/src/adapters/maplibre/patternImages.js +0 -27
- package/plugins/beta/datasets/src/adapters/maplibre/symbolImages.js +0 -31
- package/plugins/beta/datasets/src/components/KeySvg.jsx +0 -24
- package/plugins/beta/datasets/src/components/KeySvgLine.jsx +0 -19
- package/plugins/beta/datasets/src/components/KeySvgRect.jsx +0 -22
- package/plugins/beta/datasets/src/index.maplibre.umd.js +0 -23
- package/plugins/beta/datasets/src/panels/Key.jsx +0 -62
- package/plugins/beta/datasets/src/panels/Layers.jsx +0 -141
- package/plugins/beta/datasets/src/reducer.js +0 -219
- package/plugins/beta/datasets/src/reducers/keyReducer.js +0 -34
- package/plugins/beta/datasets/src/utils/filters.js +0 -34
- package/plugins/beta/datasets/src/utils/mergeSublayer.js +0 -86
- package/plugins/beta/draw-ml/dist/css/index.css +0 -21
- /package/plugins/beta/datasets/dist/umd/{maplibre/im-datasets-maplibre-adapter.js.LICENSE.txt → im-datasets-ml-adapter.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/dist/umd/{maplibre/im-datasets-plugin.js.LICENSE.txt → im-datasets-plugin.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/dist/umd/{maplibre/index.js.LICENSE.txt → index.js.LICENSE.txt} +0 -0
- /package/plugins/beta/datasets/src/components/{EmptyKey.jsx → Key/EmptyKey.jsx} +0 -0
- /package/plugins/beta/datasets/src/components/{EmptyKey.test.jsx → Key/EmptyKey.test.jsx} +0 -0
- /package/plugins/beta/datasets/src/{panels → components/Key}/Key.module.scss +0 -0
- /package/plugins/beta/datasets/src/components/{svgProperties.js → Key/svgProperties.js} +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import DemoMapSelectBuilding from '../../demo/DemoMapSelectBuilding.js'
|
|
2
|
+
import CodeTabs from '../../demo/js/codeTabs.js'
|
|
3
|
+
|
|
4
|
+
# Select a feature
|
|
5
|
+
|
|
6
|
+
Use the interact plugin to add feature selection to your map. This example adds the ability to select a building from the OS Open Zoomstack `Buildings 3D` layer and display its properties in a panel. Selecting another building replaces the current selection; clicking outside clears it.
|
|
7
|
+
|
|
8
|
+
:::note
|
|
9
|
+
The layer ID used here (`buildings 3D`) is specific to the OS Open Zoomstack outdoor style. For other tile styles, set `debug: true` in the plugin options, open the browser console, and click the map to see which layer IDs are available at that point.
|
|
10
|
+
:::
|
|
11
|
+
|
|
12
|
+
<DemoMapSelectBuilding />
|
|
13
|
+
|
|
14
|
+
<CodeTabs tabs={[
|
|
15
|
+
{
|
|
16
|
+
label: 'ESM',
|
|
17
|
+
language: 'js',
|
|
18
|
+
code: `
|
|
19
|
+
import InteractiveMap from '@defra/interactive-map'
|
|
20
|
+
import maplibreProvider from '@defra/interactive-map/providers/maplibre'
|
|
21
|
+
import createInteractPlugin from '@defra/interactive-map/plugins/interact'
|
|
22
|
+
|
|
23
|
+
const PANEL_ID = 'building-info'
|
|
24
|
+
|
|
25
|
+
const interactPlugin = createInteractPlugin({
|
|
26
|
+
interactionModes: ['selectFeature'],
|
|
27
|
+
deselectOnClickOutside: true,
|
|
28
|
+
layers: [
|
|
29
|
+
{ layerId: 'buildings 3D', idProperty: 'uuid' }
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const map = new InteractiveMap('my-map', {
|
|
34
|
+
behaviour: 'inline',
|
|
35
|
+
mapProvider: maplibreProvider(),
|
|
36
|
+
mapStyle: {
|
|
37
|
+
url: 'https://your-tile-url/style.json',
|
|
38
|
+
attribution: 'Your tile attribution'
|
|
39
|
+
},
|
|
40
|
+
center: [-1.55, 53.80],
|
|
41
|
+
zoom: 14.5,
|
|
42
|
+
maxZoom: 14.5,
|
|
43
|
+
containerHeight: '516px',
|
|
44
|
+
plugins: [interactPlugin]
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
map.on('map:ready', () => {
|
|
48
|
+
interactPlugin.enable()
|
|
49
|
+
|
|
50
|
+
map.addPanel(PANEL_ID, {
|
|
51
|
+
focus: false,
|
|
52
|
+
label: 'Selected building',
|
|
53
|
+
html: '<div id="building-info-content"></div>',
|
|
54
|
+
mobile: { slot: 'drawer', dismissible: true },
|
|
55
|
+
tablet: { slot: 'left-top', dismissible: true, width: '300px' },
|
|
56
|
+
desktop: { slot: 'left-top', dismissible: true, width: '300px' }
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
map.on('interact:selectionchange', ({ selectedFeatures }) => {
|
|
61
|
+
if (selectedFeatures.length > 0) {
|
|
62
|
+
let html = ''
|
|
63
|
+
for (const [k, v] of Object.entries(selectedFeatures[0].properties)) {
|
|
64
|
+
html += '<p class="govuk-body govuk-!-margin-bottom-1"><strong>' + k + ':</strong> ' + v + '</p>'
|
|
65
|
+
}
|
|
66
|
+
document.getElementById('building-info-content').innerHTML = html
|
|
67
|
+
map.showPanel(PANEL_ID)
|
|
68
|
+
} else {
|
|
69
|
+
map.hidePanel(PANEL_ID)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
map.on('app:panelclosed', ({ panelId }) => {
|
|
74
|
+
if (panelId === PANEL_ID) {
|
|
75
|
+
interactPlugin.clear()
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
`
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: 'UMD',
|
|
82
|
+
language: 'html',
|
|
83
|
+
code: `
|
|
84
|
+
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
85
|
+
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
86
|
+
<script src="/your-assets-path/interact-plugin/index.js"></script>
|
|
87
|
+
|
|
88
|
+
<script>
|
|
89
|
+
const PANEL_ID = 'building-info'
|
|
90
|
+
|
|
91
|
+
const interactPlugin = defra.interactPlugin({
|
|
92
|
+
interactionModes: ['selectFeature'],
|
|
93
|
+
deselectOnClickOutside: true,
|
|
94
|
+
layers: [
|
|
95
|
+
{ layerId: 'buildings 3D', idProperty: 'uuid' }
|
|
96
|
+
]
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const map = new defra.InteractiveMap('my-map', {
|
|
100
|
+
behaviour: 'inline',
|
|
101
|
+
mapProvider: defra.maplibreProvider(),
|
|
102
|
+
mapStyle: {
|
|
103
|
+
url: 'https://your-tile-url/style.json',
|
|
104
|
+
attribution: 'Your tile attribution'
|
|
105
|
+
},
|
|
106
|
+
center: [-1.55, 53.80],
|
|
107
|
+
zoom: 17,
|
|
108
|
+
containerHeight: '516px',
|
|
109
|
+
plugins: [interactPlugin]
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
map.on('map:ready', () => {
|
|
113
|
+
interactPlugin.enable()
|
|
114
|
+
|
|
115
|
+
map.addPanel(PANEL_ID, {
|
|
116
|
+
focus: false,
|
|
117
|
+
label: 'Selected building',
|
|
118
|
+
html: '<div id="building-info-content"></div>',
|
|
119
|
+
mobile: { slot: 'drawer', dismissible: true },
|
|
120
|
+
tablet: { slot: 'left-top', dismissible: true, width: '300px' },
|
|
121
|
+
desktop: { slot: 'left-top', dismissible: true, width: '300px' }
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
map.on('interact:selectionchange', ({ selectedFeatures }) => {
|
|
126
|
+
if (selectedFeatures.length > 0) {
|
|
127
|
+
let html = ''
|
|
128
|
+
for (const [k, v] of Object.entries(selectedFeatures[0].properties)) {
|
|
129
|
+
html += '<p class="govuk-body govuk-!-margin-bottom-1"><strong>' + k + ':</strong> ' + v + '</p>'
|
|
130
|
+
}
|
|
131
|
+
document.getElementById('building-info-content').innerHTML = html
|
|
132
|
+
map.showPanel(PANEL_ID)
|
|
133
|
+
} else {
|
|
134
|
+
map.hidePanel(PANEL_ID)
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
map.on('app:panelclosed', ({ panelId }) => {
|
|
139
|
+
if (panelId === PANEL_ID) {
|
|
140
|
+
interactPlugin.clear()
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
</script>
|
|
144
|
+
`
|
|
145
|
+
}
|
|
146
|
+
]} />
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import DemoMapStyleSwitcher from '../../demo/DemoMapStyleSwitcher.js'
|
|
2
|
+
import CodeTabs from '../../demo/js/codeTabs.js'
|
|
3
|
+
|
|
4
|
+
# Change map style
|
|
5
|
+
|
|
6
|
+
Provide alternative basemaps using the map styles plugin to support different use cases — such as dark or high contrast styles for accessibility needs, or aerial views for specific mapping tasks. You can also scale the map to enlarge text and features for users with visual impairment. The plugin accepts any vector tile style — in production you would typically use the [OS Vector Tile API](https://osdatahub.os.uk/docs/vts/overview) or [OS NGD Tiles API](https://osdatahub.os.uk/docs/ngd/overview).
|
|
7
|
+
|
|
8
|
+
:::note
|
|
9
|
+
The live demo uses OS Open Zoomstack tiles from OS Labs, which do not require an API key. This is only suitable for the demo — it is not intended for production use.
|
|
10
|
+
:::
|
|
11
|
+
|
|
12
|
+
<DemoMapStyleSwitcher />
|
|
13
|
+
|
|
14
|
+
<CodeTabs tabs={[
|
|
15
|
+
{
|
|
16
|
+
label: 'ESM',
|
|
17
|
+
language: 'js',
|
|
18
|
+
code: `
|
|
19
|
+
import InteractiveMap from '@defra/interactive-map'
|
|
20
|
+
import maplibreProvider from '@defra/interactive-map/providers/maplibre'
|
|
21
|
+
import createMapStylesPlugin from '@defra/interactive-map/plugins/map-styles'
|
|
22
|
+
|
|
23
|
+
const attribution = 'Contains OS data © Crown copyright and database rights 2025'
|
|
24
|
+
|
|
25
|
+
const mapStyles = [
|
|
26
|
+
{
|
|
27
|
+
id: 'outdoor',
|
|
28
|
+
label: 'Outdoor',
|
|
29
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-outdoor/style.json',
|
|
30
|
+
thumbnail: '/path/to/outdoor-thumbnail.jpg',
|
|
31
|
+
attribution,
|
|
32
|
+
backgroundColor: '#f5f5f0'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'night',
|
|
36
|
+
label: 'Night',
|
|
37
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-night/style.json',
|
|
38
|
+
thumbnail: '/path/to/night-thumbnail.jpg',
|
|
39
|
+
attribution,
|
|
40
|
+
mapColorScheme: 'dark',
|
|
41
|
+
appColorScheme: 'dark'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'deuteranopia',
|
|
45
|
+
label: 'Deuteranopia',
|
|
46
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-deuteranopia/style.json',
|
|
47
|
+
thumbnail: '/path/to/deuteranopia-thumbnail.jpg',
|
|
48
|
+
attribution,
|
|
49
|
+
backgroundColor: '#f5f5f0'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'tritanopia',
|
|
53
|
+
label: 'Tritanopia',
|
|
54
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-tritanopia/style.json',
|
|
55
|
+
thumbnail: '/path/to/tritanopia-thumbnail.jpg',
|
|
56
|
+
attribution,
|
|
57
|
+
backgroundColor: '#f5f5f0'
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
const mapStylesPlugin = createMapStylesPlugin({ mapStyles })
|
|
62
|
+
|
|
63
|
+
new InteractiveMap('my-map', {
|
|
64
|
+
behaviour: 'inline',
|
|
65
|
+
mapProvider: maplibreProvider(),
|
|
66
|
+
mapStyle: mapStyles[0],
|
|
67
|
+
center: [-0.1276, 51.5074],
|
|
68
|
+
zoom: 12,
|
|
69
|
+
containerHeight: '516px',
|
|
70
|
+
plugins: [mapStylesPlugin]
|
|
71
|
+
})
|
|
72
|
+
`
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
label: 'UMD',
|
|
76
|
+
language: 'html',
|
|
77
|
+
code: `
|
|
78
|
+
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
79
|
+
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
80
|
+
<script src="/your-assets-path/map-styles-plugin/index.js"></script>
|
|
81
|
+
|
|
82
|
+
<script>
|
|
83
|
+
const attribution = 'Contains OS data © Crown copyright and database rights 2025'
|
|
84
|
+
|
|
85
|
+
const mapStyles = [
|
|
86
|
+
{
|
|
87
|
+
id: 'outdoor',
|
|
88
|
+
label: 'Outdoor',
|
|
89
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-outdoor/style.json',
|
|
90
|
+
thumbnail: '/path/to/outdoor-thumbnail.jpg',
|
|
91
|
+
attribution,
|
|
92
|
+
backgroundColor: '#f5f5f0'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'night',
|
|
96
|
+
label: 'Night',
|
|
97
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-night/style.json',
|
|
98
|
+
thumbnail: '/path/to/night-thumbnail.jpg',
|
|
99
|
+
attribution,
|
|
100
|
+
mapColorScheme: 'dark',
|
|
101
|
+
appColorScheme: 'dark'
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'deuteranopia',
|
|
105
|
+
label: 'Deuteranopia',
|
|
106
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-deuteranopia/style.json',
|
|
107
|
+
thumbnail: '/path/to/deuteranopia-thumbnail.jpg',
|
|
108
|
+
attribution,
|
|
109
|
+
backgroundColor: '#f5f5f0'
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'tritanopia',
|
|
113
|
+
label: 'Tritanopia',
|
|
114
|
+
url: 'https://labs.os.uk/tiles/styles/open-zoomstack-tritanopia/style.json',
|
|
115
|
+
thumbnail: '/path/to/tritanopia-thumbnail.jpg',
|
|
116
|
+
attribution,
|
|
117
|
+
backgroundColor: '#f5f5f0'
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
const mapStylesPlugin = defra.mapStylesPlugin({ mapStyles })
|
|
122
|
+
|
|
123
|
+
new defra.InteractiveMap('my-map', {
|
|
124
|
+
behaviour: 'inline',
|
|
125
|
+
mapProvider: defra.maplibreProvider(),
|
|
126
|
+
mapStyle: mapStyles[0],
|
|
127
|
+
center: [-0.1276, 51.5074],
|
|
128
|
+
zoom: 12,
|
|
129
|
+
containerHeight: '516px',
|
|
130
|
+
plugins: [mapStylesPlugin]
|
|
131
|
+
})
|
|
132
|
+
</script>
|
|
133
|
+
`
|
|
134
|
+
}
|
|
135
|
+
]} />
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import DemoMapToggleMarkerLabel from '../../demo/DemoMapToggleMarkerLabel.js'
|
|
2
2
|
import CodeTabs from '../../demo/js/codeTabs.js'
|
|
3
3
|
|
|
4
|
-
# Toggle marker label
|
|
4
|
+
# Toggle marker label
|
|
5
5
|
|
|
6
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
7
|
|
|
@@ -29,7 +29,7 @@ Add a marker with a hidden label, then use the interact plugin to show the label
|
|
|
29
29
|
},
|
|
30
30
|
center: [-2.96, 54.43],
|
|
31
31
|
zoom: 15,
|
|
32
|
-
containerHeight: '
|
|
32
|
+
containerHeight: '516px',
|
|
33
33
|
plugins: [interactPlugin]
|
|
34
34
|
})
|
|
35
35
|
|
|
@@ -68,7 +68,7 @@ Add a marker with a hidden label, then use the interact plugin to show the label
|
|
|
68
68
|
},
|
|
69
69
|
center: [-2.96, 54.43],
|
|
70
70
|
zoom: 15,
|
|
71
|
-
containerHeight: '
|
|
71
|
+
containerHeight: '516px',
|
|
72
72
|
plugins: [interactPlugin]
|
|
73
73
|
})
|
|
74
74
|
|