@defra/forms-engine-plugin 4.14.4 → 4.15.0
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/.public/assets-manifest.json +10 -1
- package/.public/javascripts/im-search-plugin.min.js +2 -0
- package/.public/javascripts/im-search-plugin.min.js.map +1 -0
- package/.public/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.public/javascripts/vendor/@defra.min.js +2 -0
- package/.public/javascripts/vendor/@defra.min.js.map +1 -0
- package/.public/javascripts/vendor/maplibre-gl.min.js +3 -0
- package/.public/javascripts/vendor/maplibre-gl.min.js.LICENSE.txt +4 -0
- package/.public/javascripts/vendor/maplibre-gl.min.js.map +1 -0
- package/.public/javascripts/vendor/preact.min.js +2 -0
- package/.public/javascripts/vendor/preact.min.js.map +1 -0
- package/.public/stylesheets/application.min.css +1 -1
- package/.public/stylesheets/application.min.css.map +1 -1
- package/.server/client/javascripts/geospatial-map.js +9 -4
- package/.server/client/javascripts/geospatial-map.js.map +1 -1
- package/.server/client/javascripts/map.js +18 -12
- package/.server/client/javascripts/map.js.map +1 -1
- package/.server/client/stylesheets/shared.scss +7 -0
- package/.server/server/plugins/map/routes/index.d.ts +1 -2
- package/.server/server/plugins/map/routes/index.js +2 -32
- package/.server/server/plugins/map/routes/index.js.map +1 -1
- package/.server/server/plugins/map/service.d.ts +0 -7
- package/.server/server/plugins/map/service.js +0 -12
- package/.server/server/plugins/map/service.js.map +1 -1
- package/.server/server/plugins/map/service.test.js +0 -43
- package/.server/server/plugins/map/service.test.js.map +1 -1
- package/package.json +2 -1
- package/src/client/javascripts/geospatial-map.js +9 -5
- package/src/client/javascripts/map.js +18 -13
- package/src/client/stylesheets/shared.scss +7 -0
- package/src/server/plugins/map/routes/index.js +1 -37
- package/src/server/plugins/map/service.js +0 -13
- package/.server/server/plugins/map/test/__stubs__/nearest.d.ts +0 -37
- package/.server/server/plugins/map/test/__stubs__/nearest.js +0 -38
- package/.server/server/plugins/map/test/__stubs__/nearest.js.map +0 -1
- package/src/server/plugins/map/test/__stubs__/nearest.js +0 -46
|
@@ -4,7 +4,7 @@ import { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model';
|
|
|
4
4
|
import { StatusCodes } from 'http-status-codes';
|
|
5
5
|
import Joi from 'joi';
|
|
6
6
|
import { getAccessToken } from "./get-os-token.js";
|
|
7
|
-
import { find
|
|
7
|
+
import { find } from "../service.js";
|
|
8
8
|
import { get, request as httpRequest } from "../../../services/httpService.js";
|
|
9
9
|
const filePath = resolve(import.meta.dirname, './vts/countries.geojson');
|
|
10
10
|
|
|
@@ -20,7 +20,7 @@ export const countrySchema = Joi.string().valid(...Object.values(GeospatialField
|
|
|
20
20
|
* @param {MapConfiguration} options - ordnance survey names api key
|
|
21
21
|
*/
|
|
22
22
|
export function getRoutes(options) {
|
|
23
|
-
return [mapStyleResourceRoutes(), mapProxyRoute(options), tileProxyRoute(options), geocodeProxyRoute(options),
|
|
23
|
+
return [mapStyleResourceRoutes(), mapProxyRoute(options), tileProxyRoute(options), geocodeProxyRoute(options), getGeospatialCountries()];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -134,36 +134,6 @@ function geocodeProxyRoute(options) {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
/**
|
|
138
|
-
* Proxies ordnance survey reverse geocode requests from the front end to api.os.uk
|
|
139
|
-
* Used to find name from easting and northing points.
|
|
140
|
-
* N.B this endpoint is currently not used by the front end but will be soon in "maps V2"
|
|
141
|
-
* @param {MapConfiguration} options - the map options
|
|
142
|
-
* @returns {ServerRoute<MapReverseGeocodeGetRequestRefs>}
|
|
143
|
-
*/
|
|
144
|
-
function reverseGeocodeProxyRoute(options) {
|
|
145
|
-
return {
|
|
146
|
-
method: 'GET',
|
|
147
|
-
path: '/api/reverse-geocode-proxy',
|
|
148
|
-
async handler(request, _h) {
|
|
149
|
-
const {
|
|
150
|
-
query
|
|
151
|
-
} = request;
|
|
152
|
-
const data = await nearest(query.easting, query.northing, options.ordnanceSurveyApiKey);
|
|
153
|
-
return data;
|
|
154
|
-
},
|
|
155
|
-
options: {
|
|
156
|
-
auth: false,
|
|
157
|
-
validate: {
|
|
158
|
-
query: Joi.object().keys({
|
|
159
|
-
easting: Joi.number().required(),
|
|
160
|
-
northing: Joi.number().required()
|
|
161
|
-
}).required()
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
137
|
/**
|
|
168
138
|
* Resource routes to return sprites and glyphs
|
|
169
139
|
* @returns {ServerRoute<MapProxyGetRequestRefs>}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fs","resolve","GeospatialFieldOptionsCountryEnum","StatusCodes","Joi","getAccessToken","find","nearest","get","request","httpRequest","filePath","import","meta","dirname","countries","JSON","parse","readFileSync","countrySchema","string","valid","Object","values","getRoutes","options","mapStyleResourceRoutes","mapProxyRoute","tileProxyRoute","geocodeProxyRoute","reverseGeocodeProxyRoute","getGeospatialCountries","method","path","handler","h","query","targetUrl","URL","decodeURIComponent","url","token","searchParams","set","proxyResponse","toString","headers","Authorization","buffer","payload","contentType","res","response","type","auth","validate","object","keys","required","optional","z","y","x","params","getBuffer","Accept","json","gunzip","statusCode","OK","valueOf","code","header","_h","data","ordnanceSurveyApiKey","easting","northing","number","directory","omit","only","features","filter","feature","id"],"sources":["../../../../../src/server/plugins/map/routes/index.js"],"sourcesContent":["import fs from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { getAccessToken } from '~/src/server/plugins/map/routes/get-os-token.js'\nimport { find, nearest } from '~/src/server/plugins/map/service.js'\nimport {\n get,\n request as httpRequest\n} from '~/src/server/services/httpService.js'\n\nconst filePath = resolve(import.meta.dirname, './vts/countries.geojson')\n\n/**\n * @type {FeatureCollection}\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const countries = JSON.parse(fs.readFileSync(filePath, 'utf8'))\n\nexport const countrySchema = Joi.string().valid(\n ...Object.values(GeospatialFieldOptionsCountryEnum)\n)\n\n/**\n * Gets the map support routes\n * @param {MapConfiguration} options - ordnance survey names api key\n */\nexport function getRoutes(options) {\n return [\n mapStyleResourceRoutes(),\n mapProxyRoute(options),\n tileProxyRoute(options),\n geocodeProxyRoute(options),\n reverseGeocodeProxyRoute(options),\n getGeospatialCountries()\n ]\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.com\n * Used for the VTS map source by forwarding on the request\n * and adding the auth token and SRS (spatial reference system)\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/map-proxy',\n handler: async (request, h) => {\n const { query } = request\n const targetUrl = new URL(decodeURIComponent(query.url))\n const token = await getAccessToken(options)\n\n targetUrl.searchParams.set('srs', '3857')\n\n const proxyResponse = await httpRequest('get', targetUrl.toString(), {\n headers: {\n Authorization: `Bearer ${token}`\n }\n })\n const buffer = proxyResponse.payload\n const contentType = proxyResponse.res.headers['content-type']\n const response = h.response(buffer)\n\n if (contentType) {\n response.type(contentType)\n }\n\n return response\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n url: Joi.string().required()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.uk\n * Used for VTS map tiles forwarding on the request and adding the auth token\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction tileProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/tile/{z}/{y}/{x}.pbf',\n handler: async (request, h) => {\n const { z, y, x } = request.params\n const token = await getAccessToken(options)\n\n const url = `https://api.os.uk/maps/vector/v1/vts/tile/${z}/${y}/${x}.pbf?srs=3857`\n\n const getBuffer = /** @type {typeof get<Buffer>} */ (get)\n\n const { payload, res } = await getBuffer(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n Accept: 'application/x-protobuf'\n },\n json: false,\n gunzip: true\n })\n\n if (res.statusCode && res.statusCode !== StatusCodes.OK.valueOf()) {\n return h.response('Tile fetch failed').code(res.statusCode)\n }\n\n return h\n .response(payload)\n .type('application/x-protobuf')\n .header('Cache-Control', 'public, max-age=86400')\n },\n options: {\n auth: false\n }\n }\n}\n\n/**\n * Proxies ordnance survey geocode requests from the front end to api.os.uk\n * Used for the gazzeteer address lookup to find name from query strings like postcode and place names\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapGeocodeGetRequestRefs>}\n */\nfunction geocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await find(query.query, options.ordnanceSurveyApiKey)\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n query: Joi.string().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey reverse geocode requests from the front end to api.os.uk\n * Used to find name from easting and northing points.\n * N.B this endpoint is currently not used by the front end but will be soon in \"maps V2\"\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapReverseGeocodeGetRequestRefs>}\n */\nfunction reverseGeocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/reverse-geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await nearest(\n query.easting,\n query.northing,\n options.ordnanceSurveyApiKey\n )\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n easting: Joi.number().required(),\n northing: Joi.number().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapStyleResourceRoutes() {\n return {\n method: 'GET',\n path: '/api/maps/vts/{path*}',\n options: {\n auth: false,\n handler: {\n directory: {\n path: resolve(import.meta.dirname, './vts')\n }\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<GeospatialCountriesGetRequestRefs>}\n */\nfunction getGeospatialCountries() {\n return {\n method: 'GET',\n path: '/api/maps/countries.geojson',\n handler: (request) => {\n const { omit, only } = request.query\n\n if (omit) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id !== omit)\n }\n }\n\n if (only) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id === only)\n }\n }\n\n return countries\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n omit: countrySchema.optional(),\n only: countrySchema.optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @import { ServerRoute } from '@hapi/hapi'\n * @import { FeatureCollection } from 'geojson'\n * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, MapReverseGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '~/src/server/plugins/map/types.js'\n */\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,SAAS;AACxB,SAASC,OAAO,QAAQ,WAAW;AAEnC,SAASC,iCAAiC,QAAQ,oBAAoB;AACtE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,cAAc;AACvB,SAASC,IAAI,EAAEC,OAAO;AACtB,SACEC,GAAG,EACHC,OAAO,IAAIC,WAAW;AAGxB,MAAMC,QAAQ,GAAGV,OAAO,CAACW,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE,yBAAyB,CAAC;;AAExE;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGC,IAAI,CAACC,KAAK,CAACjB,EAAE,CAACkB,YAAY,CAACP,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEtE,OAAO,MAAMQ,aAAa,GAAGf,GAAG,CAACgB,MAAM,CAAC,CAAC,CAACC,KAAK,CAC7C,GAAG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I;QACtE,CAAC;MACH;MAEA,OAAOlE,SAAS;IAClB,CAAC;IACDU,OAAO,EAAE;MACP6B,IAAI,EAAE,KAAK;MACXC,QAAQ,EAAE;QACRnB,KAAK,EAAEhC,GAAG,CAACoD,MAAM,CAAC,CAAC,CAChBC,IAAI,CAAC;UACJuB,IAAI,EAAE7D,aAAa,CAACwC,QAAQ,CAAC,CAAC;UAC9BsB,IAAI,EAAE9D,aAAa,CAACwC,QAAQ,CAAC;QAC/B,CAAC,CAAC,CACDA,QAAQ,CAAC;MACd;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fs","resolve","GeospatialFieldOptionsCountryEnum","StatusCodes","Joi","getAccessToken","find","get","request","httpRequest","filePath","import","meta","dirname","countries","JSON","parse","readFileSync","countrySchema","string","valid","Object","values","getRoutes","options","mapStyleResourceRoutes","mapProxyRoute","tileProxyRoute","geocodeProxyRoute","getGeospatialCountries","method","path","handler","h","query","targetUrl","URL","decodeURIComponent","url","token","searchParams","set","proxyResponse","toString","headers","Authorization","buffer","payload","contentType","res","response","type","auth","validate","object","keys","required","optional","z","y","x","params","getBuffer","Accept","json","gunzip","statusCode","OK","valueOf","code","header","_h","data","ordnanceSurveyApiKey","directory","omit","only","features","filter","feature","id"],"sources":["../../../../../src/server/plugins/map/routes/index.js"],"sourcesContent":["import fs from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { getAccessToken } from '~/src/server/plugins/map/routes/get-os-token.js'\nimport { find } from '~/src/server/plugins/map/service.js'\nimport {\n get,\n request as httpRequest\n} from '~/src/server/services/httpService.js'\n\nconst filePath = resolve(import.meta.dirname, './vts/countries.geojson')\n\n/**\n * @type {FeatureCollection}\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const countries = JSON.parse(fs.readFileSync(filePath, 'utf8'))\n\nexport const countrySchema = Joi.string().valid(\n ...Object.values(GeospatialFieldOptionsCountryEnum)\n)\n\n/**\n * Gets the map support routes\n * @param {MapConfiguration} options - ordnance survey names api key\n */\nexport function getRoutes(options) {\n return [\n mapStyleResourceRoutes(),\n mapProxyRoute(options),\n tileProxyRoute(options),\n geocodeProxyRoute(options),\n getGeospatialCountries()\n ]\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.com\n * Used for the VTS map source by forwarding on the request\n * and adding the auth token and SRS (spatial reference system)\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/map-proxy',\n handler: async (request, h) => {\n const { query } = request\n const targetUrl = new URL(decodeURIComponent(query.url))\n const token = await getAccessToken(options)\n\n targetUrl.searchParams.set('srs', '3857')\n\n const proxyResponse = await httpRequest('get', targetUrl.toString(), {\n headers: {\n Authorization: `Bearer ${token}`\n }\n })\n const buffer = proxyResponse.payload\n const contentType = proxyResponse.res.headers['content-type']\n const response = h.response(buffer)\n\n if (contentType) {\n response.type(contentType)\n }\n\n return response\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n url: Joi.string().required()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.uk\n * Used for VTS map tiles forwarding on the request and adding the auth token\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction tileProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/tile/{z}/{y}/{x}.pbf',\n handler: async (request, h) => {\n const { z, y, x } = request.params\n const token = await getAccessToken(options)\n\n const url = `https://api.os.uk/maps/vector/v1/vts/tile/${z}/${y}/${x}.pbf?srs=3857`\n\n const getBuffer = /** @type {typeof get<Buffer>} */ (get)\n\n const { payload, res } = await getBuffer(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n Accept: 'application/x-protobuf'\n },\n json: false,\n gunzip: true\n })\n\n if (res.statusCode && res.statusCode !== StatusCodes.OK.valueOf()) {\n return h.response('Tile fetch failed').code(res.statusCode)\n }\n\n return h\n .response(payload)\n .type('application/x-protobuf')\n .header('Cache-Control', 'public, max-age=86400')\n },\n options: {\n auth: false\n }\n }\n}\n\n/**\n * Proxies ordnance survey geocode requests from the front end to api.os.uk\n * Used for the gazzeteer address lookup to find name from query strings like postcode and place names\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapGeocodeGetRequestRefs>}\n */\nfunction geocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await find(query.query, options.ordnanceSurveyApiKey)\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n query: Joi.string().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapStyleResourceRoutes() {\n return {\n method: 'GET',\n path: '/api/maps/vts/{path*}',\n options: {\n auth: false,\n handler: {\n directory: {\n path: resolve(import.meta.dirname, './vts')\n }\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<GeospatialCountriesGetRequestRefs>}\n */\nfunction getGeospatialCountries() {\n return {\n method: 'GET',\n path: '/api/maps/countries.geojson',\n handler: (request) => {\n const { omit, only } = request.query\n\n if (omit) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id !== omit)\n }\n }\n\n if (only) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id === only)\n }\n }\n\n return countries\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n omit: countrySchema.optional(),\n only: countrySchema.optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @import { ServerRoute } from '@hapi/hapi'\n * @import { FeatureCollection } from 'geojson'\n * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, MapReverseGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '~/src/server/plugins/map/types.js'\n */\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,SAAS;AACxB,SAASC,OAAO,QAAQ,WAAW;AAEnC,SAASC,iCAAiC,QAAQ,oBAAoB;AACtE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,cAAc;AACvB,SAASC,IAAI;AACb,SACEC,GAAG,EACHC,OAAO,IAAIC,WAAW;AAGxB,MAAMC,QAAQ,GAAGT,OAAO,CAACU,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE,yBAAyB,CAAC;;AAExE;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGC,IAAI,CAACC,KAAK,CAAChB,EAAE,CAACiB,YAAY,CAACP,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEtE,OAAO,MAAMQ,aAAa,GAAGd,GAAG,CAACe,MAAM,CAAC,CAAC,CAACC,KAAK,CAC7C,GAAGC,MAAM,CAACC,MAAM,CAACpB,iCAAiC,CACpD,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASqB,SAASA,CAACC,OAAO,EAAE;EACjC,OAAO,CACLC,sBAAsB,CAAC,CAAC,EACxBC,aAAa,CAACF,OAAO,CAAC,EACtBG,cAAc,CAACH,OAAO,CAAC,EACvBI,iBAAiB,CAACJ,OAAO,CAAC,EAC1BK,sBAAsB,CAAC,CAAC,CACzB;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASH,aAAaA,CAACF,OAAO,EAAE;EAC9B,OAAO;IACLM,MAAM,EAAE,KAAK;IACbC,IAAI,EAAE,gBAAgB;IACtBC,OAAO,EAAE,MAAAA,CAAOxB,OAAO,EAAEyB,CAAC,KAAK;MAC7B,MAAM;QAAEC;MAAM,CAAC,GAAG1B,OAAO;MACzB,MAAM2B,SAAS,GAAG,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AAE;QACRnB,KAAK,EAAE9B,GAAG,CAACkD,MAAM,CAAC,CAAC,CAChBC,IAAI,CAAC;UACJoB,IAAI,EAAEzD,aAAa,CAACuC,QAAQ,CAAC,CAAC;UAC9BmB,IAAI,EAAE1D,aAAa,CAACuC,QAAQ,CAAC;QAC/B,CAAC,CAAC,CACDA,QAAQ,CAAC;MACd;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -4,11 +4,4 @@
|
|
|
4
4
|
* @param {string} apiKey - the OS api key
|
|
5
5
|
*/
|
|
6
6
|
export function find(query: string, apiKey: string): Promise<OsNamesFindResponse>;
|
|
7
|
-
/**
|
|
8
|
-
* OS names search nearest by E/N
|
|
9
|
-
* @param {number} easting - the easting
|
|
10
|
-
* @param {number} northing - the northing
|
|
11
|
-
* @param {string} apiKey - the OS api key
|
|
12
|
-
*/
|
|
13
|
-
export function nearest(easting: number, northing: number, apiKey: string): Promise<OsNamesFindResponse>;
|
|
14
7
|
import type { OsNamesFindResponse } from '../../../server/plugins/map/types.js';
|
|
@@ -60,18 +60,6 @@ export async function find(query, apiKey) {
|
|
|
60
60
|
return getData(url, endpoint);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* OS names search nearest by E/N
|
|
65
|
-
* @param {number} easting - the easting
|
|
66
|
-
* @param {number} northing - the northing
|
|
67
|
-
* @param {string} apiKey - the OS api key
|
|
68
|
-
*/
|
|
69
|
-
export async function nearest(easting, northing, apiKey) {
|
|
70
|
-
const endpoint = 'nearest';
|
|
71
|
-
const url = `https://api.os.uk/search/names/v1/nearest?key=${apiKey}&point=${easting},${northing}&radius=1000&fq=local_type:Airfield%20local_type:Airport%20local_type:Bus_Station%20local_type:Chemical_Works%20local_type:City%20local_type:Coach_Station%20local_type:Electricity_Distribution%20local_type:Electricity_Production%20local_type:Further_Education%20local_type:Gas_Distribution_or_Storage%20local_type:Hamlet%20local_type:Harbour%20local_type:Helicopter_Station%20local_type:Heliport%20local_type:Higher_or_University_Education%20local_type:Hill_Or_Mountain%20local_type:Hospice%20local_type:Hospital%20local_type:Medical_Care_Accommodation%20local_type:Named_Road%20local_type:Non_State_Primary_Education%20local_type:Non_State_Secondary_Education%20local_type:Other_Settlement%20local_type:Passenger_Ferry_Terminal%20local_type:Port_Consisting_of_Docks_and_Nautical_Berthing%20local_type:Postcode%20local_type:Primary_Education%20local_type:Railway_Station%20local_type:Road_User_Services%20local_type:Secondary_Education%20local_type:Section_Of_Named_Road%20local_type:Section_Of_Numbered_Road%20local_type:Special_Needs_Education%20local_type:Suburban_Area%20local_type:Town%20local_type:Urban_Greenspace%20local_type:Vehicular_Ferry_Terminal%20local_type:Vehicular_Rail_Terminal%20local_type:Village%20local_type:Waterfall%20`;
|
|
72
|
-
return getData(url, endpoint);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
63
|
/**
|
|
76
64
|
* @import { OsNamesFindResponse, OsNamesFindResult } from '../../../server/plugins/map/types.js'
|
|
77
65
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","names":["getErrorMessage","Boom","logger","getJson","empty","results","header","logErrorAndReturnEmpty","err","endpoint","boomData","isBoom","data","msg","payload","error","message","getData","url","getJsonByType","response","find","query","apiKey"
|
|
1
|
+
{"version":3,"file":"service.js","names":["getErrorMessage","Boom","logger","getJson","empty","results","header","logErrorAndReturnEmpty","err","endpoint","boomData","isBoom","data","msg","payload","error","message","getData","url","getJsonByType","response","find","query","apiKey"],"sources":["../../../../src/server/plugins/map/service.js"],"sourcesContent":["import { getErrorMessage } from '@defra/forms-model'\nimport Boom from '@hapi/boom'\n\nimport { logger } from '~/src/server/common/helpers/logging/logger.js'\nimport { getJson } from '~/src/server/services/httpService.js'\n\n/**\n * Returns an empty result set\n */\nfunction empty() {\n /** @type {OsNamesFindResult[]} */\n const results = []\n\n return /** @type {OsNamesFindResponse} */ ({ header: {}, results })\n}\n\n/**\n * Logs OS names errors\n * @param {unknown} err - the error\n * @param {string} endpoint - the OS api endpoint\n */\nfunction logErrorAndReturnEmpty(err, endpoint) {\n /** @type {{ payload?: { error?: { message?: string } } } | false} */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const boomData = Boom.isBoom(err) && err.data\n const msg = `${getErrorMessage(err)} ${(boomData && boomData.payload?.error?.message) ?? ''}`\n\n logger.error(err, `Exception occured calling OS names ${endpoint} - ${msg}}`)\n\n return empty()\n}\n\n/**\n * Fetch data from OS names API\n * @param {string} url - the url to get address json data from\n * @param {string} endpoint - the url endpoint description for logging\n */\nasync function getData(url, endpoint) {\n const getJsonByType = /** @type {typeof getJson<OsNamesFindResponse>} */ (\n getJson\n )\n\n try {\n const response = await getJsonByType(url)\n\n if (response.error) {\n return logErrorAndReturnEmpty(response.error, endpoint)\n }\n\n const results = response.payload\n\n return results\n } catch (err) {\n return logErrorAndReturnEmpty(err, endpoint)\n }\n}\n\n/**\n * OS names search find by query\n * @param {string} query - the search term\n * @param {string} apiKey - the OS api key\n */\nexport async function find(query, apiKey) {\n const endpoint = 'find'\n const url = `https://api.os.uk/search/names/v1/find?key=${apiKey}&query=${query}&fq=local_type:postcode%20local_type:hamlet%20local_type:village%20local_type:town%20local_type:city%20local_type:other_settlement&maxresults=8`\n\n return getData(url, endpoint)\n}\n\n/**\n * @import { OsNamesFindResponse, OsNamesFindResult } from '~/src/server/plugins/map/types.js'\n */\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,OAAOC,IAAI,MAAM,YAAY;AAE7B,SAASC,MAAM;AACf,SAASC,OAAO;;AAEhB;AACA;AACA;AACA,SAASC,KAAKA,CAAA,EAAG;EACf;EACA,MAAMC,OAAO,GAAG,EAAE;EAElB,OAAO,kCAAoC;IAAEC,MAAM,EAAE,CAAC,CAAC;IAAED;EAAQ,CAAC;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASE,sBAAsBA,CAACC,GAAG,EAAEC,QAAQ,EAAE;EAC7C;EACA;EACA,MAAMC,QAAQ,GAAGT,IAAI,CAACU,MAAM,CAACH,GAAG,CAAC,IAAIA,GAAG,CAACI,IAAI;EAC7C,MAAMC,GAAG,GAAG,GAAGb,eAAe,CAACQ,GAAG,CAAC,IAAI,CAACE,QAAQ,IAAIA,QAAQ,CAACI,OAAO,EAAEC,KAAK,EAAEC,OAAO,KAAK,EAAE,EAAE;EAE7Fd,MAAM,CAACa,KAAK,CAACP,GAAG,EAAE,sCAAsCC,QAAQ,MAAMI,GAAG,GAAG,CAAC;EAE7E,OAAOT,KAAK,CAAC,CAAC;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA,eAAea,OAAOA,CAACC,GAAG,EAAET,QAAQ,EAAE;EACpC,MAAMU,aAAa,GAAG;EACpBhB,OACD;EAED,IAAI;IACF,MAAMiB,QAAQ,GAAG,MAAMD,aAAa,CAACD,GAAG,CAAC;IAEzC,IAAIE,QAAQ,CAACL,KAAK,EAAE;MAClB,OAAOR,sBAAsB,CAACa,QAAQ,CAACL,KAAK,EAAEN,QAAQ,CAAC;IACzD;IAEA,MAAMJ,OAAO,GAAGe,QAAQ,CAACN,OAAO;IAEhC,OAAOT,OAAO;EAChB,CAAC,CAAC,OAAOG,GAAG,EAAE;IACZ,OAAOD,sBAAsB,CAACC,GAAG,EAAEC,QAAQ,CAAC;EAC9C;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeY,IAAIA,CAACC,KAAK,EAAEC,MAAM,EAAE;EACxC,MAAMd,QAAQ,GAAG,MAAM;EACvB,MAAMS,GAAG,GAAG,8CAA8CK,MAAM,UAAUD,KAAK,iJAAiJ;EAEhO,OAAOL,OAAO,CAACC,GAAG,EAAET,QAAQ,CAAC;AAC/B;;AAEA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Boom from '@hapi/boom';
|
|
2
2
|
import * as service from "./service.js";
|
|
3
3
|
import { result as findResult } from "./test/__stubs__/find.js";
|
|
4
|
-
import { result as nearestResult } from "./test/__stubs__/nearest.js";
|
|
5
4
|
import { getJson } from "../../services/httpService.js";
|
|
6
5
|
jest.mock("../../services/httpService.ts");
|
|
7
6
|
describe('Maps service', () => {
|
|
@@ -70,48 +69,6 @@ describe('Maps service', () => {
|
|
|
70
69
|
expect(results).toEqual([]);
|
|
71
70
|
});
|
|
72
71
|
});
|
|
73
|
-
describe('nearest', () => {
|
|
74
|
-
it('should return entries', async () => {
|
|
75
|
-
jest.mocked(getJson).mockResolvedValueOnce({
|
|
76
|
-
res: (/** @type {IncomingMessage} */{
|
|
77
|
-
statusCode: 200,
|
|
78
|
-
headers: {}
|
|
79
|
-
}),
|
|
80
|
-
payload: nearestResult,
|
|
81
|
-
error: undefined
|
|
82
|
-
});
|
|
83
|
-
const {
|
|
84
|
-
results
|
|
85
|
-
} = await service.nearest(700000, 1300000, 'apikey');
|
|
86
|
-
expect(results).toHaveLength(1);
|
|
87
|
-
expect(results.at(0)).toEqual({
|
|
88
|
-
GAZETTEER_ENTRY: {
|
|
89
|
-
ID: 'NW26XE',
|
|
90
|
-
NAMES_URI: 'http://data.ordnancesurvey.co.uk/id/postcodeunit/NW26XE',
|
|
91
|
-
NAME1: 'NW2 6XE',
|
|
92
|
-
TYPE: 'other',
|
|
93
|
-
LOCAL_TYPE: 'Postcode',
|
|
94
|
-
GEOMETRY_X: 523065,
|
|
95
|
-
GEOMETRY_Y: 185795,
|
|
96
|
-
MOST_DETAIL_VIEW_RES: 3500,
|
|
97
|
-
LEAST_DETAIL_VIEW_RES: 18000,
|
|
98
|
-
POPULATED_PLACE: 'London',
|
|
99
|
-
POPULATED_PLACE_URI: 'http://data.ordnancesurvey.co.uk/id/4000000074813508',
|
|
100
|
-
POPULATED_PLACE_TYPE: 'http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city',
|
|
101
|
-
DISTRICT_BOROUGH: 'Brent',
|
|
102
|
-
DISTRICT_BOROUGH_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000011447',
|
|
103
|
-
DISTRICT_BOROUGH_TYPE: 'http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough',
|
|
104
|
-
COUNTY_UNITARY: 'Greater London',
|
|
105
|
-
COUNTY_UNITARY_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041441',
|
|
106
|
-
COUNTY_UNITARY_TYPE: 'http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority',
|
|
107
|
-
REGION: 'London',
|
|
108
|
-
REGION_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041428',
|
|
109
|
-
COUNTRY: 'England',
|
|
110
|
-
COUNTRY_URI: 'http://data.ordnancesurvey.co.uk/id/country/england'
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
72
|
});
|
|
116
73
|
|
|
117
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.test.js","names":["Boom","service","result","findResult","
|
|
1
|
+
{"version":3,"file":"service.test.js","names":["Boom","service","result","findResult","getJson","jest","mock","describe","it","mocked","mockResolvedValueOnce","res","statusCode","headers","payload","error","undefined","results","find","expect","toHaveLength","at","toEqual","GAZETTEER_ENTRY","ID","NAMES_URI","NAME1","TYPE","LOCAL_TYPE","GEOMETRY_X","GEOMETRY_Y","MOST_DETAIL_VIEW_RES","LEAST_DETAIL_VIEW_RES","POPULATED_PLACE","POPULATED_PLACE_URI","POPULATED_PLACE_TYPE","DISTRICT_BOROUGH","DISTRICT_BOROUGH_URI","DISTRICT_BOROUGH_TYPE","COUNTY_UNITARY","COUNTY_UNITARY_URI","COUNTY_UNITARY_TYPE","REGION","REGION_URI","COUNTRY","COUNTRY_URI","Error","mockRejectedValueOnce","badRequest"],"sources":["../../../../src/server/plugins/map/service.test.js"],"sourcesContent":["import Boom from '@hapi/boom'\n\nimport * as service from '~/src/server/plugins/map/service.js'\nimport { result as findResult } from '~/src/server/plugins/map/test/__stubs__/find.js'\nimport { getJson } from '~/src/server/services/httpService.js'\n\njest.mock('~/src/server/services/httpService.ts')\n\ndescribe('Maps service', () => {\n describe('find', () => {\n it('should return entires', async () => {\n jest.mocked(getJson).mockResolvedValueOnce({\n res: /** @type {IncomingMessage} */ ({\n statusCode: 200,\n headers: {}\n }),\n payload: findResult,\n error: undefined\n })\n\n const { results } = await service.find('NW1 6XE', 'apikey')\n\n expect(results).toHaveLength(8)\n expect(results.at(1)).toEqual({\n GAZETTEER_ENTRY: {\n ID: 'NW26XE',\n NAMES_URI: 'http://data.ordnancesurvey.co.uk/id/postcodeunit/NW26XE',\n NAME1: 'NW2 6XE',\n TYPE: 'other',\n LOCAL_TYPE: 'Postcode',\n GEOMETRY_X: 523065,\n GEOMETRY_Y: 185795,\n MOST_DETAIL_VIEW_RES: 3500,\n LEAST_DETAIL_VIEW_RES: 18000,\n POPULATED_PLACE: 'London',\n POPULATED_PLACE_URI:\n 'http://data.ordnancesurvey.co.uk/id/4000000074813508',\n POPULATED_PLACE_TYPE:\n 'http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city',\n DISTRICT_BOROUGH: 'Brent',\n DISTRICT_BOROUGH_URI:\n 'http://data.ordnancesurvey.co.uk/id/7000000000011447',\n DISTRICT_BOROUGH_TYPE:\n 'http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough',\n COUNTY_UNITARY: 'Greater London',\n COUNTY_UNITARY_URI:\n 'http://data.ordnancesurvey.co.uk/id/7000000000041441',\n COUNTY_UNITARY_TYPE:\n 'http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority',\n REGION: 'London',\n REGION_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041428',\n COUNTRY: 'England',\n COUNTRY_URI: 'http://data.ordnancesurvey.co.uk/id/country/england'\n }\n })\n })\n\n it('should return an empty response when an error is encountered', async () => {\n jest.mocked(getJson).mockResolvedValueOnce({\n res: /** @type {IncomingMessage} */ ({\n statusCode: 300,\n headers: {}\n }),\n payload: undefined,\n error: new Error('Unknown error')\n })\n\n const { results } = await service.find('NW1 6XE', 'apikey')\n\n expect(results).toHaveLength(0)\n expect(results).toEqual([])\n })\n\n it('should return an empty response when a non 200 response is encountered', async () => {\n jest\n .mocked(getJson)\n .mockRejectedValueOnce(\n Boom.badRequest(\n 'OS API error',\n new Error('Invalid postcode segments')\n )\n )\n\n const { results } = await service.find('invalid postcode', 'apikey')\n\n expect(results).toHaveLength(0)\n expect(results).toEqual([])\n })\n })\n})\n\n/**\n * @import { IncomingMessage } from 'node:http'\n */\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,YAAY;AAE7B,OAAO,KAAKC,OAAO;AACnB,SAASC,MAAM,IAAIC,UAAU;AAC7B,SAASC,OAAO;AAEhBC,IAAI,CAACC,IAAI,gCAAuC,CAAC;AAEjDC,QAAQ,CAAC,cAAc,EAAE,MAAM;EAC7BA,QAAQ,CAAC,MAAM,EAAE,MAAM;IACrBC,EAAE,CAAC,uBAAuB,EAAE,YAAY;MACtCH,IAAI,CAACI,MAAM,CAACL,OAAO,CAAC,CAACM,qBAAqB,CAAC;QACzCC,GAAG,GAAE,8BAAgC;UACnCC,UAAU,EAAE,GAAG;UACfC,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC;QACFC,OAAO,EAAEX,UAAU;QACnBY,KAAK,EAAEC;MACT,CAAC,CAAC;MAEF,MAAM;QAAEC;MAAQ,CAAC,GAAG,MAAMhB,OAAO,CAACiB,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC;MAE3DC,MAAM,CAACF,OAAO,CAAC,CAACG,YAAY,CAAC,CAAC,CAAC;MAC/BD,MAAM,CAACF,OAAO,CAACI,EAAE,CAAC,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC;QAC5BC,eAAe,EAAE;UACfC,EAAE,EAAE,QAAQ;UACZC,SAAS,EAAE,yDAAyD;UACpEC,KAAK,EAAE,SAAS;UAChBC,IAAI,EAAE,OAAO;UACbC,UAAU,EAAE,UAAU;U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H,MAAM;QAAE7B;MAAQ,CAAC,GAAG,MAAMhB,OAAO,CAACiB,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC;MAEpEC,MAAM,CAACF,OAAO,CAAC,CAACG,YAAY,CAAC,CAAC,CAAC;MAC/BD,MAAM,CAACF,OAAO,CAAC,CAACK,OAAO,CAAC,EAAE,CAAC;IAC7B,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC;;AAEF;AACA;AACA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/forms-engine-plugin",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.0",
|
|
4
4
|
"description": "Defra forms engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"joi": "^17.13.3",
|
|
131
131
|
"liquidjs": "^10.24.0",
|
|
132
132
|
"lodash": "^4.17.21",
|
|
133
|
+
"maplibre-gl": "^5.24.0",
|
|
133
134
|
"marked": "^15.0.12",
|
|
134
135
|
"nunjucks": "^3.2.4",
|
|
135
136
|
"obscenity": "^0.4.5",
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// @ts-expect-error - no types
|
|
2
|
+
import createDatasetsPlugin from '@defra/interactive-map/plugins/datasets'
|
|
3
|
+
// @ts-expect-error - no types
|
|
4
|
+
import { maplibreLayerAdapter } from '@defra/interactive-map/plugins/datasets/adapters/maplibre'
|
|
5
|
+
// @ts-expect-error - no types
|
|
6
|
+
import createDrawPlugin from '@defra/interactive-map/plugins/draw-ml'
|
|
1
7
|
import { bbox } from '@turf/bbox'
|
|
2
8
|
|
|
3
9
|
import {
|
|
@@ -151,9 +157,6 @@ export function getBoundingBox(geojson) {
|
|
|
151
157
|
* @param {number} index - the 0-based index
|
|
152
158
|
*/
|
|
153
159
|
export function processGeospatial(config, geospatial, index) {
|
|
154
|
-
// @ts-expect-error - Defra namespace currently comes from UMD support files
|
|
155
|
-
const defra = window.defra
|
|
156
|
-
|
|
157
160
|
if (!(geospatial instanceof HTMLDivElement)) {
|
|
158
161
|
return
|
|
159
162
|
}
|
|
@@ -166,14 +169,15 @@ export function processGeospatial(config, geospatial, index) {
|
|
|
166
169
|
const { listEl, mapId } = createContainers(geospatialInput, index)
|
|
167
170
|
const geojson = getGeoJSON(geospatialInput)
|
|
168
171
|
const bounds = geojson.features.length ? getBoundingBox(geojson) : undefined
|
|
169
|
-
const drawPlugin =
|
|
172
|
+
const drawPlugin = createDrawPlugin()
|
|
170
173
|
const plugins = [drawPlugin]
|
|
171
174
|
const country = geospatial.dataset.country
|
|
172
175
|
|
|
173
176
|
if (country) {
|
|
174
177
|
// Add the country bounds as a dataset plugin to show the valid area on the map
|
|
175
178
|
// and provide feedback to the user when they add features outside of the bounds.
|
|
176
|
-
const datasetsPlugin =
|
|
179
|
+
const datasetsPlugin = createDatasetsPlugin({
|
|
180
|
+
layerAdapter: maplibreLayerAdapter,
|
|
177
181
|
datasets: [
|
|
178
182
|
{
|
|
179
183
|
id: 'invalid-area',
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// @ts-expect-error - no types
|
|
2
|
+
import InteractiveMap from '@defra/interactive-map'
|
|
3
|
+
// @ts-expect-error - no types
|
|
4
|
+
import createInteractPlugin from '@defra/interactive-map/plugins/interact'
|
|
5
|
+
// @ts-expect-error - no types
|
|
6
|
+
import createMapStylesPlugin from '@defra/interactive-map/plugins/map-styles'
|
|
7
|
+
// @ts-expect-error - no types
|
|
8
|
+
import createScaleBarPlugin from '@defra/interactive-map/plugins/scale-bar'
|
|
9
|
+
// @ts-expect-error - no types
|
|
10
|
+
import createSearchPlugin from '@defra/interactive-map/plugins/search'
|
|
11
|
+
// @ts-expect-error - no types
|
|
12
|
+
import maplibreProvider from '@defra/interactive-map/providers/maplibre'
|
|
1
13
|
import { centroid } from '@turf/centroid'
|
|
2
14
|
// @ts-expect-error - no types
|
|
3
15
|
import OsGridRef, { LatLon } from 'geodesy/osgridref.js'
|
|
@@ -249,24 +261,17 @@ export function makeTileRequestTransformer(apiPath) {
|
|
|
249
261
|
export function createMap(mapId, initConfig, mapsConfig) {
|
|
250
262
|
const { assetPath, apiPath, data = defaultData } = mapsConfig
|
|
251
263
|
const logoAltText = 'Ordnance survey logo'
|
|
252
|
-
|
|
253
|
-
// @ts-expect-error - Defra namespace currently comes from UMD support files
|
|
254
|
-
const defra = window.defra
|
|
255
|
-
|
|
256
|
-
const interactPlugin = defra.interactPlugin({
|
|
264
|
+
const interactPlugin = createInteractPlugin({
|
|
257
265
|
markerColor: { outdoor: '#ff0000', dark: '#00ff00' },
|
|
258
266
|
interactionModes: ['placeMarker'],
|
|
259
267
|
multiSelect: false
|
|
260
268
|
})
|
|
261
269
|
|
|
262
270
|
/** @type {InteractiveMap} */
|
|
263
|
-
const map = new
|
|
271
|
+
const map = new InteractiveMap(mapId, {
|
|
264
272
|
enableFullscreen: true,
|
|
265
273
|
autoColorScheme: false,
|
|
266
|
-
mapProvider:
|
|
267
|
-
reverseGeocodeProvider: defra.openNamesProvider({
|
|
268
|
-
url: `${apiPath}/reverse-geocode-proxy?easting={easting}&northing={northing}`
|
|
269
|
-
}),
|
|
274
|
+
mapProvider: maplibreProvider(),
|
|
270
275
|
behaviour: 'inline',
|
|
271
276
|
minZoom: 6,
|
|
272
277
|
maxZoom: 18,
|
|
@@ -275,7 +280,7 @@ export function createMap(mapId, initConfig, mapsConfig) {
|
|
|
275
280
|
transformRequest: makeTileRequestTransformer(apiPath),
|
|
276
281
|
...initConfig,
|
|
277
282
|
plugins: [
|
|
278
|
-
|
|
283
|
+
createMapStylesPlugin({
|
|
279
284
|
mapStyles: [
|
|
280
285
|
{
|
|
281
286
|
id: 'outdoor',
|
|
@@ -319,12 +324,12 @@ export function createMap(mapId, initConfig, mapsConfig) {
|
|
|
319
324
|
]
|
|
320
325
|
}),
|
|
321
326
|
interactPlugin,
|
|
322
|
-
|
|
327
|
+
createSearchPlugin({
|
|
323
328
|
osNamesURL: `${apiPath}/geocode-proxy?query={query}`,
|
|
324
329
|
width: '300px',
|
|
325
330
|
showMarker: false
|
|
326
331
|
}),
|
|
327
|
-
|
|
332
|
+
createScaleBarPlugin({
|
|
328
333
|
units: 'metric'
|
|
329
334
|
}),
|
|
330
335
|
...(initConfig.plugins ?? [])
|
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
@use "summary-list";
|
|
5
5
|
@use "location-fields";
|
|
6
6
|
|
|
7
|
+
@use "@defra/interactive-map/css" as core;
|
|
8
|
+
@use "@defra/interactive-map/plugins/interact/css" as interact;
|
|
9
|
+
@use "@defra/interactive-map/plugins/map-styles/css" as mapStyles;
|
|
10
|
+
@use "@defra/interactive-map/plugins/search/css" as search;
|
|
11
|
+
@use "@defra/interactive-map/plugins/scale-bar/css" as scaleBar;
|
|
12
|
+
@use "@defra/interactive-map/plugins/draw-ml/css" as drawMl;
|
|
13
|
+
|
|
7
14
|
// Use default GDS Transport font for autocomplete
|
|
8
15
|
.autocomplete__hint,
|
|
9
16
|
.autocomplete__input,
|
|
@@ -6,7 +6,7 @@ import { StatusCodes } from 'http-status-codes'
|
|
|
6
6
|
import Joi from 'joi'
|
|
7
7
|
|
|
8
8
|
import { getAccessToken } from './get-os-token.js'
|
|
9
|
-
import { find
|
|
9
|
+
import { find } from '../service.js'
|
|
10
10
|
import {
|
|
11
11
|
get,
|
|
12
12
|
request as httpRequest
|
|
@@ -34,7 +34,6 @@ export function getRoutes(options) {
|
|
|
34
34
|
mapProxyRoute(options),
|
|
35
35
|
tileProxyRoute(options),
|
|
36
36
|
geocodeProxyRoute(options),
|
|
37
|
-
reverseGeocodeProxyRoute(options),
|
|
38
37
|
getGeospatialCountries()
|
|
39
38
|
]
|
|
40
39
|
}
|
|
@@ -156,41 +155,6 @@ function geocodeProxyRoute(options) {
|
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
/**
|
|
160
|
-
* Proxies ordnance survey reverse geocode requests from the front end to api.os.uk
|
|
161
|
-
* Used to find name from easting and northing points.
|
|
162
|
-
* N.B this endpoint is currently not used by the front end but will be soon in "maps V2"
|
|
163
|
-
* @param {MapConfiguration} options - the map options
|
|
164
|
-
* @returns {ServerRoute<MapReverseGeocodeGetRequestRefs>}
|
|
165
|
-
*/
|
|
166
|
-
function reverseGeocodeProxyRoute(options) {
|
|
167
|
-
return {
|
|
168
|
-
method: 'GET',
|
|
169
|
-
path: '/api/reverse-geocode-proxy',
|
|
170
|
-
async handler(request, _h) {
|
|
171
|
-
const { query } = request
|
|
172
|
-
const data = await nearest(
|
|
173
|
-
query.easting,
|
|
174
|
-
query.northing,
|
|
175
|
-
options.ordnanceSurveyApiKey
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
return data
|
|
179
|
-
},
|
|
180
|
-
options: {
|
|
181
|
-
auth: false,
|
|
182
|
-
validate: {
|
|
183
|
-
query: Joi.object()
|
|
184
|
-
.keys({
|
|
185
|
-
easting: Joi.number().required(),
|
|
186
|
-
northing: Joi.number().required()
|
|
187
|
-
})
|
|
188
|
-
.required()
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
158
|
/**
|
|
195
159
|
* Resource routes to return sprites and glyphs
|
|
196
160
|
* @returns {ServerRoute<MapProxyGetRequestRefs>}
|
|
@@ -67,19 +67,6 @@ export async function find(query, apiKey) {
|
|
|
67
67
|
return getData(url, endpoint)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/**
|
|
71
|
-
* OS names search nearest by E/N
|
|
72
|
-
* @param {number} easting - the easting
|
|
73
|
-
* @param {number} northing - the northing
|
|
74
|
-
* @param {string} apiKey - the OS api key
|
|
75
|
-
*/
|
|
76
|
-
export async function nearest(easting, northing, apiKey) {
|
|
77
|
-
const endpoint = 'nearest'
|
|
78
|
-
const url = `https://api.os.uk/search/names/v1/nearest?key=${apiKey}&point=${easting},${northing}&radius=1000&fq=local_type:Airfield%20local_type:Airport%20local_type:Bus_Station%20local_type:Chemical_Works%20local_type:City%20local_type:Coach_Station%20local_type:Electricity_Distribution%20local_type:Electricity_Production%20local_type:Further_Education%20local_type:Gas_Distribution_or_Storage%20local_type:Hamlet%20local_type:Harbour%20local_type:Helicopter_Station%20local_type:Heliport%20local_type:Higher_or_University_Education%20local_type:Hill_Or_Mountain%20local_type:Hospice%20local_type:Hospital%20local_type:Medical_Care_Accommodation%20local_type:Named_Road%20local_type:Non_State_Primary_Education%20local_type:Non_State_Secondary_Education%20local_type:Other_Settlement%20local_type:Passenger_Ferry_Terminal%20local_type:Port_Consisting_of_Docks_and_Nautical_Berthing%20local_type:Postcode%20local_type:Primary_Education%20local_type:Railway_Station%20local_type:Road_User_Services%20local_type:Secondary_Education%20local_type:Section_Of_Named_Road%20local_type:Section_Of_Numbered_Road%20local_type:Special_Needs_Education%20local_type:Suburban_Area%20local_type:Town%20local_type:Urban_Greenspace%20local_type:Vehicular_Ferry_Terminal%20local_type:Vehicular_Rail_Terminal%20local_type:Village%20local_type:Waterfall%20`
|
|
79
|
-
|
|
80
|
-
return getData(url, endpoint)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
70
|
/**
|
|
84
71
|
* @import { OsNamesFindResponse, OsNamesFindResult } from './types.js'
|
|
85
72
|
*/
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export namespace result {
|
|
2
|
-
namespace header {
|
|
3
|
-
let uri: string;
|
|
4
|
-
let query: string;
|
|
5
|
-
let format: string;
|
|
6
|
-
let maxresults: number;
|
|
7
|
-
let offset: number;
|
|
8
|
-
let totalresults: number;
|
|
9
|
-
let filter: string;
|
|
10
|
-
}
|
|
11
|
-
let results: {
|
|
12
|
-
GAZETTEER_ENTRY: {
|
|
13
|
-
ID: string;
|
|
14
|
-
NAMES_URI: string;
|
|
15
|
-
NAME1: string;
|
|
16
|
-
TYPE: string;
|
|
17
|
-
LOCAL_TYPE: string;
|
|
18
|
-
GEOMETRY_X: number;
|
|
19
|
-
GEOMETRY_Y: number;
|
|
20
|
-
MOST_DETAIL_VIEW_RES: number;
|
|
21
|
-
LEAST_DETAIL_VIEW_RES: number;
|
|
22
|
-
POPULATED_PLACE: string;
|
|
23
|
-
POPULATED_PLACE_URI: string;
|
|
24
|
-
POPULATED_PLACE_TYPE: string;
|
|
25
|
-
DISTRICT_BOROUGH: string;
|
|
26
|
-
DISTRICT_BOROUGH_URI: string;
|
|
27
|
-
DISTRICT_BOROUGH_TYPE: string;
|
|
28
|
-
COUNTY_UNITARY: string;
|
|
29
|
-
COUNTY_UNITARY_URI: string;
|
|
30
|
-
COUNTY_UNITARY_TYPE: string;
|
|
31
|
-
REGION: string;
|
|
32
|
-
REGION_URI: string;
|
|
33
|
-
COUNTRY: string;
|
|
34
|
-
COUNTRY_URI: string;
|
|
35
|
-
};
|
|
36
|
-
}[];
|
|
37
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export const result = {
|
|
2
|
-
header: {
|
|
3
|
-
uri: 'https://api.os.uk/search/names/v1/nearest?point=523065%2C185795&radius=1000&fq=local_type%3AAirfield%20local_type%3AAirport%20local_type%3ABus_Station%20local_type%3AChemical_Works%20local_type%3ACity%20local_type%3ACoach_Station%20local_type%3AElectricity_Distribution%20local_type%3AElectricity_Production%20local_type%3AFurther_Education%20local_type%3AGas_Distribution_or_Storage%20local_type%3AHamlet%20local_type%3AHarbour%20local_type%3AHelicopter_Station%20local_type%3AHeliport%20local_type%3AHigher_or_University_Education%20local_type%3AHill_Or_Mountain%20local_type%3AHospice%20local_type%3AHospital%20local_type%3AMedical_Care_Accommodation%20local_type%3ANamed_Road%20local_type%3ANon_State_Primary_Education%20local_type%3ANon_State_Secondary_Education%20local_type%3AOther_Settlement%20local_type%3APassenger_Ferry_Terminal%20local_type%3APort_Consisting_of_Docks_and_Nautical_Berthing%20local_type%3APostcode%20local_type%3APrimary_Education%20local_type%3ARailway_Station%20local_type%3ARoad_User_Services%20local_type%3ASecondary_Education%20local_type%3ASection_Of_Named_Road%20local_type%3ASection_Of_Numbered_Road%20local_type%3ASpecial_Needs_Education%20local_type%3ASuburban_Area%20local_type%3ATown%20local_type%3AUrban_Greenspace%20local_type%3AVehicular_Ferry_Terminal%20local_type%3AVehicular_Rail_Terminal%20local_type%3AVillage%20local_type%3AWaterfall%20',
|
|
4
|
-
query: 'point=523065,185795 radius=1000',
|
|
5
|
-
format: 'JSON',
|
|
6
|
-
maxresults: 1,
|
|
7
|
-
offset: 0,
|
|
8
|
-
totalresults: 1,
|
|
9
|
-
filter: 'fq=local_type:Airfield local_type:Airport local_type:Bus_Station local_type:Chemical_Works local_type:City local_type:Coach_Station local_type:Electricity_Distribution local_type:Electricity_Production local_type:Further_Education local_type:Gas_Distribution_or_Storage local_type:Hamlet local_type:Harbour local_type:Helicopter_Station local_type:Heliport local_type:Higher_or_University_Education local_type:Hill_Or_Mountain local_type:Hospice local_type:Hospital local_type:Medical_Care_Accommodation local_type:Named_Road local_type:Non_State_Primary_Education local_type:Non_State_Secondary_Education local_type:Other_Settlement local_type:Passenger_Ferry_Terminal local_type:Port_Consisting_of_Docks_and_Nautical_Berthing local_type:Postcode local_type:Primary_Education local_type:Railway_Station local_type:Road_User_Services local_type:Secondary_Education local_type:Section_Of_Named_Road local_type:Section_Of_Numbered_Road local_type:Special_Needs_Education local_type:Suburban_Area local_type:Town local_type:Urban_Greenspace local_type:Vehicular_Ferry_Terminal local_type:Vehicular_Rail_Terminal local_type:Village local_type:Waterfall'
|
|
10
|
-
},
|
|
11
|
-
results: [{
|
|
12
|
-
GAZETTEER_ENTRY: {
|
|
13
|
-
ID: 'NW26XE',
|
|
14
|
-
NAMES_URI: 'http://data.ordnancesurvey.co.uk/id/postcodeunit/NW26XE',
|
|
15
|
-
NAME1: 'NW2 6XE',
|
|
16
|
-
TYPE: 'other',
|
|
17
|
-
LOCAL_TYPE: 'Postcode',
|
|
18
|
-
GEOMETRY_X: 523065,
|
|
19
|
-
GEOMETRY_Y: 185795,
|
|
20
|
-
MOST_DETAIL_VIEW_RES: 3500,
|
|
21
|
-
LEAST_DETAIL_VIEW_RES: 18000,
|
|
22
|
-
POPULATED_PLACE: 'London',
|
|
23
|
-
POPULATED_PLACE_URI: 'http://data.ordnancesurvey.co.uk/id/4000000074813508',
|
|
24
|
-
POPULATED_PLACE_TYPE: 'http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city',
|
|
25
|
-
DISTRICT_BOROUGH: 'Brent',
|
|
26
|
-
DISTRICT_BOROUGH_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000011447',
|
|
27
|
-
DISTRICT_BOROUGH_TYPE: 'http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough',
|
|
28
|
-
COUNTY_UNITARY: 'Greater London',
|
|
29
|
-
COUNTY_UNITARY_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041441',
|
|
30
|
-
COUNTY_UNITARY_TYPE: 'http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority',
|
|
31
|
-
REGION: 'London',
|
|
32
|
-
REGION_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041428',
|
|
33
|
-
COUNTRY: 'England',
|
|
34
|
-
COUNTRY_URI: 'http://data.ordnancesurvey.co.uk/id/country/england'
|
|
35
|
-
}
|
|
36
|
-
}]
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=nearest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nearest.js","names":["result","header","uri","query","format","maxresults","offset","totalresults","filter","results","GAZETTEER_ENTRY","ID","NAMES_URI","NAME1","TYPE","LOCAL_TYPE","GEOMETRY_X","GEOMETRY_Y","MOST_DETAIL_VIEW_RES","LEAST_DETAIL_VIEW_RES","POPULATED_PLACE","POPULATED_PLACE_URI","POPULATED_PLACE_TYPE","DISTRICT_BOROUGH","DISTRICT_BOROUGH_URI","DISTRICT_BOROUGH_TYPE","COUNTY_UNITARY","COUNTY_UNITARY_URI","COUNTY_UNITARY_TYPE","REGION","REGION_URI","COUNTRY","COUNTRY_URI"],"sources":["../../../../../../src/server/plugins/map/test/__stubs__/nearest.js"],"sourcesContent":["export const result = {\n header: {\n uri: 'https://api.os.uk/search/names/v1/nearest?point=523065%2C185795&radius=1000&fq=local_type%3AAirfield%20local_type%3AAirport%20local_type%3ABus_Station%20local_type%3AChemical_Works%20local_type%3ACity%20local_type%3ACoach_Station%20local_type%3AElectricity_Distribution%20local_type%3AElectricity_Production%20local_type%3AFurther_Education%20local_type%3AGas_Distribution_or_Storage%20local_type%3AHamlet%20local_type%3AHarbour%20local_type%3AHelicopter_Station%20local_type%3AHeliport%20local_type%3AHigher_or_University_Education%20local_type%3AHill_Or_Mountain%20local_type%3AHospice%20local_type%3AHospital%20local_type%3AMedical_Care_Accommodation%20local_type%3ANamed_Road%20local_type%3ANon_State_Primary_Education%20local_type%3ANon_State_Secondary_Education%20local_type%3AOther_Settlement%20local_type%3APassenger_Ferry_Terminal%20local_type%3APort_Consisting_of_Docks_and_Nautical_Berthing%20local_type%3APostcode%20local_type%3APrimary_Education%20local_type%3ARailway_Station%20local_type%3ARoad_User_Services%20local_type%3ASecondary_Education%20local_type%3ASection_Of_Named_Road%20local_type%3ASection_Of_Numbered_Road%20local_type%3ASpecial_Needs_Education%20local_type%3ASuburban_Area%20local_type%3ATown%20local_type%3AUrban_Greenspace%20local_type%3AVehicular_Ferry_Terminal%20local_type%3AVehicular_Rail_Terminal%20local_type%3AVillage%20local_type%3AWaterfall%20',\n query: 'point=523065,185795 radius=1000',\n format: 'JSON',\n maxresults: 1,\n offset: 0,\n totalresults: 1,\n filter:\n 'fq=local_type:Airfield local_type:Airport local_type:Bus_Station local_type:Chemical_Works local_type:City local_type:Coach_Station local_type:Electricity_Distribution local_type:Electricity_Production local_type:Further_Education local_type:Gas_Distribution_or_Storage local_type:Hamlet local_type:Harbour local_type:Helicopter_Station local_type:Heliport local_type:Higher_or_University_Education local_type:Hill_Or_Mountain local_type:Hospice local_type:Hospital local_type:Medical_Care_Accommodation local_type:Named_Road local_type:Non_State_Primary_Education local_type:Non_State_Secondary_Education local_type:Other_Settlement local_type:Passenger_Ferry_Terminal local_type:Port_Consisting_of_Docks_and_Nautical_Berthing local_type:Postcode local_type:Primary_Education local_type:Railway_Station local_type:Road_User_Services local_type:Secondary_Education local_type:Section_Of_Named_Road local_type:Section_Of_Numbered_Road local_type:Special_Needs_Education local_type:Suburban_Area local_type:Town local_type:Urban_Greenspace local_type:Vehicular_Ferry_Terminal local_type:Vehicular_Rail_Terminal local_type:Village local_type:Waterfall'\n },\n results: [\n {\n GAZETTEER_ENTRY: {\n ID: 'NW26XE',\n NAMES_URI: 'http://data.ordnancesurvey.co.uk/id/postcodeunit/NW26XE',\n NAME1: 'NW2 6XE',\n TYPE: 'other',\n LOCAL_TYPE: 'Postcode',\n GEOMETRY_X: 523065,\n GEOMETRY_Y: 185795,\n MOST_DETAIL_VIEW_RES: 3500,\n LEAST_DETAIL_VIEW_RES: 18000,\n POPULATED_PLACE: 'London',\n POPULATED_PLACE_URI:\n 'http://data.ordnancesurvey.co.uk/id/4000000074813508',\n POPULATED_PLACE_TYPE:\n 'http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city',\n DISTRICT_BOROUGH: 'Brent',\n DISTRICT_BOROUGH_URI:\n 'http://data.ordnancesurvey.co.uk/id/7000000000011447',\n DISTRICT_BOROUGH_TYPE:\n 'http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough',\n COUNTY_UNITARY: 'Greater London',\n COUNTY_UNITARY_URI:\n 'http://data.ordnancesurvey.co.uk/id/7000000000041441',\n COUNTY_UNITARY_TYPE:\n 'http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority',\n REGION: 'London',\n REGION_URI: 'http://data.ordnancesurvey.co.uk/id/7000000000041428',\n COUNTRY: 'England',\n COUNTRY_URI: 'http://data.ordnancesurvey.co.uk/id/country/england'\n }\n }\n ]\n}\n"],"mappings":"AAAA,OAAO,MAAMA,MAAM,GAAG;EACpBC,MAAM,EAAE;IACNC,GAAG,EAAE,22CAA22C;IACh3CC,KAAK,EAAE,iCAAiC;IACxCC,MAAM,EAAE,MAAM;IACdC,UAAU,EAAE,CAAC;IACbC,MAAM,EAAE,CAAC;IACTC,YAAY,EAAE,CAAC;IACfC,MAAM,EACJ;EACJ,CAAC;EACDC,OAAO,EAAE,CACP;IACEC,eAAe,EAAE;MACfC,EAAE,EAAE,QAAQ;MACZC,SAAS,EAAE,yDAAyD;MACpEC,KAAK,EAAE,SAAS;MAChBC,IAAI,EAAE,OAAO;MACbC,UAAU,EAAE,UAAU;MACtBC,UAAU,EAAE,MAAM;MAClBC,UAAU,EAAE,MAAM;MAClBC,oBAAoB,EAAE,IAAI;MAC1BC,qBAAqB,EAAE,KAAK;MAC5BC,eAAe,EAAE,QAAQ;MACzBC,mBAAmB,EACjB,sDAAsD;MACxDC,oBAAoB,EAClB,kEAAkE;MACpEC,gBAAgB,EAAE,OAAO;MACzBC,oBAAoB,EAClB,sDAAsD;MACxDC,qBAAqB,EACnB,kEAAkE;MACpEC,cAAc,EAAE,gBAAgB;MAChCC,kBAAkB,EAChB,sDAAsD;MACxDC,mBAAmB,EACjB,2EAA2E;MAC7EC,MAAM,EAAE,QAAQ;MAChBC,UAAU,EAAE,sDAAsD;MAClEC,OAAO,EAAE,SAAS;MAClBC,WAAW,EAAE;IACf;EACF,CAAC;AAEL,CAAC","ignoreList":[]}
|