@defra/forms-engine-plugin 5.0.0-alpha.24 → 5.0.0-alpha.26
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/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.server/client/javascripts/geospatial-map.d.ts +6 -0
- package/.server/client/javascripts/geospatial-map.js +2 -2
- package/.server/client/javascripts/geospatial-map.js.map +1 -1
- package/.server/client/javascripts/geospatial-map.test.js +152 -0
- package/.server/client/javascripts/geospatial-map.test.js.map +1 -0
- package/.server/client/javascripts/map.d.ts +2 -2
- package/.server/client/javascripts/map.js +0 -1
- package/.server/client/javascripts/map.js.map +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.js +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.js +4 -4
- package/.server/server/plugins/engine/components/helpers/geospatial.js.map +1 -1
- package/.server/server/plugins/map/routes/index.d.ts +4 -0
- package/.server/server/plugins/map/routes/index.js +12 -4
- package/.server/server/plugins/map/routes/index.js.map +1 -1
- package/.server/server/plugins/map/routes/vts/README.md +38 -0
- package/.server/server/plugins/map/routes/vts/countries-5dp.geojson +4 -0
- package/.server/server/plugins/map/routes/vts/countries.geojson +10 -39283
- package/.server/server/plugins/map/types.d.ts +24 -2
- package/.server/server/plugins/map/types.js +9 -2
- package/.server/server/plugins/map/types.js.map +1 -1
- package/.server/server/plugins/nunjucks/enviroment.test.js +11 -4
- package/.server/server/plugins/nunjucks/enviroment.test.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/models/index.js +16 -3
- package/.server/server/plugins/postcode-lookup/models/index.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/routes/index.js +17 -3
- package/.server/server/plugins/postcode-lookup/routes/index.js.map +1 -1
- package/.server/typings/geodesy/index.d.js +2 -0
- package/.server/typings/geodesy/index.d.js.map +1 -0
- package/package.json +1 -1
- package/src/client/javascripts/geospatial-map.js +2 -2
- package/src/client/javascripts/map.js +0 -1
- package/src/server/plugins/engine/components/ComponentCollection.ts +1 -4
- package/src/server/plugins/engine/components/helpers/geospatial.ts +6 -6
- package/src/server/plugins/map/routes/index.js +26 -4
- package/src/server/plugins/map/routes/vts/README.md +38 -0
- package/src/server/plugins/map/routes/vts/countries-5dp.geojson +4 -0
- package/src/server/plugins/map/routes/vts/countries.geojson +10 -39283
- package/src/server/plugins/map/types.js +9 -2
- package/src/server/plugins/postcode-lookup/models/index.js +16 -3
- package/src/server/plugins/postcode-lookup/routes/index.js +23 -8
- package/src/typings/geodesy/index.d.ts +18 -0
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
import Bourne from '@hapi/bourne'
|
|
6
6
|
import { booleanWithin } from '@turf/boolean-within'
|
|
7
7
|
import { point } from '@turf/helpers'
|
|
8
|
-
// @ts-expect-error - no types
|
|
9
8
|
import OsGridRef from 'geodesy/osgridref.js'
|
|
10
9
|
import JoiBase, { type CustomValidator } from 'joi'
|
|
11
10
|
|
|
@@ -17,7 +16,8 @@ import {
|
|
|
17
16
|
type FeatureProperties,
|
|
18
17
|
type Geometry
|
|
19
18
|
} from '../../types.js'
|
|
20
|
-
import {
|
|
19
|
+
import { countriesValidate } from '../../../map/routes/index.js'
|
|
20
|
+
import { CountryMap } from '../../../map/types.js'
|
|
21
21
|
|
|
22
22
|
const Joi = JoiBase.extend({
|
|
23
23
|
type: 'array',
|
|
@@ -158,8 +158,8 @@ export function getGeospatialSchema(
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
const validateCountryBounds: CustomValidator = (value, helpers) => {
|
|
161
|
-
const countryFeature =
|
|
162
|
-
(feature) => feature.id === country
|
|
161
|
+
const countryFeature = countriesValidate.features.find(
|
|
162
|
+
(feature) => feature.id === CountryMap[country]
|
|
163
163
|
)
|
|
164
164
|
|
|
165
165
|
if (!countryFeature) {
|
|
@@ -192,8 +192,8 @@ export function getEastingNorthingCountryValidator(
|
|
|
192
192
|
country: GeospatialFieldOptionsCountry
|
|
193
193
|
) {
|
|
194
194
|
const validateCountryBounds: CustomValidator = (value, helpers) => {
|
|
195
|
-
const countryFeature =
|
|
196
|
-
(feature) => feature.id === country
|
|
195
|
+
const countryFeature = countriesValidate.features.find(
|
|
196
|
+
(feature) => feature.id === CountryMap[country]
|
|
197
197
|
)
|
|
198
198
|
|
|
199
199
|
if (!countryFeature) {
|
|
@@ -7,18 +7,36 @@ import Joi from 'joi'
|
|
|
7
7
|
|
|
8
8
|
import { getAccessToken } from './get-os-token.js'
|
|
9
9
|
import { find } from '../service.js'
|
|
10
|
+
import { CountryMap } from '../types.js'
|
|
10
11
|
import {
|
|
11
12
|
get,
|
|
12
13
|
request as httpRequest
|
|
13
14
|
} from '../../../services/httpService.js'
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
+
const countriesDisplayFilePath = resolve(
|
|
17
|
+
import.meta.dirname,
|
|
18
|
+
'./vts/countries.geojson'
|
|
19
|
+
)
|
|
20
|
+
const countriesValidateFilePath = resolve(
|
|
21
|
+
import.meta.dirname,
|
|
22
|
+
'./vts/countries-5dp.geojson'
|
|
23
|
+
)
|
|
16
24
|
|
|
17
25
|
/**
|
|
18
26
|
* @type {FeatureCollection}
|
|
19
27
|
*/
|
|
20
28
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
21
|
-
export const countries = JSON.parse(
|
|
29
|
+
export const countries = JSON.parse(
|
|
30
|
+
fs.readFileSync(countriesDisplayFilePath, 'utf8')
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @type {FeatureCollection}
|
|
35
|
+
*/
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
37
|
+
export const countriesValidate = JSON.parse(
|
|
38
|
+
fs.readFileSync(countriesValidateFilePath, 'utf8')
|
|
39
|
+
)
|
|
22
40
|
|
|
23
41
|
export const countrySchema = Joi.string().valid(
|
|
24
42
|
...Object.values(GeospatialFieldOptionsCountryEnum)
|
|
@@ -188,14 +206,18 @@ function getGeospatialCountries() {
|
|
|
188
206
|
if (omit) {
|
|
189
207
|
return {
|
|
190
208
|
...countries,
|
|
191
|
-
features: countries.features.filter(
|
|
209
|
+
features: countries.features.filter(
|
|
210
|
+
(feature) => feature.id !== CountryMap[omit]
|
|
211
|
+
)
|
|
192
212
|
}
|
|
193
213
|
}
|
|
194
214
|
|
|
195
215
|
if (only) {
|
|
196
216
|
return {
|
|
197
217
|
...countries,
|
|
198
|
-
features: countries.features.filter(
|
|
218
|
+
features: countries.features.filter(
|
|
219
|
+
(feature) => feature.id === CountryMap[only]
|
|
220
|
+
)
|
|
199
221
|
}
|
|
200
222
|
}
|
|
201
223
|
|
|
@@ -1,5 +1,43 @@
|
|
|
1
|
+
# VTS
|
|
2
|
+
|
|
1
3
|
File in this directory are sourced from https://github.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets
|
|
2
4
|
|
|
3
5
|
VTS_OUTDOOR_URL=https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main/OS_VTS_3857_Outdoor.json
|
|
4
6
|
VTS_DARK_URL=https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main/OS_VTS_3857_Dark.json
|
|
5
7
|
VTS_BLACK_AND_WHITE_URL=https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main/OS_VTS_3857_Black_and_White.json
|
|
8
|
+
|
|
9
|
+
# Country boundaries
|
|
10
|
+
|
|
11
|
+
The [Office for National Statistics provides full-resolution boundaries](https://www.ons.gov.uk/methodology/geography/geographicalproducts/digitalboundaries) in two coastal forms.
|
|
12
|
+
We use "BFE" a full resolution — extent of the realm and generally extends to Mean Low Water rather than clipping at Mean High Water.
|
|
13
|
+
|
|
14
|
+
The latest version of the data is from 2025 and can be found at the following links:
|
|
15
|
+
|
|
16
|
+
https://geoportal.statistics.gov.uk/datasets/591803c2a3b94804a3d7895cc127d7c0_0/explore?location=50.529309%2C-4.098782%2C7
|
|
17
|
+
|
|
18
|
+
Download from: http://geoportal.statistics.gov.uk/ or https://geoportal.statistics.gov.uk/datasets/ons::countries-december-2025-boundaries-uk-bfe/about
|
|
19
|
+
|
|
20
|
+
The source data is for the 2025 revision is 179MB so needs to be reduced to allow rendering in a Web map and used for validation on the server. The downloaded file is named `boundaries-bfe.geojson`. `org2ogr` is used to produce two files:
|
|
21
|
+
|
|
22
|
+
## Server-side validation (boundaries-bfe-5dp.geojson)
|
|
23
|
+
|
|
24
|
+
This is the full file but with coordinate precision reduced from 14 to 5 decimal places, resulting in a smaller file of 83.7MB.
|
|
25
|
+
This data is then used server-side to validate points, shapes and lines that include country restrictions.
|
|
26
|
+
|
|
27
|
+
`ogr2ogr --config OGR_GEOJSON_MAX_OBJ_SIZE 0 -f GeoJSON boundaries-bfe-5dp.geojson boundaries-bfe.geojson -lco COORDINATE_PRECISION=5`
|
|
28
|
+
|
|
29
|
+
## Client-side display on map (boundaries-bfe-5dp.geojson)
|
|
30
|
+
|
|
31
|
+
To produce a file suitable for use in the map in the browser we use `ogr2ogr`'s `simplify` option.
|
|
32
|
+
|
|
33
|
+
`-simplify 0.001` uses the units of the input CRS. In EPSG:4326, that's degrees, not metres so a tolerance of 0.001° is roughly 111 metres north–south, which is quite a substantial simplification for coastal boundaries. For 0.001 to mean approximately one metre, we have to reproject to a suitable projected CRS (BNG, EPSG:27700) before simplifying:
|
|
34
|
+
|
|
35
|
+
The following command produces `boundaries-bng.geojson`, the source file reprojected to BNG.
|
|
36
|
+
|
|
37
|
+
`ogr2ogr --config OGR_GEOJSON_MAX_OBJ_SIZE 0 -f GeoJSON boundaries-bng.geojson boundaries-bfe.geojson -t_srs EPSG:27700`
|
|
38
|
+
|
|
39
|
+
We then use this to create a simplified dataset, `countries.geojson`, reprojected back in ESPG:4326:
|
|
40
|
+
|
|
41
|
+
`ogr2ogr --config OGR_GEOJSON_MAX_OBJ_SIZE 0 -f GeoJSON countries.geojson boundaries-bng.json -simplify 100 -t_srs EPSG:4326 -lco COORDINATE_PRECISION=5`
|
|
42
|
+
|
|
43
|
+
The result is a file of 940kB that is suitable to use in the web map.
|