@defra/interactive-map 0.0.31-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/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.md +55 -0
- package/docs/assets/css/docusaurus.scss +22 -6
- package/docs/assets/images/add-polygons.jpg +0 -0
- package/docs/assets/images/add-symbols.jpg +0 -0
- package/docs/assets/images/place-marker.jpg +0 -0
- package/docs/assets/images/screenshot.jpg +0 -0
- package/docs/examples/add-marker-with-panel.mdx +1 -1
- package/docs/examples/add-polygons.mdx +225 -0
- package/docs/examples/add-symbols.mdx +177 -0
- package/docs/examples/{draw.mdx → draw-tools.mdx} +2 -2
- package/docs/examples/index.mdx +38 -2
- package/docs/examples/place-marker.mdx +151 -0
- package/docs/plugins/datasets.md +144 -96
- package/docs/plugins/interact.md +1 -4
- package/docusaurus.config.cjs +5 -2
- package/govuk-prototype-kit.config.json +52 -2
- package/package.json +1 -1
- package/plugins/beta/datasets/dist/css/index.css +1 -2
- package/plugins/beta/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/index.js +1 -1
- package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +27 -9
- package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +46 -4
- package/plugins/beta/datasets/src/api/setFeatureVisibility.js +10 -1
- package/plugins/beta/datasets/src/api/setFeatureVisibility.test.js +48 -6
- package/plugins/beta/datasets/src/components/LayersMenu/Layers.module.scss +12 -12
- package/plugins/beta/datasets/src/reducers/datasetsToMenu.js +11 -6
- package/plugins/beta/datasets/src/reducers/datasetsToMenu.test.js +49 -0
- package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.js +8 -1
- package/plugins/beta/datasets/src/reducers/pluginState.js +1 -1
- package/plugins/beta/datasets/src/registry/dataset.js +7 -3
- package/plugins/beta/datasets/src/registry/dataset.test.js +14 -0
- package/plugins/beta/datasets/src/registry/dynamicGeoJson.js +1 -1
- 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/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 +1 -3
- package/plugins/interact/src/InteractInit.test.js +0 -2
- package/plugins/interact/src/events.test.js +1 -1
- 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 +5 -11
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +5 -25
- 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/src/App/components/CrossHair/CrossHair.module.scss +8 -8
- package/src/App/hooks/useLayoutMeasurements.js +10 -2
- package/src/App/hooks/useResizeObserver.js +4 -2
- package/src/InteractiveMap/InteractiveMap.js +4 -4
- package/src/InteractiveMap/InteractiveMap.test.js +3 -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/events.js +21 -3
- package/docs/assets/images/screens-blue.jpg +0 -0
- package/docs/assets/images/screens-white.jpg +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import DemoMapSymbols from '../../demo/DemoMapSymbols.js'
|
|
2
|
+
import CodeTabs from '../../demo/js/codeTabs.js'
|
|
3
|
+
|
|
4
|
+
# Add symbols
|
|
5
|
+
|
|
6
|
+
Use the datasets plugin to overlay GeoJSON data on your map. Each dataset can contain sublayers with independent filters and styles. This example shows historic monument points categorised by period, each styled with a distinct symbol and colour.
|
|
7
|
+
|
|
8
|
+
<DemoMapSymbols />
|
|
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 createDatasetsPlugin from '@defra/interactive-map/plugins/datasets'
|
|
18
|
+
|
|
19
|
+
const symbolGraphic = 'M3 15H1V1h2v2h2V1h2v5h2V4h2v2h2V4h2v11H6V9H3v6z'
|
|
20
|
+
|
|
21
|
+
// GeoJSON can also be loaded from a URL; use the tiles property for vector tile sources
|
|
22
|
+
const geojson = {
|
|
23
|
+
type: 'FeatureCollection',
|
|
24
|
+
features: [{
|
|
25
|
+
type: 'Feature',
|
|
26
|
+
properties: { category: 'prehistoric', name: 'Prehistoric feature' },
|
|
27
|
+
geometry: { type: 'Point', coordinates: [-2.4615, 54.5616] }
|
|
28
|
+
}, {
|
|
29
|
+
type: 'Feature',
|
|
30
|
+
properties: { category: 'roman', name: 'Roman feature' },
|
|
31
|
+
geometry: { type: 'Point', coordinates: [-2.4628, 54.5541] }
|
|
32
|
+
}, {
|
|
33
|
+
type: 'Feature',
|
|
34
|
+
properties: { category: 'medieval', name: 'Medieval feature' },
|
|
35
|
+
geometry: { type: 'Point', coordinates: [-2.4578, 54.5569] }
|
|
36
|
+
}]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const datasetsPlugin = createDatasetsPlugin({
|
|
40
|
+
datasets: [{
|
|
41
|
+
id: 'historic-monuments',
|
|
42
|
+
label: 'Historic monuments',
|
|
43
|
+
geojson: geojson,
|
|
44
|
+
minZoom: 10,
|
|
45
|
+
maxZoom: 24,
|
|
46
|
+
showInKey: true,
|
|
47
|
+
showInMenu: true,
|
|
48
|
+
sublayers: [{
|
|
49
|
+
id: 'prehistoric',
|
|
50
|
+
label: 'Prehistoric',
|
|
51
|
+
filter: ['in', ['get', 'category'], 'prehistoric'],
|
|
52
|
+
style: {
|
|
53
|
+
symbol: 'square',
|
|
54
|
+
symbolGraphic,
|
|
55
|
+
symbolBackgroundColor: '#00897B'
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
id: 'roman',
|
|
59
|
+
label: 'Roman',
|
|
60
|
+
filter: ['in', ['get', 'category'], 'roman'],
|
|
61
|
+
style: {
|
|
62
|
+
symbol: 'square',
|
|
63
|
+
symbolGraphic,
|
|
64
|
+
symbolBackgroundColor: '#ca3535'
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
id: 'medieval',
|
|
68
|
+
label: 'Medieval',
|
|
69
|
+
filter: ['in', ['get', 'category'], 'medieval'],
|
|
70
|
+
style: {
|
|
71
|
+
symbol: 'square',
|
|
72
|
+
symbolGraphic,
|
|
73
|
+
symbolBackgroundColor: '#1565C0'
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
}]
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
new InteractiveMap('my-map', {
|
|
80
|
+
behaviour: 'inline',
|
|
81
|
+
mapProvider: maplibreProvider(),
|
|
82
|
+
mapStyle: {
|
|
83
|
+
url: 'https://your-tile-url/style.json',
|
|
84
|
+
attribution: 'Your tile attribution'
|
|
85
|
+
},
|
|
86
|
+
center: [-2.4608, 54.5574],
|
|
87
|
+
zoom: 14,
|
|
88
|
+
containerHeight: '516px',
|
|
89
|
+
plugins: [datasetsPlugin]
|
|
90
|
+
})
|
|
91
|
+
`
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
label: 'UMD',
|
|
95
|
+
language: 'html',
|
|
96
|
+
code: `
|
|
97
|
+
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
98
|
+
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
99
|
+
<script src="/your-assets-path/datasets-plugin/index.js"></script>
|
|
100
|
+
|
|
101
|
+
<script>
|
|
102
|
+
const symbolGraphic = 'M3 15H1V1h2v2h2V1h2v5h2V4h2v2h2V4h2v11H6V9H3v6z'
|
|
103
|
+
|
|
104
|
+
// GeoJSON can also be loaded from a URL; use the tiles property for vector tile sources
|
|
105
|
+
const geojson = {
|
|
106
|
+
type: 'FeatureCollection',
|
|
107
|
+
features: [{
|
|
108
|
+
type: 'Feature',
|
|
109
|
+
properties: { category: 'prehistoric', name: 'Prehistoric feature' },
|
|
110
|
+
geometry: { type: 'Point', coordinates: [-2.4615, 54.5616] }
|
|
111
|
+
}, {
|
|
112
|
+
type: 'Feature',
|
|
113
|
+
properties: { category: 'roman', name: 'Roman feature' },
|
|
114
|
+
geometry: { type: 'Point', coordinates: [-2.4628, 54.5541] }
|
|
115
|
+
}, {
|
|
116
|
+
type: 'Feature',
|
|
117
|
+
properties: { category: 'medieval', name: 'Medieval feature' },
|
|
118
|
+
geometry: { type: 'Point', coordinates: [-2.4578, 54.5569] }
|
|
119
|
+
}]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const datasetsPlugin = defra.datasetsPlugin({
|
|
123
|
+
datasets: [{
|
|
124
|
+
id: 'historic-monuments',
|
|
125
|
+
label: 'Historic monuments',
|
|
126
|
+
geojson: geojson,
|
|
127
|
+
minZoom: 10,
|
|
128
|
+
maxZoom: 24,
|
|
129
|
+
showInKey: true,
|
|
130
|
+
showInMenu: true,
|
|
131
|
+
sublayers: [{
|
|
132
|
+
id: 'prehistoric',
|
|
133
|
+
label: 'Prehistoric',
|
|
134
|
+
filter: ['in', ['get', 'category'], 'prehistoric'],
|
|
135
|
+
style: {
|
|
136
|
+
symbol: 'square',
|
|
137
|
+
symbolGraphic,
|
|
138
|
+
symbolBackgroundColor: '#00897B'
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
id: 'roman',
|
|
142
|
+
label: 'Roman',
|
|
143
|
+
filter: ['in', ['get', 'category'], 'roman'],
|
|
144
|
+
style: {
|
|
145
|
+
symbol: 'square',
|
|
146
|
+
symbolGraphic,
|
|
147
|
+
symbolBackgroundColor: '#ca3535'
|
|
148
|
+
}
|
|
149
|
+
}, {
|
|
150
|
+
id: 'medieval',
|
|
151
|
+
label: 'Medieval',
|
|
152
|
+
filter: ['in', ['get', 'category'], 'medieval'],
|
|
153
|
+
style: {
|
|
154
|
+
symbol: 'square',
|
|
155
|
+
symbolGraphic,
|
|
156
|
+
symbolBackgroundColor: '#1565C0'
|
|
157
|
+
}
|
|
158
|
+
}]
|
|
159
|
+
}]
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
new defra.InteractiveMap('my-map', {
|
|
163
|
+
behaviour: 'inline',
|
|
164
|
+
mapProvider: defra.maplibreProvider(),
|
|
165
|
+
mapStyle: {
|
|
166
|
+
url: 'https://your-tile-url/style.json',
|
|
167
|
+
attribution: 'Your tile attribution'
|
|
168
|
+
},
|
|
169
|
+
center: [-2.4608, 54.5574],
|
|
170
|
+
zoom: 14,
|
|
171
|
+
containerHeight: '516px',
|
|
172
|
+
plugins: [datasetsPlugin]
|
|
173
|
+
})
|
|
174
|
+
</script>
|
|
175
|
+
`
|
|
176
|
+
}
|
|
177
|
+
]} />
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import DemoMapDrawTools from '../../demo/DemoMapDrawTools.js'
|
|
2
2
|
import CodeTabs from '../../demo/js/codeTabs.js'
|
|
3
3
|
|
|
4
4
|
# Draw tools
|
|
@@ -9,7 +9,7 @@ Draw, edit, select and delete polygons and lines using the draw and interact plu
|
|
|
9
9
|
The draw plugin (`draw-ml`) is currently in beta.
|
|
10
10
|
:::
|
|
11
11
|
|
|
12
|
-
<
|
|
12
|
+
<DemoMapDrawTools />
|
|
13
13
|
|
|
14
14
|
<CodeTabs tabs={[
|
|
15
15
|
{
|
package/docs/examples/index.mdx
CHANGED
|
@@ -2,11 +2,14 @@ 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 placeMarkerImg from '../assets/images/place-marker.jpg'
|
|
5
6
|
import toggleMarkerLabelImg from '../assets/images/toggle-marker-label.jpg'
|
|
6
7
|
import searchImg from '../assets/images/search.jpg'
|
|
7
8
|
import selectFeatureImg from '../assets/images/select-feature.jpg'
|
|
8
9
|
import styleSwitcherImg from '../assets/images/style-switcher.jpg'
|
|
9
10
|
import drawImg from '../assets/images/draw.jpg'
|
|
11
|
+
import addSymbolsImg from '../assets/images/add-symbols.jpg'
|
|
12
|
+
import addPolygonsImg from '../assets/images/add-polygons.jpg'
|
|
10
13
|
|
|
11
14
|
export function ExampleCards() {
|
|
12
15
|
const basicHref = useBaseUrl('/examples/basic-map')
|
|
@@ -16,7 +19,10 @@ export function ExampleCards() {
|
|
|
16
19
|
const searchControlHref = useBaseUrl('/examples/search-control')
|
|
17
20
|
const selectFeatureHref = useBaseUrl('/examples/select-feature')
|
|
18
21
|
const styleSwitcherHref = useBaseUrl('/examples/style-switcher')
|
|
19
|
-
const drawHref = useBaseUrl('/examples/draw')
|
|
22
|
+
const drawHref = useBaseUrl('/examples/draw-tools')
|
|
23
|
+
const placeMarkerHref = useBaseUrl('/examples/place-marker')
|
|
24
|
+
const datasetsHref = useBaseUrl('/examples/add-symbols')
|
|
25
|
+
const polygonsHref = useBaseUrl('/examples/add-polygons')
|
|
20
26
|
|
|
21
27
|
return (
|
|
22
28
|
<div className='govuk-grid-row app-example-cards'>
|
|
@@ -45,7 +51,7 @@ export function ExampleCards() {
|
|
|
45
51
|
<img src={markerPanelImg} alt='' />
|
|
46
52
|
<div className='app-example-card__body'>
|
|
47
53
|
<h2 className='govuk-heading-s'>
|
|
48
|
-
<a href={interactHref}>
|
|
54
|
+
<a href={interactHref}>Map with marker and panel</a>
|
|
49
55
|
</h2>
|
|
50
56
|
</div>
|
|
51
57
|
</div>
|
|
@@ -60,6 +66,16 @@ export function ExampleCards() {
|
|
|
60
66
|
</div>
|
|
61
67
|
</div>
|
|
62
68
|
</div>
|
|
69
|
+
<div className='govuk-grid-column-one-third'>
|
|
70
|
+
<div className='app-example-card'>
|
|
71
|
+
<img src={placeMarkerImg} alt='' />
|
|
72
|
+
<div className='app-example-card__body'>
|
|
73
|
+
<h2 className='govuk-heading-s'>
|
|
74
|
+
<a href={placeMarkerHref}>Place a marker to continue</a>
|
|
75
|
+
</h2>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
63
79
|
<div className='govuk-grid-column-one-third'>
|
|
64
80
|
<div className='app-example-card'>
|
|
65
81
|
<img src={searchImg} alt='' />
|
|
@@ -100,6 +116,26 @@ export function ExampleCards() {
|
|
|
100
116
|
</div>
|
|
101
117
|
</div>
|
|
102
118
|
</div>
|
|
119
|
+
<div className='govuk-grid-column-one-third'>
|
|
120
|
+
<div className='app-example-card'>
|
|
121
|
+
<img src={addSymbolsImg} alt='' />
|
|
122
|
+
<div className='app-example-card__body'>
|
|
123
|
+
<h2 className='govuk-heading-s'>
|
|
124
|
+
<a href={datasetsHref}>Add symbols</a>
|
|
125
|
+
</h2>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
<div className='govuk-grid-column-one-third'>
|
|
130
|
+
<div className='app-example-card'>
|
|
131
|
+
<img src={addPolygonsImg} alt='' />
|
|
132
|
+
<div className='app-example-card__body'>
|
|
133
|
+
<h2 className='govuk-heading-s'>
|
|
134
|
+
<a href={polygonsHref}>Add polygons</a>
|
|
135
|
+
</h2>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
103
139
|
</div>
|
|
104
140
|
)
|
|
105
141
|
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import DemoMapPlaceMarker from '../../demo/DemoMapPlaceMarker.js'
|
|
2
|
+
import CodeTabs from '../../demo/js/codeTabs.js'
|
|
3
|
+
|
|
4
|
+
# Place a marker to continue
|
|
5
|
+
|
|
6
|
+
Use the interact plugin's `placeMarker` mode to let users drop a location pin on the map before continuing a journey.
|
|
7
|
+
|
|
8
|
+
Two patterns work together in this example:
|
|
9
|
+
|
|
10
|
+
- **Hybrid behaviour with built-in back and continue** — on mobile the map opens fullscreen and the `backAndContinue` option renders Back and Continue buttons inside the map. The Continue button is enabled declaratively via `continueEnabledWhen` once a marker has been placed.
|
|
11
|
+
- **External Continue button for inline** — when the map is inline (tablet/desktop), a Continue button sits outside the map container. It uses `app:opened`, `app:closed`, and `app:fullscreenchange` to show and hide in sync with the map's display mode, and `interact:markerchange` to enable once a marker is placed.
|
|
12
|
+
|
|
13
|
+
<DemoMapPlaceMarker />
|
|
14
|
+
|
|
15
|
+
<CodeTabs tabs={[
|
|
16
|
+
{
|
|
17
|
+
label: 'ESM',
|
|
18
|
+
language: 'js',
|
|
19
|
+
code: `
|
|
20
|
+
import InteractiveMap from '@defra/interactive-map'
|
|
21
|
+
import maplibreProvider from '@defra/interactive-map/providers/maplibre'
|
|
22
|
+
import createInteractPlugin from '@defra/interactive-map/plugins/interact'
|
|
23
|
+
|
|
24
|
+
const interactPlugin = createInteractPlugin({
|
|
25
|
+
interactionModes: ['placeMarker']
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const map = new InteractiveMap('my-map', {
|
|
29
|
+
behaviour: 'hybrid',
|
|
30
|
+
mapProvider: maplibreProvider(),
|
|
31
|
+
mapStyle: {
|
|
32
|
+
url: 'https://your-tile-url/style.json',
|
|
33
|
+
attribution: 'Your tile attribution'
|
|
34
|
+
},
|
|
35
|
+
center: [-0.1276, 51.5074],
|
|
36
|
+
zoom: 12,
|
|
37
|
+
containerHeight: '516px',
|
|
38
|
+
plugins: [interactPlugin],
|
|
39
|
+
// Back and Continue buttons shown inside the map when fullscreen (mobile)
|
|
40
|
+
backAndContinue: {
|
|
41
|
+
backLabel: 'Back',
|
|
42
|
+
continueLabel: 'Continue',
|
|
43
|
+
continueEnabledWhen: ({ mapState }) =>
|
|
44
|
+
mapState.markers.items.some(m => m.id === 'location')
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
map.on('map:ready', () => {
|
|
49
|
+
interactPlugin.enable()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// Fired when the built-in Continue button is clicked (mobile/fullscreen)
|
|
53
|
+
map.on('app:continue', ({ mapState }) => {
|
|
54
|
+
const marker = mapState.markers.items.find(m => m.id === 'location')
|
|
55
|
+
// navigate to next step with marker.coords
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// --- External Continue button for inline (tablet/desktop) ---
|
|
59
|
+
|
|
60
|
+
const continueBtn = document.getElementById('continue-btn')
|
|
61
|
+
const externalButtons = document.getElementById('external-buttons')
|
|
62
|
+
|
|
63
|
+
// Show/hide external buttons based on whether the map is inline or fullscreen.
|
|
64
|
+
// app:opened fires on first load and when the map is shown after being hidden.
|
|
65
|
+
// app:fullscreenchange fires when the viewport resizes while the map is already visible.
|
|
66
|
+
const setInline = (isFullscreen) => {
|
|
67
|
+
externalButtons.hidden = isFullscreen
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
map.on('app:opened', ({ isFullscreen }) => { setInline(isFullscreen) })
|
|
71
|
+
map.on('app:closed', () => { externalButtons.hidden = true })
|
|
72
|
+
map.on('app:fullscreenchange', ({ isFullscreen }) => { setInline(isFullscreen) })
|
|
73
|
+
|
|
74
|
+
map.on('interact:markerchange', () => {
|
|
75
|
+
continueBtn.disabled = false
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
continueBtn.addEventListener('click', () => {
|
|
79
|
+
// navigate to next step
|
|
80
|
+
})
|
|
81
|
+
`
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
label: 'UMD',
|
|
85
|
+
language: 'html',
|
|
86
|
+
code: `
|
|
87
|
+
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
88
|
+
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
89
|
+
<script src="/your-assets-path/interact-plugin/index.js"></script>
|
|
90
|
+
|
|
91
|
+
<div id="my-map"></div>
|
|
92
|
+
<div id="external-buttons" hidden>
|
|
93
|
+
<button class="govuk-button" id="continue-btn" disabled>Continue</button>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<script>
|
|
97
|
+
var interactPlugin = defra.interactPlugin({
|
|
98
|
+
interactionModes: ['placeMarker']
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
var map = new defra.InteractiveMap('my-map', {
|
|
102
|
+
behaviour: 'hybrid',
|
|
103
|
+
mapProvider: defra.maplibreProvider(),
|
|
104
|
+
mapStyle: {
|
|
105
|
+
url: 'https://your-tile-url/style.json',
|
|
106
|
+
attribution: 'Your tile attribution'
|
|
107
|
+
},
|
|
108
|
+
center: [-0.1276, 51.5074],
|
|
109
|
+
zoom: 12,
|
|
110
|
+
containerHeight: '516px',
|
|
111
|
+
plugins: [interactPlugin],
|
|
112
|
+
backAndContinue: {
|
|
113
|
+
backLabel: 'Back',
|
|
114
|
+
continueLabel: 'Continue',
|
|
115
|
+
continueEnabledWhen: function (context) {
|
|
116
|
+
return context.mapState.markers.items.some(function (m) { return m.id === 'location' })
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
map.on('map:ready', function () {
|
|
122
|
+
interactPlugin.enable()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
map.on('app:continue', function (context) {
|
|
126
|
+
var marker = context.mapState.markers.items.find(function (m) { return m.id === 'location' })
|
|
127
|
+
// navigate to next step with marker.coords
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
var continueBtn = document.getElementById('continue-btn')
|
|
131
|
+
var externalButtons = document.getElementById('external-buttons')
|
|
132
|
+
|
|
133
|
+
function setInline(isFullscreen) {
|
|
134
|
+
externalButtons.hidden = isFullscreen
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
map.on('app:opened', function (e) { setInline(e.isFullscreen) })
|
|
138
|
+
map.on('app:closed', function () { externalButtons.hidden = true })
|
|
139
|
+
map.on('app:fullscreenchange', function (e) { setInline(e.isFullscreen) })
|
|
140
|
+
|
|
141
|
+
map.on('interact:markerchange', function () {
|
|
142
|
+
continueBtn.disabled = false
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
continueBtn.addEventListener('click', function () {
|
|
146
|
+
// navigate to next step
|
|
147
|
+
})
|
|
148
|
+
</script>
|
|
149
|
+
`
|
|
150
|
+
}
|
|
151
|
+
]} />
|