diff --git a/.gitignore b/.gitignore index d7c6ab32..bc9bf190 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,6 @@ stats.json .docusaurus build .playwright-mcp + +# Copied into the engine packages when they are built +packages/*/assets diff --git a/assets/templates/add-polygons.njk b/assets/templates/add-polygons.njk index deb39600..896355b1 100644 --- a/assets/templates/add-polygons.njk +++ b/assets/templates/add-polygons.njk @@ -39,7 +39,6 @@ {% block pageScripts %} - @@ -132,7 +131,6 @@ new defra.InteractiveMap('map', { behaviour: 'inline', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://tiles.openfreemap.org/styles/liberty', attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap', diff --git a/assets/templates/add-symbols.njk b/assets/templates/add-symbols.njk index a6570f70..5cb82a5c 100644 --- a/assets/templates/add-symbols.njk +++ b/assets/templates/add-symbols.njk @@ -39,7 +39,6 @@ {% block pageScripts %} - @@ -108,7 +107,6 @@ new defra.InteractiveMap('map', { behaviour: 'inline', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://tiles.openfreemap.org/styles/liberty', attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap', diff --git a/assets/templates/basic-map.njk b/assets/templates/basic-map.njk index db9c1c6e..7372eaf0 100644 --- a/assets/templates/basic-map.njk +++ b/assets/templates/basic-map.njk @@ -37,12 +37,10 @@ {% block pageScripts %} - - - @@ -54,7 +53,6 @@ const interactiveMap = new defra.InteractiveMap('map', { behaviour: 'hybrid', - mapProvider: defra.maplibreProvider(), mapStyle: { id: 'default', url: 'https://tiles.openfreemap.org/styles/liberty', diff --git a/assets/templates/marker-panel.njk b/assets/templates/marker-panel.njk index 60f3000d..13d6e57e 100644 --- a/assets/templates/marker-panel.njk +++ b/assets/templates/marker-panel.njk @@ -37,7 +37,6 @@ {% block pageScripts %} - - - - @@ -113,7 +112,6 @@ const map = new defra.InteractiveMap('map', { behaviour: 'inline', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://tiles.openfreemap.org/styles/liberty', attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap', diff --git a/assets/templates/style-switcher.njk b/assets/templates/style-switcher.njk index d48cac90..e6baf1be 100644 --- a/assets/templates/style-switcher.njk +++ b/assets/templates/style-switcher.njk @@ -38,7 +38,6 @@ {% block pageScripts %} - - - - @@ -218,7 +215,6 @@ Use the datasets plugin to overlay GeoJSON polygon data on your map. This exampl new defra.InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', diff --git a/docs/examples/add-symbols.mdx b/docs/examples/add-symbols.mdx index 2c2b41b9..309159c2 100644 --- a/docs/examples/add-symbols.mdx +++ b/docs/examples/add-symbols.mdx @@ -13,7 +13,6 @@ Use the datasets plugin to overlay GeoJSON data on your map. Each dataset can co language: 'js', code: ` import InteractiveMap from '@defra/interactive-map' - import maplibreProvider from '@defra/interactive-map/providers/maplibre' import createDatasetsPlugin from '@defra/interactive-map/plugins/datasets' import createMapKeyPlugin from '@defra/interactive-map/plugins/map-key' @@ -81,7 +80,6 @@ Use the datasets plugin to overlay GeoJSON data on your map. Each dataset can co new InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', @@ -100,7 +98,6 @@ Use the datasets plugin to overlay GeoJSON data on your map. Each dataset can co language: 'html', code: ` - @@ -170,7 +167,6 @@ Use the datasets plugin to overlay GeoJSON data on your map. Each dataset can co new defra.InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', diff --git a/docs/examples/basic-map.mdx b/docs/examples/basic-map.mdx index 7a7372e5..49cfef06 100644 --- a/docs/examples/basic-map.mdx +++ b/docs/examples/basic-map.mdx @@ -13,11 +13,9 @@ Embed an interactive map directly on the page, allowing users to explore and int language: 'js', code: ` import InteractiveMap from '@defra/interactive-map' - import maplibreProvider from '@defra/interactive-map/providers/maplibre' new InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', @@ -35,13 +33,11 @@ Embed an interactive map directly on the page, allowing users to explore and int language: 'html', code: ` - - - @@ -174,7 +171,6 @@ This example configures snapping (`snapLayers`) against the base map style's woo const interactiveMap = new defra.InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', diff --git a/docs/examples/place-marker.mdx b/docs/examples/place-marker.mdx index 30f73ac3..75a62e75 100644 --- a/docs/examples/place-marker.mdx +++ b/docs/examples/place-marker.mdx @@ -3,12 +3,9 @@ import CodeTabs from '../../demo/js/codeTabs.js' # Place a marker to continue -Use the interact plugin's `placeMarker` mode to let users drop a location pin on the map before continuing a journey. +Use the interact plugin's `placeMarker` mode to let users drop a location pin on the map before continuing a journey. Two patterns work together in this example, depending on the screen size. -Two patterns work together in this example: - -- **Hybrid behaviour with built-in back and continue** — on mobile the map opens fullscreen and the `backAndContinue` option renders Back and Continue buttons inside the map. The Continue button is enabled declaratively via `continueEnabledWhen` once a marker has been placed. -- **External Continue button for inline** — when the map is inline (tablet/desktop), a Continue button sits outside the map container. It uses `app:opened`, `app:closed`, and `app:fullscreenchange` to show and hide in sync with the map's display mode, and `interact:markerchange` to enable once a marker is placed. +On mobile, the map opens fullscreen and the `backAndContinue` option adds Back and Continue buttons inside the map, with Continue enabled by `continueEnabledWhen` once a marker is placed. On tablet and desktop, the map is inline and a Continue button sits outside it. That button uses `app:opened`, `app:closed` and `app:fullscreenchange` to show and hide with the map, and `interact:markerchange` to enable once a marker is placed. @@ -18,7 +15,6 @@ Two patterns work together in this example: language: 'js', code: ` import InteractiveMap from '@defra/interactive-map' - import maplibreProvider from '@defra/interactive-map/providers/maplibre' import createInteractPlugin from '@defra/interactive-map/plugins/interact' const interactPlugin = createInteractPlugin({ @@ -27,7 +23,6 @@ Two patterns work together in this example: const map = new InteractiveMap('my-map', { behaviour: 'hybrid', - mapProvider: maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', @@ -87,7 +82,6 @@ Two patterns work together in this example: language: 'html', code: ` -
@@ -103,7 +97,6 @@ Two patterns work together in this example: const map = new defra.InteractiveMap('my-map', { behaviour: 'hybrid', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', diff --git a/docs/examples/search-control.mdx b/docs/examples/search-control.mdx index c8a56504..2998ba8f 100644 --- a/docs/examples/search-control.mdx +++ b/docs/examples/search-control.mdx @@ -17,7 +17,6 @@ This requires an OS Data Hub API key. Embedding the key in the URL is the simple language: 'js', code: ` import InteractiveMap from '@defra/interactive-map' - import maplibreProvider from '@defra/interactive-map/providers/maplibre' import createSearchPlugin from '@defra/interactive-map/plugins/search' const searchPlugin = createSearchPlugin({ @@ -27,7 +26,6 @@ This requires an OS Data Hub API key. Embedding the key in the URL is the simple new InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', @@ -46,7 +44,6 @@ This requires an OS Data Hub API key. Embedding the key in the URL is the simple language: 'html', code: ` - - @@ -212,7 +209,6 @@ The layer ID used here (`field-parcels`) comes from the datasets plugin — a da const map = new defra.InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: defra.maplibreProvider(), mapStyle: { url: 'https://your-tile-url/style.json', logo: '/path/to/logo.svg', diff --git a/docs/examples/style-switcher.mdx b/docs/examples/style-switcher.mdx index d802ad81..7c191aeb 100644 --- a/docs/examples/style-switcher.mdx +++ b/docs/examples/style-switcher.mdx @@ -17,7 +17,6 @@ The live demo uses OS Open Zoomstack tiles from OS Labs, which do not require an language: 'js', code: ` import InteractiveMap from '@defra/interactive-map' - import maplibreProvider from '@defra/interactive-map/providers/maplibre' import createMapStylesPlugin from '@defra/interactive-map/plugins/map-styles' const mapStyles = [ @@ -58,7 +57,6 @@ The live demo uses OS Open Zoomstack tiles from OS Labs, which do not require an new InteractiveMap('my-map', { behaviour: 'inline', - mapProvider: maplibreProvider(), mapStyle: mapStyles[0], center: [-0.1276, 51.5074], zoom: 12, @@ -72,7 +70,6 @@ The live demo uses OS Open Zoomstack tiles from OS Labs, which do not require an language: 'html', code: ` - - + + + +``` -### Webpack +The Esri package can only be used with a bundler. -```js -import webpack from 'webpack' +## Content Security Policy -export default { - // ... - plugins: [ - new webpack.IgnorePlugin({ resourceRegExp: /^(ol|proj4|@arcgis\/core)(\/|$)/ }) - ] -} -``` +`@defra/interactive-map` and `@defra/interactive-map-openlayers` work under a strict Content Security Policy (CSP). The Esri package doesn't. -### Vite +Serve the map's files from your own site. For scripts, use either: -This applies to production builds; the dev server only warns. +- `script-src 'self'` +- a nonce on each of the map's ` - - + + - - -
- + ] + }) + + ``` - -> [!NOTE] -> Load the scripts with `defer` and create the map inside a `DOMContentLoaded` listener, as above, so the page isn't blocked while they download. Don't use `async`, as the scripts must run in order. -> -> Scripts are loaded dynamically — all files in each `umd/` folder must be served from the same directory as their `index.js`. - -## Using plugins - -**ESM** — add the plugin import alongside your existing core imports, then pass it to `plugins`: - -```js -import createInteractPlugin from '@defra/interactive-map/plugins/interact' - -const interactiveMap = new InteractiveMap('map', { - // ...your existing options - plugins: [createInteractPlugin()] -}) -``` - -**UMD** — copy the plugin's `dist/umd/` folder to your assets if you haven't already, then add its script to your page skeleton: - -```html - -``` - -Then pass the plugin in your initialisation: - -```js -const interactiveMap = new defra.InteractiveMap('map', { - // ...your existing options - plugins: [defra.interactPlugin()] -}) -``` - -The datasets, draw, frame, map-key, map-styles, menu, scale-bar and search plugins also have their own CSS. With ESM, import it alongside the plugin, for example `import '@defra/interactive-map/plugins/datasets/css'`. With UMD, copy the plugin's `dist/css/index.css` to your assets and add it to your page with a ``. diff --git a/docs/plugins/datasets.md b/docs/plugins/datasets.md index 33a2439b..73e95de8 100644 --- a/docs/plugins/datasets.md +++ b/docs/plugins/datasets.md @@ -2,11 +2,8 @@ The datasets plugin renders GeoJSON and vector tile datasets on the map, with support for polygon, line, and symbol (point) layer types, sublayer style rules, layer visibility toggling, and runtime style and data updates. -> [!IMPORTANT] -> **Upgrading?** This plugin no longer renders key of symbols itself — that button and panel have been removed. Add the [Map Key](./map-key.md) plugin to restore it. Your `showInKey` config is unaffected and needs no changes. - -> [!IMPORTANT] -> **Using a bundler (ESM)?** This plugin includes adapters for more than one map provider, so your bundler needs to ignore the map engines you haven't installed. See [Bundler configuration](../getting-started.md#bundler-configuration-esm). +> [!NOTE] +> To show a key of the datasets' symbols, also add the [Map Key](./map-key.md) plugin. Datasets and sublayers with `showInKey: true` appear in the key. ## ESM usage @@ -66,7 +63,6 @@ const datasetsPlugin = defra.datasetsPlugin({ }) const interactiveMap = new defra.InteractiveMap('map', { - mapProvider: defra.maplibreProvider(), plugins: [datasetsPlugin] }) ``` diff --git a/docs/plugins/draw.md b/docs/plugins/draw.md index 2e14635c..905ab7e4 100644 --- a/docs/plugins/draw.md +++ b/docs/plugins/draw.md @@ -4,10 +4,10 @@ The draw plugin lets users draw and edit points, lines and polygons on the map. Hooks let you add your own checks at each stage: as vertices are placed, as the shape changes, and when it's finished. Use them to apply your own rules, help users fix or review their shapes, and attach your own data. -It works the same with the MapLibre and OpenLayers map providers. The plugin picks the right one from the `mapProvider` you pass to `InteractiveMap`, so there's nothing to configure. +It works the same with `@defra/interactive-map` (MapLibre) and `@defra/interactive-map-openlayers`. -> [!IMPORTANT] -> **Using a bundler (ESM)?** This plugin includes adapters for more than one map provider, so your bundler needs to ignore the map engines you haven't installed. See [Bundler configuration](../getting-started.md#bundler-configuration-esm). +> [!NOTE] +> `@defra/interactive-map-esri` has a separate draw plugin, imported the same way, with limited features. It only draws and edits polygons, and doesn't support the options, validation or most of the methods below. ## ESM usage @@ -30,7 +30,7 @@ interactiveMap.on('map:ready', () => { ## UMD usage -Copy the entire `plugins/draw/dist/umd/` directory to `/your-assets-path/plugins/draw/umd/`. The plugin uses dynamic imports to load MapLibre or OpenLayers support on demand, so all files in the directory must be served from the same location. Then add the script tag: +Copy the entire `plugins/draw/dist/umd/` directory to `/your-assets-path/plugins/draw/umd/`. The plugin loads the rest of its files when it's used, so all files in the directory must be served from the same location. Then add the script tag: ```html @@ -40,7 +40,6 @@ Copy the entire `plugins/draw/dist/umd/` directory to `/your-assets-path/plugins const drawPlugin = defra.drawPlugin() const interactiveMap = new defra.InteractiveMap('map', { - mapProvider: defra.maplibreProvider(), plugins: [drawPlugin] }) ``` diff --git a/docs/plugins/map-key.md b/docs/plugins/map-key.md index a0c4a5ce..04a5d20b 100644 --- a/docs/plugins/map-key.md +++ b/docs/plugins/map-key.md @@ -69,7 +69,6 @@ const datasetsPlugin = defra.datasetsPlugin({ const mapKeyPlugin = defra.mapKeyPlugin() const interactiveMap = new defra.InteractiveMap('map', { - mapProvider: defra.maplibreProvider(), plugins: [datasetsPlugin, mapKeyPlugin] }) ``` diff --git a/docs/upgrading-to-v1.md b/docs/upgrading-to-v1.md new file mode 100644 index 00000000..9010d95f --- /dev/null +++ b/docs/upgrading-to-v1.md @@ -0,0 +1,102 @@ +# Upgrading to v1 + +In v1, each map engine has its own package, and the package sets up the map engine for you. You no longer pass a map provider or tell your bundler to ignore the engines you don't use. + +## 1. Change package if you use OpenLayers or Esri + +`@defra/interactive-map` now uses MapLibre only. If you use another engine, install its package instead: + +| You used | Install | +|---|---| +| `maplibreProvider` | `@defra/interactive-map` | +| `openLayersProvider` | `@defra/interactive-map-openlayers` | +| `esriProvider` | `@defra/interactive-map-esri` | + +Each package installs its own map engine, so you no longer need to install `ol`, `proj4` or `@arcgis/core` yourself. The Esri package can only be used with a bundler. + +## 2. With a bundler + +### Change your imports + +All three packages have the same imports, so only the package name changes. For example: + +```js +// Before +import createDatasetsPlugin from '@defra/interactive-map/plugins/datasets' + +// After, with OpenLayers +import createDatasetsPlugin from '@defra/interactive-map-openlayers/plugins/datasets' +``` + +With Esri, the draw plugin has moved from `plugins/draw-es` to `plugins/draw`. The provider's CSS is now part of `@defra/interactive-map-esri/css`, so remove the `providers/esri/css` import. + +### Remove the map provider + +Remove the provider import and the `mapProvider` option. If you passed settings to the provider, pass them in [`mapProviderOptions`](./api.md#mapprovideroptions) instead: + +```js +// Before +import InteractiveMap from '@defra/interactive-map' +import maplibreProvider from '@defra/interactive-map/providers/maplibre' + +const interactiveMap = new InteractiveMap('map', { + mapProvider: maplibreProvider({ workerUrl: '/your-assets-path/maplibre-gl-worker.mjs' }) +}) + +// After +import InteractiveMap from '@defra/interactive-map' + +const interactiveMap = new InteractiveMap('map', { + mapProviderOptions: { workerUrl: '/your-assets-path/maplibre-gl-worker.mjs' } +}) +``` + +### Remove the engine ignore rules from your bundler config + +Remove the config that told your bundler to ignore the map engines you don't use, such as webpack's `IgnorePlugin` or the `external` option in Vite, Rollup or esbuild. Each package only includes its own engine, so it's no longer needed. + +The MapLibre worker setup for Rollup and esbuild hasn't changed. See [Rollup and esbuild](./getting-started.md#rollup-and-esbuild). + +## 3. Without a bundler + +### Copy the new scripts and CSS + +Replace the map's and plugins' scripts and CSS in your assets with the ones from your v1 package. With OpenLayers, copy them from `@defra/interactive-map-openlayers`. Keep each folder's files together, as the map loads the rest of its scripts when it opens. + +### Remove the map provider + +Remove the provider's ` + + + + + + +``` + +If you passed settings to the provider, such as `zoomAlignment` with OpenLayers, pass them in [`mapProviderOptions`](./api.md#mapprovideroptions) instead: + +```js +// Before +mapProvider: defra.openLayersProvider({ zoomAlignment: 'world' }) + +// After +mapProviderOptions: { zoomAlignment: 'world' } +``` diff --git a/docusaurus.config.cjs b/docusaurus.config.cjs index 51c32304..a7076585 100644 --- a/docusaurus.config.cjs +++ b/docusaurus.config.cjs @@ -134,9 +134,11 @@ const config = { sidebar: [ { text: 'Installation', href: '/getting-started#installation' }, { text: 'GOV.UK Prototype kit', href: '/getting-started#govuk-prototype-kit' }, - { text: 'Manual setup', href: '/getting-started#manual-setup' }, - { text: 'Basic usage', href: '/getting-started#basic-usage' }, - { text: 'Using plugins', href: '/getting-started#using-plugins' } + { text: 'With a bundler', href: '/getting-started#setting-up-a-map-with-a-bundler' }, + { text: 'Without a bundler', href: '/getting-started#setting-up-a-map-without-a-bundler' }, + { text: 'Content Security Policy', href: '/getting-started#content-security-policy' }, + { text: 'Using plugins', href: '/getting-started#using-plugins' }, + { text: 'Upgrading to v1', href: '/upgrading-to-v1' } ], }, { diff --git a/engines.mjs b/engines.mjs index 64bac59c..fde7812d 100644 --- a/engines.mjs +++ b/engines.mjs @@ -21,6 +21,7 @@ const DRAW_ADAPTER = 'plugins/draw/src/adapters/loadDrawAdapter.js' * bundled with its plugin and no other engine is referenced. * - providerChunk: the name of the provider's lazy file in the core build * - umd: whether the package has UMD scripts + * - copy: folders copied into the package as they are, such as the GOV.UK Prototype Kit templates */ export const ENGINES = { maplibre: { @@ -32,7 +33,8 @@ export const ENGINES = { [DRAW_ADAPTER]: 'plugins/draw/src/adapters/maplibre/loadDrawAdapter.js' }, providerChunk: { maplibreProvider: 'im-maplibre-provider' }, - umd: true + umd: true, + copy: ['assets'] }, openlayers: { exclude: [...ENGINE_PROVIDERS, 'plugins/draw-es'], @@ -43,7 +45,8 @@ export const ENGINES = { [DRAW_ADAPTER]: 'plugins/draw/src/adapters/openlayers/loadDrawAdapter.js' }, providerChunk: { openlayersProvider: 'im-openlayers-provider' }, - umd: true + umd: true, + copy: [] }, // Esri's draw is its own, more basic plugin, published at the same path as the others' esri: { @@ -54,7 +57,8 @@ export const ENGINES = { [DATASETS_ADAPTER]: 'plugins/datasets/src/adapters/esri/importLayerAdapter.js' }, providerChunk: { esriProvider: 'im-esri-provider' }, - umd: false + umd: false, + copy: [] } } diff --git a/govuk-prototype-kit.config.json b/govuk-prototype-kit.config.json deleted file mode 100644 index c4beb1a2..00000000 --- a/govuk-prototype-kit.config.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "templates": [ - { - "name": "Basic map", - "path": "/assets/templates/basic-map.njk", - "type": "nunjucks" - }, - { - "name": "Map with marker and panel", - "path": "/assets/templates/marker-panel.njk", - "type": "nunjucks" - }, - { - "name": "Button-triggered map", - "path": "/assets/templates/button-map.njk", - "type": "nunjucks" - }, - { - "name": "Toggle marker label", - "path": "/assets/templates/toggle-marker-label.njk", - "type": "nunjucks" - }, - { - "name": "Place a marker to continue", - "path": "/assets/templates/place-marker.njk", - "type": "nunjucks" - }, - { - "name": "Add a search control", - "path": "/assets/templates/search-control.njk", - "type": "nunjucks" - }, - { - "name": "Select a feature", - "path": "/assets/templates/select-feature.njk", - "type": "nunjucks" - }, - { - "name": "Change map style", - "path": "/assets/templates/style-switcher.njk", - "type": "nunjucks" - }, - { - "name": "Draw tools", - "path": "/assets/templates/draw-tools.njk", - "type": "nunjucks" - }, - { - "name": "Add symbols", - "path": "/assets/templates/add-symbols.njk", - "type": "nunjucks" - }, - { - "name": "Add polygons", - "path": "/assets/templates/add-polygons.njk", - "type": "nunjucks" - } - ], - "assets": [ - "/assets/", - "/dist/css/", - "/dist/umd/", - "/providers/maplibre/dist", - "/plugins/interact/dist", - "/plugins/search/dist", - "/plugins/draw/dist", - "/providers/open-names/dist", - "/providers/openlayers/dist", - "/plugins/datasets/dist", - "/plugins/map-key/dist", - "/plugins/menu/dist", - "/plugins/map-styles/dist", - "/plugins/scale-bar/dist", - "/plugins/use-location/dist", - "/plugins/frame/dist" - ] -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 24c43790..ccc6ff08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -94,49 +94,6 @@ "webpack-dev-server": "^5.2.2", "webpack-merge": "^6.0.1", "webpack-remove-empty-scripts": "^1.1.1" - }, - "peerDependencies": { - "@arcgis/core": "^5.0.9", - "ol": "^10.10.0", - "proj4": "^2.20.8" - }, - "peerDependenciesMeta": { - "@arcgis/core": { - "optional": true - }, - "ol": { - "optional": true - }, - "proj4": { - "optional": true - } - } - }, - "../../docusaurus-govuk": { - "name": "docusaurus-theme-govuk", - "version": "0.1.0", - "extraneous": true, - "license": "MIT", - "dependencies": { - "@mdx-js/react": "^3.0.0", - "@not-govuk/simple-components": "^0.17.3", - "clsx": "^2.0.0", - "copy-webpack-plugin": "^11.0.0", - "css-loader": "^7.1.0", - "govuk-frontend": "^5.14.0", - "postcss-loader": "^8.2.0", - "prism-react-renderer": "^2.3.0", - "sass": "^1.97.0", - "sass-loader": "^16.0.0", - "style-loader": "^4.0.0" - }, - "engines": { - "node": ">=18.0" - }, - "peerDependencies": { - "@docusaurus/core": "^3.0.0", - "react": "^18.0.0 || ^19.0.0", - "react-dom": "^18.0.0 || ^19.0.0" } }, "node_modules/@adobe/css-tools": { diff --git a/package.json b/package.json index e1a13a2d..4bb6a1a8 100755 --- a/package.json +++ b/package.json @@ -7,79 +7,6 @@ "type": "git", "url": "https://github.com/DEFRA/interactive-map" }, - "main": "dist/umd/index.js", - "module": "dist/esm/index.js", - "exports": { - ".": { - "import": "./dist/esm/index.js", - "require": "./dist/umd/index.js" - }, - "./providers/maplibre": { - "import": "./providers/maplibre/dist/esm/index.js", - "require": "./providers/maplibre/dist/umd/index.js" - }, - "./providers/open-names": { - "import": "./providers/open-names/dist/esm/index.js", - "require": "./providers/open-names/dist/umd/index.js" - }, - "./providers/esri": { - "import": "./providers/esri/dist/esm/index.js" - }, - "./providers/openlayers": { - "import": "./providers/openlayers/dist/esm/index.js", - "require": "./providers/openlayers/dist/umd/index.js" - }, - "./plugins/scale-bar": { - "import": "./plugins/scale-bar/dist/esm/index.js", - "require": "./plugins/scale-bar/dist/umd/index.js" - }, - "./plugins/use-location": { - "import": "./plugins/use-location/dist/esm/index.js", - "require": "./plugins/use-location/dist/umd/index.js" - }, - "./plugins/search": { - "import": "./plugins/search/dist/esm/index.js", - "require": "./plugins/search/dist/umd/index.js" - }, - "./plugins/interact": { - "import": "./plugins/interact/dist/esm/index.js", - "require": "./plugins/interact/dist/umd/index.js" - }, - "./plugins/datasets": { - "import": "./plugins/datasets/dist/esm/index.js" - }, - "./plugins/menu": { - "import": "./plugins/menu/dist/esm/index.js" - }, - "./plugins/map-key": { - "import": "./plugins/map-key/dist/esm/index.js" - }, - "./plugins/map-styles": { - "import": "./plugins/map-styles/dist/esm/index.js", - "require": "./plugins/map-styles/dist/umd/index.js" - }, - "./plugins/draw-es": { - "import": "./plugins/draw-es/dist/esm/index.js" - }, - "./plugins/draw": { - "import": "./plugins/draw/dist/esm/index.js", - "require": "./plugins/draw/dist/umd/index.js" - }, - "./plugins/frame": { - "import": "./plugins/frame/dist/esm/index.js", - "require": "./plugins/frame/dist/umd/index.js" - }, - "./css": "./dist/css/index.css", - "./plugins/draw/css": "./plugins/draw/dist/css/index.css", - "./plugins/scale-bar/css": "./plugins/scale-bar/dist/css/index.css", - "./plugins/datasets/css": "./plugins/datasets/dist/css/index.css", - "./plugins/menu/css": "./plugins/menu/dist/css/index.css", - "./plugins/map-key/css": "./plugins/map-key/dist/css/index.css", - "./plugins/frame/css": "./plugins/frame/dist/css/index.css", - "./plugins/map-styles/css": "./plugins/map-styles/dist/css/index.css", - "./plugins/search/css": "./plugins/search/dist/css/index.css", - "./providers/esri/css": "./providers/esri/dist/css/index.css" - }, "type": "module", "sideEffects": [ "**/*.css", @@ -126,22 +53,6 @@ "node_modules" ] }, - "peerDependencies": { - "@arcgis/core": "^5.0.9", - "ol": "^10.10.0", - "proj4": "^2.20.8" - }, - "peerDependenciesMeta": { - "@arcgis/core": { - "optional": true - }, - "ol": { - "optional": true - }, - "proj4": { - "optional": true - } - }, "devDependencies": { "@arcgis/core": "^5.1.13", "@babel/core": "^7.28.0", diff --git a/packages/maplibre/govuk-prototype-kit.config.json b/packages/maplibre/govuk-prototype-kit.config.json index c317f15b..aff2d1a0 100644 --- a/packages/maplibre/govuk-prototype-kit.config.json +++ b/packages/maplibre/govuk-prototype-kit.config.json @@ -1,5 +1,6 @@ { "assets": [ + "/assets/images", "/dist", "/providers/open-names/dist", "/plugins/datasets/dist", @@ -12,5 +13,62 @@ "/plugins/scale-bar/dist", "/plugins/search/dist", "/plugins/use-location/dist" + ], + "templates": [ + { + "name": "Basic map", + "path": "/assets/templates/basic-map.njk", + "type": "nunjucks" + }, + { + "name": "Map with marker and panel", + "path": "/assets/templates/marker-panel.njk", + "type": "nunjucks" + }, + { + "name": "Button-triggered map", + "path": "/assets/templates/button-map.njk", + "type": "nunjucks" + }, + { + "name": "Toggle marker label", + "path": "/assets/templates/toggle-marker-label.njk", + "type": "nunjucks" + }, + { + "name": "Place a marker to continue", + "path": "/assets/templates/place-marker.njk", + "type": "nunjucks" + }, + { + "name": "Add a search control", + "path": "/assets/templates/search-control.njk", + "type": "nunjucks" + }, + { + "name": "Select a feature", + "path": "/assets/templates/select-feature.njk", + "type": "nunjucks" + }, + { + "name": "Change map style", + "path": "/assets/templates/style-switcher.njk", + "type": "nunjucks" + }, + { + "name": "Draw tools", + "path": "/assets/templates/draw-tools.njk", + "type": "nunjucks" + }, + { + "name": "Add symbols", + "path": "/assets/templates/add-symbols.njk", + "type": "nunjucks" + }, + { + "name": "Add polygons", + "path": "/assets/templates/add-polygons.njk", + "type": "nunjucks" + } ] } diff --git a/packages/maplibre/package.json b/packages/maplibre/package.json index 4bdc16c0..05f82add 100644 --- a/packages/maplibre/package.json +++ b/packages/maplibre/package.json @@ -72,6 +72,7 @@ "./package.json": "./package.json" }, "files": [ + "assets", "dist", "plugins", "providers", diff --git a/rollup.engine.mjs b/rollup.engine.mjs index fcc220c0..6d937a8e 100644 --- a/rollup.engine.mjs +++ b/rollup.engine.mjs @@ -1,8 +1,22 @@ // Builds each engine package's ESM files into packages//, reusing the normal ESM build // for every entry the engine includes (see engines.mjs). ENGINE= builds just that engine. +import fs from 'node:fs' + import { createESMConfig, ALL_BUILDS, MAP_ENGINE_EXTERNALS } from './rollup.esm.mjs' import { enginesToBuild, buildsForEngine, packageOutDir, adapterReplacements } from './engines.mjs' +// Copies the engine's copy folders into its package, replacing any earlier copy +const copyFoldersPlugin = (engineName, folders) => ({ + name: 'engine-copy-folders', + buildStart () { + folders.forEach(folder => { + const to = `packages/${engineName}/${folder}` + fs.rmSync(to, { recursive: true, force: true }) + fs.cpSync(folder, to, { recursive: true }) + }) + } +}) + // Resolves each runtime adapter lookup to the engine's own version const engineAdapterPlugin = (replacements) => ({ name: 'engine-adapter', @@ -21,6 +35,7 @@ export default enginesToBuild().flatMap(([engineName, engine]) => { const config = createESMConfig(b.entryPath, packageOutDir(engineName, engine, b.outDir), b.isCore || false, b.manualChunks || null, chunkNames) if (b.isCore) { config.external = [...config.external, ...MAP_ENGINE_EXTERNALS] + config.plugins.push(copyFoldersPlugin(engineName, engine.copy)) } config.plugins.unshift(engineAdapterPlugin(replacements)) return config