Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ stats.json
.docusaurus
build
.playwright-mcp

# Copied into the engine packages when they are built
packages/*/assets
2 changes: 0 additions & 2 deletions assets/templates/add-polygons.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/datasets/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/map-key/dist/umd/index.js"></script>

Expand Down Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/add-symbols.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/datasets/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/map-key/dist/umd/index.js"></script>

Expand Down Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/basic-map.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>

<script>
new defra.InteractiveMap('map', {
behaviour: 'inline',
mapProvider: defra.maplibreProvider(),
mapStyle: {
url: 'https://tiles.openfreemap.org/styles/liberty',
attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/button-map.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>

<script>
new defra.InteractiveMap('map', {
behaviour: 'buttonFirst',
mapProvider: defra.maplibreProvider(),
mapStyle: {
url: 'https://tiles.openfreemap.org/styles/liberty',
attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/draw-tools.njk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/draw/dist/umd/index.js"></script>

Expand All @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/marker-panel.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>

<script>
Expand All @@ -47,7 +46,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',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/place-marker.njk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>

<script>
Expand All @@ -51,7 +50,6 @@

const map = new defra.InteractiveMap('map', {
behaviour: 'hybrid',
mapProvider: defra.maplibreProvider(),
mapStyle: {
url: 'https://tiles.openfreemap.org/styles/liberty',
attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/search-control.njk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/search/dist/umd/index.js"></script>

<script>
Expand Down Expand Up @@ -83,7 +82,6 @@

new defra.InteractiveMap('map', {
behaviour: 'inline',
mapProvider: defra.maplibreProvider(),
mapStyle: {
url: 'https://tiles.openfreemap.org/styles/liberty',
attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/select-feature.njk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/datasets/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>

Expand Down Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/style-switcher.njk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/map-styles/dist/umd/index.js"></script>

<script>
Expand Down Expand Up @@ -76,7 +75,6 @@

new defra.InteractiveMap('map', {
behaviour: 'inline',
mapProvider: defra.maplibreProvider(),
mapStyle: mapStyles[0],
center: [-0.1276, 51.5074],
zoom: 12,
Expand Down
2 changes: 0 additions & 2 deletions assets/templates/toggle-marker-label.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
{% block pageScripts %}
<!-- Defra library scripts -->
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>

<script>
Expand All @@ -47,7 +46,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',
Expand Down
49 changes: 26 additions & 23 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,51 +338,54 @@ new InteractiveMap('map', {

---

### `mapProvider`
**Type:** `function`
**Required**

A function that returns a map provider — the abstraction layer that interfaces with the underlying map engine. It is called only when the map is opened so the provider code is not sent to the user unless needed.

```js
new InteractiveMap('map', {
mapProvider: maplibreProvider()
})
```
### `mapProviderOptions`
**Type:** `Object`

#### MapLibre provider options
Settings for the map engine. Which settings apply depends on the package.

`maplibreProvider()` accepts an optional config object.
#### MapLibre (`@defra/interactive-map`)

##### `workerUrl`
**Type:** `string`
**Default:** `undefined`

URL of the MapLibre worker file. This is set automatically with webpack, Vite and the UMD build.
URL of the MapLibre worker file. This is set for you with webpack, Vite and the UMD scripts.

With other bundlers (such as Rollup and esbuild), copy `node_modules/maplibre-gl/dist/maplibre-gl-worker.mjs` to your assets and set its URL here. If it's missing, the console explains this.
With Rollup or esbuild, copy `node_modules/maplibre-gl/dist/maplibre-gl-worker.mjs` to your assets and set its URL here. If it's missing, the console explains this.

```js
maplibreProvider({ workerUrl: '/your-assets-path/maplibre-gl-worker.mjs' })
mapProviderOptions: { workerUrl: '/your-assets-path/maplibre-gl-worker.mjs' }
```

#### OpenLayers provider options
#### OpenLayers (`@defra/interactive-map-openlayers`)

`openLayersProvider()` accepts an optional config object. The provider renders in British National Grid (EPSG:27700) — this isn't configurable.
The map is always in British National Grid (EPSG:27700).

##### `zoomAlignment`
**Type:** `string`
**Default:** `'uk'`

Which zoom-level sequence the map's view resolutions follow.
Which zoom levels the map uses.

| Possible values | Description |
| :--- | :--- |
| `'uk'` | OS tile grid zoom levels (0–13); zoom 0 shows all of Great Britain. |
| `'world'` | ESRI LOD sequence, for zoom levels that match the ESRI SDK; full UK visible around zoom 7. |
| `'uk'` | OS tile grid zoom levels (0–13). Zoom 0 shows all of Great Britain. |
| `'world'` | The same zoom levels as the ArcGIS SDK. All of the UK shows at about zoom 7. |

```js
mapProviderOptions: { zoomAlignment: 'world' }
```

#### Esri (`@defra/interactive-map-esri`)

##### `setupConfig`
**Type:** `function`

Called with the ArcGIS SDK's `esriConfig` before the map is created, for example to set an API key.

```js
openLayersProvider({ zoomAlignment: 'world' })
mapProviderOptions: {
setupConfig: (esriConfig) => { esriConfig.apiKey = 'YOUR_API_KEY' }
}
```

---
Expand Down
4 changes: 0 additions & 4 deletions docs/examples/add-marker-with-panel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Add markers to the map and allow users to select them. Selecting a marker fires
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({
Expand All @@ -22,7 +21,6 @@ Add markers to the map and allow users to select them. Selecting a marker fires

const map = new InteractiveMap('my-map', {
behaviour: 'inline',
mapProvider: maplibreProvider(),
mapStyle: {
url: 'https://your-tile-url/style.json',
logo: '/path/to/logo.svg',
Expand Down Expand Up @@ -70,7 +68,6 @@ Add markers to the map and allow users to select them. Selecting a marker fires
language: 'html',
code: `
<script defer src="/your-assets-path/interactive-map/index.js"></script>
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>
<script defer src="/your-assets-path/interact-plugin/index.js"></script>

<script>
Expand All @@ -81,7 +78,6 @@ Add markers to the map and allow users to select them. Selecting a marker fires

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',
Expand Down
4 changes: 0 additions & 4 deletions docs/examples/add-polygons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Use the datasets plugin to overlay GeoJSON polygon data on your map. This exampl
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'

Expand Down Expand Up @@ -105,7 +104,6 @@ Use the datasets plugin to overlay GeoJSON polygon data on your map. This exampl

new InteractiveMap('my-map', {
behaviour: 'inline',
mapProvider: maplibreProvider(),
mapStyle: {
url: 'https://your-tile-url/style.json',
logo: '/path/to/logo.svg',
Expand All @@ -124,7 +122,6 @@ Use the datasets plugin to overlay GeoJSON polygon data on your map. This exampl
language: 'html',
code: `
<script defer src="/your-assets-path/interactive-map/index.js"></script>
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>
<script defer src="/your-assets-path/datasets-plugin/index.js"></script>
<script defer src="/your-assets-path/map-key-plugin/index.js"></script>

Expand Down Expand Up @@ -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',
Expand Down
4 changes: 0 additions & 4 deletions docs/examples/add-symbols.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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',
Expand All @@ -100,7 +98,6 @@ Use the datasets plugin to overlay GeoJSON data on your map. Each dataset can co
language: 'html',
code: `
<script defer src="/your-assets-path/interactive-map/index.js"></script>
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>
<script defer src="/your-assets-path/datasets-plugin/index.js"></script>
<script defer src="/your-assets-path/map-key-plugin/index.js"></script>

Expand Down Expand Up @@ -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',
Expand Down
4 changes: 0 additions & 4 deletions docs/examples/basic-map.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -35,13 +33,11 @@ Embed an interactive map directly on the page, allowing users to explore and int
language: 'html',
code: `
<script defer src="/your-assets-path/interactive-map/index.js"></script>
<script defer src="/your-assets-path/maplibre-provider/index.js"></script>

<script>
document.addEventListener('DOMContentLoaded', function () {
new defra.InteractiveMap('my-map', {
behaviour: 'inline',
mapProvider: defra.maplibreProvider(),
mapStyle: {
url: 'https://your-tile-url/style.json',
logo: '/path/to/logo.svg',
Expand Down
Loading
Loading