@defra/forms-engine-plugin 5.0.0-alpha → 5.0.0-alpha.2

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.
Files changed (56) hide show
  1. package/.public/assets-manifest.json +3 -5
  2. package/.public/javascripts/application.min.js.map +1 -1
  3. package/.public/javascripts/im-core.min.js +2 -0
  4. package/.public/javascripts/im-core.min.js.map +1 -0
  5. package/.public/javascripts/shared.min.js +1 -1
  6. package/.public/javascripts/shared.min.js.map +1 -1
  7. package/.public/javascripts/vendor/@defra.min.js +1 -1
  8. package/.public/javascripts/vendor/@defra.min.js.map +1 -1
  9. package/.public/stylesheets/application.min.css +1 -1
  10. package/.public/stylesheets/application.min.css.map +1 -1
  11. package/.server/client/javascripts/geospatial-map.js +8 -6
  12. package/.server/client/javascripts/geospatial-map.js.map +1 -1
  13. package/.server/client/javascripts/location-map.js +8 -1
  14. package/.server/client/javascripts/location-map.js.map +1 -1
  15. package/.server/client/javascripts/map.d.ts +6 -0
  16. package/.server/client/javascripts/map.js +10 -0
  17. package/.server/client/javascripts/map.js.map +1 -1
  18. package/.server/client/javascripts/shared.d.ts +1 -0
  19. package/.server/client/javascripts/shared.js +1 -0
  20. package/.server/client/javascripts/shared.js.map +1 -1
  21. package/.server/client/javascripts/sssi-dataset.d.ts +34 -0
  22. package/.server/client/javascripts/sssi-dataset.js +101 -0
  23. package/.server/client/javascripts/sssi-dataset.js.map +1 -0
  24. package/.server/client/stylesheets/shared.scss +0 -2
  25. package/.server/server/plugins/engine/components/EastingNorthingField.d.ts +2 -0
  26. package/.server/server/plugins/engine/components/GeospatialField.d.ts +1 -0
  27. package/.server/server/plugins/engine/components/GeospatialField.js +2 -0
  28. package/.server/server/plugins/engine/components/GeospatialField.js.map +1 -1
  29. package/.server/server/plugins/engine/components/LatLongField.d.ts +2 -0
  30. package/.server/server/plugins/engine/components/LocationFieldHelpers.d.ts +5 -0
  31. package/.server/server/plugins/engine/components/LocationFieldHelpers.js +12 -1
  32. package/.server/server/plugins/engine/components/LocationFieldHelpers.js.map +1 -1
  33. package/.server/server/plugins/engine/views/components/_location-field-base.html +3 -1
  34. package/.server/server/plugins/engine/views/components/geospatialfield.html +4 -1
  35. package/.server/server/plugins/map/routes/index.js +1 -1
  36. package/.server/server/plugins/map/routes/index.js.map +1 -1
  37. package/.server/server/plugins/map/types.d.ts +1 -25
  38. package/.server/server/plugins/map/types.js +1 -16
  39. package/.server/server/plugins/map/types.js.map +1 -1
  40. package/package.json +3 -3
  41. package/src/client/javascripts/geospatial-map.js +10 -6
  42. package/src/client/javascripts/location-map.js +11 -0
  43. package/src/client/javascripts/map.js +10 -0
  44. package/src/client/javascripts/shared.js +1 -0
  45. package/src/client/javascripts/sssi-dataset.js +106 -0
  46. package/src/client/stylesheets/shared.scss +0 -2
  47. package/src/server/plugins/engine/components/GeospatialField.ts +2 -0
  48. package/src/server/plugins/engine/components/LocationFieldHelpers.ts +21 -1
  49. package/src/server/plugins/engine/views/components/_location-field-base.html +3 -1
  50. package/src/server/plugins/engine/views/components/geospatialfield.html +4 -1
  51. package/src/server/plugins/map/routes/index.js +1 -1
  52. package/src/server/plugins/map/types.js +1 -16
  53. package/.public/javascripts/im-search-plugin.min.js +0 -2
  54. package/.public/javascripts/im-search-plugin.min.js.map +0 -1
  55. package/.public/javascripts/vendor/preact.min.js +0 -2
  56. package/.public/javascripts/vendor/preact.min.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"map.js","names":["InteractiveMap","createInteractPlugin","createMapStylesPlugin","createScaleBarPlugin","createSearchPlugin","maplibreProvider","centroid","OsGridRef","LatLon","processGeospatial","processLocation","DEFAULT_LAT","DEFAULT_LONG","COMPANY_SYMBOL_CODE","defaultData","VTS_OUTDOOR_URL","VTS_DARK_URL","VTS_BLACK_AND_WHITE_URL","VTS_AERIAL_URL","latLongToEastingNorthing","lat","long","point","toOsGrid","eastingNorthingToLatLong","easting","northing","latLong","toLatLon","latitude","longitude","latLongToOsGridRef","toString","osGridRefToLatLong","osGridRef","parse","getCoordinateGridRef","feature","geometry","type","coordinates","getCentroidGridRef","centre","defaultConfig","zoom","center","EVENTS","mapReady","interactMarkerChange","drawReady","drawCreated","drawEdited","drawCancelled","formSubmitFactory","buttons","onFormSubmit","e","submitter","HTMLButtonElement","includes","preventDefault","initMaps","config","assetPath","apiPath","data","locations","document","querySelectorAll","geospatials","length","form","closest","Array","from","addEventListener","forEach","location","index","geospatial","makeTileRequestTransformer","transformTileRequest","url","resourceType","startsWith","replace","window","origin","headers","encodeURIComponent","spritesPath","path","substring","createMap","mapId","initConfig","mapsConfig","logoAltText","interactPlugin","markerColor","outdoor","dark","interactionModes","multiSelect","map","enableFullscreen","autoColorScheme","mapProvider","behaviour","minZoom","maxZoom","containerHeight","enableZoomControls","transformRequest","plugins","mapStyles","id","label","thumbnail","logo","attribution","String","fromCodePoint","Date","getFullYear","backgroundColor","mapColorScheme","appColorScheme","osNamesURL","width","showMarker","units","centerMap","addMarker","flyTo","essential"],"sources":["../../../src/client/javascripts/map.js"],"sourcesContent":["// @ts-expect-error - no types\nimport InteractiveMap from '@defra/interactive-map'\n// @ts-expect-error - no types\nimport createInteractPlugin from '@defra/interactive-map/plugins/interact'\n// @ts-expect-error - no types\nimport createMapStylesPlugin from '@defra/interactive-map/plugins/map-styles'\n// @ts-expect-error - no types\nimport createScaleBarPlugin from '@defra/interactive-map/plugins/scale-bar'\n// @ts-expect-error - no types\nimport createSearchPlugin from '@defra/interactive-map/plugins/search'\n// @ts-expect-error - no types\nimport maplibreProvider from '@defra/interactive-map/providers/maplibre'\nimport { centroid } from '@turf/centroid'\n// @ts-expect-error - no types\nimport OsGridRef, { LatLon } from 'geodesy/osgridref.js'\n\nimport { processGeospatial } from '~/src/client/javascripts/geospatial-map.js'\nimport { processLocation } from '~/src/client/javascripts/location-map.js'\n\n// Center of UK\nconst DEFAULT_LAT = 53.825564\nconst DEFAULT_LONG = -2.421975\nconst COMPANY_SYMBOL_CODE = 169\n\nconst defaultData = {\n VTS_OUTDOOR_URL: '/api/maps/vts/OS_VTS_3857_Outdoor.json',\n VTS_DARK_URL: '/api/maps/vts/OS_VTS_3857_Dark.json',\n VTS_BLACK_AND_WHITE_URL: '/api/maps/vts/OS_VTS_3857_Black_and_White.json',\n VTS_AERIAL_URL: '/api/maps/vts/esri-aerial.json'\n}\n\n/**\n * Converts lat long to easting and northing\n * @param {object} param\n * @param {number} param.lat\n * @param {number} param.long\n * @returns {{ easting: number, northing: number }}\n */\nexport function latLongToEastingNorthing({ lat, long }) {\n const point = new LatLon(lat, long)\n\n return point.toOsGrid()\n}\n\n/**\n * Converts easting and northing to lat long\n * @param {object} param\n * @param {number} param.easting\n * @param {number} param.northing\n * @returns {{ lat: number, long: number }}\n */\nexport function eastingNorthingToLatLong({ easting, northing }) {\n const point = new OsGridRef(easting, northing)\n const latLong = point.toLatLon()\n\n return { lat: latLong.latitude, long: latLong.longitude }\n}\n\n/**\n * Converts lat long to an ordnance survey grid reference\n * @param {object} param\n * @param {number} param.lat\n * @param {number} param.long\n * @returns {string}\n */\nexport function latLongToOsGridRef({ lat, long }) {\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n}\n\n/**\n * Converts an ordnance survey grid reference to lat long\n * @param {string} osGridRef\n * @returns {{ lat: number, long: number }}\n */\nexport function osGridRefToLatLong(osGridRef) {\n const point = OsGridRef.parse(osGridRef)\n const latLong = point.toLatLon()\n\n return { lat: latLong.latitude, long: latLong.longitude }\n}\n\n/**\n * Get the grid ref from the first coordinate of a long/lat feature\n * @param {Feature} feature\n */\nexport function getCoordinateGridRef(feature) {\n if (feature.geometry.type === 'Point') {\n const [long, lat] = feature.geometry.coordinates\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n } else if (feature.geometry.type === 'LineString') {\n const [long, lat] = feature.geometry.coordinates[0]\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n } else {\n const [long, lat] = feature.geometry.coordinates[0][0]\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n }\n}\n\n/**\n * Get the centroid grid ref from a long/lat feature\n * @param {Feature} feature\n */\nexport function getCentroidGridRef(feature) {\n if (feature.geometry.type === 'Point') {\n const [long, lat] = feature.geometry.coordinates\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n } else {\n const centre = centroid(feature)\n const [long, lat] = centre.geometry.coordinates\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n }\n}\n\n/** @type {InteractiveMapInitConfig} */\nexport const defaultConfig = {\n zoom: '6',\n center: [DEFAULT_LONG, DEFAULT_LAT]\n}\n\nexport const EVENTS = {\n mapReady: 'map:ready',\n interactMarkerChange: 'interact:markerchange',\n drawReady: 'draw:ready',\n drawCreated: 'draw:created',\n drawEdited: 'draw:edited',\n drawCancelled: 'draw:cancelled'\n}\n\n/**\n * Make a form submit handler that only allows submissions from allowed buttons\n * @param {HTMLButtonElement[]} buttons - the form buttons to allow submissions\n */\nexport function formSubmitFactory(buttons) {\n /**\n * The submit handler\n * @param {SubmitEvent} e\n */\n const onFormSubmit = function (e) {\n if (\n !(e.submitter instanceof HTMLButtonElement) ||\n !buttons.includes(e.submitter)\n ) {\n e.preventDefault()\n }\n }\n\n return onFormSubmit\n}\n\n/**\n * Initialise location maps\n * @param {Partial<MapsEnvironmentConfig>} config - the map configuration\n */\nexport function initMaps(config = {}) {\n const {\n assetPath = '/assets',\n apiPath = '/form/api',\n data = defaultData\n } = config\n const locations = document.querySelectorAll('.app-location-field')\n const geospatials = document.querySelectorAll('.app-geospatial-field')\n\n // TODO: Fix this in `interactive-map`\n // If there are location components on the page fix up the main form submit\n // handler so it doesn't fire when using the integrated map search feature\n if (locations.length) {\n const form = locations[0].closest('form')\n\n if (form === null) {\n return\n }\n\n const buttons = Array.from(form.querySelectorAll('button'))\n form.addEventListener('submit', formSubmitFactory(buttons), false)\n }\n\n if (geospatials.length) {\n const form = geospatials[0].closest('form')\n\n if (form === null) {\n return\n }\n\n const buttons = Array.from(form.querySelectorAll('button'))\n form.addEventListener('submit', formSubmitFactory(buttons), false)\n }\n\n locations.forEach((location, index) => {\n processLocation({ assetPath, apiPath, data }, location, index)\n })\n\n geospatials.forEach((geospatial, index) => {\n processGeospatial({ assetPath, apiPath, data }, geospatial, index)\n })\n}\n\n/**\n * OS API request proxy factory\n * @param {string} apiPath - the root API path\n */\nexport function makeTileRequestTransformer(apiPath) {\n /**\n * Proxy OS API requests via our server\n * @param {string} url - the request URL\n * @param {string} resourceType - the resource type\n */\n return function transformTileRequest(url, resourceType) {\n if (url.startsWith('https://api.os.uk')) {\n if (resourceType === 'Tile') {\n return {\n url: url.replace(\n 'https://api.os.uk/maps/vector/v1/vts',\n `${window.location.origin}${apiPath}`\n ),\n headers: {}\n }\n }\n\n if (resourceType !== 'Style') {\n return {\n url: `${apiPath}/map-proxy?url=${encodeURIComponent(url)}`,\n headers: {}\n }\n }\n }\n\n const spritesPath =\n 'https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main'\n\n // Proxy sprite requests\n if (url.startsWith(spritesPath)) {\n const path = url.substring(spritesPath.length)\n return {\n url: `${apiPath}/maps/vts${path}`,\n headers: {}\n }\n }\n\n return { url, headers: {} }\n }\n}\n\n/**\n * Create a Defra map instance\n * @param {string} mapId - the map id\n * @param {InteractiveMapInitConfig} initConfig - the map initial configuration\n * @param {MapsEnvironmentConfig} mapsConfig - the map environment params\n */\nexport function createMap(mapId, initConfig, mapsConfig) {\n const { assetPath, apiPath, data = defaultData } = mapsConfig\n const logoAltText = 'Ordnance survey logo'\n const interactPlugin = createInteractPlugin({\n markerColor: { outdoor: '#ff0000', dark: '#00ff00' },\n interactionModes: ['placeMarker'],\n multiSelect: false\n })\n\n /** @type {InteractiveMap} */\n const map = new InteractiveMap(mapId, {\n enableFullscreen: true,\n autoColorScheme: false,\n mapProvider: maplibreProvider(),\n behaviour: 'inline',\n minZoom: 6,\n maxZoom: 18,\n containerHeight: '400px',\n enableZoomControls: true,\n transformRequest: makeTileRequestTransformer(apiPath),\n ...initConfig,\n plugins: [\n createMapStylesPlugin({\n mapStyles: [\n {\n id: 'outdoor',\n label: 'Outdoor',\n url: data.VTS_OUTDOOR_URL,\n thumbnail: `${assetPath}/interactive-map/assets/images/outdoor-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/os-logo.svg`,\n logoAltText,\n attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`,\n backgroundColor: '#f5f5f0'\n },\n {\n id: 'dark',\n label: 'Dark',\n url: data.VTS_DARK_URL,\n mapColorScheme: 'dark',\n appColorScheme: 'dark',\n thumbnail: `${assetPath}/interactive-map/assets/images/dark-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/os-logo-white.svg`,\n logoAltText,\n attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`\n },\n {\n id: 'black-and-white',\n label: 'Black/White',\n url: data.VTS_BLACK_AND_WHITE_URL,\n thumbnail: `${assetPath}/interactive-map/assets/images/black-and-white-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/os-logo-black.svg`,\n logoAltText,\n attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`\n },\n {\n id: 'aerial',\n label: 'Aerial',\n url: data.VTS_AERIAL_URL,\n thumbnail: `${assetPath}/interactive-map/assets/images/aerial-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/esri-logo.png`,\n logoAltText: 'Powered by Esri',\n attribution: `Tiles ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community ${new Date().getFullYear()}`\n }\n ]\n }),\n interactPlugin,\n createSearchPlugin({\n osNamesURL: `${apiPath}/geocode-proxy?query={query}`,\n width: '300px',\n showMarker: false\n }),\n createScaleBarPlugin({\n units: 'metric'\n }),\n ...(initConfig.plugins ?? [])\n ]\n })\n\n return { map, interactPlugin }\n}\n\n/**\n * Updates the marker position and moves the map view port the new location\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n * @param {MapCenter} center - the point\n */\nexport function centerMap(map, mapProvider, center) {\n // Move the 'location' marker to the new point\n map.addMarker('location', center)\n\n // Pan & zoom the map to the new valid location\n mapProvider.flyTo({\n center,\n zoom: 14,\n essential: true\n })\n}\n\n/**\n * @typedef {object} InteractiveMap - an instance of a InteractiveMap\n * @property {Function} on - register callback listeners to map events\n * @property {Function} addPanel - adds a new panel to the map\n * @property {Function} addMarker - adds/updates a marker\n * @property {Function} removeMarker - removes a marker\n * @property {Function} addButton - adds/updates a button\n * @property {Function} toggleButtonState - toggle the state of a button\n */\n\n/**\n * @typedef {object} MapLibreMap\n * @property {Function} flyTo - pans/zooms to a new location\n * @property {Function} fitBounds - fits the my to the new bounds\n */\n\n/**\n * @typedef {[number, number]} MapCenter - Map center point as [long, lat]\n */\n\n/**\n * @typedef {object} InteractiveMapInitConfig - additional config that can be provided to InteractiveMap\n * @property {string} zoom - the zoom level of the map\n * @property {MapCenter} center - the center point of the map\n * @property {{ id: string, coords: MapCenter }[]} [markers] - the markers to add to the map\n * @property {any[]} [plugins] - additional plugins\n */\n\n/**\n * @typedef {object} TileData\n * @property {string} VTS_OUTDOOR_URL - the outdoor tile URL\n * @property {string} VTS_DARK_URL - the dark tile URL\n * @property {string} VTS_BLACK_AND_WHITE_URL - the black and white tile URL\n * @property {string} VTS_AERIAL_URL - the aerial tile URL\n */\n\n/**\n * @typedef {object} MapsEnvironmentConfig\n * @property {string} assetPath - the root asset path\n * @property {string} apiPath - the root API path\n * @property {TileData} data - the tile data config\n */\n\n/**\n * @typedef {object} UIManagerOptions\n * @property {string} [geometryTypes] - the CSV list of geometry types that a user can create\n */\n\n/**\n * @import { Feature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B,WAAW,EAAE,SAASC,MAAM,CAACC,aAAa,CAAC7G,mBAAmB,CAAC,kFAAkF,IAAI8G,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC;MAC3K,CAAC;IAEL,CAAC,CAAC,EACF1B,cAAc,EACd9F,kBAAkB,CAAC;MACjB4H,UAAU,EAAE,GAAGhE,OAAO,8BAA8B;MACpDiE,KAAK,EAAE,OAAO;MACdC,UAAU,EAAE;IACd,CAAC,CAAC,EACF/H,oBAAoB,CAAC;MACnBgI,KAAK,EAAE;IACT,CAAC,CAAC,EACF,IAAIpC,UAAU,CAACmB,OAAO,IAAI,EAAE,CAAC;EAEjC,CAAC,CAAC;EAEF,OAAO;IAAEV,GAAG;IAAEN;EAAe,CAAC;AAChC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASkC,SAASA,CAAC5B,GAAG,EAAEG,WAAW,EAAE9D,MAAM,EAAE;EAClD;EACA2D,GAAG,CAAC6B,SAAS,CAAC,UAAU,EAAExF,MAAM,CAAC;;EAEjC;EACA8D,WAAW,CAAC2B,KAAK,CAAC;IAChBzF,MAAM;IACND,IAAI,EAAE,EAAE;IACR2F,SAAS,EAAE;EACb,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"map.js","names":["InteractiveMap","createInteractPlugin","createMapStylesPlugin","createScaleBarPlugin","createSearchPlugin","maplibreProvider","centroid","OsGridRef","LatLon","processGeospatial","processLocation","DEFAULT_LAT","DEFAULT_LONG","COMPANY_SYMBOL_CODE","defaultData","VTS_OUTDOOR_URL","VTS_DARK_URL","VTS_BLACK_AND_WHITE_URL","VTS_AERIAL_URL","latLongToEastingNorthing","lat","long","point","toOsGrid","eastingNorthingToLatLong","easting","northing","latLong","toLatLon","latitude","longitude","latLongToOsGridRef","toString","osGridRefToLatLong","osGridRef","parse","getCoordinateGridRef","feature","geometry","type","coordinates","getCentroidGridRef","centre","defaultConfig","zoom","center","EVENTS","mapReady","interactMarkerChange","drawReady","drawCreated","drawEdited","drawCancelled","formSubmitFactory","buttons","onFormSubmit","e","submitter","HTMLButtonElement","includes","preventDefault","initMaps","config","assetPath","apiPath","data","locations","document","querySelectorAll","geospatials","length","form","closest","Array","from","addEventListener","forEach","location","index","geospatial","makeTileRequestTransformer","transformTileRequest","url","resourceType","startsWith","replace","window","origin","headers","encodeURIComponent","spritesPath","path","substring","createMap","mapId","initConfig","mapsConfig","logoAltText","interactPlugin","markerColor","outdoor","dark","interactionModes","multiSelect","map","enableFullscreen","autoColorScheme","mapProvider","behaviour","minZoom","maxZoom","containerHeight","enableZoomControls","transformRequest","plugins","mapStyles","id","label","thumbnail","logo","attribution","String","fromCodePoint","Date","getFullYear","backgroundColor","mapColorScheme","appColorScheme","osNamesURL","width","showMarker","units","centerMap","addMarker","flyTo","essential","getMapLayers","layers","trimmed","trim","split"],"sources":["../../../src/client/javascripts/map.js"],"sourcesContent":["// @ts-expect-error - no types\nimport InteractiveMap from '@defra/interactive-map'\n// @ts-expect-error - no types\nimport createInteractPlugin from '@defra/interactive-map/plugins/interact'\n// @ts-expect-error - no types\nimport createMapStylesPlugin from '@defra/interactive-map/plugins/map-styles'\n// @ts-expect-error - no types\nimport createScaleBarPlugin from '@defra/interactive-map/plugins/scale-bar'\n// @ts-expect-error - no types\nimport createSearchPlugin from '@defra/interactive-map/plugins/search'\n// @ts-expect-error - no types\nimport maplibreProvider from '@defra/interactive-map/providers/maplibre'\nimport { centroid } from '@turf/centroid'\n// @ts-expect-error - no types\nimport OsGridRef, { LatLon } from 'geodesy/osgridref.js'\n\nimport { processGeospatial } from '~/src/client/javascripts/geospatial-map.js'\nimport { processLocation } from '~/src/client/javascripts/location-map.js'\n\n// Center of UK\nconst DEFAULT_LAT = 53.825564\nconst DEFAULT_LONG = -2.421975\nconst COMPANY_SYMBOL_CODE = 169\n\nconst defaultData = {\n VTS_OUTDOOR_URL: '/api/maps/vts/OS_VTS_3857_Outdoor.json',\n VTS_DARK_URL: '/api/maps/vts/OS_VTS_3857_Dark.json',\n VTS_BLACK_AND_WHITE_URL: '/api/maps/vts/OS_VTS_3857_Black_and_White.json',\n VTS_AERIAL_URL: '/api/maps/vts/esri-aerial.json'\n}\n\n/**\n * Converts lat long to easting and northing\n * @param {object} param\n * @param {number} param.lat\n * @param {number} param.long\n * @returns {{ easting: number, northing: number }}\n */\nexport function latLongToEastingNorthing({ lat, long }) {\n const point = new LatLon(lat, long)\n\n return point.toOsGrid()\n}\n\n/**\n * Converts easting and northing to lat long\n * @param {object} param\n * @param {number} param.easting\n * @param {number} param.northing\n * @returns {{ lat: number, long: number }}\n */\nexport function eastingNorthingToLatLong({ easting, northing }) {\n const point = new OsGridRef(easting, northing)\n const latLong = point.toLatLon()\n\n return { lat: latLong.latitude, long: latLong.longitude }\n}\n\n/**\n * Converts lat long to an ordnance survey grid reference\n * @param {object} param\n * @param {number} param.lat\n * @param {number} param.long\n * @returns {string}\n */\nexport function latLongToOsGridRef({ lat, long }) {\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n}\n\n/**\n * Converts an ordnance survey grid reference to lat long\n * @param {string} osGridRef\n * @returns {{ lat: number, long: number }}\n */\nexport function osGridRefToLatLong(osGridRef) {\n const point = OsGridRef.parse(osGridRef)\n const latLong = point.toLatLon()\n\n return { lat: latLong.latitude, long: latLong.longitude }\n}\n\n/**\n * Get the grid ref from the first coordinate of a long/lat feature\n * @param {Feature} feature\n */\nexport function getCoordinateGridRef(feature) {\n if (feature.geometry.type === 'Point') {\n const [long, lat] = feature.geometry.coordinates\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n } else if (feature.geometry.type === 'LineString') {\n const [long, lat] = feature.geometry.coordinates[0]\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n } else {\n const [long, lat] = feature.geometry.coordinates[0][0]\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n }\n}\n\n/**\n * Get the centroid grid ref from a long/lat feature\n * @param {Feature} feature\n */\nexport function getCentroidGridRef(feature) {\n if (feature.geometry.type === 'Point') {\n const [long, lat] = feature.geometry.coordinates\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n } else {\n const centre = centroid(feature)\n const [long, lat] = centre.geometry.coordinates\n const point = new LatLon(lat, long)\n\n return point.toOsGrid().toString()\n }\n}\n\n/** @type {InteractiveMapInitConfig} */\nexport const defaultConfig = {\n zoom: '6',\n center: [DEFAULT_LONG, DEFAULT_LAT]\n}\n\nexport const EVENTS = {\n mapReady: 'map:ready',\n interactMarkerChange: 'interact:markerchange',\n drawReady: 'draw:ready',\n drawCreated: 'draw:created',\n drawEdited: 'draw:edited',\n drawCancelled: 'draw:cancelled'\n}\n\n/**\n * Make a form submit handler that only allows submissions from allowed buttons\n * @param {HTMLButtonElement[]} buttons - the form buttons to allow submissions\n */\nexport function formSubmitFactory(buttons) {\n /**\n * The submit handler\n * @param {SubmitEvent} e\n */\n const onFormSubmit = function (e) {\n if (\n !(e.submitter instanceof HTMLButtonElement) ||\n !buttons.includes(e.submitter)\n ) {\n e.preventDefault()\n }\n }\n\n return onFormSubmit\n}\n\n/**\n * Initialise location maps\n * @param {Partial<MapsEnvironmentConfig>} config - the map configuration\n */\nexport function initMaps(config = {}) {\n const {\n assetPath = '/assets',\n apiPath = '/form/api',\n data = defaultData\n } = config\n const locations = document.querySelectorAll('.app-location-field')\n const geospatials = document.querySelectorAll('.app-geospatial-field')\n\n // TODO: Fix this in `interactive-map`\n // If there are location components on the page fix up the main form submit\n // handler so it doesn't fire when using the integrated map search feature\n if (locations.length) {\n const form = locations[0].closest('form')\n\n if (form === null) {\n return\n }\n\n const buttons = Array.from(form.querySelectorAll('button'))\n form.addEventListener('submit', formSubmitFactory(buttons), false)\n }\n\n if (geospatials.length) {\n const form = geospatials[0].closest('form')\n\n if (form === null) {\n return\n }\n\n const buttons = Array.from(form.querySelectorAll('button'))\n form.addEventListener('submit', formSubmitFactory(buttons), false)\n }\n\n locations.forEach((location, index) => {\n processLocation({ assetPath, apiPath, data }, location, index)\n })\n\n geospatials.forEach((geospatial, index) => {\n processGeospatial({ assetPath, apiPath, data }, geospatial, index)\n })\n}\n\n/**\n * OS API request proxy factory\n * @param {string} apiPath - the root API path\n */\nexport function makeTileRequestTransformer(apiPath) {\n /**\n * Proxy OS API requests via our server\n * @param {string} url - the request URL\n * @param {string} resourceType - the resource type\n */\n return function transformTileRequest(url, resourceType) {\n if (url.startsWith('https://api.os.uk')) {\n if (resourceType === 'Tile') {\n return {\n url: url.replace(\n 'https://api.os.uk/maps/vector/v1/vts',\n `${window.location.origin}${apiPath}`\n ),\n headers: {}\n }\n }\n\n if (resourceType !== 'Style') {\n return {\n url: `${apiPath}/map-proxy?url=${encodeURIComponent(url)}`,\n headers: {}\n }\n }\n }\n\n const spritesPath =\n 'https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main'\n\n // Proxy sprite requests\n if (url.startsWith(spritesPath)) {\n const path = url.substring(spritesPath.length)\n return {\n url: `${apiPath}/maps/vts${path}`,\n headers: {}\n }\n }\n\n return { url, headers: {} }\n }\n}\n\n/**\n * Create a Defra map instance\n * @param {string} mapId - the map id\n * @param {InteractiveMapInitConfig} initConfig - the map initial configuration\n * @param {MapsEnvironmentConfig} mapsConfig - the map environment params\n */\nexport function createMap(mapId, initConfig, mapsConfig) {\n const { assetPath, apiPath, data = defaultData } = mapsConfig\n const logoAltText = 'Ordnance survey logo'\n const interactPlugin = createInteractPlugin({\n markerColor: { outdoor: '#ff0000', dark: '#00ff00' },\n interactionModes: ['placeMarker'],\n multiSelect: false\n })\n\n /** @type {InteractiveMap} */\n const map = new InteractiveMap(mapId, {\n enableFullscreen: true,\n autoColorScheme: false,\n mapProvider: maplibreProvider(),\n behaviour: 'inline',\n minZoom: 6,\n maxZoom: 18,\n containerHeight: '400px',\n enableZoomControls: true,\n transformRequest: makeTileRequestTransformer(apiPath),\n ...initConfig,\n plugins: [\n createMapStylesPlugin({\n mapStyles: [\n {\n id: 'outdoor',\n label: 'Outdoor',\n url: data.VTS_OUTDOOR_URL,\n thumbnail: `${assetPath}/interactive-map/assets/images/outdoor-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/os-logo.svg`,\n logoAltText,\n attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`,\n backgroundColor: '#f5f5f0'\n },\n {\n id: 'dark',\n label: 'Dark',\n url: data.VTS_DARK_URL,\n mapColorScheme: 'dark',\n appColorScheme: 'dark',\n thumbnail: `${assetPath}/interactive-map/assets/images/dark-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/os-logo-white.svg`,\n logoAltText,\n attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`\n },\n {\n id: 'black-and-white',\n label: 'Black/White',\n url: data.VTS_BLACK_AND_WHITE_URL,\n thumbnail: `${assetPath}/interactive-map/assets/images/black-and-white-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/os-logo-black.svg`,\n logoAltText,\n attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`\n },\n {\n id: 'aerial',\n label: 'Aerial',\n url: data.VTS_AERIAL_URL,\n thumbnail: `${assetPath}/interactive-map/assets/images/aerial-map-thumb.jpg`,\n logo: `${assetPath}/interactive-map/assets/images/esri-logo.png`,\n logoAltText: 'Powered by Esri',\n attribution: `Tiles ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community ${new Date().getFullYear()}`\n }\n ]\n }),\n interactPlugin,\n createSearchPlugin({\n osNamesURL: `${apiPath}/geocode-proxy?query={query}`,\n width: '300px',\n showMarker: false\n }),\n createScaleBarPlugin({\n units: 'metric'\n }),\n ...(initConfig.plugins ?? [])\n ]\n })\n\n return { map, interactPlugin }\n}\n\n/**\n * Updates the marker position and moves the map view port the new location\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n * @param {MapCenter} center - the point\n */\nexport function centerMap(map, mapProvider, center) {\n // Move the 'location' marker to the new point\n map.addMarker('location', center)\n\n // Pan & zoom the map to the new valid location\n mapProvider.flyTo({\n center,\n zoom: 14,\n essential: true\n })\n}\n\n/**\n * Parse CSV string layers\n * @param {string | undefined} layers\n * @returns {string[]}\n */\nexport function getMapLayers(layers) {\n const trimmed = layers?.trim()\n return trimmed ? trimmed.split(',') : []\n}\n\n/**\n * @typedef {object} InteractiveMap - an instance of a InteractiveMap\n * @property {Function} on - register callback listeners to map events\n * @property {Function} addPanel - adds a new panel to the map\n * @property {Function} addMarker - adds/updates a marker\n * @property {Function} removeMarker - removes a marker\n * @property {Function} addButton - adds/updates a button\n * @property {Function} toggleButtonState - toggle the state of a button\n */\n\n/**\n * @typedef {object} MapLibreMap\n * @property {Function} flyTo - pans/zooms to a new location\n * @property {Function} fitBounds - fits the my to the new bounds\n */\n\n/**\n * @typedef {[number, number]} MapCenter - Map center point as [long, lat]\n */\n\n/**\n * @typedef {object} InteractiveMapInitConfig - additional config that can be provided to InteractiveMap\n * @property {string} zoom - the zoom level of the map\n * @property {MapCenter} center - the center point of the map\n * @property {{ id: string, coords: MapCenter }[]} [markers] - the markers to add to the map\n * @property {any[]} [plugins] - additional plugins\n */\n\n/**\n * @typedef {object} TileData\n * @property {string} VTS_OUTDOOR_URL - the outdoor tile URL\n * @property {string} VTS_DARK_URL - the dark tile URL\n * @property {string} VTS_BLACK_AND_WHITE_URL - the black and white tile URL\n * @property {string} VTS_AERIAL_URL - the aerial tile URL\n */\n\n/**\n * @typedef {object} MapsEnvironmentConfig\n * @property {string} assetPath - the root asset path\n * @property {string} apiPath - the root API path\n * @property {TileData} data - the tile data config\n */\n\n/**\n * @typedef {object} UIManagerOptions\n * @property {string} [geometryTypes] - the CSV list of geometry types that a user can create\n */\n\n/**\n * @import { Feature } from '~/src/server/plugins/engine/types.js'\n */\n"],"mappings":"AAAA;AACA,OAAOA,cAAc,MAAM,wBAAwB;AACnD;AACA,OAAOC,oBAAoB,MAAM,yCAAyC;AAC1E;AACA,OAAOC,qBAAqB,MAAM,2CAA2C;AAC7E;AACA,OAAOC,oBAAoB,MAAM,0CAA0C;AAC3E;AACA,OAAOC,kBAAkB,MAAM,uCAAuC;AACtE;AACA,OAAOC,gBAAgB,MAAM,2CAA2C;AACxE,SAASC,QAAQ,QAAQ,gBAAgB;AACzC;AACA,OAAOC,SAAS,IAAIC,MAAM,QAAQ,sBAAsB;AAExD,SAASC,iBAAiB;AAC1B,SAASC,eAAe;;AAExB;AACA,MAAMC,WAAW,GAAG,SAAS;AAC7B,MAAMC,YAAY,GAAG,CAAC,QAAQ;AAC9B,MAAMC,mBAAmB,GAAG,GAAG;AAE/B,MAAMC,WAAW,GAAG;EAClBC,eAAe,EAAE,wCAAwC;EACzDC,YAAY,EAAE,qCAAqC;EACnDC,uBAAuB,EAAE,gDAAgD;EACzEC,cAAc,EAAE;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,wBAAwBA,CAAC;EAAEC,GAAG;EAAEC;AAAK,CAAC,EAAE;EACtD,MAAMC,KAAK,GAAG,IAAId,MAAM,CAACY,GAAG,EAAEC,IAAI,CAAC;EAEnC,OAAOC,KAAK,CAACC,QAAQ,CAAC,CAAC;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,wBAAwBA,CAAC;EAAEC,OAAO;EAAE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AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA","ignoreList":[]}
@@ -5,6 +5,7 @@ export function initAll(): void;
5
5
  export { initMaps } from "../../client/javascripts/map.js";
6
6
  export * as map from "../../client/javascripts/map.js";
7
7
  export * as geospatialMap from "../../client/javascripts/geospatial-map.js";
8
+ export * as sssiDataset from "../../client/javascripts/sssi-dataset.js";
8
9
  export const initAllGovuk: typeof initAllGovukImp;
9
10
  export const initAllAutocomplete: typeof initAllAutocompleteImp;
10
11
  export const initDebounceClick: typeof initDebounceClickImp;
@@ -6,6 +6,7 @@ import { initPreviewCloseLink as initPreviewCloseLinkImp } from "./preview-close
6
6
  export { initMaps } from "./map.js";
7
7
  export * as map from "./map.js";
8
8
  export * as geospatialMap from "./geospatial-map.js";
9
+ export * as sssiDataset from "./sssi-dataset.js";
9
10
  export const initAllGovuk = initAllGovukImp;
10
11
  export const initAllAutocomplete = initAllAutocompleteImp;
11
12
  export const initDebounceClick = initDebounceClickImp;
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","names":["initAllAutocomplete","initAllAutocompleteImp","initDebounceClick","initDebounceClickImp","initFileUpload","initFileUploadImp","initAllGovuk","initAllGovukImp","initPreviewCloseLink","initPreviewCloseLinkImp","initMaps","map","geospatialMap","initAll"],"sources":["../../../src/client/javascripts/shared.js"],"sourcesContent":["import { initAllAutocomplete as initAllAutocompleteImp } from '~/src/client/javascripts/autocomplete.js'\nimport { initDebounceClick as initDebounceClickImp } from '~/src/client/javascripts/debounce-click.js'\nimport { initFileUpload as initFileUploadImp } from '~/src/client/javascripts/file-upload.js'\nimport { initAllGovuk as initAllGovukImp } from '~/src/client/javascripts/govuk.js'\nimport { initPreviewCloseLink as initPreviewCloseLinkImp } from '~/src/client/javascripts/preview-close-link.js'\nexport { initMaps } from '~/src/client/javascripts/map.js'\nexport * as map from '~/src/client/javascripts/map.js'\nexport * as geospatialMap from '~/src/client/javascripts/geospatial-map.js'\n\nexport const initAllGovuk = initAllGovukImp\nexport const initAllAutocomplete = initAllAutocompleteImp\nexport const initDebounceClick = initDebounceClickImp\nexport const initFileUpload = initFileUploadImp\nexport const initPreviewCloseLink = initPreviewCloseLinkImp\n\n/**\n * Initialise all clientside components (but not maps as this will be an opt-in for now given the additional UMD assets that are required)\n */\nexport function initAll() {\n initAllGovuk()\n initAllAutocomplete()\n initDebounceClick()\n initFileUpload()\n initPreviewCloseLink()\n}\n"],"mappings":"AAAA,SAASA,mBAAmB,IAAIC,sBAAsB;AACtD,SAASC,iBAAiB,IAAIC,oBAAoB;AAClD,SAASC,cAAc,IAAIC,iBAAiB;AAC5C,SAASC,YAAY,IAAIC,eAAe;AACxC,SAASC,oBAAoB,IAAIC,uBAAuB;AACxD,SAASC,QAAQ;AACjB,OAAO,KAAKC,GAAG;AACf,OAAO,KAAKC,aAAa;AAEzB,OAAO,MAAMN,YAAY,GAAGC,eAAe;AAC3C,OAAO,MAAMP,mBAAmB,GAAGC,sBAAsB;AACzD,OAAO,MAAMC,iBAAiB,GAAGC,oBAAoB;AACrD,OAAO,MAAMC,cAAc,GAAGC,iBAAiB;AAC/C,OAAO,MAAMG,oBAAoB,GAAGC,uBAAuB;;AAE3D;AACA;AACA;AACA,OAAO,SAASI,OAAOA,CAAA,EAAG;EACxBP,YAAY,CAAC,CAAC;EACdN,mBAAmB,CAAC,CAAC;EACrBE,iBAAiB,CAAC,CAAC;EACnBE,cAAc,CAAC,CAAC;EAChBI,oBAAoB,CAAC,CAAC;AACxB","ignoreList":[]}
1
+ {"version":3,"file":"shared.js","names":["initAllAutocomplete","initAllAutocompleteImp","initDebounceClick","initDebounceClickImp","initFileUpload","initFileUploadImp","initAllGovuk","initAllGovukImp","initPreviewCloseLink","initPreviewCloseLinkImp","initMaps","map","geospatialMap","sssiDataset","initAll"],"sources":["../../../src/client/javascripts/shared.js"],"sourcesContent":["import { initAllAutocomplete as initAllAutocompleteImp } from '~/src/client/javascripts/autocomplete.js'\nimport { initDebounceClick as initDebounceClickImp } from '~/src/client/javascripts/debounce-click.js'\nimport { initFileUpload as initFileUploadImp } from '~/src/client/javascripts/file-upload.js'\nimport { initAllGovuk as initAllGovukImp } from '~/src/client/javascripts/govuk.js'\nimport { initPreviewCloseLink as initPreviewCloseLinkImp } from '~/src/client/javascripts/preview-close-link.js'\nexport { initMaps } from '~/src/client/javascripts/map.js'\nexport * as map from '~/src/client/javascripts/map.js'\nexport * as geospatialMap from '~/src/client/javascripts/geospatial-map.js'\nexport * as sssiDataset from '~/src/client/javascripts/sssi-dataset.js'\n\nexport const initAllGovuk = initAllGovukImp\nexport const initAllAutocomplete = initAllAutocompleteImp\nexport const initDebounceClick = initDebounceClickImp\nexport const initFileUpload = initFileUploadImp\nexport const initPreviewCloseLink = initPreviewCloseLinkImp\n\n/**\n * Initialise all clientside components (but not maps as this will be an opt-in for now given the additional UMD assets that are required)\n */\nexport function initAll() {\n initAllGovuk()\n initAllAutocomplete()\n initDebounceClick()\n initFileUpload()\n initPreviewCloseLink()\n}\n"],"mappings":"AAAA,SAASA,mBAAmB,IAAIC,sBAAsB;AACtD,SAASC,iBAAiB,IAAIC,oBAAoB;AAClD,SAASC,cAAc,IAAIC,iBAAiB;AAC5C,SAASC,YAAY,IAAIC,eAAe;AACxC,SAASC,oBAAoB,IAAIC,uBAAuB;AACxD,SAASC,QAAQ;AACjB,OAAO,KAAKC,GAAG;AACf,OAAO,KAAKC,aAAa;AACzB,OAAO,KAAKC,WAAW;AAEvB,OAAO,MAAMP,YAAY,GAAGC,eAAe;AAC3C,OAAO,MAAMP,mBAAmB,GAAGC,sBAAsB;AACzD,OAAO,MAAMC,iBAAiB,GAAGC,oBAAoB;AACrD,OAAO,MAAMC,cAAc,GAAGC,iBAAiB;AAC/C,OAAO,MAAMG,oBAAoB,GAAGC,uBAAuB;;AAE3D;AACA;AACA;AACA,OAAO,SAASK,OAAOA,CAAA,EAAG;EACxBR,YAAY,CAAC,CAAC;EACdN,mBAAmB,CAAC,CAAC;EACrBE,iBAAiB,CAAC,CAAC;EACnBE,cAAc,CAAC,CAAC;EAChBI,oBAAoB,CAAC,CAAC;AACxB","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ export function sssiEnglandRequestTransformer(url: string, options: TransformRequestOptions): any;
2
+ export function sssiWalesRequestTransformer(url: string, options: TransformRequestOptions): any;
3
+ export function sssiScotlandRequestTransformer(url: string, options: TransformRequestOptions): any;
4
+ declare namespace _default {
5
+ let datasets: {
6
+ id: string;
7
+ label: string;
8
+ dynamicGeoJSON: {
9
+ url: string;
10
+ idProperty: string;
11
+ transformRequest: typeof sssiEnglandRequestTransformer;
12
+ };
13
+ minZoom: number;
14
+ style: {
15
+ stroke: string;
16
+ fillPattern: string;
17
+ fillPatternForegroundColor: string;
18
+ fillPatternBackgroundColor: string;
19
+ };
20
+ showInKey: boolean;
21
+ showInMenu: boolean;
22
+ }[];
23
+ }
24
+ export default _default;
25
+ export type TransformRequestOptions = {
26
+ /**
27
+ * - the bounding box coordinates
28
+ */
29
+ bbox: string[];
30
+ };
31
+ /**
32
+ * Transforms the request URL with bounding box parameters
33
+ */
34
+ export type TransformRequestArgs = (url: string, options: TransformRequestOptions) => any;
@@ -0,0 +1,101 @@
1
+ const style = {
2
+ stroke: '#00897B',
3
+ fillPattern: 'diagonal-cross-hatch',
4
+ fillPatternForegroundColor: '#00897B',
5
+ fillPatternBackgroundColor: 'transparent'
6
+ };
7
+ const minZoom = 12;
8
+ const englandWFS = 'https://environment.data.gov.uk/geoservices/datasets/ba8dc201-66ef-4983-9d46-7378af21027e/ogc/features/v1/collections/Sites_of_Special_Scientific_Interest_England/items?f=json';
9
+ const walesWFS = 'https://datamap.gov.wales/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&typeNames=inspire-nrw:NRW_SSSI&outputFormat=application/json&srsName=EPSG:4326';
10
+ const scotlandWFS = 'https://services1.arcgis.com/LM9GyVFsughzHdbO/ArcGIS/rest/services/Sites_of_Special_Scientific_Interest/FeatureServer/0/query?f=geojson&where=1%3D1&geometryType=esriGeometryEnvelope&inSR=4326&spatialRel=esriSpatialRelIntersects&returnGeometry=true&outFields=*';
11
+
12
+ /**
13
+ * @type {TransformRequestArgs}
14
+ */
15
+ export function sssiEnglandRequestTransformer(url, {
16
+ bbox
17
+ }) {
18
+ const uri = new URL(url);
19
+ uri.searchParams.set('bbox', bbox.join(','));
20
+ return {
21
+ url: uri.toString()
22
+ };
23
+ }
24
+
25
+ /**
26
+ * @type {TransformRequestArgs}
27
+ */
28
+ export function sssiWalesRequestTransformer(url, {
29
+ bbox
30
+ }) {
31
+ const uri = new URL(url);
32
+ uri.searchParams.set('bbox', `${bbox.join(',')},EPSG:4326`);
33
+ return {
34
+ url: uri.toString()
35
+ };
36
+ }
37
+
38
+ /**
39
+ * @type {TransformRequestArgs}
40
+ */
41
+ export function sssiScotlandRequestTransformer(url, {
42
+ bbox
43
+ }) {
44
+ const uri = new URL(url);
45
+ uri.searchParams.set('geometry', bbox.join(','));
46
+ return {
47
+ url: uri.toString()
48
+ };
49
+ }
50
+ export default {
51
+ datasets: [{
52
+ id: 'sssi-england',
53
+ label: 'Sites of Special Scientific Interest',
54
+ dynamicGeoJSON: {
55
+ url: englandWFS,
56
+ idProperty: 'ref_code',
57
+ transformRequest: sssiEnglandRequestTransformer
58
+ },
59
+ minZoom,
60
+ style,
61
+ showInKey: true,
62
+ showInMenu: false
63
+ }, {
64
+ id: 'sssi-wales',
65
+ label: 'SSSI Wales',
66
+ dynamicGeoJSON: {
67
+ url: walesWFS,
68
+ idProperty: 'id',
69
+ transformRequest: sssiWalesRequestTransformer
70
+ },
71
+ minZoom,
72
+ style,
73
+ showInKey: false,
74
+ showInMenu: false
75
+ }, {
76
+ id: 'sssi-scotland',
77
+ label: 'SSSI Scotland',
78
+ dynamicGeoJSON: {
79
+ url: scotlandWFS,
80
+ idProperty: 'OBJECTID',
81
+ transformRequest: sssiScotlandRequestTransformer
82
+ },
83
+ minZoom,
84
+ style,
85
+ showInKey: false,
86
+ showInMenu: false
87
+ }]
88
+ };
89
+
90
+ /**
91
+ * @typedef {object} TransformRequestOptions
92
+ * @property {string[]} bbox - the bounding box coordinates
93
+ */
94
+
95
+ /**
96
+ * Transforms the request URL with bounding box parameters
97
+ * @callback TransformRequestArgs
98
+ * @param {string} url - the request URL
99
+ * @param {TransformRequestOptions} options - the bounding box coordinates
100
+ */
101
+ //# sourceMappingURL=sssi-dataset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sssi-dataset.js","names":["style","stroke","fillPattern","fillPatternForegroundColor","fillPatternBackgroundColor","minZoom","englandWFS","walesWFS","scotlandWFS","sssiEnglandRequestTransformer","url","bbox","uri","URL","searchParams","set","join","toString","sssiWalesRequestTransformer","sssiScotlandRequestTransformer","datasets","id","label","dynamicGeoJSON","idProperty","transformRequest","showInKey","showInMenu"],"sources":["../../../src/client/javascripts/sssi-dataset.js"],"sourcesContent":["const style = {\n stroke: '#00897B',\n fillPattern: 'diagonal-cross-hatch',\n fillPatternForegroundColor: '#00897B',\n fillPatternBackgroundColor: 'transparent'\n}\nconst minZoom = 12\n\nconst englandWFS =\n 'https://environment.data.gov.uk/geoservices/datasets/ba8dc201-66ef-4983-9d46-7378af21027e/ogc/features/v1/collections/Sites_of_Special_Scientific_Interest_England/items?f=json'\nconst walesWFS =\n 'https://datamap.gov.wales/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&typeNames=inspire-nrw:NRW_SSSI&outputFormat=application/json&srsName=EPSG:4326'\nconst scotlandWFS =\n 'https://services1.arcgis.com/LM9GyVFsughzHdbO/ArcGIS/rest/services/Sites_of_Special_Scientific_Interest/FeatureServer/0/query?f=geojson&where=1%3D1&geometryType=esriGeometryEnvelope&inSR=4326&spatialRel=esriSpatialRelIntersects&returnGeometry=true&outFields=*'\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiEnglandRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('bbox', bbox.join(','))\n\n return {\n url: uri.toString()\n }\n}\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiWalesRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('bbox', `${bbox.join(',')},EPSG:4326`)\n\n return {\n url: uri.toString()\n }\n}\n\n/**\n * @type {TransformRequestArgs}\n */\nexport function sssiScotlandRequestTransformer(url, { bbox }) {\n const uri = new URL(url)\n uri.searchParams.set('geometry', bbox.join(','))\n\n return {\n url: uri.toString()\n }\n}\n\nexport default {\n datasets: [\n {\n id: 'sssi-england',\n label: 'Sites of Special Scientific Interest',\n dynamicGeoJSON: {\n url: englandWFS,\n idProperty: 'ref_code',\n transformRequest: sssiEnglandRequestTransformer\n },\n minZoom,\n style,\n showInKey: true,\n showInMenu: false\n },\n {\n id: 'sssi-wales',\n label: 'SSSI Wales',\n dynamicGeoJSON: {\n url: walesWFS,\n idProperty: 'id',\n transformRequest: sssiWalesRequestTransformer\n },\n minZoom,\n style,\n showInKey: false,\n showInMenu: false\n },\n {\n id: 'sssi-scotland',\n label: 'SSSI Scotland',\n dynamicGeoJSON: {\n url: scotlandWFS,\n idProperty: 'OBJECTID',\n transformRequest: sssiScotlandRequestTransformer\n },\n minZoom,\n style,\n showInKey: false,\n showInMenu: false\n }\n ]\n}\n\n/**\n * @typedef {object} TransformRequestOptions\n * @property {string[]} bbox - the bounding box coordinates\n */\n\n/**\n * Transforms the request URL with bounding box parameters\n * @callback TransformRequestArgs\n * @param {string} url - the request URL\n * @param {TransformRequestOptions} options - the bounding box coordinates\n */\n"],"mappings":"AAAA,MAAMA,KAAK,GAAG;EACZC,MAAM,EAAE,SAAS;EACjBC,WAAW,EAAE,sBAAsB;EACnCC,0BAA0B,EAAE,SAAS;EACrCC,0BAA0B,EAAE;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G,EAAEJ,UAAU;MACfkB,UAAU,EAAE,UAAU;MACtBC,gBAAgB,EAAEhB;IACpB,CAAC;IACDJ,OAAO;IACPL,KAAK;IACL0B,SAAS,EAAE,IAAI;IACfC,UAAU,EAAE;EACd,CAAC,EACD;IACEN,EAAE,EAAE,YAAY;IAChBC,KAAK,EAAE,YAAY;IACnBC,cAAc,EAAE;MACdb,GAAG,EAAEH,QAAQ;MACbiB,UAAU,EAAE,IAAI;MAChBC,gBAAgB,EAAEP;IACpB,CAAC;IACDb,OAAO;IACPL,KAAK;IACL0B,SAAS,EAAE,KAAK;IAChBC,UAAU,EAAE;EACd,CAAC,EACD;IACEN,EAAE,EAAE,eAAe;IACnBC,KAAK,EAAE,eAAe;IACtBC,cAAc,EAAE;MACdb,GAAG,EAAEF,WAAW;MAChBgB,UAAU,EAAE,UAAU;MACtBC,gBAAgB,EAAEN;IACpB,CAAC;IACDd,OAAO;IACPL,KAAK;IACL0B,SAAS,EAAE,KAAK;IAChBC,UAAU,EAAE;EACd,CAAC;AAEL,CAAC;;AAED;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -5,11 +5,9 @@
5
5
  @use "location-fields";
6
6
 
7
7
  @use "@defra/interactive-map/css" as core;
8
- @use "@defra/interactive-map/plugins/interact/css" as interact;
9
8
  @use "@defra/interactive-map/plugins/map-styles/css" as mapStyles;
10
9
  @use "@defra/interactive-map/plugins/search/css" as search;
11
10
  @use "@defra/interactive-map/plugins/scale-bar/css" as scaleBar;
12
- @use "@defra/interactive-map/plugins/draw-ml/css" as drawMl;
13
11
 
14
12
  // Use default GDS Transport font for autocomplete
15
13
  .autocomplete__hint,
@@ -22,6 +22,7 @@ export declare class EastingNorthingField extends FormComponent {
22
22
  legend?: import("../../../../server/plugins/engine/components/types.js").Label;
23
23
  };
24
24
  items: import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
25
+ mapLayers: string;
25
26
  label: import("../../../../server/plugins/engine/components/types.js").Label;
26
27
  type?: string;
27
28
  id: string;
@@ -69,6 +70,7 @@ export declare class EastingNorthingField extends FormComponent {
69
70
  legend?: import("../../../../server/plugins/engine/components/types.js").Label;
70
71
  };
71
72
  items: import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
73
+ mapLayers: string;
72
74
  label: import("../../../../server/plugins/engine/components/types.js").Label;
73
75
  type?: string;
74
76
  id: string;
@@ -19,6 +19,7 @@ export declare class GeospatialField extends FormComponent {
19
19
  getViewModel(context: RenderContext): {
20
20
  country: import("@defra/forms-model").GeospatialFieldOptionsCountry | undefined;
21
21
  geometryTypes: import("@defra/forms-model").GeospatialFieldGeometryTypesEnum[] | undefined;
22
+ mapLayers: string;
22
23
  value: string;
23
24
  label: {
24
25
  text: string;
@@ -1,4 +1,5 @@
1
1
  import { FormComponent, isGeospatialState } from "./FormComponent.js";
2
+ import { getMapLayers } from "./LocationFieldHelpers.js";
2
3
  import { getGeospatialSchema } from "./helpers/geospatial.js";
3
4
  import { messageTemplate } from "../pageControllers/validationOptions.js";
4
5
  export class GeospatialField extends FormComponent {
@@ -56,6 +57,7 @@ export class GeospatialField extends FormComponent {
56
57
  ...viewModel,
57
58
  country: this.options.countries?.at(0),
58
59
  geometryTypes: this.options.geometryTypes,
60
+ mapLayers: getMapLayers(this),
59
61
  value
60
62
  };
61
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"GeospatialField.js","names":["FormComponent","isGeospatialState","getGeospatialSchema","messageTemplate","GeospatialField","constructor","def","props","options","formSchema","label","messages","featuresMin","featuresMax","featuresLength","stateSchema","default","required","allow","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getDisplayStringFromFormValue","features","translator","length","t","count","getDisplayStringFromState","getContextValueFromFormValue","map","id","getContextValueFromState","getViewModel","context","viewModel","JSON","stringify","country","countries","at","geometryTypes","getErrors","errors","fieldErrors","forEach","err","href","path","text","Number","getViewErrors","getAllPossibleErrors","staticErrors","advancedSettingsErrors","baseErrors","type","template","selectRequired","format"],"sources":["../../../../../src/server/plugins/engine/components/GeospatialField.ts"],"sourcesContent":["import { type GeospatialFieldComponent } from '@defra/forms-model'\nimport { type ArraySchema } from 'joi'\n\nimport { type ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport {\n FormComponent,\n isGeospatialState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { getGeospatialSchema } from '~/src/server/plugins/engine/components/helpers/geospatial.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type GeospatialState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class GeospatialField extends FormComponent {\n declare options: GeospatialFieldComponent['options']\n declare formSchema: ArraySchema<GeospatialState>\n declare stateSchema: ArraySchema<GeospatialState>\n\n constructor(\n def: GeospatialFieldComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { options } = def\n\n const formSchema = getGeospatialSchema(def).label(this.label).messages({\n 'array.min': messageTemplate.featuresMin,\n 'array.max': messageTemplate.featuresMax,\n 'array.length': messageTemplate.featuresLength\n })\n\n this.formSchema = formSchema\n this.stateSchema = formSchema.default(null)\n\n if (options.required === false) {\n this.stateSchema = this.stateSchema.allow(null)\n }\n\n this.options = options\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(\n features: GeospatialState | undefined,\n translator: Translator\n ): string {\n if (!features?.length) {\n return ''\n }\n\n return translator.t('components.geospatialField.added', {\n count: features.length\n })\n }\n\n getDisplayStringFromState(\n state: FormSubmissionState,\n translator: Translator\n ) {\n const features = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(features, translator)\n }\n\n getContextValueFromFormValue(\n features: GeospatialState | undefined\n ): string[] | null {\n return features?.map(({ id }) => id) ?? null\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const features = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(features)\n }\n\n getViewModel(context: RenderContext) {\n const viewModel = super.getViewModel(context)\n const value =\n typeof viewModel.value === 'string'\n ? viewModel.value\n : JSON.stringify(viewModel.value, null, 2)\n\n return {\n ...viewModel,\n country: this.options.countries?.at(0),\n geometryTypes: this.options.geometryTypes,\n value\n }\n }\n\n getErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const fieldErrors = super.getErrors(translator, errors)\n\n fieldErrors?.forEach((err) => {\n if (err.name === 'description') {\n err.href = `#description_${err.path[1]}`\n err.text = translator.t(\n 'components.geospatialField.validation.descriptionRequired',\n { count: Number(err.path[1]) + 1 }\n )\n } else if (typeof err.name === 'number' && err.context?.country) {\n err.href = `#description_${err.path[1]}`\n err.text = translator.t(\n 'components.geospatialField.validation.wrongCountry',\n { count: Number(err.path[1]) + 1, country: err.context.country }\n )\n }\n })\n\n return fieldErrors\n }\n\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getErrors(translator, errors)\n }\n\n isValue(value?: FormStateValue | FormState): value is GeospatialState {\n return isGeospatialState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n const staticErrors = GeospatialField.getAllPossibleErrors()\n return {\n ...staticErrors,\n advancedSettingsErrors: [...staticErrors.advancedSettingsErrors]\n }\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.selectRequired },\n {\n type: 'array.min',\n template: '{{#title}} must contain at least 1 items'\n },\n { type: 'object.invalidj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AoBA,CAAA,EAA6B;IACtD,OAAO;MACLG,UAAU,EAAE,CACV;QAAEC,IAAI,EAAE,UAAU;QAAEC,QAAQ,EAAE1D,eAAe,CAAC2D;MAAe,CAAC,EAC9D;QACEF,IAAI,EAAE,WAAW;QACjBC,QAAQ,EAAE;MACZ,CAAC,EACD;QAAED,IAAI,EAAE,oBAAoB;QAAEC,QAAQ,EAAE1D,eAAe,CAAC4D;MAAO,CAAC,CACjE;MACDL,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
1
+ {"version":3,"file":"GeospatialField.js","names":["FormComponent","isGeospatialState","getMapLayers","getGeospatialSchema","messageTemplate","GeospatialField","constructor","def","props","options","formSchema","label","messages","featuresMin","featuresMax","featuresLength","stateSchema","default","required","allow","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","getDisplayStringFromFormValue","features","translator","length","t","count","getDisplayStringFromState","getContextValueFromFormValue","map","id","getContextValueFromState","getViewModel","context","viewModel","JSON","stringify","country","countries","at","geometryTypes","mapLayers","getErrors","errors","fieldErrors","forEach","err","href","path","text","Number","getViewErrors","getAllPossibleErrors","staticErrors","advancedSettingsErrors","baseErrors","type","template","selectRequired","format"],"sources":["../../../../../src/server/plugins/engine/components/GeospatialField.ts"],"sourcesContent":["import { type GeospatialFieldComponent } from '@defra/forms-model'\nimport { type ArraySchema } from 'joi'\n\nimport { type ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport {\n FormComponent,\n isGeospatialState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { getMapLayers } from '~/src/server/plugins/engine/components/LocationFieldHelpers.js'\nimport { getGeospatialSchema } from '~/src/server/plugins/engine/components/helpers/geospatial.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type GeospatialState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class GeospatialField extends FormComponent {\n declare options: GeospatialFieldComponent['options']\n declare formSchema: ArraySchema<GeospatialState>\n declare stateSchema: ArraySchema<GeospatialState>\n\n constructor(\n def: GeospatialFieldComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { options } = def\n\n const formSchema = getGeospatialSchema(def).label(this.label).messages({\n 'array.min': messageTemplate.featuresMin,\n 'array.max': messageTemplate.featuresMax,\n 'array.length': messageTemplate.featuresLength\n })\n\n this.formSchema = formSchema\n this.stateSchema = formSchema.default(null)\n\n if (options.required === false) {\n this.stateSchema = this.stateSchema.allow(null)\n }\n\n this.options = options\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(\n features: GeospatialState | undefined,\n translator: Translator\n ): string {\n if (!features?.length) {\n return ''\n }\n\n return translator.t('components.geospatialField.added', {\n count: features.length\n })\n }\n\n getDisplayStringFromState(\n state: FormSubmissionState,\n translator: Translator\n ) {\n const features = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(features, translator)\n }\n\n getContextValueFromFormValue(\n features: GeospatialState | undefined\n ): string[] | null {\n return features?.map(({ id }) => id) ?? null\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const features = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(features)\n }\n\n getViewModel(context: RenderContext) {\n const viewModel = super.getViewModel(context)\n const value =\n typeof viewModel.value === 'string'\n ? viewModel.value\n : JSON.stringify(viewModel.value, null, 2)\n\n return {\n ...viewModel,\n country: this.options.countries?.at(0),\n geometryTypes: this.options.geometryTypes,\n mapLayers: getMapLayers(this),\n value\n }\n }\n\n getErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const fieldErrors = super.getErrors(translator, errors)\n\n fieldErrors?.forEach((err) => {\n if (err.name === 'description') {\n err.href = `#description_${err.path[1]}`\n err.text = translator.t(\n 'components.geospatialField.validation.descriptionRequired',\n { count: Number(err.path[1]) + 1 }\n )\n } else if (typeof err.name === 'number' && err.context?.country) {\n err.href = `#description_${err.path[1]}`\n err.text = translator.t(\n 'components.geospatialField.validation.wrongCountry',\n { count: Number(err.path[1]) + 1, country: err.context.country }\n )\n }\n })\n\n return fieldErrors\n }\n\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getErrors(translator, errors)\n }\n\n isValue(value?: FormStateValue | FormState): value is GeospatialState {\n return isGeospatialState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n const staticErrors = GeospatialField.getAllPossibleErrors()\n return {\n ...staticErrors,\n advancedSettingsErrors: [...staticErrors.advancedSettingsErrors]\n }\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.selectRequired },\n {\n type: 'array.min',\n template: '{{#title}} must contain at least 1 items'\n },\n { type: 'object.invalidjson', template: messageTemplate.format }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAIA,SACEA,aAAa,EACbC,iBAAiB;AAEnB,SAASC,YAAY;AACrB,SAASC,mBAAmB;AAG5B,SAASC,eAAe;AAUxB,OAAO,MAAMC,eAAe,SAASL,aAAa,CAAC;EAKjDM,WAAWA,CACTC,GAA6B,EAC7BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC;IAAQ,CAAC,GAAGF,GAAG;IAEvB,MAAMG,UAAU,GAAGP,mBAAmB,CAACI,GAAG,CAAC,CAACI,KAAK,CAAC,IAAI,CAACA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LongField extends FormComponent {
22
22
  legend?: import("../../../../server/plugins/engine/components/types.js").Label;
23
23
  };
24
24
  items: import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
25
+ mapLayers: string;
25
26
  label: import("../../../../server/plugins/engine/components/types.js").Label;
26
27
  type?: string;
27
28
  id: string;
@@ -69,6 +70,7 @@ export declare class LatLongField extends FormComponent {
69
70
  legend?: import("../../../../server/plugins/engine/components/types.js").Label;
70
71
  };
71
72
  items: import("../../../../server/plugins/engine/components/types.js").DateInputItem[];
73
+ mapLayers: string;
72
74
  label: import("../../../../server/plugins/engine/components/types.js").Label;
73
75
  type?: string;
74
76
  id: string;
@@ -1,6 +1,8 @@
1
1
  import { type CustomValidator } from 'joi';
2
2
  import { type EastingNorthingField } from '../../../../server/plugins/engine/components/EastingNorthingField.js';
3
+ import { type GeospatialField } from '../../../../server/plugins/engine/components/GeospatialField.js';
3
4
  import { type LatLongField } from '../../../../server/plugins/engine/components/LatLongField.js';
5
+ import { type OsGridRefField } from '../../../../server/plugins/engine/components/OsGridRefField.js';
4
6
  import { type DateInputItem, type Label, type RenderContext, type ViewModel } from '../../../../server/plugins/engine/components/types.js';
5
7
  import { type FormSubmissionError, type FormValue } from '../../../../server/plugins/engine/types.js';
6
8
  export type LocationField = InstanceType<typeof EastingNorthingField> | InstanceType<typeof LatLongField>;
@@ -8,6 +10,7 @@ export declare function joinWithAnd(items: string[]): string;
8
10
  export declare function formatErrorList(messages: string[]): string;
9
11
  export declare function mergeCssClasses(...classNames: (string | undefined)[]): string | undefined;
10
12
  export declare function deduplicateErrorsByHref(errors?: FormSubmissionError[]): FormSubmissionError[] | undefined;
13
+ export declare function getMapLayers(component: GeospatialField | OsGridRefField | LatLongField | EastingNorthingField): string;
11
14
  export declare function getLocationFieldViewModel(component: LocationField, viewModel: ViewModel & {
12
15
  label: Label;
13
16
  id: string;
@@ -19,6 +22,7 @@ export declare function getLocationFieldViewModel(component: LocationField, view
19
22
  legend?: Label;
20
23
  };
21
24
  items: DateInputItem[];
25
+ mapLayers: string;
22
26
  label: Label;
23
27
  type?: string;
24
28
  id: string;
@@ -66,6 +70,7 @@ export declare function getLocationFieldViewModel(component: LocationField, view
66
70
  legend?: Label;
67
71
  };
68
72
  items: DateInputItem[];
73
+ mapLayers: string;
69
74
  label: Label;
70
75
  type?: string;
71
76
  id: string;
@@ -45,6 +45,16 @@ export function deduplicateErrorsByHref(errors) {
45
45
  }
46
46
  return errors.filter((error, index, self) => index === self.findIndex(err => err.href === error.href));
47
47
  }
48
+ export function getMapLayers(component) {
49
+ const {
50
+ mapLayers
51
+ } = component.options;
52
+ const layers = [];
53
+ if (mapLayers?.sssi) {
54
+ layers.push('sssi');
55
+ }
56
+ return layers.join(',');
57
+ }
48
58
  export function getLocationFieldViewModel(component, viewModel, context) {
49
59
  const {
50
60
  collection
@@ -112,7 +122,8 @@ export function getLocationFieldViewModel(component, viewModel, context) {
112
122
  const result = {
113
123
  ...viewModel,
114
124
  fieldset,
115
- items
125
+ items,
126
+ mapLayers: getMapLayers(component)
116
127
  };
117
128
  if (component.options.instructionText) {
118
129
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"LocationFieldHelpers.js","names":["isFormValue","lowercaseMessageStart","message","startsWith","slice","charAt","toLowerCase","joinWithAnd","items","length","leading","join","last","formatErrorList","messages","formattedMessages","map","msg","index","mergeCssClasses","classNames","tokens","flatMap","name","split","token","trim","filter","Boolean","undefined","Array","from","Set","deduplicateErrorsByHref","errors","error","self","findIndex","err","href","getLocationFieldViewModel","component","viewModel","context","collection","fieldset","existingFieldset","label","subViewModels","getViewModel","fieldErrors","forEach","model","errorMessage","text","push","hasFieldErrors","type","value","classes","prefix","suffix","toString","baseItem","id","showFieldsetError","legend","result","options","instructionText","createLocationFieldValidator","payload","helpers","values","getFormValueFromState","getStateFromValidForm","missing","keys","key","isState","required"],"sources":["../../../../../src/server/plugins/engine/components/LocationFieldHelpers.ts"],"sourcesContent":["import { type Context, type CustomValidator } from 'joi'\n\nimport { type EastingNorthingField } from '~/src/server/plugins/engine/components/EastingNorthingField.js'\nimport { isFormValue } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type LatLongField } from '~/src/server/plugins/engine/components/LatLongField.js'\nimport {\n type DateInputItem,\n type Label,\n type RenderContext,\n type ViewModel\n} from '~/src/server/plugins/engine/components/types.js'\nimport {\n type FormPayload,\n type FormSubmissionError,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport type LocationField =\n | InstanceType<typeof EastingNorthingField>\n | InstanceType<typeof LatLongField>\n\n/**\n * Lowercases the start of a message for concatenation.\n * Handles patterns like:\n * - \"Enter latitude\" -> \"enter latitude\"\n * - \"Enter a valid latitude...\" -> \"enter a valid latitude...\"\n * - \"latitude must be...\" -> \"latitude must be...\"\n */\nfunction lowercaseMessageStart(message: string): string {\n if (message.startsWith('Enter ')) {\n return 'enter' + message.slice(5)\n }\n\n // Lowercase first character for any other message\n return message.charAt(0).toLowerCase() + message.slice(1)\n}\n\nexport function joinWithAnd(items: string[]): string {\n if (items.length === 2) {\n return `${items[0]} and ${items[1]}`\n }\n\n const leading = items.slice(0, -1).join(', ')\n const last = items[items.length - 1]\n return `${leading} and ${last}`\n}\n\nexport function formatErrorList(messages: string[]): string {\n if (!messages.length) {\n return ''\n }\n\n if (messages.length === 1) {\n return messages[0]\n }\n\n const formattedMessages = messages.map((msg, index) =>\n index === 0 ? msg : lowercaseMessageStart(msg)\n )\n\n return joinWithAnd(formattedMessages)\n}\n\nexport function mergeCssClasses(...classNames: (string | undefined)[]) {\n const tokens = classNames\n .flatMap((name) => name?.split(/\\s+/) ?? [])\n .map((token) => token.trim())\n .filter(Boolean)\n\n if (!tokens.length) {\n return undefined\n }\n\n return Array.from(new Set(tokens)).join(' ')\n}\n\nexport function deduplicateErrorsByHref(\n errors?: FormSubmissionError[]\n): FormSubmissionError[] | undefined {\n if (!errors?.length) {\n return undefined\n }\n\n return errors.filter(\n (error, index, self) =>\n index === self.findIndex((err) => err.href === error.href)\n )\n}\n\nexport function getLocationFieldViewModel(\n component: LocationField,\n viewModel: ViewModel & {\n label: Label\n id: string\n name: string\n value: FormValue\n },\n context: RenderContext\n) {\n const { collection } = component\n const { fieldset: existingFieldset, label } = viewModel\n\n const subViewModels = collection.getViewModel(context)\n\n const fieldErrors: string[] = []\n subViewModels.forEach(({ model }) => {\n if (model.errorMessage?.text) {\n fieldErrors.push(model.errorMessage.text)\n }\n })\n\n const hasFieldErrors = fieldErrors.length > 0\n\n const items: DateInputItem[] = subViewModels.map(\n ({ model }): DateInputItem => {\n let { label, type, value, classes, prefix, suffix, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text\n }\n\n if (!isFormValue(value)) {\n value = undefined\n }\n\n const baseItem: DateInputItem = {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes: mergeCssClasses(\n classes,\n hasFieldErrors ? 'govuk-input--error' : undefined\n ),\n prefix,\n suffix\n }\n\n if (!hasFieldErrors && errorMessage) {\n baseItem.errorMessage = errorMessage\n }\n\n return baseItem\n }\n )\n\n const showFieldsetError =\n hasFieldErrors || Boolean(viewModel.errorMessage?.text)\n\n viewModel.showFieldsetError = showFieldsetError\n\n if (hasFieldErrors) {\n viewModel.errorMessage = {\n text:\n fieldErrors.length === 1 ? fieldErrors[0] : formatErrorList(fieldErrors)\n }\n }\n\n const fieldset = existingFieldset ?? {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const result = {\n ...viewModel,\n fieldset,\n items\n }\n\n if (component.options.instructionText) {\n return {\n ...result,\n instructionText: component.options.instructionText\n }\n }\n\n return result\n}\n\n/**\n * Validator factory for location-based fields.\n * This creates a validator that ensures all required fields are present.\n */\nexport function createLocationFieldValidator(\n component: LocationField\n): CustomValidator {\n return (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n return payload\n }\n}\n"],"mappings":"AAGA,SAASA,WAAW;AAkBpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,qBAAqBA,CAACC,OAAe,EAAU;EACtD,IAAIA,OAAO,CAACC,UAAU,CAAC,QAAQ,CAAC,EAAE;IAChC,OAAO,OAAO,GAAGD,OAAO,CAACE,KAAK,CAAC,CAAC,CAAC;EACnC;;EAEA;EACA,OAAOF,OAAO,CAACG,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGJ,OAAO,CAACE,KAAK,CAAC,CAAC,CAAC;AAC3D;AAEA,OAAO,SAASG,WAAWA,CAACC,KAAe,EAAU;EACnD,IAAIA,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,GAAGD,KAAK,CAAC,CAAC,CAAC,QAAQA,KAAK,CAAC,CAAC,CAAC,EAAE;EACtC;EAEA,MAAME,OAAO,GAAGF,KAAK,CAACJ,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACO,IAAI,CAAC,IAAI,CAAC;EAC7C,MAAMC,IAAI,GAAGJ,KAAK,CAACA,KAAK,CAACC,MAAM,GAAG,CAAC,CAAC;EACpC,OAAO,GAAGC,OAAO,QAAQE,IAAI,EAAE;AACjC;AAEA,OAAO,SAASC,eAAeA,CAACC,QAAkB,EAAU;EAC1D,IAAI,CAACA,QAAQ,CAACL,MAAM,EAAE;IACpB,OAAO,EAAE;EACX;EAEA,IAAIK,QAAQ,CAACL,MAAM,KAAK,CAAC,EAAE;IACzB,OAAOK,QAAQ,CAAC,CAAC,CAAC;EACpB;EAEA,MAAMC,iBAAiB,GAAGD,QAAQ,CAACE,GAAG,CAAC,CAACC,GAAG,EAAEC,KAAK,KAChDA,KAAK,KAAK,CAAC,GAAGD,GAAG,GAAGhB,qBAAqB,CAACgB,GAAG,CAC/C,CAAC;EAED,OAAOV,WAAW,CAACQ,iBAAiB,CA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QAAQ,GAAGC,gBAAgB,IAAI;IACnCoB,MAAM,EAAE;MACNZ,IAAI,EAAEP,KAAK,CAACO,IAAI;MAChBK,OAAO,EAAE;IACX;EACF,CAAC;EAED,MAAMQ,MAAM,GAAG;IACb,GAAGzB,SAAS;IACZG,QAAQ;IACRrC;EACF,CAAC;EAED,IAAIiC,SAAS,CAAC2B,OAAO,CAACC,eAAe,EAAE;IACrC,OAAO;MACL,GAAGF,MAAM;MACTE,eAAe,EAAE5B,SAAS,CAAC2B,OAAO,CAACC;IACrC,CAAC;EACH;EAEA,OAAOF,MAAM;AACf;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,4BAA4BA,CAC1C7B,SAAwB,EACP;EACjB,OAAO,CAAC8B,OAAoB,EAAEC,OAAO,KAAK;IACxC,MAAM;MAAE5B,UAAU;MAAErB,IAAI;MAAE6C;IAAQ,CAAC,GAAG3B,SAAS;IAE/C,MAAMgC,MAAM,GAAGhC,SAAS,CAACiC,qBAAqB,CAC5CjC,SAAS,CAACkC,qBAAqB,CAACJ,OAAO,CACzC,CAAC;IAED,MAAM5B,OAAgB,GAAG;MACvBiC,OAAO,EAAEhC,UAAU,CAACiC,IAAI;MACxBC,GAAG,EAAEvD;IACP,CAAC;IAED,IAAI,CAACkB,SAAS,CAACsC,OAAO,CAACN,MAAM,CAAC,EAAE;MAC9B,OAAOL,OAAO,CAACY,QAAQ,KAAK,KAAK,GAC7BR,OAAO,CAACrC,KAAK,CAAC,iBAAiB,EAAEQ,OAAO,CAAC,GACzC4B,OAAO;IACb;IAEA,OAAOA,OAAO;EAChB,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"LocationFieldHelpers.js","names":["isFormValue","lowercaseMessageStart","message","startsWith","slice","charAt","toLowerCase","joinWithAnd","items","length","leading","join","last","formatErrorList","messages","formattedMessages","map","msg","index","mergeCssClasses","classNames","tokens","flatMap","name","split","token","trim","filter","Boolean","undefined","Array","from","Set","deduplicateErrorsByHref","errors","error","self","findIndex","err","href","getMapLayers","component","mapLayers","options","layers","sssi","push","getLocationFieldViewModel","viewModel","context","collection","fieldset","existingFieldset","label","subViewModels","getViewModel","fieldErrors","forEach","model","errorMessage","text","hasFieldErrors","type","value","classes","prefix","suffix","toString","baseItem","id","showFieldsetError","legend","result","instructionText","createLocationFieldValidator","payload","helpers","values","getFormValueFromState","getStateFromValidForm","missing","keys","key","isState","required"],"sources":["../../../../../src/server/plugins/engine/components/LocationFieldHelpers.ts"],"sourcesContent":["import { type Context, type CustomValidator } from 'joi'\n\nimport { type EastingNorthingField } from '~/src/server/plugins/engine/components/EastingNorthingField.js'\nimport { isFormValue } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type GeospatialField } from '~/src/server/plugins/engine/components/GeospatialField.js'\nimport { type LatLongField } from '~/src/server/plugins/engine/components/LatLongField.js'\nimport { type OsGridRefField } from '~/src/server/plugins/engine/components/OsGridRefField.js'\nimport {\n type DateInputItem,\n type Label,\n type RenderContext,\n type ViewModel\n} from '~/src/server/plugins/engine/components/types.js'\nimport {\n type FormPayload,\n type FormSubmissionError,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport type LocationField =\n | InstanceType<typeof EastingNorthingField>\n | InstanceType<typeof LatLongField>\n\n/**\n * Lowercases the start of a message for concatenation.\n * Handles patterns like:\n * - \"Enter latitude\" -> \"enter latitude\"\n * - \"Enter a valid latitude...\" -> \"enter a valid latitude...\"\n * - \"latitude must be...\" -> \"latitude must be...\"\n */\nfunction lowercaseMessageStart(message: string): string {\n if (message.startsWith('Enter ')) {\n return 'enter' + message.slice(5)\n }\n\n // Lowercase first character for any other message\n return message.charAt(0).toLowerCase() + message.slice(1)\n}\n\nexport function joinWithAnd(items: string[]): string {\n if (items.length === 2) {\n return `${items[0]} and ${items[1]}`\n }\n\n const leading = items.slice(0, -1).join(', ')\n const last = items[items.length - 1]\n return `${leading} and ${last}`\n}\n\nexport function formatErrorList(messages: string[]): string {\n if (!messages.length) {\n return ''\n }\n\n if (messages.length === 1) {\n return messages[0]\n }\n\n const formattedMessages = messages.map((msg, index) =>\n index === 0 ? msg : lowercaseMessageStart(msg)\n )\n\n return joinWithAnd(formattedMessages)\n}\n\nexport function mergeCssClasses(...classNames: (string | undefined)[]) {\n const tokens = classNames\n .flatMap((name) => name?.split(/\\s+/) ?? [])\n .map((token) => token.trim())\n .filter(Boolean)\n\n if (!tokens.length) {\n return undefined\n }\n\n return Array.from(new Set(tokens)).join(' ')\n}\n\nexport function deduplicateErrorsByHref(\n errors?: FormSubmissionError[]\n): FormSubmissionError[] | undefined {\n if (!errors?.length) {\n return undefined\n }\n\n return errors.filter(\n (error, index, self) =>\n index === self.findIndex((err) => err.href === error.href)\n )\n}\n\nexport function getMapLayers(\n component:\n | GeospatialField\n | OsGridRefField\n | LatLongField\n | EastingNorthingField\n) {\n const { mapLayers } = component.options\n const layers = []\n\n if (mapLayers?.sssi) {\n layers.push('sssi')\n }\n\n return layers.join(',')\n}\n\nexport function getLocationFieldViewModel(\n component: LocationField,\n viewModel: ViewModel & {\n label: Label\n id: string\n name: string\n value: FormValue\n },\n context: RenderContext\n) {\n const { collection } = component\n const { fieldset: existingFieldset, label } = viewModel\n\n const subViewModels = collection.getViewModel(context)\n\n const fieldErrors: string[] = []\n subViewModels.forEach(({ model }) => {\n if (model.errorMessage?.text) {\n fieldErrors.push(model.errorMessage.text)\n }\n })\n\n const hasFieldErrors = fieldErrors.length > 0\n\n const items: DateInputItem[] = subViewModels.map(\n ({ model }): DateInputItem => {\n let { label, type, value, classes, prefix, suffix, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text\n }\n\n if (!isFormValue(value)) {\n value = undefined\n }\n\n const baseItem: DateInputItem = {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes: mergeCssClasses(\n classes,\n hasFieldErrors ? 'govuk-input--error' : undefined\n ),\n prefix,\n suffix\n }\n\n if (!hasFieldErrors && errorMessage) {\n baseItem.errorMessage = errorMessage\n }\n\n return baseItem\n }\n )\n\n const showFieldsetError =\n hasFieldErrors || Boolean(viewModel.errorMessage?.text)\n\n viewModel.showFieldsetError = showFieldsetError\n\n if (hasFieldErrors) {\n viewModel.errorMessage = {\n text:\n fieldErrors.length === 1 ? fieldErrors[0] : formatErrorList(fieldErrors)\n }\n }\n\n const fieldset = existingFieldset ?? {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const result = {\n ...viewModel,\n fieldset,\n items,\n mapLayers: getMapLayers(component)\n }\n\n if (component.options.instructionText) {\n return {\n ...result,\n instructionText: component.options.instructionText\n }\n }\n\n return result\n}\n\n/**\n * Validator factory for location-based fields.\n * This creates a validator that ensures all required fields are present.\n */\nexport function createLocationFieldValidator(\n component: LocationField\n): CustomValidator {\n return (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n return payload\n }\n}\n"],"mappings":"AAGA,SAASA,WAAW;AAoBpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,qBAAqBA,CAACC,OAAe,EAAU;EACtD,IAAIA,OAAO,CAACC,UAAU,CAAC,QAAQ,CAAC,EAAE;IAChC,OAAO,OAAO,GAAGD,OAAO,CAACE,KAAK,CAAC,CAAC,CAAC;EACnC;;EAEA;EACA,OAAOF,OAAO,CAACG,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGJ,OAAO,CAACE,KAAK,CAAC,CAAC,CAAC;AAC3D;AAEA,OAAO,SAASG,WAAWA,CAACC,KAAe,EAAU;EACnD,IAAIA,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,GAAGD,KAAK,CAAC,CAAC,CAAC,QAAQA,KAAK,CAAC,CAAC,CAAC,EAAE;EACtC;EAEA,MAAME,OAAO,GAAGF,KAAK,C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,EAAEhC,SAAS,CAACE,OAAO,CAAC8B;IACrC,CAAC;EACH;EAEA,OAAOD,MAAM;AACf;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASE,4BAA4BA,CAC1CjC,SAAwB,EACP;EACjB,OAAO,CAACkC,OAAoB,EAAEC,OAAO,KAAK;IACxC,MAAM;MAAE1B,UAAU;MAAE3B,IAAI;MAAEoB;IAAQ,CAAC,GAAGF,SAAS;IAE/C,MAAMoC,MAAM,GAAGpC,SAAS,CAACqC,qBAAqB,CAC5CrC,SAAS,CAACsC,qBAAqB,CAACJ,OAAO,CACzC,CAAC;IAED,MAAM1B,OAAgB,GAAG;MACvB+B,OAAO,EAAE9B,UAAU,CAAC+B,IAAI;MACxBC,GAAG,EAAE3D;IACP,CAAC;IAED,IAAI,CAACkB,SAAS,CAAC0C,OAAO,CAACN,MAAM,CAAC,EAAE;MAC9B,OAAOlC,OAAO,CAACyC,QAAQ,KAAK,KAAK,GAC7BR,OAAO,CAACzC,KAAK,CAAC,iBAAiB,EAAEc,OAAO,CAAC,GACzC0B,OAAO;IACb;IAEA,OAAOA,OAAO;EAChB,CAAC;AACH","ignoreList":[]}
@@ -70,7 +70,9 @@
70
70
 
71
71
  {% set hasErrors = showFieldsetError and component.model.errorMessage %}
72
72
 
73
- <div class="govuk-form-group app-location-field {{ "govuk-form-group--error" if hasErrors }}" data-locationtype="{{component.type | lower}}">
73
+ <div class="govuk-form-group app-location-field {{ "govuk-form-group--error" if hasErrors }}"
74
+ data-locationtype="{{component.type | lower}}"
75
+ data-maplayers="{{component.model.mapLayers}}">
74
76
  {{ govukFieldset({
75
77
  legend: {
76
78
  text: component.model.fieldset.legend.text,
@@ -1,7 +1,10 @@
1
1
  {% from "govuk/components/textarea/macro.njk" import govukTextarea %}
2
2
 
3
3
  {% macro GeospatialField(component) %}
4
- <div class="app-geospatial-field" data-country="{{component.model.country}}" data-geometryTypes="{{component.model.geometryTypes}}">
4
+ <div class="app-geospatial-field"
5
+ data-country="{{component.model.country}}"
6
+ data-geometryTypes="{{component.model.geometryTypes}}"
7
+ data-maplayers="{{component.model.mapLayers}}">
5
8
  {{ govukTextarea(component.model) }}
6
9
  </div>
7
10
  {% endmacro %}
@@ -195,6 +195,6 @@ function getGeospatialCountries() {
195
195
  /**
196
196
  * @import { ServerRoute } from '@hapi/hapi'
197
197
  * @import { FeatureCollection } from 'geojson'
198
- * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, MapReverseGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '../../../../server/plugins/map/types.js'
198
+ * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '../../../../server/plugins/map/types.js'
199
199
  */
200
200
  //# sourceMappingURL=index.js.map