Skip to main content

alphaThis is a new frontend component. Help us improve it and give your feedback on Slack.

Map Styles Plugin

Adds a control for switching between basemap styles and, where the map provider supports it, changing the map size. The chosen style and size are saved in localStorage.

Usage

import createMapStylesPlugin from '@defra/interactive-map/plugins/map-styles'
const mapStylesPlugin = createMapStylesPlugin({
mapStyles: [
{
id: 'default',
label: 'Default',
url: '/styles/default.json',
thumbnail: '/images/default-thumb.png'
},
{
id: 'satellite',
label: 'Satellite',
url: '/styles/satellite.json',
thumbnail: '/images/satellite-thumb.png'
}
]
})
const interactiveMap = new InteractiveMap({
plugins: [mapStylesPlugin]
})

Options

Options are passed to the factory function when creating the plugin.


mapStyles

Type:
MapStyleConfig[] (required)

The basemap styles to choose from. Each style appears as an option in the style switcher.

See MapStyleConfig for full details.

createMapStylesPlugin({
mapStyles: [
{
id: 'outdoor',
label: 'Outdoor',
url: '/styles/outdoor.json',
appColorScheme: 'light',
mapColorScheme: 'light',
backgroundColor: '#f5f5f0',
thumbnail: '/images/outdoor-thumb.png'
},
{
id: 'dark',
label: 'Dark',
url: '/styles/dark.json',
appColorScheme: 'dark',
mapColorScheme: 'dark',
backgroundColor: '#1a1a1a',
thumbnail: '/images/dark-thumb.png'
}
]
})

manifest

Type:
Partial<PluginManifest>

Overrides for the plugin's buttons, panels and controls, matched by id. See PluginDescriptor.manifest.


Map size

When the active map provider supports map sizes (i.e. mapProvider.capabilities.supportsMapSizes is true), the panel also shows a map size control. This lets users choose between three size levels:

SizeDescription
smallDefault size
medium1.5× scale
large2× scale

Increasing the map size scales all features — labels, lines, polygons, and symbols — proportionally larger. If the map provider does not support this capability, the size control is not shown.


Persistence

The selected map style and map size are automatically saved to localStorage and restored on the next page load, keyed by the map instance ID. Users' choices therefore persist across sessions without any additional configuration.


Methods

This plugin does not expose any public methods.


Events


map:setstyle

Emitted when the user selects a map style.

Payload:
The full MapStyleConfig object for the selected style.
interactiveMap.on('map:setstyle', (mapStyle) => {
console.log('Style changed to:', mapStyle.id)
})

map:setsize

Emitted when the user selects a map size. Only fired when the map provider supports map sizes.

Payload:
'small' | 'medium' | 'large'
interactiveMap.on('map:setsize', (size) => {
console.log('Map size changed to:', size)
})