From 77f02fb8a3d7642829082eaf94ecdf99b441ea2f Mon Sep 17 00:00:00 2001 From: David Stone Date: Wed, 22 Jul 2026 11:58:09 +0100 Subject: [PATCH 1/2] Create a single map dataset plugin --- src/client/javascripts/geospatial-map.js | 59 ++++++++--------- src/client/javascripts/location-map.js | 7 +- src/client/javascripts/sssi-dataset.js | 81 ++++++++++++------------ 3 files changed, 75 insertions(+), 72 deletions(-) diff --git a/src/client/javascripts/geospatial-map.js b/src/client/javascripts/geospatial-map.js index 7d7a12dfb..7842e5b07 100644 --- a/src/client/javascripts/geospatial-map.js +++ b/src/client/javascripts/geospatial-map.js @@ -172,45 +172,46 @@ export function processGeospatial(config, geospatial, index) { const bounds = geojson.features.length ? getBoundingBox(geojson) : undefined const drawPlugin = createDrawPlugin() const plugins = [drawPlugin] + const datasets = [] const country = geospatial.dataset.country const mapLayers = getMapLayers(geospatial.dataset.maplayers) if (country) { // Add the country bounds as a dataset plugin to show the valid area on the map // and provide feedback to the user when they add features outside of the bounds. - const countriesDatasetPlugin = createDatasetsPlugin({ - datasets: [ - { - id: 'invalid-area', - label: 'Invalid areas', - geojson: `${config.apiPath}/maps/countries.geojson?omit=${country}`, - showInKey: false, - showInMenu: false, - style: { - stroke: 'gray', - strokeWidth: 1, - fill: 'rgba(211,211,211,0.8)' - } - }, - { - id: 'valid-area', - label: 'Valid areas', - geojson: `${config.apiPath}/maps/countries.geojson?only=${country}`, - showInKey: false, - showInMenu: false, - style: { - stroke: 'rgba(0,112,60,1)', - strokeWidth: 1 - } + datasets.push( + { + id: 'invalid-area', + label: 'Invalid areas', + geojson: `${config.apiPath}/maps/countries.geojson?omit=${country}`, + showInKey: false, + showInMenu: false, + style: { + stroke: 'gray', + strokeWidth: 1, + fill: 'rgba(211,211,211,0.8)' } - ] - }) - - plugins.push(countriesDatasetPlugin) + }, + { + id: 'valid-area', + label: 'Valid areas', + geojson: `${config.apiPath}/maps/countries.geojson?only=${country}`, + showInKey: false, + showInMenu: false, + style: { + stroke: 'rgba(0,112,60,1)', + strokeWidth: 1 + } + } + ) } if (mapLayers.includes('sssi')) { - plugins.push(createDatasetsPlugin(sssiDataset)) + datasets.push(...sssiDataset) + } + + if (datasets.length) { + plugins.push(createDatasetsPlugin({ datasets })) } const initConfig = { diff --git a/src/client/javascripts/location-map.js b/src/client/javascripts/location-map.js index a41a93f12..1b1004710 100644 --- a/src/client/javascripts/location-map.js +++ b/src/client/javascripts/location-map.js @@ -423,10 +423,15 @@ export function processLocation(config, location, index) { locationInputs.after(mapContainer) + const datasets = [] const mapLayers = getMapLayers(location.dataset.maplayers) if (mapLayers.includes('sssi')) { - initConfig.plugins = [createDatasetsPlugin(sssiDataset)] + datasets.push(...sssiDataset) + } + + if (datasets.length) { + initConfig.plugins = [createDatasetsPlugin({ datasets })] } const { map, interactPlugin } = createMap(mapId, initConfig, config) diff --git a/src/client/javascripts/sssi-dataset.js b/src/client/javascripts/sssi-dataset.js index e9cce0ab7..6829a0dc5 100644 --- a/src/client/javascripts/sssi-dataset.js +++ b/src/client/javascripts/sssi-dataset.js @@ -49,50 +49,47 @@ export function sssiScotlandRequestTransformer(url, { bbox }) { } } -export default { - datasets: [ - { - id: 'sssi-england', - label: 'Sites of Special Scientific Interest', - dynamicGeoJSON: { - url: englandWFS, - idProperty: 'ref_code', - transformRequest: sssiEnglandRequestTransformer - }, - minZoom, - style, - showInKey: true, - showInMenu: false +export default [ + { + id: 'sssi-england', + label: 'Sites of Special Scientific Interest', + dynamicGeoJSON: { + url: englandWFS, + idProperty: 'ref_code', + transformRequest: sssiEnglandRequestTransformer }, - { - id: 'sssi-wales', - label: 'SSSI Wales', - dynamicGeoJSON: { - url: walesWFS, - idProperty: 'id', - transformRequest: sssiWalesRequestTransformer - }, - minZoom, - style, - showInKey: false, - showInMenu: false + minZoom, + style, + showInKey: true, + showInMenu: false + }, + { + id: 'sssi-wales', + label: 'SSSI Wales', + dynamicGeoJSON: { + url: walesWFS, + idProperty: 'id', + transformRequest: sssiWalesRequestTransformer }, - { - id: 'sssi-scotland', - label: 'SSSI Scotland', - dynamicGeoJSON: { - url: scotlandWFS, - idProperty: 'OBJECTID', - transformRequest: sssiScotlandRequestTransformer - }, - minZoom, - style, - showInKey: false, - showInMenu: false - } - ] -} - + minZoom, + style, + showInKey: false, + showInMenu: false + }, + { + id: 'sssi-scotland', + label: 'SSSI Scotland', + dynamicGeoJSON: { + url: scotlandWFS, + idProperty: 'OBJECTID', + transformRequest: sssiScotlandRequestTransformer + }, + minZoom, + style, + showInKey: false, + showInMenu: false + } +] /** * @typedef {object} TransformRequestOptions * @property {string[]} bbox - the bounding box coordinates From ee9ac3bf3ab889be686e4b781ce536ec8558792b Mon Sep 17 00:00:00 2001 From: David Stone Date: Wed, 22 Jul 2026 12:12:40 +0100 Subject: [PATCH 2/2] Update comments --- src/client/javascripts/geospatial-map.js | 3 ++- src/client/javascripts/location-map.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/javascripts/geospatial-map.js b/src/client/javascripts/geospatial-map.js index 7842e5b07..da328b244 100644 --- a/src/client/javascripts/geospatial-map.js +++ b/src/client/javascripts/geospatial-map.js @@ -177,7 +177,7 @@ export function processGeospatial(config, geospatial, index) { const mapLayers = getMapLayers(geospatial.dataset.maplayers) if (country) { - // Add the country bounds as a dataset plugin to show the valid area on the map + // Add the country bounds to the datasets array to show the valid area on the map // and provide feedback to the user when they add features outside of the bounds. datasets.push( { @@ -210,6 +210,7 @@ export function processGeospatial(config, geospatial, index) { datasets.push(...sssiDataset) } + // Create a map dataset plugin if there are any present if (datasets.length) { plugins.push(createDatasetsPlugin({ datasets })) } diff --git a/src/client/javascripts/location-map.js b/src/client/javascripts/location-map.js index 1b1004710..4d5b38de7 100644 --- a/src/client/javascripts/location-map.js +++ b/src/client/javascripts/location-map.js @@ -430,6 +430,7 @@ export function processLocation(config, location, index) { datasets.push(...sssiDataset) } + // Create a map dataset plugin if there are any present if (datasets.length) { initConfig.plugins = [createDatasetsPlugin({ datasets })] }