Skip to main content

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

Add a search control

Add a search control using the built-in OS Names API integration.

NOTE

The live demo below uses Nominatim (no API key required) — the code example uses OS Names, so results may differ slightly. Embedding the key in the URL is the simplest approach for prototyping; for production, transformRequest can be used to inject auth headers, or you may need to route requests through your own server-side proxy.

The map requires JavaScript to be enabled.
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({
osNamesURL: 'https://api.os.uk/search/names/v1/find?query={query}&key=YOUR_API_KEY',
width: '300px'
})
new InteractiveMap('my-map', {
behaviour: 'inline',
mapProvider: maplibreProvider(),
mapStyle: {
url: 'https://your-tile-url/style.json',
attribution: 'Your tile attribution'
},
center: [-1.6, 53.1],
zoom: 6,
containerHeight: '516px',
plugins: [searchPlugin]
})