From 006e0f3de7a156ba807b84e0d04d4a84662f6842 Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 8 Jan 2026 13:03:28 +0000 Subject: [PATCH 1/7] Update OS API KEY config to inform it is used for both postcode lookup and maps --- src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/index.ts b/src/config/index.ts index d47f83dda..4aa94277f 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -301,7 +301,7 @@ export const config = convict({ }, ordnanceSurveyApiKey: { - doc: 'The ordnance survey api key used by the postcode lookup plugin', + doc: 'The ordnance survey api key used by the postcode lookup and maps plugin', format: String, nullable: true, default: undefined, From e082e08b2cb558455b605c3027383aa7295ec0ba Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 8 Jan 2026 13:04:00 +0000 Subject: [PATCH 2/7] Import maps clientside JS and initialise --- src/client/javascripts/application.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/javascripts/application.js b/src/client/javascripts/application.js index 5d5f074e8..c72199197 100644 --- a/src/client/javascripts/application.js +++ b/src/client/javascripts/application.js @@ -1,3 +1,4 @@ -import { initAll } from '@defra/forms-engine-plugin/shared.js' +import { initAll, initMaps } from '@defra/forms-engine-plugin/shared.js' initAll() +initMaps() From f0e3a028f994eabb8918b6957c9c3ff1ee3c1134 Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 8 Jan 2026 13:05:28 +0000 Subject: [PATCH 3/7] Copy defra-map UMD assets --- webpack.config.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index c9643be4c..b6bd2a7c1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,6 +14,10 @@ const govukFrontendPath = dirname( require.resolve('govuk-frontend/package.json') ) +const pluginPath = dirname( + require.resolve('@defra/forms-engine-plugin/package.json') +) + /** * @type {Configuration} */ @@ -172,7 +176,23 @@ export default { new WebpackAssetsManifest(), new CopyPlugin({ patterns: [ - { from: join(govukFrontendPath, 'dist/govuk/assets'), to: 'assets' } + { from: join(govukFrontendPath, 'dist/govuk/assets'), to: 'assets' }, + { + from: join(pluginPath, 'node_modules/@defra/defra-map/dist'), + to: 'assets/defra-map' + }, + { + from: join(pluginPath, 'node_modules/@defra/defra-map/providers'), + to: 'assets/defra-map/providers' + }, + { + from: join(pluginPath, 'node_modules/@defra/defra-map/plugins'), + to: 'assets/defra-map/plugins' + }, + { + from: join(pluginPath, 'node_modules/@defra/defra-map/assets'), + to: 'assets/defra-map/assets' + } ] }) ], @@ -185,5 +205,5 @@ export default { } /** - * @import { Configuration, NormalModule } from 'webpack' + * @import { Configuration } from 'webpack' */ From 998dc6a32971f3ba9b3c4d5777ba00d290c6d467 Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 8 Jan 2026 13:12:45 +0000 Subject: [PATCH 4/7] Include defra-maps styles in the main page layout --- src/server/views/layout.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/server/views/layout.html b/src/server/views/layout.html index 216b52979..830a1c4c0 100644 --- a/src/server/views/layout.html +++ b/src/server/views/layout.html @@ -32,6 +32,12 @@ + + + + + + {% endblock %} {% block pageTitle -%} @@ -156,6 +162,16 @@

Default page template

{% endblock %} {% block bodyEnd %} + + + + + + + + + + {% if config.googleAnalyticsTrackingId and cookieConsent.analytics === true %} From f6b6c28a298c561e59b8d65a38c27a569b1d21bd Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 8 Jan 2026 13:13:33 +0000 Subject: [PATCH 5/7] Update CSP to support defra-map --- src/server/plugins/blankie.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/plugins/blankie.ts b/src/server/plugins/blankie.ts index b589ba534..1ecacd4a7 100644 --- a/src/server/plugins/blankie.ts +++ b/src/server/plugins/blankie.ts @@ -29,6 +29,7 @@ export const configureBlankiePlugin = (): ServerRegisterPluginObject< fontSrc: ['self', 'data:'], connectSrc: [ ['self'], + ['https://raw.githubusercontent.com', 'https://api.os.uk'], gaTrackingId ? googleAnalyticsOptions.connectSrc : [], uploaderUrl ? [uploaderUrl] : [] ].flat(), @@ -38,10 +39,11 @@ export const configureBlankiePlugin = (): ServerRegisterPluginObject< ].flat(), styleSrc: ['self', 'unsafe-inline'], imgSrc: [ - ['self'], + ['self', 'data:'], gaTrackingId ? googleAnalyticsOptions.imgSrc : [] ].flat(), frameSrc: ['self', 'data:'], + workerSrc: ['self', 'blob:'], generateNonces: true } } From 0941c6dca1eadc62d34cb4f2efac1f902bd34f94 Mon Sep 17 00:00:00 2001 From: David Stone Date: Mon, 19 Jan 2026 17:06:29 +0000 Subject: [PATCH 6/7] Remove githubusercontent domain for map styles and sprites --- src/server/plugins/blankie.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/plugins/blankie.ts b/src/server/plugins/blankie.ts index 1ecacd4a7..d50d5ee60 100644 --- a/src/server/plugins/blankie.ts +++ b/src/server/plugins/blankie.ts @@ -29,7 +29,7 @@ export const configureBlankiePlugin = (): ServerRegisterPluginObject< fontSrc: ['self', 'data:'], connectSrc: [ ['self'], - ['https://raw.githubusercontent.com', 'https://api.os.uk'], + ['https://api.os.uk'], gaTrackingId ? googleAnalyticsOptions.connectSrc : [], uploaderUrl ? [uploaderUrl] : [] ].flat(), From f1e7a3c03fdde177c14bc3efdfe2acd49325df58 Mon Sep 17 00:00:00 2001 From: David Stone Date: Tue, 20 Jan 2026 10:48:58 +0000 Subject: [PATCH 7/7] Add maps feature flag --- src/client/javascripts/application.js | 3 +-- src/client/javascripts/maps.js | 3 +++ src/config/index.ts | 9 ++++++++- src/server/plugins/nunjucks/context.js | 3 ++- src/server/views/layout.html | 23 +++++++++++++---------- webpack.config.js | 3 +++ 6 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 src/client/javascripts/maps.js diff --git a/src/client/javascripts/application.js b/src/client/javascripts/application.js index c72199197..5d5f074e8 100644 --- a/src/client/javascripts/application.js +++ b/src/client/javascripts/application.js @@ -1,4 +1,3 @@ -import { initAll, initMaps } from '@defra/forms-engine-plugin/shared.js' +import { initAll } from '@defra/forms-engine-plugin/shared.js' initAll() -initMaps() diff --git a/src/client/javascripts/maps.js b/src/client/javascripts/maps.js new file mode 100644 index 000000000..0cc8ddab7 --- /dev/null +++ b/src/client/javascripts/maps.js @@ -0,0 +1,3 @@ +import { initMaps } from '@defra/forms-engine-plugin/shared.js' + +initMaps() diff --git a/src/config/index.ts b/src/config/index.ts index 4aa94277f..0a98ff720 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -306,7 +306,14 @@ export const config = convict({ nullable: true, default: undefined, env: 'ORDNANCE_SURVEY_API_KEY' - } as SchemaObj + } as SchemaObj, + + useMapsFeature: { + doc: 'Feature flag to control maps', + format: Boolean, + default: false, + env: 'USE_MAPS_FEATURE' + } }) config.validate({ allowed: 'strict' }) diff --git a/src/server/plugins/nunjucks/context.js b/src/server/plugins/nunjucks/context.js index 529fa01eb..116a08740 100644 --- a/src/server/plugins/nunjucks/context.js +++ b/src/server/plugins/nunjucks/context.js @@ -52,7 +52,8 @@ export function context(request) { phaseTag: config.get('phaseTag'), serviceBannerText: config.get('serviceBannerText'), serviceName: config.get('serviceName'), - serviceVersion: config.get('serviceVersion') + serviceVersion: config.get('serviceVersion'), + useMapsFeature: config.get('useMapsFeature') }, cspNonce: request?.plugins.blankie?.nonces?.script, currentPath: request ? `${request.path}${request.url.search}` : undefined, diff --git a/src/server/views/layout.html b/src/server/views/layout.html index 830a1c4c0..0e4551850 100644 --- a/src/server/views/layout.html +++ b/src/server/views/layout.html @@ -162,18 +162,21 @@

Default page template

{% endblock %} {% block bodyEnd %} - - - - - - - - - - + {% if config.useMapsFeature %} + + + + + + + + + + + {% endif %} + {% if config.googleAnalyticsTrackingId and cookieConsent.analytics === true %}