@defra/forms-engine-plugin 4.3.0 → 4.4.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.
Files changed (83) hide show
  1. package/.public/javascripts/application.min.js.map +1 -1
  2. package/.public/javascripts/shared.min.js +1 -1
  3. package/.public/javascripts/shared.min.js.map +1 -1
  4. package/.public/javascripts/vendor/accessible-autocomplete.min.js.map +1 -1
  5. package/.public/stylesheets/application.min.css +1 -1
  6. package/.public/stylesheets/application.min.css.map +1 -1
  7. package/.server/client/javascripts/geospatial-map.d.ts +189 -0
  8. package/.server/client/javascripts/geospatial-map.js +1068 -0
  9. package/.server/client/javascripts/geospatial-map.js.map +1 -0
  10. package/.server/client/javascripts/location-map.d.ts +6 -91
  11. package/.server/client/javascripts/location-map.js +78 -385
  12. package/.server/client/javascripts/location-map.js.map +1 -1
  13. package/.server/client/javascripts/map.d.ts +199 -0
  14. package/.server/client/javascripts/map.js +384 -0
  15. package/.server/client/javascripts/map.js.map +1 -0
  16. package/.server/client/javascripts/shared.d.ts +3 -1
  17. package/.server/client/javascripts/shared.js +3 -1
  18. package/.server/client/javascripts/shared.js.map +1 -1
  19. package/.server/client/stylesheets/shared.scss +7 -0
  20. package/.server/server/plugins/engine/components/ComponentBase.d.ts +1 -0
  21. package/.server/server/plugins/engine/components/ComponentBase.js +2 -0
  22. package/.server/server/plugins/engine/components/ComponentBase.js.map +1 -1
  23. package/.server/server/plugins/engine/components/FormComponent.d.ts +9 -1
  24. package/.server/server/plugins/engine/components/FormComponent.js +22 -0
  25. package/.server/server/plugins/engine/components/FormComponent.js.map +1 -1
  26. package/.server/server/plugins/engine/components/GeospatialField.d.ts +77 -0
  27. package/.server/server/plugins/engine/components/GeospatialField.js +102 -0
  28. package/.server/server/plugins/engine/components/GeospatialField.js.map +1 -0
  29. package/.server/server/plugins/engine/components/helpers/__stubs__/geospatial.d.ts +3 -0
  30. package/.server/server/plugins/engine/components/helpers/__stubs__/geospatial.js +63 -0
  31. package/.server/server/plugins/engine/components/helpers/__stubs__/geospatial.js.map +1 -0
  32. package/.server/server/plugins/engine/components/helpers/components.d.ts +1 -1
  33. package/.server/server/plugins/engine/components/helpers/components.js +7 -0
  34. package/.server/server/plugins/engine/components/helpers/components.js.map +1 -1
  35. package/.server/server/plugins/engine/components/helpers/geospatial.d.ts +6 -0
  36. package/.server/server/plugins/engine/components/helpers/geospatial.js +71 -0
  37. package/.server/server/plugins/engine/components/helpers/geospatial.js.map +1 -0
  38. package/.server/server/plugins/engine/components/helpers/geospatial.test.js +42 -0
  39. package/.server/server/plugins/engine/components/helpers/geospatial.test.js.map +1 -0
  40. package/.server/server/plugins/engine/components/index.d.ts +1 -0
  41. package/.server/server/plugins/engine/components/index.js +1 -0
  42. package/.server/server/plugins/engine/components/index.js.map +1 -1
  43. package/.server/server/plugins/engine/pageControllers/PageController.d.ts +1 -0
  44. package/.server/server/plugins/engine/pageControllers/PageController.js +2 -0
  45. package/.server/server/plugins/engine/pageControllers/PageController.js.map +1 -1
  46. package/.server/server/plugins/engine/pageControllers/helpers/submission.js +13 -1
  47. package/.server/server/plugins/engine/pageControllers/helpers/submission.js.map +1 -1
  48. package/.server/server/plugins/engine/pageControllers/validationOptions.js +2 -1
  49. package/.server/server/plugins/engine/pageControllers/validationOptions.js.map +1 -1
  50. package/.server/server/plugins/engine/types.d.ts +63 -2
  51. package/.server/server/plugins/engine/types.js +33 -0
  52. package/.server/server/plugins/engine/types.js.map +1 -1
  53. package/.server/server/plugins/engine/views/components/geospatialfield.html +7 -0
  54. package/.server/server/plugins/nunjucks/context.test.js.map +1 -1
  55. package/.server/server/plugins/nunjucks/filters/field.d.ts +1 -1
  56. package/.server/server/routes/types.js.map +1 -1
  57. package/.server/server/services/cacheService.js +3 -0
  58. package/.server/server/services/cacheService.js.map +1 -1
  59. package/package.json +9 -5
  60. package/src/client/javascripts/geospatial-map.js +1023 -0
  61. package/src/client/javascripts/location-map.js +94 -390
  62. package/src/client/javascripts/map.js +389 -0
  63. package/src/client/javascripts/shared.js +3 -1
  64. package/src/client/stylesheets/shared.scss +7 -0
  65. package/src/server/plugins/engine/components/ComponentBase.ts +2 -0
  66. package/src/server/plugins/engine/components/FormComponent.ts +29 -0
  67. package/src/server/plugins/engine/components/GeospatialField.test.ts +380 -0
  68. package/src/server/plugins/engine/components/GeospatialField.ts +145 -0
  69. package/src/server/plugins/engine/components/helpers/__stubs__/geospatial.ts +85 -0
  70. package/src/server/plugins/engine/components/helpers/components.test.ts +44 -0
  71. package/src/server/plugins/engine/components/helpers/components.ts +10 -0
  72. package/src/server/plugins/engine/components/helpers/geospatial.test.js +55 -0
  73. package/src/server/plugins/engine/components/helpers/geospatial.ts +93 -0
  74. package/src/server/plugins/engine/components/index.ts +1 -0
  75. package/src/server/plugins/engine/pageControllers/PageController.ts +2 -0
  76. package/src/server/plugins/engine/pageControllers/helpers/submission.test.ts +74 -0
  77. package/src/server/plugins/engine/pageControllers/helpers/submission.ts +17 -1
  78. package/src/server/plugins/engine/pageControllers/validationOptions.ts +3 -1
  79. package/src/server/plugins/engine/types.ts +77 -4
  80. package/src/server/plugins/engine/views/components/geospatialfield.html +7 -0
  81. package/src/server/plugins/nunjucks/context.test.js +2 -3
  82. package/src/server/routes/types.ts +4 -2
  83. package/src/server/services/cacheService.ts +2 -0
@@ -1,343 +1,5 @@
1
- // @ts-expect-error - no types
2
- import OsGridRef, { LatLon } from 'geodesy/osgridref.js';
3
-
4
- /**
5
- * Converts lat long to easting and northing
6
- * @param {object} param
7
- * @param {number} param.lat
8
- * @param {number} param.long
9
- * @returns {{ easting: number, northing: number }}
10
- */
11
- function latLongToEastingNorthing({
12
- lat,
13
- long
14
- }) {
15
- const point = new LatLon(lat, long);
16
- return point.toOsGrid();
17
- }
18
-
19
- /**
20
- * Converts easting and northing to lat long
21
- * @param {object} param
22
- * @param {number} param.easting
23
- * @param {number} param.northing
24
- * @returns {{ lat: number, long: number }}
25
- */
26
- function eastingNorthingToLatLong({
27
- easting,
28
- northing
29
- }) {
30
- const point = new OsGridRef(easting, northing);
31
- const latLong = point.toLatLon();
32
- return {
33
- lat: latLong.latitude,
34
- long: latLong.longitude
35
- };
36
- }
37
-
38
- /**
39
- * Converts lat long to an ordnance survey grid reference
40
- * @param {object} param
41
- * @param {number} param.lat
42
- * @param {number} param.long
43
- * @returns {string}
44
- */
45
- function latLongToOsGridRef({
46
- lat,
47
- long
48
- }) {
49
- const point = new LatLon(lat, long);
50
- return point.toOsGrid().toString();
51
- }
52
-
53
- /**
54
- * Converts an ordnance survey grid reference to lat long
55
- * @param {string} osGridRef
56
- * @returns {{ lat: number, long: number }}
57
- */
58
- function osGridRefToLatLong(osGridRef) {
59
- const point = OsGridRef.parse(osGridRef);
60
- const latLong = point.toLatLon();
61
- return {
62
- lat: latLong.latitude,
63
- long: latLong.longitude
64
- };
65
- }
66
-
67
- // Center of UK
68
- const DEFAULT_LAT = 53.825564;
69
- const DEFAULT_LONG = -2.421975;
70
-
71
- /** @type {InteractiveMapInitConfig} */
72
- const defaultConfig = {
73
- zoom: '6',
74
- center: [DEFAULT_LONG, DEFAULT_LAT]
75
- };
76
- const COMPANY_SYMBOL_CODE = 169;
1
+ import { EVENTS, centerMap, createMap, defaultConfig, eastingNorthingToLatLong, latLongToEastingNorthing, latLongToOsGridRef, osGridRefToLatLong } from "./map.js";
77
2
  const LOCATION_FIELD_SELECTOR = 'input.govuk-input';
78
- const EVENTS = {
79
- interactMarkerChange: 'interact:markerchange'
80
- };
81
- const defaultData = {
82
- VTS_OUTDOOR_URL: '/api/maps/vts/OS_VTS_3857_Outdoor.json',
83
- VTS_DARK_URL: '/api/maps/vts/OS_VTS_3857_Dark.json',
84
- VTS_BLACK_AND_WHITE_URL: '/api/maps/vts/OS_VTS_3857_Black_and_White.json'
85
- };
86
-
87
- /**
88
- * Make a form submit handler that only allows submissions from allowed buttons
89
- * @param {HTMLButtonElement[]} buttons - the form buttons to allow submissions
90
- */
91
- export function formSubmitFactory(buttons) {
92
- /**
93
- * The submit handler
94
- * @param {SubmitEvent} e
95
- */
96
- const onFormSubmit = function (e) {
97
- if (!(e.submitter instanceof HTMLButtonElement) || !buttons.includes(e.submitter)) {
98
- e.preventDefault();
99
- }
100
- };
101
- return onFormSubmit;
102
- }
103
-
104
- /**
105
- * Initialise location maps
106
- * @param {Partial<MapsEnvironmentConfig>} config - the map configuration
107
- */
108
- export function initMaps(config = {}) {
109
- const {
110
- assetPath = '/assets',
111
- apiPath = '/form/api',
112
- data = defaultData
113
- } = config;
114
- const locations = document.querySelectorAll('.app-location-field');
115
-
116
- // TODO: Fix this in `interactive-map`
117
- // If there are location components on the page fix up the main form submit
118
- // handler so it doesn't fire when using the integrated map search feature
119
- if (locations.length) {
120
- const form = locations[0].closest('form');
121
- if (form === null) {
122
- return;
123
- }
124
- const buttons = Array.from(form.querySelectorAll('button'));
125
- form.addEventListener('submit', formSubmitFactory(buttons), false);
126
- }
127
- locations.forEach((location, index) => {
128
- processLocation({
129
- assetPath,
130
- apiPath,
131
- data
132
- }, location, index);
133
- });
134
- }
135
-
136
- /**
137
- * OS API request proxy factory
138
- * @param {string} apiPath - the root API path
139
- */
140
- export function makeTileRequestTransformer(apiPath) {
141
- /**
142
- * Proxy OS API requests via our server
143
- * @param {string} url - the request URL
144
- * @param {string} resourceType - the resource type
145
- */
146
- return function transformTileRequest(url, resourceType) {
147
- if (url.startsWith('https://api.os.uk')) {
148
- if (resourceType === 'Tile') {
149
- return {
150
- url: url.replace('https://api.os.uk/maps/vector/v1/vts', `${window.location.origin}${apiPath}`),
151
- headers: {}
152
- };
153
- }
154
- if (resourceType !== 'Style') {
155
- return {
156
- url: `${apiPath}/map-proxy?url=${encodeURIComponent(url)}`,
157
- headers: {}
158
- };
159
- }
160
- }
161
- const spritesPath = 'https://raw.githubusercontent.com/OrdnanceSurvey/OS-Vector-Tile-API-Stylesheets/main';
162
-
163
- // Proxy sprite requests
164
- if (url.startsWith(spritesPath)) {
165
- const path = url.substring(spritesPath.length);
166
- return {
167
- url: `${apiPath}/maps/vts${path}`,
168
- headers: {}
169
- };
170
- }
171
- return {
172
- url,
173
- headers: {}
174
- };
175
- };
176
- }
177
-
178
- /**
179
- * Processes a location field to add map capability
180
- * @param {MapsEnvironmentConfig} config - the location field element
181
- * @param {Element} location - the location field element
182
- * @param {*} index - the 0-based index
183
- */
184
- function processLocation(config, location, index) {
185
- if (!(location instanceof HTMLDivElement)) {
186
- return;
187
- }
188
- const locationInputs = location.querySelector('.app-location-field-inputs');
189
- if (!(locationInputs instanceof HTMLDivElement)) {
190
- return;
191
- }
192
- const locationType = location.dataset.locationtype;
193
-
194
- // Check for support
195
- const supportedLocations = ['latlongfield', 'eastingnorthingfield', 'osgridreffield'];
196
- if (!locationType || !supportedLocations.includes(locationType)) {
197
- return;
198
- }
199
- const mapContainer = document.createElement('div');
200
- const mapId = `map_${index}`;
201
- mapContainer.setAttribute('id', mapId);
202
- mapContainer.setAttribute('class', 'map-container');
203
- const initConfig = getInitMapConfig(location) ?? defaultConfig;
204
- locationInputs.after(mapContainer);
205
- const {
206
- map,
207
- interactPlugin
208
- } = createMap(mapId, initConfig, config);
209
- map.on('map:ready',
210
- /**
211
- * Callback function which fires when the map is ready
212
- * @param {object} e - the event
213
- * @param {MapLibreMap} e.map - the map provider instance
214
- */
215
- function onMapReady(e) {
216
- switch (locationType) {
217
- case 'latlongfield':
218
- bindLatLongField(location, map, e.map);
219
- break;
220
- case 'eastingnorthingfield':
221
- bindEastingNorthingField(location, map, e.map);
222
- break;
223
- case 'osgridreffield':
224
- bindOsGridRefField(location, map, e.map);
225
- break;
226
- default:
227
- throw new Error('Not implemented');
228
- }
229
-
230
- // Add info panel
231
- map.addPanel('info', {
232
- showLabel: true,
233
- label: 'How to use the map',
234
- mobile: {
235
- slot: 'bottom',
236
- initiallyOpen: true,
237
- dismissable: true,
238
- modal: false
239
- },
240
- tablet: {
241
- slot: 'bottom',
242
- initiallyOpen: true,
243
- dismissable: true,
244
- modal: false
245
- },
246
- desktop: {
247
- slot: 'bottom',
248
- initiallyOpen: true,
249
- dismissable: true,
250
- modal: false
251
- },
252
- html: 'If using a map click on a point to update the location.<br><br>If using a keyboard, navigate to the point, centering the crosshair at the location and press enter.'
253
- });
254
-
255
- // Enable the interact plugin
256
- interactPlugin.enable();
257
- });
258
- }
259
-
260
- /**
261
- * Create a Defra map instance
262
- * @param {string} mapId - the map id
263
- * @param {InteractiveMapInitConfig} initConfig - the map initial configuration
264
- * @param {MapsEnvironmentConfig} mapsConfig - the map environment params
265
- */
266
- function createMap(mapId, initConfig, mapsConfig) {
267
- const {
268
- assetPath,
269
- apiPath,
270
- data = defaultData
271
- } = mapsConfig;
272
- const logoAltText = 'Ordnance survey logo';
273
-
274
- // @ts-expect-error - Defra namespace currently comes from UMD support files
275
- const defra = window.defra;
276
- const interactPlugin = defra.interactPlugin({
277
- dataLayers: [],
278
- markerColor: {
279
- outdoor: '#ff0000',
280
- dark: '#00ff00'
281
- },
282
- interactionMode: 'marker',
283
- multiSelect: false
284
- });
285
-
286
- /** @type {InteractiveMap} */
287
- const map = new defra.InteractiveMap(mapId, {
288
- ...initConfig,
289
- mapProvider: defra.maplibreProvider(),
290
- reverseGeocodeProvider: defra.openNamesProvider({
291
- url: `${apiPath}/reverse-geocode-proxy?easting={easting}&northing={northing}`
292
- }),
293
- behaviour: 'inline',
294
- minZoom: 6,
295
- maxZoom: 18,
296
- containerHeight: '400px',
297
- enableZoomControls: true,
298
- transformRequest: makeTileRequestTransformer(apiPath),
299
- plugins: [defra.mapStylesPlugin({
300
- mapStyles: [{
301
- id: 'outdoor',
302
- label: 'Outdoor',
303
- url: data.VTS_OUTDOOR_URL,
304
- thumbnail: `${assetPath}/interactive-map/assets/images/outdoor-map-thumb.jpg`,
305
- logo: `${assetPath}/interactive-map/assets/images/os-logo.svg`,
306
- logoAltText,
307
- attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`,
308
- backgroundColor: '#f5f5f0'
309
- }, {
310
- id: 'dark',
311
- label: 'Dark',
312
- url: data.VTS_DARK_URL,
313
- mapColorScheme: 'dark',
314
- appColorScheme: 'dark',
315
- thumbnail: `${assetPath}/interactive-map/assets/images/dark-map-thumb.jpg`,
316
- logo: `${assetPath}/interactive-map/assets/images/os-logo-white.svg`,
317
- logoAltText,
318
- attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`
319
- }, {
320
- id: 'black-and-white',
321
- label: 'Black/White',
322
- url: data.VTS_BLACK_AND_WHITE_URL,
323
- thumbnail: `${assetPath}/interactive-map/assets/images/black-and-white-map-thumb.jpg`,
324
- logo: `${assetPath}/interactive-map/assets/images/os-logo-black.svg`,
325
- logoAltText,
326
- attribution: `Contains OS data ${String.fromCodePoint(COMPANY_SYMBOL_CODE)} Crown copyright and database rights ${new Date().getFullYear()}`
327
- }]
328
- }), interactPlugin, defra.searchPlugin({
329
- osNamesURL: `${apiPath}/geocode-proxy?query={query}`,
330
- width: '300px',
331
- showMarker: false
332
- }), defra.scaleBarPlugin({
333
- units: 'metric'
334
- })]
335
- });
336
- return {
337
- map,
338
- interactPlugin
339
- };
340
- }
341
3
 
342
4
  /**
343
5
  * Gets initial map config for a location field
@@ -693,57 +355,88 @@ function bindOsGridRefField(locationField, map, mapProvider) {
693
355
  }
694
356
 
695
357
  /**
696
- * Updates the marker position and moves the map view port the new location
697
- * @param {InteractiveMap} map - the map component instance (of InteractiveMap)
698
- * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)
699
- * @param {MapCenter} center - the point
700
- */
701
- function centerMap(map, mapProvider, center) {
702
- // Move the 'location' marker to the new point
703
- map.addMarker('location', center);
704
-
705
- // Pan & zoom the map to the new valid location
706
- mapProvider.flyTo({
707
- center,
708
- zoom: 14,
709
- essential: true
710
- });
711
- }
712
-
713
- /**
714
- * @typedef {object} InteractiveMap - an instance of a InteractiveMap
715
- * @property {Function} on - register callback listeners to map events
716
- * @property {Function} addPanel - adds a new panel to the map
717
- * @property {Function} addMarker - adds/updates a marker
718
- */
719
-
720
- /**
721
- * @typedef {object} MapLibreMap
722
- * @property {Function} flyTo - pans/zooms to a new location
358
+ * Processes a location field to add map capability
359
+ * @param {MapsEnvironmentConfig} config - the location field element
360
+ * @param {Element} location - the location field element
361
+ * @param {number} index - the 0-based index
723
362
  */
363
+ export function processLocation(config, location, index) {
364
+ if (!(location instanceof HTMLDivElement)) {
365
+ return;
366
+ }
367
+ const locationInputs = location.querySelector('.app-location-field-inputs');
368
+ if (!(locationInputs instanceof HTMLDivElement)) {
369
+ return;
370
+ }
371
+ const locationType = location.dataset.locationtype;
724
372
 
725
- /**
726
- * @typedef {[number, number]} MapCenter - Map center point as [long, lat]
727
- */
373
+ // Check for support
374
+ const supportedLocations = ['latlongfield', 'eastingnorthingfield', 'osgridreffield'];
375
+ if (!locationType || !supportedLocations.includes(locationType)) {
376
+ return;
377
+ }
378
+ const mapContainer = document.createElement('div');
379
+ const mapId = `map_${index}`;
380
+ mapContainer.setAttribute('id', mapId);
381
+ mapContainer.setAttribute('class', 'map-container');
382
+ const initConfig = getInitMapConfig(location) ?? defaultConfig;
383
+ locationInputs.after(mapContainer);
384
+ const {
385
+ map,
386
+ interactPlugin
387
+ } = createMap(mapId, initConfig, config);
388
+ map.on(EVENTS.mapReady,
389
+ /**
390
+ * Callback function which fires when the map is ready
391
+ * @param {object} e - the event
392
+ * @param {MapLibreMap} e.map - the map provider instance
393
+ */
394
+ function onMapReady(e) {
395
+ switch (locationType) {
396
+ case 'latlongfield':
397
+ bindLatLongField(location, map, e.map);
398
+ break;
399
+ case 'eastingnorthingfield':
400
+ bindEastingNorthingField(location, map, e.map);
401
+ break;
402
+ case 'osgridreffield':
403
+ bindOsGridRefField(location, map, e.map);
404
+ break;
405
+ default:
406
+ throw new Error('Not implemented');
407
+ }
728
408
 
729
- /**
730
- * @typedef {object} InteractiveMapInitConfig - additional config that can be provided to InteractiveMap
731
- * @property {string} zoom - the zoom level of the map
732
- * @property {MapCenter} center - the center point of the map
733
- * @property {{ id: string, coords: MapCenter}[]} [markers] - the markers to add to the map
734
- */
409
+ // Add info panel
410
+ map.addPanel('info', {
411
+ showLabel: true,
412
+ label: 'How to use the map',
413
+ mobile: {
414
+ slot: 'bottom',
415
+ open: true,
416
+ dismissible: true,
417
+ modal: false
418
+ },
419
+ tablet: {
420
+ slot: 'bottom',
421
+ open: true,
422
+ dismissible: true,
423
+ modal: false
424
+ },
425
+ desktop: {
426
+ slot: 'bottom',
427
+ open: true,
428
+ dismissible: true,
429
+ modal: false
430
+ },
431
+ html: 'If using a map click on a point to update the location.<br><br>If using a keyboard, navigate to the point, centering the crosshair at the location and press enter.'
432
+ });
735
433
 
736
- /**
737
- * @typedef {object} TileData
738
- * @property {string} VTS_OUTDOOR_URL - the outdoor tile URL
739
- * @property {string} VTS_DARK_URL - the dark tile URL
740
- * @property {string} VTS_BLACK_AND_WHITE_URL - the black and white tile URL
741
- */
434
+ // Enable the interact plugin
435
+ interactPlugin.enable();
436
+ });
437
+ }
742
438
 
743
439
  /**
744
- * @typedef {object} MapsEnvironmentConfig
745
- * @property {string} assetPath - the root asset path
746
- * @property {string} apiPath - the root API path
747
- * @property {TileData} data - the tile data config
440
+ * @import { InteractiveMap, InteractiveMapInitConfig, MapCenter, MapLibreMap, MapsEnvironmentConfig } from '~/src/client/javascripts/map.js'
748
441
  */
749
442
  //# sourceMappingURL=location-map.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"location-map.js","names":["OsGridRef","LatLon","latLongToEastingNorthing","lat","long","point","toOsGrid","eastingNorthingToLatLong","easting","northing","latLong","toLatLon","latitude","longitude","latLongToOsGridRef","toString","osGridRefToLatLong","osGridRef","parse","DEFAULT_LAT","DEFAULT_LONG","defaultConfig","zoom","center","COMPANY_SYMBOL_CODE","LOCATION_FIELD_SELECTOR","EVENTS","interactMarkerChange","defaultData","VTS_OUTDOOR_URL","VTS_DARK_URL","VTS_BLACK_AND_WHITE_URL","formSubmitFactory","buttons","onFormSubmit","e","submitter","HTMLButtonElement","includes","preventDefault","initMaps","config","assetPath","apiPath","data","locations","document","querySelectorAll","length","form","closest","Array","from","addEventListener","forEach","location","index","processLocation","makeTileRequestTransformer","transformTileRequest","url","resourceType","startsWith","replace","window","origin","headers","encodeURIComponent","spritesPath","path","substring","HTMLDivElement","locationInputs","querySelector","locationType","dataset","locationtype","supportedLocations","mapContainer","createElement","mapId","setAttribute","initConfig","getInitMapConfig","after","map","interactPlugin","createMap","on","onMapReady","bindLatLongField","bindEastingNorthingField","bindOsGridRefField","Error","addPanel","showLabel","label","mobile","slot","initiallyOpen","dismissable","modal","tablet","desktop","html","enable","mapsConfig","logoAltText","defra","dataLayers","markerColor","outdoor","dark","interactionMode","multiSelect","InteractiveMap","mapProvider","maplibreProvider","reverseGeocodeProvider","openNamesProvider","behaviour","minZoom","maxZoom","containerHeight","enableZoomControls","transformRequest","plugins","mapStylesPlugin","mapStyles","id","thumbnail","logo","attribution","String","fromCodePoint","Date","getFullYear","backgroundColor","mapColorScheme","appColorScheme","searchPlugin","osNamesURL","width","showMarker","scaleBarPlugin","units","locationField","getInitLatLongMapConfig","getInitEastingNorthingMapConfig","getInitOsGridRefMapConfig","validateLatLong","strLat","strLong","trim","Number","valid","latMin","latMax","longMin","longMax","latInBounds","longInBounds","value","validateEastingNorthing","strEasting","strNorthing","eastingMin","eastingMax","northingMin","northingMax","validateOsGridRef","pattern","match","exec","getLatLongInputs","inputs","latInput","longInput","getEastingNorthingInputs","eastingInput","northingInput","getOsGridRefInput","input","getInitMapCenterConfig","markers","coords","result","undefined","latlong","osGridRefInput","onInteractMarkerChange","maxPrecision","toFixed","onUpdateInputs","centerMap","onUpdateInput","addMarker","flyTo","essential"],"sources":["../../../src/client/javascripts/location-map.js"],"sourcesContent":["// @ts-expect-error - no types\nimport OsGridRef, { LatLon } from 'geodesy/osgridref.js'\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 */\nfunction 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 */\nfunction 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 */\nfunction 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 */\nfunction 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// Center of UK\nconst DEFAULT_LAT = 53.825564\nconst DEFAULT_LONG = -2.421975\n\n/** @type {InteractiveMapInitConfig} */\nconst defaultConfig = {\n zoom: '6',\n center: [DEFAULT_LONG, DEFAULT_LAT]\n}\n\nconst COMPANY_SYMBOL_CODE = 169\nconst LOCATION_FIELD_SELECTOR = 'input.govuk-input'\nconst EVENTS = {\n interactMarkerChange: 'interact:markerchange'\n}\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}\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\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 locations.forEach((location, index) => {\n processLocation({ assetPath, apiPath, data }, location, 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 * Processes a location field to add map capability\n * @param {MapsEnvironmentConfig} config - the location field element\n * @param {Element} location - the location field element\n * @param {*} index - the 0-based index\n */\nfunction processLocation(config, location, index) {\n if (!(location instanceof HTMLDivElement)) {\n return\n }\n\n const locationInputs = location.querySelector('.app-location-field-inputs')\n if (!(locationInputs instanceof HTMLDivElement)) {\n return\n }\n const locationType = location.dataset.locationtype\n\n // Check for support\n const supportedLocations = [\n 'latlongfield',\n 'eastingnorthingfield',\n 'osgridreffield'\n ]\n if (!locationType || !supportedLocations.includes(locationType)) {\n return\n }\n\n const mapContainer = document.createElement('div')\n const mapId = `map_${index}`\n\n mapContainer.setAttribute('id', mapId)\n mapContainer.setAttribute('class', 'map-container')\n\n const initConfig = getInitMapConfig(location) ?? defaultConfig\n\n locationInputs.after(mapContainer)\n\n const { map, interactPlugin } = createMap(mapId, initConfig, config)\n\n map.on(\n 'map:ready',\n /**\n * Callback function which fires when the map is ready\n * @param {object} e - the event\n * @param {MapLibreMap} e.map - the map provider instance\n */\n function onMapReady(e) {\n switch (locationType) {\n case 'latlongfield':\n bindLatLongField(location, map, e.map)\n break\n case 'eastingnorthingfield':\n bindEastingNorthingField(location, map, e.map)\n break\n case 'osgridreffield':\n bindOsGridRefField(location, map, e.map)\n break\n default:\n throw new Error('Not implemented')\n }\n\n // Add info panel\n map.addPanel('info', {\n showLabel: true,\n label: 'How to use the map',\n mobile: {\n slot: 'bottom',\n initiallyOpen: true,\n dismissable: true,\n modal: false\n },\n tablet: {\n slot: 'bottom',\n initiallyOpen: true,\n dismissable: true,\n modal: false\n },\n desktop: {\n slot: 'bottom',\n initiallyOpen: true,\n dismissable: true,\n modal: false\n },\n html: 'If using a map click on a point to update the location.<br><br>If using a keyboard, navigate to the point, centering the crosshair at the location and press enter.'\n })\n\n // Enable the interact plugin\n interactPlugin.enable()\n }\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 */\nfunction createMap(mapId, initConfig, mapsConfig) {\n const { assetPath, apiPath, data = defaultData } = mapsConfig\n const logoAltText = 'Ordnance survey logo'\n\n // @ts-expect-error - Defra namespace currently comes from UMD support files\n const defra = window.defra\n\n const interactPlugin = defra.interactPlugin({\n dataLayers: [],\n markerColor: { outdoor: '#ff0000', dark: '#00ff00' },\n interactionMode: 'marker',\n multiSelect: false\n })\n\n /** @type {InteractiveMap} */\n const map = new defra.InteractiveMap(mapId, {\n ...initConfig,\n mapProvider: defra.maplibreProvider(),\n reverseGeocodeProvider: defra.openNamesProvider({\n url: `${apiPath}/reverse-geocode-proxy?easting={easting}&northing={northing}`\n }),\n behaviour: 'inline',\n minZoom: 6,\n maxZoom: 18,\n containerHeight: '400px',\n enableZoomControls: true,\n transformRequest: makeTileRequestTransformer(apiPath),\n plugins: [\n defra.mapStylesPlugin({\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 }),\n interactPlugin,\n defra.searchPlugin({\n osNamesURL: `${apiPath}/geocode-proxy?query={query}`,\n width: '300px',\n showMarker: false\n }),\n defra.scaleBarPlugin({\n units: 'metric'\n })\n ]\n })\n\n return { map, interactPlugin }\n}\n\n/**\n * Gets initial map config for a location field\n * @param {HTMLDivElement} locationField - the location field element\n */\nfunction getInitMapConfig(locationField) {\n const locationType = locationField.dataset.locationtype\n\n switch (locationType) {\n case 'latlongfield':\n return getInitLatLongMapConfig(locationField)\n case 'eastingnorthingfield':\n return getInitEastingNorthingMapConfig(locationField)\n case 'osgridreffield':\n return getInitOsGridRefMapConfig(locationField)\n default:\n throw new Error('Not implemented')\n }\n}\n\n/**\n * Validates lat and long is numeric and within UK bounds\n * @param {string} strLat - the latitude string\n * @param {string} strLong - the longitude string\n * @returns {{ valid: false } | { valid: true, value: { lat: number, long: number } }}\n */\nfunction validateLatLong(strLat, strLong) {\n const lat = strLat.trim() && Number(strLat.trim())\n const long = strLong.trim() && Number(strLong.trim())\n\n if (!lat || !long) {\n return { valid: false }\n }\n\n const latMin = 49.85\n const latMax = 60.859\n const longMin = -13.687\n const longMax = 1.767\n\n const latInBounds = lat >= latMin && lat <= latMax\n const longInBounds = long >= longMin && long <= longMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { lat, long } }\n}\n\n/**\n * Validates easting and northing is numeric and within UK bounds\n * @param {string} strEasting - the easting string\n * @param {string} strNorthing - the northing string\n * @returns {{ valid: false } | { valid: true, value: { easting: number, northing: number } }}\n */\nfunction validateEastingNorthing(strEasting, strNorthing) {\n const easting = strEasting.trim() && Number(strEasting.trim())\n const northing = strNorthing.trim() && Number(strNorthing.trim())\n\n if (!easting || !northing) {\n return { valid: false }\n }\n\n const eastingMin = 0\n const eastingMax = 700000\n const northingMin = 0\n const northingMax = 1300000\n\n const latInBounds = easting >= eastingMin && easting <= eastingMax\n const longInBounds = northing >= northingMin && northing <= northingMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { easting, northing } }\n}\n\n/**\n * Validates OS grid reference is correct\n * @param {string} osGridRef - the OsGridRef\n * @returns {{ valid: false } | { valid: true, value: string }}\n */\nfunction validateOsGridRef(osGridRef) {\n if (!osGridRef) {\n return { valid: false }\n }\n\n const pattern =\n /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\\s?(([0-9]{3})\\s?([0-9]{3})|([0-9]{4})\\s?([0-9]{4})|([0-9]{5})\\s?([0-9]{5}))$/\n\n const match = pattern.exec(osGridRef)\n\n if (match === null) {\n return { valid: false }\n }\n\n return { valid: true, value: match[0] }\n}\n\n/**\n * Gets the inputs for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n */\nfunction getLatLongInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for lat and long')\n }\n\n const latInput = /** @type {HTMLInputElement} */ (inputs[0])\n const longInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { latInput, longInput }\n}\n\n/**\n * Gets the inputs for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n */\nfunction getEastingNorthingInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for easting and northing')\n }\n\n const eastingInput = /** @type {HTMLInputElement} */ (inputs[0])\n const northingInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { eastingInput, northingInput }\n}\n\n/**\n * Gets the input for a OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n */\nfunction getOsGridRefInput(locationField) {\n const input = locationField.querySelector(LOCATION_FIELD_SELECTOR)\n\n if (input === null) {\n throw new Error('Expected 1 input for osgridref')\n }\n\n return /** @type {HTMLInputElement} */ (input)\n}\n\n/**\n * Get the initial map config for a center point\n * @param {MapCenter} center - the point\n */\nfunction getInitMapCenterConfig(center) {\n return {\n zoom: '16',\n center,\n markers: [\n {\n id: 'location',\n coords: center\n }\n ]\n }\n}\n\n/**\n * Gets initial map config for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitLatLongMapConfig(locationField) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitEastingNorthingMapConfig(locationField) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for an OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitOsGridRefMapConfig(locationField) {\n const osGridRefInput = getOsGridRefInput(locationField)\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Bind a latlong field to the map\n * @param {HTMLDivElement} locationField - the latlong location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindLatLongField(locationField, map, mapProvider) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 7\n latInput.value = e.coords[1].toFixed(maxPrecision)\n longInput.value = e.coords[0].toFixed(maxPrecision)\n }\n )\n\n /**\n * Lat & long input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (result.valid) {\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n latInput.addEventListener('change', onUpdateInputs, false)\n longInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an eastingnorthing field to the map\n * @param {HTMLDivElement} locationField - the eastingnorthing location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindEastingNorthingField(locationField, map, mapProvider) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 0\n const point = latLongToEastingNorthing({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n eastingInput.value = point.easting.toFixed(maxPrecision)\n northingInput.value = point.northing.toFixed(maxPrecision)\n }\n )\n\n /**\n * Easting & northing input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (result.valid) {\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n eastingInput.addEventListener('change', onUpdateInputs, false)\n northingInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an OS grid reference field to the map\n * @param {HTMLDivElement} locationField - the osgridref location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindOsGridRefField(locationField, map, mapProvider) {\n const osGridRefInput = getOsGridRefInput(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const point = latLongToOsGridRef({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n osGridRefInput.value = point\n }\n )\n\n /**\n * OS grid reference input change event listener\n * Update the map view location when the input is changed\n */\n function onUpdateInput() {\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (result.valid) {\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n osGridRefInput.addEventListener('change', onUpdateInput, false)\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 */\nfunction 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 */\n\n/**\n * @typedef {object} MapLibreMap\n * @property {Function} flyTo - pans/zooms to a new location\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 */\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 */\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"],"mappings":"AAAA;AACA,OAAOA,SAAS,IAAIC,MAAM,QAAQ,sBAAsB;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,wBAAwBA,CAAC;EAAEC,GAAG;EAAEC;AAAK,CAAC,EAAE;EAC/C,MAAMC,KAAK,GAAG,IAAIJ,MAAM,CAACE,GAAG,EAAEC,IAAI,CAAC;EAEnC,OAAOC,KAAK,CAACC,QAAQ,CAAC,CAAC;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,wBAAwBA,CAAC;EAAEC,OAAO;EAAEC;AAAS,CAAC,EAAE;EACvD,MAAMJ,KAAK,GAAG,IAAIL,SAAS,CAACQ,OAAO,EAAEC,QAAQ,CAAC;EAC9C,MAAMC,OAAO,GAAGL,KAAK,CAACM,QAAQ,CAAC,CAAC;EAEhC,OAAO;IAAER,GAAG,EAAEO,OAAO,CAACE,QAAQ;IAAER,IAAI,EAAEM,OAAO,CAACG;EAAU,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,kBAAkBA,CAAC;EAAEX,GAAG;EAAEC;AAAK,CAAC,EAAE;EACzC,MAAMC,KAAK,GAAG,IAAIJ,MAAM,CAACE,GAAG,EAAEC,IAAI,CAAC;EAEnC,OAAOC,KAAK,CAACC,QAAQ,CAAC,CAAC,CAACS,QAAQ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,WAAW,EAAE7F,MAAM,CAAC;IACrC;EACF;EAEAsK,cAAc,CAACxI,gBAAgB,CAAC,QAAQ,EAAE8I,aAAa,EAAE,KAAK,CAAC;AACjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASD,SAASA,CAAC7G,GAAG,EAAE+B,WAAW,EAAE7F,MAAM,EAAE;EAC3C;EACA8D,GAAG,CAAC+G,SAAS,CAAC,UAAU,EAAE7K,MAAM,CAAC;;EAEjC;EACA6F,WAAW,CAACiF,KAAK,CAAC;IAChB9K,MAAM;IACND,IAAI,EAAE,EAAE;IACRgL,SAAS,EAAE;EACb,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"location-map.js","names":["EVENTS","centerMap","createMap","defaultConfig","eastingNorthingToLatLong","latLongToEastingNorthing","latLongToOsGridRef","osGridRefToLatLong","LOCATION_FIELD_SELECTOR","getInitMapConfig","locationField","locationType","dataset","locationtype","getInitLatLongMapConfig","getInitEastingNorthingMapConfig","getInitOsGridRefMapConfig","Error","validateLatLong","strLat","strLong","lat","trim","Number","long","valid","latMin","latMax","longMin","longMax","latInBounds","longInBounds","value","validateEastingNorthing","strEasting","strNorthing","easting","northing","eastingMin","eastingMax","northingMin","northingMax","validateOsGridRef","osGridRef","pattern","match","exec","getLatLongInputs","inputs","querySelectorAll","length","latInput","longInput","getEastingNorthingInputs","eastingInput","northingInput","getOsGridRefInput","input","querySelector","getInitMapCenterConfig","center","zoom","markers","id","coords","result","undefined","latlong","osGridRefInput","bindLatLongField","map","mapProvider","on","interactMarkerChange","onInteractMarkerChange","e","maxPrecision","toFixed","onUpdateInputs","addEventListener","bindEastingNorthingField","point","bindOsGridRefField","onUpdateInput","processLocation","config","location","index","HTMLDivElement","locationInputs","supportedLocations","includes","mapContainer","document","createElement","mapId","setAttribute","initConfig","after","interactPlugin","mapReady","onMapReady","addPanel","showLabel","label","mobile","slot","open","dismissible","modal","tablet","desktop","html","enable"],"sources":["../../../src/client/javascripts/location-map.js"],"sourcesContent":["import {\n EVENTS,\n centerMap,\n createMap,\n defaultConfig,\n eastingNorthingToLatLong,\n latLongToEastingNorthing,\n latLongToOsGridRef,\n osGridRefToLatLong\n} from '~/src/client/javascripts/map.js'\n\nconst LOCATION_FIELD_SELECTOR = 'input.govuk-input'\n\n/**\n * Gets initial map config for a location field\n * @param {HTMLDivElement} locationField - the location field element\n */\nfunction getInitMapConfig(locationField) {\n const locationType = locationField.dataset.locationtype\n\n switch (locationType) {\n case 'latlongfield':\n return getInitLatLongMapConfig(locationField)\n case 'eastingnorthingfield':\n return getInitEastingNorthingMapConfig(locationField)\n case 'osgridreffield':\n return getInitOsGridRefMapConfig(locationField)\n default:\n throw new Error('Not implemented')\n }\n}\n\n/**\n * Validates lat and long is numeric and within UK bounds\n * @param {string} strLat - the latitude string\n * @param {string} strLong - the longitude string\n * @returns {{ valid: false } | { valid: true, value: { lat: number, long: number } }}\n */\nfunction validateLatLong(strLat, strLong) {\n const lat = strLat.trim() && Number(strLat.trim())\n const long = strLong.trim() && Number(strLong.trim())\n\n if (!lat || !long) {\n return { valid: false }\n }\n\n const latMin = 49.85\n const latMax = 60.859\n const longMin = -13.687\n const longMax = 1.767\n\n const latInBounds = lat >= latMin && lat <= latMax\n const longInBounds = long >= longMin && long <= longMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { lat, long } }\n}\n\n/**\n * Validates easting and northing is numeric and within UK bounds\n * @param {string} strEasting - the easting string\n * @param {string} strNorthing - the northing string\n * @returns {{ valid: false } | { valid: true, value: { easting: number, northing: number } }}\n */\nfunction validateEastingNorthing(strEasting, strNorthing) {\n const easting = strEasting.trim() && Number(strEasting.trim())\n const northing = strNorthing.trim() && Number(strNorthing.trim())\n\n if (!easting || !northing) {\n return { valid: false }\n }\n\n const eastingMin = 0\n const eastingMax = 700000\n const northingMin = 0\n const northingMax = 1300000\n\n const latInBounds = easting >= eastingMin && easting <= eastingMax\n const longInBounds = northing >= northingMin && northing <= northingMax\n\n if (!latInBounds || !longInBounds) {\n return { valid: false }\n }\n\n return { valid: true, value: { easting, northing } }\n}\n\n/**\n * Validates OS grid reference is correct\n * @param {string} osGridRef - the OsGridRef\n * @returns {{ valid: false } | { valid: true, value: string }}\n */\nfunction validateOsGridRef(osGridRef) {\n if (!osGridRef) {\n return { valid: false }\n }\n\n const pattern =\n /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\\s?(([0-9]{3})\\s?([0-9]{3})|([0-9]{4})\\s?([0-9]{4})|([0-9]{5})\\s?([0-9]{5}))$/\n\n const match = pattern.exec(osGridRef)\n\n if (match === null) {\n return { valid: false }\n }\n\n return { valid: true, value: match[0] }\n}\n\n/**\n * Gets the inputs for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n */\nfunction getLatLongInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for lat and long')\n }\n\n const latInput = /** @type {HTMLInputElement} */ (inputs[0])\n const longInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { latInput, longInput }\n}\n\n/**\n * Gets the inputs for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n */\nfunction getEastingNorthingInputs(locationField) {\n const inputs = locationField.querySelectorAll(LOCATION_FIELD_SELECTOR)\n\n if (inputs.length !== 2) {\n throw new Error('Expected 2 inputs for easting and northing')\n }\n\n const eastingInput = /** @type {HTMLInputElement} */ (inputs[0])\n const northingInput = /** @type {HTMLInputElement} */ (inputs[1])\n\n return { eastingInput, northingInput }\n}\n\n/**\n * Gets the input for a OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n */\nfunction getOsGridRefInput(locationField) {\n const input = locationField.querySelector(LOCATION_FIELD_SELECTOR)\n\n if (input === null) {\n throw new Error('Expected 1 input for osgridref')\n }\n\n return /** @type {HTMLInputElement} */ (input)\n}\n\n/**\n * Get the initial map config for a center point\n * @param {MapCenter} center - the point\n */\nfunction getInitMapCenterConfig(center) {\n return {\n zoom: '16',\n center,\n markers: [\n {\n id: 'location',\n coords: center\n }\n ]\n }\n}\n\n/**\n * Gets initial map config for a latlong location field\n * @param {HTMLDivElement} locationField - the latlong location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitLatLongMapConfig(locationField) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for a easting/northing location field\n * @param {HTMLDivElement} locationField - the eastingnorthing location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitEastingNorthingMapConfig(locationField) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Gets initial map config for an OS grid reference location field\n * @param {HTMLDivElement} locationField - the osgridref location field element\n * @returns {InteractiveMapInitConfig | undefined}\n */\nfunction getInitOsGridRefMapConfig(locationField) {\n const osGridRefInput = getOsGridRefInput(locationField)\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (!result.valid) {\n return undefined\n }\n\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n return getInitMapCenterConfig(center)\n}\n\n/**\n * Bind a latlong field to the map\n * @param {HTMLDivElement} locationField - the latlong location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindLatLongField(locationField, map, mapProvider) {\n const { latInput, longInput } = getLatLongInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 7\n latInput.value = e.coords[1].toFixed(maxPrecision)\n longInput.value = e.coords[0].toFixed(maxPrecision)\n }\n )\n\n /**\n * Lat & long input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateLatLong(latInput.value, longInput.value)\n\n if (result.valid) {\n /** @type {MapCenter} */\n const center = [result.value.long, result.value.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n latInput.addEventListener('change', onUpdateInputs, false)\n longInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an eastingnorthing field to the map\n * @param {HTMLDivElement} locationField - the eastingnorthing location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindEastingNorthingField(locationField, map, mapProvider) {\n const { eastingInput, northingInput } =\n getEastingNorthingInputs(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const maxPrecision = 0\n const point = latLongToEastingNorthing({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n eastingInput.value = point.easting.toFixed(maxPrecision)\n northingInput.value = point.northing.toFixed(maxPrecision)\n }\n )\n\n /**\n * Easting & northing input change event listener\n * Update the map view location when the inputs are changed\n */\n function onUpdateInputs() {\n const result = validateEastingNorthing(\n eastingInput.value,\n northingInput.value\n )\n\n if (result.valid) {\n const latlong = eastingNorthingToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n eastingInput.addEventListener('change', onUpdateInputs, false)\n northingInput.addEventListener('change', onUpdateInputs, false)\n}\n\n/**\n * Bind an OS grid reference field to the map\n * @param {HTMLDivElement} locationField - the osgridref location field\n * @param {InteractiveMap} map - the map component instance (of InteractiveMap)\n * @param {MapLibreMap} mapProvider - the map provider instance (of MapLibreMap)\n */\nfunction bindOsGridRefField(locationField, map, mapProvider) {\n const osGridRefInput = getOsGridRefInput(locationField)\n\n map.on(\n EVENTS.interactMarkerChange,\n /**\n * Callback function which fires when the map marker changes\n * @param {object} e - the event\n * @param {[number, number]} e.coords - the map marker coordinates\n */\n function onInteractMarkerChange(e) {\n const point = latLongToOsGridRef({\n lat: e.coords[1],\n long: e.coords[0]\n })\n\n osGridRefInput.value = point\n }\n )\n\n /**\n * OS grid reference input change event listener\n * Update the map view location when the input is changed\n */\n function onUpdateInput() {\n const result = validateOsGridRef(osGridRefInput.value)\n\n if (result.valid) {\n const latlong = osGridRefToLatLong(result.value)\n\n /** @type {MapCenter} */\n const center = [latlong.long, latlong.lat]\n\n centerMap(map, mapProvider, center)\n }\n }\n\n osGridRefInput.addEventListener('change', onUpdateInput, false)\n}\n\n/**\n * Processes a location field to add map capability\n * @param {MapsEnvironmentConfig} config - the location field element\n * @param {Element} location - the location field element\n * @param {number} index - the 0-based index\n */\nexport function processLocation(config, location, index) {\n if (!(location instanceof HTMLDivElement)) {\n return\n }\n\n const locationInputs = location.querySelector('.app-location-field-inputs')\n if (!(locationInputs instanceof HTMLDivElement)) {\n return\n }\n const locationType = location.dataset.locationtype\n\n // Check for support\n const supportedLocations = [\n 'latlongfield',\n 'eastingnorthingfield',\n 'osgridreffield'\n ]\n if (!locationType || !supportedLocations.includes(locationType)) {\n return\n }\n\n const mapContainer = document.createElement('div')\n const mapId = `map_${index}`\n\n mapContainer.setAttribute('id', mapId)\n mapContainer.setAttribute('class', 'map-container')\n\n const initConfig = getInitMapConfig(location) ?? defaultConfig\n\n locationInputs.after(mapContainer)\n\n const { map, interactPlugin } = createMap(mapId, initConfig, config)\n\n map.on(\n EVENTS.mapReady,\n /**\n * Callback function which fires when the map is ready\n * @param {object} e - the event\n * @param {MapLibreMap} e.map - the map provider instance\n */\n function onMapReady(e) {\n switch (locationType) {\n case 'latlongfield':\n bindLatLongField(location, map, e.map)\n break\n case 'eastingnorthingfield':\n bindEastingNorthingField(location, map, e.map)\n break\n case 'osgridreffield':\n bindOsGridRefField(location, map, e.map)\n break\n default:\n throw new Error('Not implemented')\n }\n\n // Add info panel\n map.addPanel('info', {\n showLabel: true,\n label: 'How to use the map',\n mobile: {\n slot: 'bottom',\n open: true,\n dismissible: true,\n modal: false\n },\n tablet: {\n slot: 'bottom',\n open: true,\n dismissible: true,\n modal: false\n },\n desktop: {\n slot: 'bottom',\n open: true,\n dismissible: true,\n modal: false\n },\n html: 'If using a map click on a point to update the location.<br><br>If using a keyboard, navigate to the point, centering the crosshair at the location and press enter.'\n })\n\n // Enable the interact plugin\n interactPlugin.enable()\n }\n )\n}\n\n/**\n * @import { InteractiveMap, InteractiveMapInitConfig, MapCenter, MapLibreMap, MapsEnvironmentConfig } from '~/src/client/javascripts/map.js'\n */\n"],"mappings":"AAAA,SACEA,MAAM,EACNC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,wBAAwB,EACxBC,wBAAwB,EACxBC,kBAAkB,EAClBC,kBAAkB;AAGpB,MAAMC,uBAAuB,GAAG,mBAAmB;;AAEnD;AACA;AACA;AACA;AACA,SAASC,gBAAgBA,CAACC,aAAa,EAAE;EACvC,MAAMC,YAAY,GAAGD,aAAa,CAACE,OAAO,CAACC,YAAY;EAEvD,QAAQF,YAAY;IAClB,KAAK,cAAc;MACjB,OAAOG,uBAAuB,CAACJ,aAAa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