@defra/interactive-map 0.0.54-alpha → 0.0.55-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/templates/add-polygons.njk +1 -1
- package/assets/templates/add-symbols.njk +4 -4
- package/assets/templates/draw-tools.njk +7 -7
- package/assets/templates/marker-panel.njk +5 -5
- package/assets/templates/place-marker.njk +8 -8
- package/assets/templates/search-control.njk +1 -1
- package/assets/templates/select-feature.njk +7 -7
- package/assets/templates/style-switcher.njk +4 -4
- package/assets/templates/toggle-marker-label.njk +3 -3
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/im-core.js.LICENSE.txt +0 -30
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.LICENSE.txt +0 -20
- package/docs/api.md +3 -13
- package/docs/building-a-plugin.md +2 -2
- package/docs/examples/add-marker-with-panel.mdx +46 -44
- package/docs/examples/add-polygons.mdx +100 -98
- package/docs/examples/add-symbols.mdx +75 -73
- package/docs/examples/basic-map.mdx +16 -14
- package/docs/examples/button-map.mdx +16 -14
- package/docs/examples/draw-tools.mdx +119 -117
- package/docs/examples/place-marker.mdx +51 -49
- package/docs/examples/search-control.mdx +22 -20
- package/docs/examples/select-feature.mdx +107 -105
- package/docs/examples/style-switcher.mdx +47 -45
- package/docs/examples/toggle-marker-label.mdx +30 -28
- package/docs/getting-started.md +26 -24
- package/docs/plugins/draw.md +10 -10
- package/docs/plugins/interact.md +9 -9
- package/docs/plugins/plugin-descriptor.md +1 -1
- package/docs/plugins/search.md +3 -3
- package/docusaurus.config.cjs +23 -0
- package/package.json +3 -7
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/index.js +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/esm/index.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/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/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/esm/index.js +1 -1
- package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
- package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/esm/index.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/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/esm/index.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/esm/index.js +1 -1
- package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/umd/index.js +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/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/index.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/index.js +27 -4
- package/providers/beta/openlayers/src/index.test.js +47 -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-framework.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
- package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +41 -12
- package/providers/maplibre/src/index.test.js +43 -12
- package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
- package/providers/maplibre/src/utils/spatial.js +22 -12
- package/providers/maplibre/src/utils/spatial.test.js +6 -6
- package/providers/maplibre/src/utils/workerUrl.js +15 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
- package/rollup.esm.mjs +38 -1
- package/src/InteractiveMap/InteractiveMap.js +2 -1
- package/src/InteractiveMap/InteractiveMap.test.js +9 -2
- package/src/InteractiveMap/domStateManager.js +21 -1
- package/src/InteractiveMap/domStateManager.test.js +48 -1
- package/src/InteractiveMap/polyfills.js +4 -3
- package/src/InteractiveMap/polyfills.test.js +12 -0
- package/src/types.js +3 -5
- package/webpack.dev.mjs +2 -0
- package/webpack.umd.mjs +28 -7
|
@@ -117,7 +117,7 @@ The layer ID used here (`field-parcels`) comes from the datasets plugin — a da
|
|
|
117
117
|
|
|
118
118
|
map.on('interact:selectionchange', ({ selectedFeatures }) => {
|
|
119
119
|
if (selectedFeatures.length > 0) {
|
|
120
|
-
const name = selectedFeatures[0].properties.name
|
|
120
|
+
const name = event.selectedFeatures[0].properties.name
|
|
121
121
|
document.getElementById('parcel-info-content').innerHTML =
|
|
122
122
|
'<p class="govuk-body govuk-!-margin-bottom-1">' + name + '</p>'
|
|
123
123
|
map.showPanel(PANEL_ID)
|
|
@@ -137,121 +137,123 @@ The layer ID used here (`field-parcels`) comes from the datasets plugin — a da
|
|
|
137
137
|
label: 'UMD',
|
|
138
138
|
language: 'html',
|
|
139
139
|
code: `
|
|
140
|
-
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
141
|
-
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
142
|
-
<script src="/your-assets-path/datasets-plugin/index.js"></script>
|
|
143
|
-
<script src="/your-assets-path/interact-plugin/index.js"></script>
|
|
140
|
+
<script defer src="/your-assets-path/interactive-map/index.js"></script>
|
|
141
|
+
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
142
|
+
<script defer src="/your-assets-path/datasets-plugin/index.js"></script>
|
|
143
|
+
<script defer src="/your-assets-path/interact-plugin/index.js"></script>
|
|
144
144
|
|
|
145
145
|
<script>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
146
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
147
|
+
// GeoJSON can also be loaded from a URL; use the tiles property for vector tile sources
|
|
148
|
+
const geojson = {
|
|
149
|
+
type: 'FeatureCollection',
|
|
150
|
+
features: [{
|
|
151
|
+
type: 'Feature',
|
|
152
|
+
id: 1,
|
|
153
|
+
properties: { name: 'Large meadow', land_use: 'Permanent grassland' },
|
|
154
|
+
geometry: { type: 'Polygon', coordinates: [[[-2.4691585,54.5552164],[-2.4692202,54.5553906],[-2.4690646,54.5554155],[-2.4690002,54.5555088],[-2.4690297,54.5556690],[-2.4690995,54.5557919],[-2.4669269,54.5566971],[-2.4662375,54.5562819],[-2.4637780,54.5574391],[-2.4628580,54.5568169],[-2.4607612,54.5560985],[-2.4608248,54.5560719],[-2.4611789,54.5558914],[-2.4613774,54.5558168],[-2.4615973,54.5557577],[-2.4617475,54.5557297],[-2.4618816,54.5556519],[-2.4620104,54.5556115],[-2.4624771,54.5555275],[-2.4627131,54.5555150],[-2.4628741,54.5554839],[-2.4630082,54.5554404],[-2.4632335,54.5553346],[-2.4633944,54.5552164],[-2.4634749,54.5551106],[-2.4635178,54.5550235],[-2.4635285,54.5548213],[-2.4635768,54.5546346],[-2.4635875,54.5544884],[-2.4636090,54.5544075],[-2.4636465,54.5543515],[-2.4636573,54.5542769],[-2.4636358,54.5541804],[-2.4637377,54.5540155],[-2.4639094,54.5538724],[-2.4643493,54.5535831],[-2.4645370,54.5535084],[-2.4647141,54.5534804],[-2.4648052,54.5534836],[-2.4648213,54.5535116],[-2.4648750,54.5535396],[-2.4650842,54.5535893],[-2.4652451,54.5536516],[-2.4652719,54.5536796],[-2.4653900,54.5537355],[-2.4655455,54.5537853],[-2.4658459,54.5539502],[-2.4663556,54.5542738],[-2.4668008,54.5545164],[-2.4668330,54.5545506],[-2.4668437,54.5546782],[-2.4668598,54.5547031],[-2.4670798,54.5548306],[-2.4671817,54.5549053],[-2.4674177,54.5549364],[-2.4677664,54.5550484],[-2.4681956,54.5551448],[-2.4684101,54.5551759],[-2.4691129,54.5552195],[-2.4691585,54.5552164]]] }
|
|
155
|
+
}, {
|
|
156
|
+
type: 'Feature',
|
|
157
|
+
id: 2,
|
|
158
|
+
properties: { name: 'Lamb field', land_use: 'Arable' },
|
|
159
|
+
geometry: { type: 'Polygon', coordinates: [[[-2.4611682,54.5562375],[-2.4628580,54.5568161],[-2.4636841,54.5573753],[-2.4637793,54.5574398],[-2.4641401,54.5576751],[-2.4642567,54.5577999],[-2.4641307,54.5578823],[-2.4636841,54.5582502],[-2.4624221,54.5592884],[-2.4623376,54.5592534],[-2.4615370,54.5586429],[-2.4611869,54.5582852],[-2.4605258,54.5581071],[-2.4598472,54.5578186],[-2.4611682,54.5562375]]] }
|
|
160
|
+
}, {
|
|
161
|
+
type: 'Feature',
|
|
162
|
+
id: 3,
|
|
163
|
+
properties: { name: 'Small hay field', land_use: 'Arable' },
|
|
164
|
+
geometry: { type: 'Polygon', coordinates: [[[-2.4598472,54.5578186],[-2.4605258,54.5581067],[-2.4611869,54.5582852],[-2.4615376,54.5586433],[-2.4623108,54.5592332],[-2.4623376,54.5592534],[-2.4624221,54.5592884],[-2.4623108,54.5594120],[-2.4616731,54.5601189],[-2.4586053,54.5601189],[-2.4584410,54.5600299],[-2.4580038,54.5596574],[-2.4581815,54.5593953],[-2.4585778,54.5590702],[-2.4587287,54.5589353],[-2.4589198,54.5586736],[-2.4591116,54.5582136],[-2.4598472,54.5578186]]] }
|
|
165
|
+
}, {
|
|
166
|
+
type: 'Feature',
|
|
167
|
+
id: 4,
|
|
168
|
+
properties: { name: 'The pasture', land_use: 'Permanent grassland' },
|
|
169
|
+
geometry: { type: 'Polygon', coordinates: [[[-2.4633756,54.5612877],[-2.4613908,54.5604315],[-2.4624221,54.5592884],[-2.4641307,54.5578823],[-2.4642567,54.5577999],[-2.4653631,54.5591733],[-2.4659613,54.5597013],[-2.4633756,54.5612877]]] }
|
|
170
|
+
}, {
|
|
171
|
+
type: 'Feature',
|
|
172
|
+
id: 5,
|
|
173
|
+
properties: { name: 'Herdwick Croft', land_use: 'Arable' },
|
|
174
|
+
geometry: { type: 'Polygon', coordinates: [[[-2.4678040,54.5590679],[-2.4661879,54.5595952],[-2.4659613,54.5597013],[-2.4653638,54.5591737],[-2.4642567,54.5577999],[-2.4641401,54.5576751],[-2.4637793,54.5574398],[-2.4662369,54.5562822],[-2.4669282,54.5566975],[-2.4678040,54.5563320],[-2.4678040,54.5590679]]] }
|
|
175
|
+
}, {
|
|
176
|
+
type: 'Feature',
|
|
177
|
+
id: 6,
|
|
178
|
+
properties: { name: "Wainwright's Rest", land_use: 'Permanent grassland' },
|
|
179
|
+
geometry: { type: 'Polygon', coordinates: [[[-2.4669316,54.5603767],[-2.4676430,54.5613102],[-2.4673292,54.5614556],[-2.4671616,54.5617468],[-2.4658446,54.5625528],[-2.4651546,54.5621528],[-2.4639215,54.5633040],[-2.4633146,54.5633040],[-2.4628372,54.5630921],[-2.4631195,54.5628195],[-2.4643741,54.5618374],[-2.4665071,54.5604793],[-2.4667056,54.5604187],[-2.4669316,54.5603767]]] }
|
|
180
|
+
}, {
|
|
181
|
+
type: 'Feature',
|
|
182
|
+
id: 7,
|
|
183
|
+
properties: { name: 'Badger Sett Copse', land_use: 'Woodland' },
|
|
184
|
+
geometry: { type: 'Polygon', coordinates: [[[-2.4599129,54.5564203],[-2.4599773,54.5565478],[-2.4599773,54.5565852],[-2.4599344,54.5566256],[-2.4596876,54.5566069],[-2.4594945,54.5566132],[-2.4593657,54.5566505],[-2.4592584,54.5567158],[-2.4592048,54.5567780],[-2.4591780,54.5568496],[-2.4591887,54.5569616],[-2.4591297,54.5570829],[-2.4590009,54.5572726],[-2.4589419,54.5573162],[-2.4588561,54.5574686],[-2.4587435,54.5575588],[-2.4586684,54.5575837],[-2.4585879,54.5575962],[-2.4584001,54.5575837],[-2.4583304,54.5575899],[-2.4580836,54.5576397],[-2.4579817,54.5576895],[-2.4579227,54.5576988],[-2.4578154,54.5576988],[-2.4576384,54.5576739],[-2.4574614,54.5576739],[-2.4573044,54.5577050],[-2.4563093,54.5573092],[-2.4563871,54.5569849],[-2.4564891,54.5560664],[-2.4565601,54.5559039],[-2.4567747,54.5559412],[-2.4571985,54.5559817],[-2.4573219,54.5560097],[-2.4576116,54.5560936],[-2.4582446,54.5562181],[-2.4584913,54.5562959],[-2.4590331,54.5563705],[-2.4599129,54.5564203]]] }
|
|
185
|
+
}]
|
|
186
|
+
}
|
|
186
187
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
188
|
+
const datasetsPlugin = defra.datasetsPlugin({
|
|
189
|
+
datasets: [{
|
|
190
|
+
id: 'field-parcels',
|
|
191
|
+
geojson: geojson,
|
|
192
|
+
minZoom: 10,
|
|
193
|
+
maxZoom: 24,
|
|
194
|
+
style: {
|
|
195
|
+
fill: '#1d70b8',
|
|
196
|
+
opacity: 0.4,
|
|
197
|
+
stroke: '#1d70b8',
|
|
198
|
+
strokeWidth: 2
|
|
199
|
+
}
|
|
200
|
+
}]
|
|
201
|
+
})
|
|
201
202
|
|
|
202
|
-
|
|
203
|
+
const PANEL_ID = 'parcel-info'
|
|
203
204
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
const interactPlugin = defra.interactPlugin({
|
|
206
|
+
interactionModes: ['selectFeature'],
|
|
207
|
+
deselectOnClickOutside: true,
|
|
208
|
+
layers: [
|
|
209
|
+
{ layerId: 'field-parcels', idProperty: 'name' }
|
|
210
|
+
]
|
|
211
|
+
})
|
|
211
212
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
213
|
+
const map = new defra.InteractiveMap('my-map', {
|
|
214
|
+
behaviour: 'inline',
|
|
215
|
+
mapProvider: defra.maplibreProvider(),
|
|
216
|
+
mapStyle: {
|
|
217
|
+
url: 'https://your-tile-url/style.json',
|
|
218
|
+
logo: '/path/to/logo.svg',
|
|
219
|
+
logoAltText: 'Your logo alt text',
|
|
220
|
+
attribution: 'Your tile attribution'
|
|
221
|
+
},
|
|
222
|
+
center: [-2.464, 54.558],
|
|
223
|
+
zoom: 14,
|
|
224
|
+
containerHeight: '516px',
|
|
225
|
+
plugins: [datasetsPlugin, interactPlugin]
|
|
226
|
+
})
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
|
|
228
|
+
map.on('map:ready', function () {
|
|
229
|
+
interactPlugin.enable()
|
|
229
230
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
231
|
+
map.addPanel(PANEL_ID, {
|
|
232
|
+
focus: false,
|
|
233
|
+
label: 'Selected parcel',
|
|
234
|
+
html: '<div id="parcel-info-content"></div>',
|
|
235
|
+
mobile: { slot: 'drawer', dismissible: true },
|
|
236
|
+
tablet: { slot: 'left-top', dismissible: true, width: '300px' },
|
|
237
|
+
desktop: { slot: 'left-top', dismissible: true, width: '300px' }
|
|
238
|
+
})
|
|
237
239
|
})
|
|
238
|
-
})
|
|
239
240
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
241
|
+
map.on('interact:selectionchange', function (event) {
|
|
242
|
+
if (event.selectedFeatures.length > 0) {
|
|
243
|
+
const name = event.selectedFeatures[0].properties.name
|
|
244
|
+
document.getElementById('parcel-info-content').innerHTML =
|
|
245
|
+
'<p class="govuk-body govuk-!-margin-bottom-1">' + name + '</p>'
|
|
246
|
+
map.showPanel(PANEL_ID)
|
|
247
|
+
} else {
|
|
248
|
+
map.hidePanel(PANEL_ID)
|
|
249
|
+
}
|
|
250
|
+
})
|
|
250
251
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
map.on('app:panelclosed', function (event) {
|
|
253
|
+
if (event.panelId === PANEL_ID) {
|
|
254
|
+
interactPlugin.clear()
|
|
255
|
+
}
|
|
256
|
+
})
|
|
255
257
|
})
|
|
256
258
|
</script>
|
|
257
259
|
`
|
|
@@ -71,55 +71,57 @@ The live demo uses OS Open Zoomstack tiles from OS Labs, which do not require an
|
|
|
71
71
|
label: 'UMD',
|
|
72
72
|
language: 'html',
|
|
73
73
|
code: `
|
|
74
|
-
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
75
|
-
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
76
|
-
<script src="/your-assets-path/map-styles-plugin/index.js"></script>
|
|
74
|
+
<script defer src="/your-assets-path/interactive-map/index.js"></script>
|
|
75
|
+
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
76
|
+
<script defer src="/your-assets-path/map-styles-plugin/index.js"></script>
|
|
77
77
|
|
|
78
78
|
<script>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
79
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
80
|
+
const mapStyles = [
|
|
81
|
+
{
|
|
82
|
+
id: 'outdoor',
|
|
83
|
+
label: 'Outdoor',
|
|
84
|
+
url: 'https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main/OS_VTS_3857_Open_Outdoor.json',
|
|
85
|
+
thumbnail: '/path/to/outdoor-thumbnail.jpg',
|
|
86
|
+
logo: '/path/to/outdoor-logo.svg',
|
|
87
|
+
logoAltText: 'Ordnance Survey logo',
|
|
88
|
+
attribution: 'Contains OS data © Crown copyright and database rights 2025',
|
|
89
|
+
backgroundColor: '#f5f5f0'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'dark',
|
|
93
|
+
label: 'Dark',
|
|
94
|
+
url: 'https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main/OS_VTS_3857_Open_Dark.json',
|
|
95
|
+
thumbnail: '/path/to/dark-thumbnail.jpg',
|
|
96
|
+
logo: '/path/to/dark-logo.svg',
|
|
97
|
+
logoAltText: 'Ordnance Survey logo',
|
|
98
|
+
attribution: 'Contains OS data © Crown copyright and database rights 2025',
|
|
99
|
+
mapColorScheme: 'dark',
|
|
100
|
+
appColorScheme: 'dark'
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'blackWhite',
|
|
104
|
+
label: 'Black/White',
|
|
105
|
+
url: 'https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main/OS_VTS_3857_Open_Black_and_White.json',
|
|
106
|
+
thumbnail: '/path/to/black-white-thumbnail.jpg',
|
|
107
|
+
logo: '/path/to/black-white-logo.svg',
|
|
108
|
+
logoAltText: 'Ordnance Survey logo',
|
|
109
|
+
attribution: 'Contains OS data © Crown copyright and database rights 2025',
|
|
110
|
+
backgroundColor: '#f5f5f0'
|
|
111
|
+
}
|
|
112
|
+
]
|
|
112
113
|
|
|
113
|
-
|
|
114
|
+
const mapStylesPlugin = defra.mapStylesPlugin({ mapStyles: mapStyles })
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
new defra.InteractiveMap('my-map', {
|
|
117
|
+
behaviour: 'inline',
|
|
118
|
+
mapProvider: defra.maplibreProvider(),
|
|
119
|
+
mapStyle: mapStyles[0],
|
|
120
|
+
center: [-0.1276, 51.5074],
|
|
121
|
+
zoom: 12,
|
|
122
|
+
containerHeight: '516px',
|
|
123
|
+
plugins: [mapStylesPlugin]
|
|
124
|
+
})
|
|
123
125
|
})
|
|
124
126
|
</script>
|
|
125
127
|
`
|
|
@@ -52,40 +52,42 @@ Add a marker with a hidden label, then use the interact plugin to show the label
|
|
|
52
52
|
label: 'UMD',
|
|
53
53
|
language: 'html',
|
|
54
54
|
code: `
|
|
55
|
-
<script src="/your-assets-path/interactive-map/index.js"></script>
|
|
56
|
-
<script src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
57
|
-
<script src="/your-assets-path/interact-plugin/index.js"></script>
|
|
55
|
+
<script defer src="/your-assets-path/interactive-map/index.js"></script>
|
|
56
|
+
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
57
|
+
<script defer src="/your-assets-path/interact-plugin/index.js"></script>
|
|
58
58
|
|
|
59
59
|
<script>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
61
|
+
const interactPlugin = defra.interactPlugin({
|
|
62
|
+
deselectOnClickOutside: true
|
|
63
|
+
})
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
65
|
+
const map = new defra.InteractiveMap('my-map', {
|
|
66
|
+
behaviour: 'inline',
|
|
67
|
+
mapProvider: defra.maplibreProvider(),
|
|
68
|
+
mapStyle: {
|
|
69
|
+
url: 'https://your-tile-url/style.json',
|
|
70
|
+
logo: '/path/to/logo.svg',
|
|
71
|
+
logoAltText: 'Your logo alt text',
|
|
72
|
+
attribution: 'Your tile attribution'
|
|
73
|
+
},
|
|
74
|
+
center: [-2.96, 54.43],
|
|
75
|
+
zoom: 15,
|
|
76
|
+
containerHeight: '516px',
|
|
77
|
+
plugins: [interactPlugin]
|
|
78
|
+
})
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
map.on('map:ready', function () {
|
|
81
|
+
map.addMarker('my-marker', [-2.96, 54.43], {
|
|
82
|
+
label: 'My location',
|
|
83
|
+
showLabel: false
|
|
84
|
+
})
|
|
85
|
+
interactPlugin.enable()
|
|
83
86
|
})
|
|
84
|
-
interactPlugin.enable()
|
|
85
|
-
})
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
map.on('interact:selectionchange', function (event) {
|
|
89
|
+
map.updateMarker('my-marker', { showLabel: event.selectedMarkers.includes('my-marker') })
|
|
90
|
+
})
|
|
89
91
|
})
|
|
90
92
|
</script>
|
|
91
93
|
`
|
package/docs/getting-started.md
CHANGED
|
@@ -19,10 +19,7 @@ See [GOV.UK Prototype Kit - Install and use plugins](https://prototype-kit.servi
|
|
|
19
19
|
|
|
20
20
|
## Manual setup
|
|
21
21
|
|
|
22
|
-
The package is
|
|
23
|
-
|
|
24
|
-
- **ESM** (ECMAScript Modules) — for projects using a bundler such as Webpack or Rollup. Import directly from the package in your JavaScript.
|
|
25
|
-
- **UMD** (Universal Module Definition) — for projects without a bundler. Copy the built files to your assets and load them via `<script>` tags.
|
|
22
|
+
The package is shipped in two formats, **ESM** (ECMAScript Modules) and **UMD** (Universal Module Definition). If your project uses a bundler, such as webpack or Vite, use the ESM build and import the package directly in your JavaScript. If it doesn't, use the UMD build: copy the built files to your assets and load them with `<script>` tags.
|
|
26
23
|
|
|
27
24
|
The map component also requires a **map provider** — a separate library that handles the underlying tile rendering engine. The provider is passed in at initialisation, which keeps the core package lean and lets you choose the engine that fits your needs.
|
|
28
25
|
|
|
@@ -30,13 +27,8 @@ The map component also requires a **map provider** — a separate library that h
|
|
|
30
27
|
|
|
31
28
|
`maplibre-gl` is installed with this package (ESM) or bundled (UMD) — no separate install needed.
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
The ESRI provider is available for ESM projects only. Install `@arcgis/core` separately:
|
|
36
|
-
|
|
37
|
-
```shell
|
|
38
|
-
npm install @arcgis/core
|
|
39
|
-
```
|
|
30
|
+
> [!NOTE]
|
|
31
|
+
> With a bundler other than webpack or Vite (such as esbuild), set the MapLibre [`workerUrl`](./api.md#workerurl) option.
|
|
40
32
|
|
|
41
33
|
### OpenLayers provider (optional)
|
|
42
34
|
|
|
@@ -48,7 +40,15 @@ npm install ol proj4
|
|
|
48
40
|
|
|
49
41
|
**UMD:** `ol` and `proj4` are bundled — no separate install needed.
|
|
50
42
|
|
|
51
|
-
###
|
|
43
|
+
### ESRI provider (optional)
|
|
44
|
+
|
|
45
|
+
The ESRI provider is built for specific use cases, so it currently has a more limited set of features than MapLibre and OpenLayers. It's available for ESM projects only. Install `@arcgis/core` separately:
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
npm install @arcgis/core
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Bundler configuration (ESM)
|
|
52
52
|
|
|
53
53
|
Some plugins work with more than one map provider. They load an adapter for your provider at runtime, and each adapter imports its own map engine. Only the adapter for your provider is ever loaded in the browser, but your bundler still builds every adapter, so it fails to resolve the engines you haven't installed:
|
|
54
54
|
|
|
@@ -64,9 +64,11 @@ Tell your bundler to ignore the engines for the providers you don't use. Plugins
|
|
|
64
64
|
| OpenLayers | `@arcgis/core` | `/^@arcgis\/core(\/\|$)/` |
|
|
65
65
|
| ESRI | `ol`, `proj4` | `/^(ol\|proj4)(\/\|$)/` |
|
|
66
66
|
|
|
67
|
+
The ignored engines are only used by adapters for other providers, which are never loaded, so nothing is missing at runtime. If you switch provider, update the pattern to match.
|
|
68
|
+
|
|
67
69
|
The examples below are for the MapLibre provider. For another provider, swap in its pattern.
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
### Webpack
|
|
70
72
|
|
|
71
73
|
```js
|
|
72
74
|
import webpack from 'webpack'
|
|
@@ -79,7 +81,9 @@ export default {
|
|
|
79
81
|
}
|
|
80
82
|
```
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
### Vite
|
|
85
|
+
|
|
86
|
+
This applies to production builds; the dev server only warns.
|
|
83
87
|
|
|
84
88
|
```js
|
|
85
89
|
export default {
|
|
@@ -91,7 +95,7 @@ export default {
|
|
|
91
95
|
}
|
|
92
96
|
```
|
|
93
97
|
|
|
94
|
-
|
|
98
|
+
### Rollup
|
|
95
99
|
|
|
96
100
|
```js
|
|
97
101
|
export default {
|
|
@@ -100,7 +104,7 @@ export default {
|
|
|
100
104
|
}
|
|
101
105
|
```
|
|
102
106
|
|
|
103
|
-
|
|
107
|
+
### esbuild
|
|
104
108
|
|
|
105
109
|
```js
|
|
106
110
|
await esbuild.build({
|
|
@@ -109,8 +113,6 @@ await esbuild.build({
|
|
|
109
113
|
})
|
|
110
114
|
```
|
|
111
115
|
|
|
112
|
-
The ignored engines are only used by adapters for other providers, which are never loaded, so nothing is missing at runtime. If you switch provider, update the pattern to match.
|
|
113
|
-
|
|
114
116
|
## Basic usage
|
|
115
117
|
|
|
116
118
|
**ESM** — add a container element to your HTML and initialise the map in your JavaScript:
|
|
@@ -151,7 +153,7 @@ const interactiveMap = new InteractiveMap('map', {
|
|
|
151
153
|
<link rel="stylesheet" href="/your-assets-path/interactive-map.css">
|
|
152
154
|
<script defer src="/your-assets-path/interactive-map/index.js"></script>
|
|
153
155
|
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>
|
|
154
|
-
<script
|
|
156
|
+
<script>
|
|
155
157
|
document.addEventListener('DOMContentLoaded', function () {
|
|
156
158
|
const interactiveMap = new defra.InteractiveMap('map', {
|
|
157
159
|
mapProvider: defra.maplibreProvider(),
|
|
@@ -176,15 +178,16 @@ const interactiveMap = new InteractiveMap('map', {
|
|
|
176
178
|
```
|
|
177
179
|
|
|
178
180
|
> [!NOTE]
|
|
181
|
+
> Load the scripts with `defer` and create the map inside a `DOMContentLoaded` listener, as above, so the page isn't blocked while they download. Don't use `async`, as the scripts must run in order.
|
|
182
|
+
>
|
|
179
183
|
> Scripts are loaded dynamically — all files in each `umd/` folder must be served from the same directory as their `index.js`.
|
|
180
184
|
|
|
181
185
|
## Using plugins
|
|
182
186
|
|
|
183
|
-
**ESM** — add the plugin import
|
|
187
|
+
**ESM** — add the plugin import alongside your existing core imports, then pass it to `plugins`:
|
|
184
188
|
|
|
185
189
|
```js
|
|
186
190
|
import createInteractPlugin from '@defra/interactive-map/plugins/interact'
|
|
187
|
-
import '@defra/interactive-map/plugins/interact/css'
|
|
188
191
|
|
|
189
192
|
const interactiveMap = new InteractiveMap('map', {
|
|
190
193
|
// ...your existing options
|
|
@@ -192,10 +195,9 @@ const interactiveMap = new InteractiveMap('map', {
|
|
|
192
195
|
})
|
|
193
196
|
```
|
|
194
197
|
|
|
195
|
-
**UMD** — copy the plugin's `dist/umd/` folder to your assets if you haven't already, then add its script
|
|
198
|
+
**UMD** — copy the plugin's `dist/umd/` folder to your assets if you haven't already, then add its script to your page skeleton:
|
|
196
199
|
|
|
197
200
|
```html
|
|
198
|
-
<link rel="stylesheet" href="/your-assets-path/interact-plugin.css">
|
|
199
201
|
<script defer src="/your-assets-path/interact-plugin/index.js"></script>
|
|
200
202
|
```
|
|
201
203
|
|
|
@@ -208,4 +210,4 @@ const interactiveMap = new defra.InteractiveMap('map', {
|
|
|
208
210
|
})
|
|
209
211
|
```
|
|
210
212
|
|
|
211
|
-
|
|
213
|
+
The datasets, draw, frame, map-key, map-styles, menu, scale-bar and search plugins also have their own CSS. With ESM, import it alongside the plugin, for example `import '@defra/interactive-map/plugins/datasets/css'`. With UMD, copy the plugin's `dist/css/index.css` to your assets and add it to your page with a `<link>`.
|
package/docs/plugins/draw.md
CHANGED
|
@@ -343,11 +343,11 @@ Always snaps to the polygon's own outline, in addition to any layers in `snapLay
|
|
|
343
343
|
```js
|
|
344
344
|
drawPlugin.split(selectedFeatureId)
|
|
345
345
|
|
|
346
|
-
interactiveMap.on('draw:split', (
|
|
347
|
-
drawPlugin.deleteFeature([
|
|
348
|
-
|
|
346
|
+
interactiveMap.on('draw:split', (event) => {
|
|
347
|
+
drawPlugin.deleteFeature([event.originalFeatureId])
|
|
348
|
+
event.featureCollection.features.forEach((feature, index) => {
|
|
349
349
|
drawPlugin.addFeature({
|
|
350
|
-
id: `${
|
|
350
|
+
id: `${event.originalFeatureId}-${index === 0 ? 'a' : 'b'}`,
|
|
351
351
|
type: feature.type,
|
|
352
352
|
geometry: feature.geometry,
|
|
353
353
|
properties: feature.properties
|
|
@@ -371,13 +371,13 @@ Merge multiple contiguous polygons into one. Like `split`, this is a pure comput
|
|
|
371
371
|
```js
|
|
372
372
|
drawPlugin.merge(selectedFeatureIds)
|
|
373
373
|
|
|
374
|
-
interactiveMap.on('draw:merge', (
|
|
375
|
-
drawPlugin.deleteFeature(
|
|
374
|
+
interactiveMap.on('draw:merge', (event) => {
|
|
375
|
+
drawPlugin.deleteFeature(event.originalFeatureIds)
|
|
376
376
|
drawPlugin.addFeature({
|
|
377
|
-
id:
|
|
378
|
-
type:
|
|
379
|
-
geometry:
|
|
380
|
-
properties:
|
|
377
|
+
id: event.originalFeatureIds[0],
|
|
378
|
+
type: event.feature.type,
|
|
379
|
+
geometry: event.feature.geometry,
|
|
380
|
+
properties: event.feature.properties
|
|
381
381
|
})
|
|
382
382
|
})
|
|
383
383
|
```
|
package/docs/plugins/interact.md
CHANGED
|
@@ -288,15 +288,15 @@ Emitted when the user confirms their selection (clicks "Done").
|
|
|
288
288
|
```
|
|
289
289
|
|
|
290
290
|
```js
|
|
291
|
-
interactiveMap.on('interact:done', (
|
|
292
|
-
if (
|
|
293
|
-
console.log('Location selected:',
|
|
291
|
+
interactiveMap.on('interact:done', (event) => {
|
|
292
|
+
if (event.coords) {
|
|
293
|
+
console.log('Location selected:', event.coords)
|
|
294
294
|
}
|
|
295
|
-
if (
|
|
296
|
-
console.log('Features selected:',
|
|
295
|
+
if (event.selectedFeatures) {
|
|
296
|
+
console.log('Features selected:', event.selectedFeatures)
|
|
297
297
|
}
|
|
298
|
-
if (
|
|
299
|
-
console.log('Markers selected:',
|
|
298
|
+
if (event.selectedMarkers) {
|
|
299
|
+
console.log('Markers selected:', event.selectedMarkers)
|
|
300
300
|
}
|
|
301
301
|
})
|
|
302
302
|
```
|
|
@@ -333,8 +333,8 @@ Emitted whenever the selected features or selected markers change.
|
|
|
333
333
|
```
|
|
334
334
|
|
|
335
335
|
```js
|
|
336
|
-
interactiveMap.on('interact:selectionchange', (
|
|
337
|
-
console.log('Selected features:',
|
|
336
|
+
interactiveMap.on('interact:selectionchange', (event) => {
|
|
337
|
+
console.log('Selected features:', event.selectedFeatures)
|
|
338
338
|
})
|
|
339
339
|
```
|
|
340
340
|
|