@defra/interactive-map 0.0.15-alpha → 0.0.17-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/css/docusaurus.css +104 -0
- package/assets/images/favicon.svg +1 -0
- package/assets/images/hero.png +0 -0
- package/assets/images/slot-map.svg +264 -0
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/slots.md +90 -6
- package/docs/api.md +4 -4
- package/docs/architecture.md +3 -1
- package/docs/{demo.mdx → examples.mdx} +1 -1
- package/docs/getting-started.md +5 -4
- package/docs/index.mdx +42 -0
- package/docs/plugins/datasets.md +561 -0
- package/docs/plugins/interact.md +176 -55
- package/docs/plugins/map-styles.md +64 -7
- package/docs/plugins/search.md +207 -63
- package/docs/plugins.md +8 -16
- package/docusaurus.config.cjs +34 -34
- package/jest.setup.js +1 -1
- package/package.json +6 -5
- package/plugins/beta/datasets/dist/css/index.css +85 -15
- package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/index.js +1 -1
- package/plugins/beta/datasets/src/DatasetsInit.jsx +24 -9
- package/plugins/beta/datasets/src/adapters/maplibre/index.js +18 -0
- package/plugins/beta/datasets/src/adapters/maplibre/layerBuilders.js +113 -0
- package/plugins/beta/datasets/src/adapters/maplibre/layerIds.js +69 -0
- package/plugins/beta/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +338 -0
- package/plugins/beta/datasets/src/adapters/maplibre/patternRegistry.js +48 -0
- package/plugins/beta/datasets/src/api/addDataset.js +3 -9
- package/plugins/beta/datasets/src/api/getOpacity.js +17 -0
- package/plugins/beta/datasets/src/api/getStyle.js +13 -0
- package/plugins/beta/datasets/src/api/removeDataset.js +3 -45
- package/plugins/beta/datasets/src/api/setData.js +8 -0
- package/plugins/beta/datasets/src/api/setDatasetVisibility.js +37 -0
- package/plugins/beta/datasets/src/api/setFeatureVisibility.js +22 -0
- package/plugins/beta/datasets/src/api/setOpacity.js +29 -0
- package/plugins/beta/datasets/src/api/setStyle.js +22 -0
- package/plugins/beta/datasets/src/datasets.js +33 -59
- package/plugins/beta/datasets/src/defaults.js +43 -9
- package/plugins/beta/datasets/src/fetch/createDynamicSource.js +39 -30
- package/plugins/beta/datasets/src/fetch/fetchGeoJSON.js +2 -2
- package/plugins/beta/datasets/src/manifest.js +27 -19
- package/plugins/beta/datasets/src/panels/Key.jsx +129 -49
- package/plugins/beta/datasets/src/panels/Key.module.scss +48 -9
- package/plugins/beta/datasets/src/panels/Layers.jsx +131 -29
- package/plugins/beta/datasets/src/panels/Layers.module.scss +50 -8
- package/plugins/beta/datasets/src/reducer.js +128 -9
- package/plugins/beta/datasets/src/styles/patterns.js +157 -0
- package/plugins/beta/datasets/src/utils/bbox.js +8 -6
- package/plugins/beta/datasets/src/utils/filters.js +5 -2
- package/plugins/beta/datasets/src/utils/mergeSublayer.js +78 -0
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/src/DrawInit.jsx +16 -16
- package/plugins/beta/draw-es/src/api/addFeature.js +3 -3
- package/plugins/beta/draw-es/src/api/deleteFeature.js +3 -3
- package/plugins/beta/draw-es/src/api/editFeature.js +3 -3
- package/plugins/beta/draw-es/src/api/newPolygon.js +3 -3
- package/plugins/beta/draw-es/src/events.js +52 -20
- package/plugins/beta/draw-es/src/events.test.js +301 -0
- package/plugins/beta/draw-es/src/graphic.js +1 -1
- package/plugins/beta/draw-es/src/manifest.js +4 -4
- package/plugins/beta/draw-es/src/reducer.js +1 -1
- package/plugins/beta/draw-es/src/sketchViewModel.js +1 -1
- package/plugins/beta/draw-ml/dist/css/index.css +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/src/DrawInit.jsx +49 -52
- package/plugins/beta/draw-ml/src/api/deleteFeature.js +1 -1
- package/plugins/beta/draw-ml/src/api/editFeature.js +8 -5
- package/plugins/beta/draw-ml/src/api/newLine.js +0 -1
- package/plugins/beta/draw-ml/src/api/newPolygon.js +0 -1
- package/plugins/beta/draw-ml/src/api/split.js +4 -4
- package/plugins/beta/draw-ml/src/defaults.js +1 -1
- package/plugins/beta/draw-ml/src/draw.scss +0 -7
- package/plugins/beta/draw-ml/src/events.js +8 -6
- package/plugins/beta/draw-ml/src/manifest.js +29 -29
- package/plugins/beta/draw-ml/src/mapboxDraw.js +1 -1
- package/plugins/beta/draw-ml/src/mapboxSnap.js +17 -18
- package/plugins/beta/draw-ml/src/modes/createDrawMode.js +31 -31
- package/plugins/beta/draw-ml/src/modes/disabledMode.js +1 -1
- package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +11 -11
- package/plugins/beta/draw-ml/src/modes/editVertex/undoHandlers.js +7 -7
- package/plugins/beta/draw-ml/src/modes/editVertex/vertexOperations.js +8 -8
- package/plugins/beta/draw-ml/src/modes/editVertex/vertexQueries.js +7 -7
- package/plugins/beta/draw-ml/src/modes/editVertexMode.js +32 -24
- package/plugins/beta/draw-ml/src/reducer.js +1 -1
- package/plugins/beta/draw-ml/src/undoStack.js +4 -4
- package/plugins/beta/draw-ml/src/utils/snapHelpers.js +12 -12
- package/plugins/beta/draw-ml/src/utils/spatial.js +11 -11
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/src/Frame.jsx +9 -9
- package/plugins/beta/frame/src/FrameInit.jsx +4 -4
- package/plugins/beta/frame/src/api/addFrame.js +1 -1
- package/plugins/beta/frame/src/api/editFeature.js +1 -1
- package/plugins/beta/frame/src/config.js +1 -1
- package/plugins/beta/frame/src/manifest.js +3 -3
- package/plugins/beta/frame/src/reducer.js +1 -1
- package/plugins/beta/frame/src/utils.js +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/src/MapStyles.jsx +18 -18
- package/plugins/beta/map-styles/src/manifest.js +1 -1
- package/plugins/beta/scale-bar/dist/css/index.css +1 -1
- package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/src/ScaleBar.jsx +5 -5
- package/plugins/beta/scale-bar/src/index.test.js +3 -3
- package/plugins/beta/scale-bar/src/manifest.js +3 -3
- package/plugins/beta/scale-bar/src/scaleBar.scss +2 -1
- package/plugins/beta/use-location/src/UseLocation.jsx +1 -1
- package/plugins/beta/use-location/src/defaults.js +1 -1
- package/plugins/beta/use-location/src/events.js +3 -3
- package/plugins/interact/dist/css/index.css +1 -1
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/src/InteractInit.jsx +1 -2
- package/plugins/interact/src/api/enable.js +8 -5
- package/plugins/interact/src/api/enable.test.js +2 -2
- package/plugins/interact/src/api/selectFeature.js +4 -4
- package/plugins/interact/src/api/unselectFeature.js +5 -5
- package/plugins/interact/src/defaults.js +0 -1
- package/plugins/interact/src/events.test.js +15 -15
- package/plugins/interact/src/hooks/useHighlightSync.js +1 -1
- package/plugins/interact/src/hooks/useInteractionHandlers.js +2 -2
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +5 -5
- package/plugins/interact/src/interact.scss +0 -7
- package/plugins/interact/src/manifest.js +15 -19
- package/plugins/interact/src/manifest.test.js +6 -5
- package/plugins/interact/src/reducer.js +3 -3
- package/plugins/interact/src/reducer.test.js +0 -1
- package/plugins/interact/src/utils/spatial.js +10 -10
- package/plugins/interact/src/utils/spatial.test.js +14 -14
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/esm/index.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/plugins/search/src/Search.jsx +7 -6
- package/plugins/search/src/Search.test.jsx +23 -23
- package/plugins/search/src/components/CloseButton/CloseButton.jsx +15 -15
- package/plugins/search/src/components/CloseButton/CloseButton.test.jsx +2 -2
- package/plugins/search/src/components/Form/Form.jsx +14 -14
- package/plugins/search/src/components/Form/Form.module.scss +2 -1
- package/plugins/search/src/components/Form/Form.test.jsx +11 -11
- package/plugins/search/src/components/OpenButton/OpenButton.jsx +16 -15
- package/plugins/search/src/components/OpenButton/OpenButton.test.jsx +6 -2
- package/plugins/search/src/components/SubmitButton/SubmitButton.jsx +15 -15
- package/plugins/search/src/components/Suggestions/Suggestions.jsx +6 -6
- package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +4 -4
- package/plugins/search/src/datasets.js +12 -13
- package/plugins/search/src/datasets.test.js +1 -1
- package/plugins/search/src/defaults.js +1 -1
- package/plugins/search/src/events/fetchSuggestions.js +3 -3
- package/plugins/search/src/events/fetchSuggestions.test.js +1 -1
- package/plugins/search/src/events/formHandlers.js +3 -3
- package/plugins/search/src/events/formHandlers.test.js +1 -1
- package/plugins/search/src/events/index.js +2 -2
- package/plugins/search/src/events/index.test.js +2 -2
- package/plugins/search/src/events/inputHandlers.js +4 -4
- package/plugins/search/src/events/inputHandlers.test.js +1 -1
- package/plugins/search/src/events/suggestionHandlers.js +2 -2
- package/plugins/search/src/events/suggestionHandlers.test.js +1 -1
- package/plugins/search/src/index.js +2 -1
- package/plugins/search/src/index.test.js +3 -3
- package/plugins/search/src/manifest.js +6 -4
- package/plugins/search/src/reducer.js +1 -2
- package/plugins/search/src/reducer.test.js +2 -2
- package/plugins/search/src/search.scss +10 -3
- package/plugins/search/src/utils/parseOsNamesResults.js +1 -2
- package/plugins/search/src/utils/parseOsNamesResults.test.js +2 -2
- package/plugins/search/src/utils/updateMap.js +1 -1
- package/plugins/search/src/utils/updateMap.test.js +5 -5
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/src/esriProvider.js +5 -5
- package/providers/beta/esri/src/utils/coords.js +1 -1
- package/providers/beta/esri/src/utils/esriFixes.js +1 -1
- package/providers/beta/esri/src/utils/query.js +4 -4
- package/providers/beta/esri/src/utils/spatial.js +1 -2
- package/providers/beta/esri/src/utils/spatial.test.js +4 -1
- package/providers/beta/open-names/src/utils/mapToLocationModel.test.js +1 -1
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/src/appEvents.test.js +1 -1
- package/providers/maplibre/src/index.js +1 -1
- package/providers/maplibre/src/index.test.js +3 -5
- package/providers/maplibre/src/mapEvents.test.js +15 -5
- package/providers/maplibre/src/maplibreProvider.test.js +6 -2
- package/providers/maplibre/src/utils/calculateLinearTextSize.js +4 -4
- package/providers/maplibre/src/utils/calculateLinearTextSize.test.js +3 -3
- package/providers/maplibre/src/utils/detectWebgl.test.js +1 -1
- package/providers/maplibre/src/utils/highlightFeatures.js +3 -2
- package/providers/maplibre/src/utils/highlightFeatures.test.js +13 -6
- package/providers/maplibre/src/utils/labels.js +19 -20
- package/providers/maplibre/src/utils/labels.test.js +15 -13
- package/providers/maplibre/src/utils/maplibreFixes.test.js +1 -1
- package/providers/maplibre/src/utils/queryFeatures.js +6 -6
- package/providers/maplibre/src/utils/queryFeatures.test.js +13 -13
- package/providers/maplibre/src/utils/spatial.js +0 -1
- package/providers/maplibre/src/utils/spatial.test.js +26 -27
- package/src/App/components/Actions/Actions.jsx +2 -2
- package/src/App/components/Actions/Actions.module.scss +0 -7
- package/src/App/components/Actions/Actions.test.jsx +1 -1
- package/src/App/components/Icon/Icon.jsx +3 -2
- package/src/App/components/Icon/Icon.module.scss +4 -0
- package/src/App/components/Icon/Icon.test.jsx +43 -4
- package/src/App/components/MapButton/MapButton.jsx +42 -17
- package/src/App/components/MapButton/MapButton.module.scss +4 -13
- package/src/App/components/MapButton/MapButton.test.jsx +27 -3
- package/src/App/components/PopupMenu/PopupMenu.jsx +51 -274
- package/src/App/components/PopupMenu/PopupMenu.module.scss +14 -7
- package/src/App/components/PopupMenu/PopupMenu.test.jsx +70 -1
- package/src/App/components/PopupMenu/usePopupMenu.js +258 -0
- package/src/App/hooks/useButtonStateEvaluator.js +12 -2
- package/src/App/hooks/useButtonStateEvaluator.test.js +38 -4
- package/src/App/hooks/useInterfaceAPI.js +6 -0
- package/src/App/hooks/useLayoutMeasurements.js +84 -18
- package/src/App/hooks/useLayoutMeasurements.test.js +124 -17
- package/src/App/layout/Layout.jsx +12 -7
- package/src/App/layout/Layout.test.jsx +2 -2
- package/src/App/layout/layout.module.scss +67 -29
- package/src/App/registry/pluginRegistry.js +17 -0
- package/src/App/registry/pluginRegistry.test.js +33 -0
- package/src/App/renderer/HtmlElementHost.jsx +2 -1
- package/src/App/renderer/HtmlElementHost.test.jsx +7 -7
- package/src/App/renderer/mapButtons.js +3 -2
- package/src/App/renderer/mapPanels.test.js +2 -2
- package/src/App/renderer/slotHelpers.js +2 -2
- package/src/App/renderer/slotHelpers.test.js +5 -5
- package/src/App/renderer/slots.js +9 -5
- package/src/App/store/AppProvider.jsx +3 -1
- package/src/App/store/AppProvider.test.jsx +1 -1
- package/src/App/store/ServiceProvider.jsx +3 -1
- package/src/App/store/appActionsMap.js +16 -0
- package/src/App/store/appActionsMap.test.js +27 -0
- package/src/App/store/appDispatchMiddleware.js +33 -1
- package/src/App/store/appDispatchMiddleware.test.js +250 -222
- package/src/App/store/appReducer.js +2 -0
- package/src/InteractiveMap/InteractiveMap.js +4 -0
- package/src/config/appConfig.js +7 -4
- package/src/config/events.js +28 -0
- package/src/scss/main.scss +1 -0
- package/src/scss/settings/_dimensions.scss +0 -1
- package/src/services/logger.js +6 -0
- package/src/services/logger.test.js +32 -0
- package/src/utils/getSafeZoneInset.js +9 -7
- package/src/utils/getSafeZoneInset.test.js +10 -10
- package/webpack.dev.mjs +23 -19
- package/docs/govuk-prototype.md +0 -23
- package/docs/index.md +0 -19
- package/plugins/beta/datasets/src/api/hideDataset.js +0 -14
- package/plugins/beta/datasets/src/api/hideFeatures.js +0 -41
- package/plugins/beta/datasets/src/api/showDataset.js +0 -14
- package/plugins/beta/datasets/src/api/showFeatures.js +0 -44
- package/plugins/beta/datasets/src/handleSetMapStyle.js +0 -54
- package/plugins/beta/datasets/src/mapLayers.js +0 -165
package/docs/plugins/search.md
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
# Search Plugin
|
|
2
2
|
|
|
3
|
-
Location search
|
|
3
|
+
Location search with autocomplete. Supports the OS Names API out of the box, and can be extended with custom datasets for searching addresses, features, or other geographic data.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
const searchPlugin = createSearchPlugin({
|
|
11
|
-
showMarker: true,
|
|
12
|
-
datasets: [
|
|
13
|
-
{
|
|
14
|
-
id: 'os-places',
|
|
15
|
-
url: '/api/search',
|
|
16
|
-
minChars: 3
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
})
|
|
8
|
+
import searchPlugin from '@defra/interactive-map/plugins/search'
|
|
20
9
|
|
|
21
10
|
const interactiveMap = new InteractiveMap({
|
|
22
|
-
plugins: [
|
|
11
|
+
plugins: [
|
|
12
|
+
searchPlugin({
|
|
13
|
+
osNamesURL: process.env.OS_NAMES_URL,
|
|
14
|
+
transformRequest: transformGeocodeRequest,
|
|
15
|
+
showMarker: true
|
|
16
|
+
})
|
|
17
|
+
]
|
|
23
18
|
})
|
|
24
19
|
```
|
|
25
20
|
|
|
@@ -29,48 +24,94 @@ Options are passed to the factory function when creating the plugin.
|
|
|
29
24
|
|
|
30
25
|
---
|
|
31
26
|
|
|
32
|
-
### `
|
|
33
|
-
**Type:** `
|
|
34
|
-
**Default:** `true`
|
|
27
|
+
### `osNamesURL`
|
|
28
|
+
**Type:** `string`
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
URL for the OS Names API, with a `{query}` placeholder. When provided, the plugin uses this as the primary search source.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
searchPlugin({
|
|
34
|
+
osNamesURL: 'https://api.os.uk/search/names/v1/find?query={query}&key=YOUR_KEY'
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
37
|
|
|
38
38
|
---
|
|
39
39
|
|
|
40
|
-
### `
|
|
41
|
-
**Type:** `
|
|
40
|
+
### `transformRequest`
|
|
41
|
+
**Type:** `Function`
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Async function called before each search request is sent. Use this to add authentication headers or modify the request. Receives the default request config and the query string, and should return a (modified) request config.
|
|
44
44
|
|
|
45
45
|
```js
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
searchPlugin({
|
|
47
|
+
transformRequest: async (request, query) => ({
|
|
48
|
+
...request,
|
|
49
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### `regions`
|
|
57
|
+
**Type:** `string[]`
|
|
58
|
+
**Default:** `['england', 'scotland', 'wales']`
|
|
59
|
+
|
|
60
|
+
Filters OS Names results to the specified UK regions. Values are matched case-insensitively against the country field in OS Names results.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
searchPlugin({
|
|
64
|
+
regions: ['england', 'wales']
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### `customDatasets`
|
|
71
|
+
**Type:** `CustomDataset[]`
|
|
72
|
+
|
|
73
|
+
Array of custom dataset configurations to extend or replace the built-in OS Names search. Each dataset defines how to fetch and parse results for a particular type of query.
|
|
74
|
+
|
|
75
|
+
See [Custom datasets](#custom-datasets) below for full details.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
searchPlugin({
|
|
79
|
+
customDatasets: [gridRefDataset, parcelDataset]
|
|
57
80
|
})
|
|
58
81
|
```
|
|
59
82
|
|
|
60
83
|
---
|
|
61
84
|
|
|
62
|
-
### `
|
|
85
|
+
### `showMarker`
|
|
63
86
|
**Type:** `boolean`
|
|
64
|
-
**Default:** `
|
|
87
|
+
**Default:** `true`
|
|
65
88
|
|
|
66
|
-
Whether the
|
|
89
|
+
Whether to place a marker on the map when a search result is selected.
|
|
67
90
|
|
|
68
91
|
---
|
|
69
92
|
|
|
70
93
|
### `markerColor`
|
|
71
94
|
**Type:** `string`
|
|
72
95
|
|
|
73
|
-
Colour of the search result marker.
|
|
96
|
+
Colour of the search result marker.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### `width`
|
|
101
|
+
**Type:** `string`
|
|
102
|
+
|
|
103
|
+
CSS width of the search input on tablet and desktop. For example `'300px'`.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### `expanded`
|
|
108
|
+
**Type:** `boolean`
|
|
109
|
+
**Default:** `false`
|
|
110
|
+
|
|
111
|
+
Controls whether the search input is always visible or hidden behind an open button.
|
|
112
|
+
|
|
113
|
+
- **Mobile** — by default the search is hidden and requires a button tap to open. When `expanded: true`, it moves to the banner slot and is shown inline at the top of the map at all times.
|
|
114
|
+
- **Tablet and desktop** — the search always sits in the `top-left` slot regardless of this setting, but setting `expanded: true` removes the open button so the input is immediately visible without interaction.
|
|
74
115
|
|
|
75
116
|
---
|
|
76
117
|
|
|
@@ -88,10 +129,117 @@ Array of mode identifiers. When set, the plugin does not render when the app is
|
|
|
88
129
|
|
|
89
130
|
---
|
|
90
131
|
|
|
132
|
+
## Custom datasets
|
|
133
|
+
|
|
134
|
+
Custom datasets let you add your own search sources alongside or instead of OS Names. Pass them via the `customDatasets` option as an array of dataset configuration objects.
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
const gridRefDataset = {
|
|
138
|
+
name: 'gridref',
|
|
139
|
+
includeRegex: /^[A-Z]{2}\d{6,10}$/i,
|
|
140
|
+
buildRequest: (query) => `https://api.example.com/gridref?q=${query}`,
|
|
141
|
+
parseResults: (json, query) => [{
|
|
142
|
+
id: query,
|
|
143
|
+
text: query,
|
|
144
|
+
marked: `<mark>${query}</mark> (Grid reference)`,
|
|
145
|
+
point: [json.lon, json.lat],
|
|
146
|
+
bounds: [json.minLon, json.minLat, json.maxLon, json.maxLat],
|
|
147
|
+
type: 'gridref'
|
|
148
|
+
}]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
searchPlugin({
|
|
152
|
+
customDatasets: [gridRefDataset]
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `CustomDataset` properties
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
#### `name`
|
|
161
|
+
**Type:** `string`
|
|
162
|
+
**Required**
|
|
163
|
+
|
|
164
|
+
Unique identifier for the dataset. Included as the `type` property in the `search:match` event payload, which lets you distinguish between results from different datasets.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
#### `buildRequest`
|
|
169
|
+
**Type:** `Function`
|
|
170
|
+
|
|
171
|
+
Function that takes the search query and returns a URL string or a `{ url, options }` fetch config object. Use this when you need custom URL construction or fetch options.
|
|
172
|
+
|
|
173
|
+
If omitted, `urlTemplate` is used instead.
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
buildRequest: (query) => ({
|
|
177
|
+
url: `https://api.example.com/search?q=${encodeURIComponent(query)}`,
|
|
178
|
+
options: { headers: { Accept: 'application/json' } }
|
|
179
|
+
})
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
#### `urlTemplate`
|
|
185
|
+
**Type:** `string`
|
|
186
|
+
|
|
187
|
+
URL template with a `{query}` placeholder. A simpler alternative to `buildRequest` for straightforward GET requests.
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
urlTemplate: 'https://api.example.com/search?q={query}'
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
#### `parseResults`
|
|
196
|
+
**Type:** `Function`
|
|
197
|
+
**Required**
|
|
198
|
+
|
|
199
|
+
Function that receives the parsed JSON response and the original query string, and returns an array of suggestion objects. Return an empty array if there are no results.
|
|
200
|
+
|
|
201
|
+
Each suggestion object must have:
|
|
202
|
+
|
|
203
|
+
| Property | Type | Description |
|
|
204
|
+
|----------|------|-------------|
|
|
205
|
+
| `id` | `string` | Unique identifier for the suggestion |
|
|
206
|
+
| `text` | `string` | Display text shown in the autocomplete list |
|
|
207
|
+
| `marked` | `string` | Optional. HTML string with query terms wrapped in `<mark>` tags. If omitted, the suggestion label will be blank |
|
|
208
|
+
| `point` | `[x, y]` | Centre coordinate for placing a marker |
|
|
209
|
+
| `bounds` | `[minX, minY, maxX, maxY]` | Bounding box to fit the map to when selected |
|
|
210
|
+
| `type` | `string` | Optional. Value to include in the `search:match` payload to identify the source dataset |
|
|
211
|
+
|
|
212
|
+
Any additional properties on the suggestion object are passed through in the `search:match` event payload.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
#### `includeRegex`
|
|
217
|
+
**Type:** `RegExp`
|
|
218
|
+
|
|
219
|
+
If provided, the dataset is only queried when the input matches this pattern. Useful for datasets that only apply to specific input formats (e.g. grid references, parcel IDs).
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
#### `excludeRegex`
|
|
224
|
+
**Type:** `RegExp`
|
|
225
|
+
|
|
226
|
+
If provided, the dataset is skipped when the input matches this pattern.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
#### `exclusive`
|
|
231
|
+
**Type:** `boolean`
|
|
232
|
+
|
|
233
|
+
When `true`, if this dataset returns results no other datasets will be queried. Useful for high-confidence lookups where you want to suppress the OS Names fallback.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
91
237
|
## Methods
|
|
92
238
|
|
|
93
239
|
This plugin does not expose any public methods.
|
|
94
240
|
|
|
241
|
+
---
|
|
242
|
+
|
|
95
243
|
## Events
|
|
96
244
|
|
|
97
245
|
Subscribe to events using `interactiveMap.on()`.
|
|
@@ -100,63 +248,59 @@ Subscribe to events using `interactiveMap.on()`.
|
|
|
100
248
|
|
|
101
249
|
### `search:match`
|
|
102
250
|
|
|
103
|
-
Emitted when a search result
|
|
251
|
+
Emitted when the user selects a search result.
|
|
104
252
|
|
|
105
253
|
**Payload:**
|
|
254
|
+
|
|
255
|
+
The full suggestion object returned by the dataset's `parseResults` function, plus the original `query` string. At minimum:
|
|
256
|
+
|
|
106
257
|
```js
|
|
107
258
|
{
|
|
108
|
-
query: '
|
|
109
|
-
|
|
259
|
+
query: 'NY7019', // The original search input
|
|
260
|
+
id: '...',
|
|
261
|
+
text: 'NY 701 924',
|
|
262
|
+
marked: '<mark>NY 701 924</mark> (Grid reference)',
|
|
110
263
|
point: [lng, lat],
|
|
111
|
-
bounds: [west, south, east, north]
|
|
264
|
+
bounds: [west, south, east, north],
|
|
265
|
+
type: 'gridref' // The dataset name, useful for distinguishing result types
|
|
266
|
+
// ...any other properties returned by parseResults
|
|
112
267
|
}
|
|
113
268
|
```
|
|
114
269
|
|
|
115
270
|
```js
|
|
116
|
-
interactiveMap.on('search:match', (
|
|
117
|
-
|
|
118
|
-
|
|
271
|
+
interactiveMap.on('search:match', (e) => {
|
|
272
|
+
if (e.type === 'parcel') {
|
|
273
|
+
interactPlugin.selectFeature({ featureId: e.properties.id, layerId: 'parcels' })
|
|
274
|
+
}
|
|
119
275
|
})
|
|
120
276
|
```
|
|
121
277
|
|
|
122
278
|
---
|
|
123
279
|
|
|
124
|
-
### `search:
|
|
280
|
+
### `search:clear`
|
|
125
281
|
|
|
126
|
-
Emitted when the search input is
|
|
282
|
+
Emitted when the search input is cleared.
|
|
127
283
|
|
|
128
284
|
**Payload:** None
|
|
129
285
|
|
|
130
286
|
```js
|
|
131
|
-
interactiveMap.on('search:
|
|
132
|
-
|
|
287
|
+
interactiveMap.on('search:clear', () => {
|
|
288
|
+
interactPlugin.unselectFeature({ featureId: selectedId })
|
|
133
289
|
})
|
|
134
290
|
```
|
|
135
291
|
|
|
136
292
|
---
|
|
137
293
|
|
|
138
|
-
### `search:
|
|
294
|
+
### `search:open`
|
|
139
295
|
|
|
140
|
-
Emitted when the search
|
|
296
|
+
Emitted when the open button is clicked to expand the search. Only applies when `expanded` is `false`, as that is the only case where an open button is rendered.
|
|
141
297
|
|
|
142
298
|
**Payload:** None
|
|
143
299
|
|
|
144
|
-
```js
|
|
145
|
-
interactiveMap.on('search:close', () => {
|
|
146
|
-
console.log('Search closed')
|
|
147
|
-
})
|
|
148
|
-
```
|
|
149
|
-
|
|
150
300
|
---
|
|
151
301
|
|
|
152
|
-
### `search:
|
|
302
|
+
### `search:close`
|
|
153
303
|
|
|
154
|
-
Emitted when the search
|
|
304
|
+
Emitted when the search is dismissed — via the close button, a click outside the search, or (on mobile only) after a suggestion is selected or the form is submitted.
|
|
155
305
|
|
|
156
306
|
**Payload:** None
|
|
157
|
-
|
|
158
|
-
```js
|
|
159
|
-
interactiveMap.on('search:clear', () => {
|
|
160
|
-
console.log('Search cleared')
|
|
161
|
-
})
|
|
162
|
-
```
|
package/docs/plugins.md
CHANGED
|
@@ -4,7 +4,7 @@ Plugins extend the InteractiveMap with additional functionality. This page lists
|
|
|
4
4
|
|
|
5
5
|
For guidance on building your own plugins, see [Building a Plugin](./building-a-plugin.md).
|
|
6
6
|
|
|
7
|
-
## Available
|
|
7
|
+
## Available plugins
|
|
8
8
|
|
|
9
9
|
The following plugins are available for use with InteractiveMap.
|
|
10
10
|
|
|
@@ -24,17 +24,17 @@ Scale bar display plugin that shows the current map scale.
|
|
|
24
24
|
|
|
25
25
|
Location search plugin with autocomplete functionality. Include custom datasets to search.
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## Coming soon
|
|
28
28
|
|
|
29
29
|
The following plugins are in early development. APIs and features may change.
|
|
30
30
|
|
|
31
|
-
### Datasets
|
|
31
|
+
### [Datasets](./plugins/datasets.md)
|
|
32
32
|
|
|
33
33
|
Add datasets to your map, configure the display, layer toggling and render a key of symbology.
|
|
34
34
|
|
|
35
35
|
### Draw for MapLibre
|
|
36
36
|
|
|
37
|
-
Draw lines and
|
|
37
|
+
Draw lines, polygons and place points using the MapLibre map provider. Includes geometry actions such as split and merge.
|
|
38
38
|
|
|
39
39
|
### Draw for ESRI SDK
|
|
40
40
|
|
|
@@ -48,15 +48,7 @@ Add a regular shaped frame to the map and control its position. Use to generate
|
|
|
48
48
|
|
|
49
49
|
Geolocation plugin that allows users to centre the map on their current location.
|
|
50
50
|
|
|
51
|
-
##
|
|
52
|
-
|
|
53
|
-
The following plugins are planned for future releases.
|
|
54
|
-
|
|
55
|
-
### Geometry Actions
|
|
56
|
-
|
|
57
|
-
Split and merge polygons.
|
|
58
|
-
|
|
59
|
-
## Using Plugins
|
|
51
|
+
## Using plugins
|
|
60
52
|
|
|
61
53
|
Plugins are registered via the `plugins` option when creating an InteractiveMap. Plugins typically export a factory function that accepts configuration options:
|
|
62
54
|
|
|
@@ -80,7 +72,7 @@ The factory function returns a [PluginDescriptor](./plugins/plugin-descriptor.md
|
|
|
80
72
|
- **load** - Function that returns a [PluginManifest](./plugins/plugin-manifest.md)
|
|
81
73
|
- **...options** - Configuration passed to the factory, available as [pluginConfig](./plugins/plugin-context.md#pluginconfig)
|
|
82
74
|
|
|
83
|
-
## Plugin
|
|
75
|
+
## Plugin events
|
|
84
76
|
|
|
85
77
|
Plugins can emit events that you can listen to using `interactiveMap.on()`:
|
|
86
78
|
|
|
@@ -94,7 +86,7 @@ interactiveMap.on('highlight:removed', ({ id }) => {
|
|
|
94
86
|
})
|
|
95
87
|
```
|
|
96
88
|
|
|
97
|
-
## Plugin
|
|
89
|
+
## Plugin methods
|
|
98
90
|
|
|
99
91
|
Plugins can expose methods that you call on the plugin instance:
|
|
100
92
|
|
|
@@ -108,7 +100,7 @@ interactiveMap.on('map:ready', () => {
|
|
|
108
100
|
|
|
109
101
|
See individual plugin documentation for available events and methods.
|
|
110
102
|
|
|
111
|
-
## Further
|
|
103
|
+
## Further reading
|
|
112
104
|
|
|
113
105
|
- [Building a Plugin](./building-a-plugin.md) - Guide to creating custom plugins
|
|
114
106
|
- [PluginDescriptor](./plugins/plugin-descriptor.md) - Plugin registration reference
|
package/docusaurus.config.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
/** @type {import('@docusaurus/types').Config} */
|
|
4
4
|
const config = {
|
|
5
5
|
staticDirectories: ['assets'],
|
|
6
|
-
title: 'Interactive Map',
|
|
6
|
+
title: 'Defra Interactive Map',
|
|
7
7
|
tagline: 'An accessibility-first interactive map component for government frontends',
|
|
8
|
-
favicon: 'images/favicon.
|
|
8
|
+
favicon: 'images/favicon.svg',
|
|
9
9
|
|
|
10
10
|
url: 'https://defra.github.io',
|
|
11
11
|
baseUrl: '/interactive-map/',
|
|
@@ -41,6 +41,14 @@ const config = {
|
|
|
41
41
|
],
|
|
42
42
|
|
|
43
43
|
plugins: [
|
|
44
|
+
function customCssPlugin() {
|
|
45
|
+
return {
|
|
46
|
+
name: 'custom-css',
|
|
47
|
+
getClientModules() {
|
|
48
|
+
return [require.resolve('./assets/css/docusaurus.css')];
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
44
52
|
[
|
|
45
53
|
'@docusaurus/plugin-content-docs',
|
|
46
54
|
{
|
|
@@ -66,18 +74,17 @@ const config = {
|
|
|
66
74
|
},
|
|
67
75
|
|
|
68
76
|
navigation: [
|
|
69
|
-
{ text: 'Getting Started', href: '/getting-started' },
|
|
70
|
-
{ text: 'Demo', href: '/demo', sidebar: 'auto' },
|
|
71
77
|
{
|
|
72
|
-
text: '
|
|
73
|
-
href: '/
|
|
78
|
+
text: 'Getting Started',
|
|
79
|
+
href: '/getting-started',
|
|
74
80
|
sidebar: [
|
|
75
|
-
{ text: '
|
|
76
|
-
{ text: '
|
|
77
|
-
{ text: '
|
|
81
|
+
{ text: 'Installation', href: '/getting-started#installation' },
|
|
82
|
+
{ text: 'Basic usage', href: '/getting-started#basic-usage' },
|
|
83
|
+
{ text: 'Using plugins', href: '/getting-started#using-plugins' },
|
|
84
|
+
{ text: 'GOV.UK Prototype kit', href: '/getting-started#govuk-prototype-kit-plugin' }
|
|
78
85
|
],
|
|
79
86
|
},
|
|
80
|
-
{ text: '
|
|
87
|
+
{ text: 'Examples', href: '/examples', sidebar: 'auto' },
|
|
81
88
|
{
|
|
82
89
|
text: 'API',
|
|
83
90
|
href: '/api',
|
|
@@ -87,31 +94,24 @@ const config = {
|
|
|
87
94
|
text: 'Plugins',
|
|
88
95
|
href: '/plugins',
|
|
89
96
|
sidebar: [
|
|
90
|
-
{ text: 'Overview', href: '/plugins' },
|
|
91
|
-
{ text: 'Building a Plugin', href: '/building-a-plugin' },
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{ text: 'Scale Bar', href: '/plugins#scale-bar' },
|
|
99
|
-
{ text: 'Search', href: '/plugins#search' },
|
|
100
|
-
],
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
text: 'Alpha Plugins',
|
|
104
|
-
href: '/plugins#alpha-plugins',
|
|
105
|
-
items: [
|
|
106
|
-
{ text: 'Datasets', href: '/plugins#datasets' },
|
|
107
|
-
{ text: 'Draw for MapLibre', href: '/plugins#draw-for-maplibre' },
|
|
108
|
-
{ text: 'Draw for ESRI SDK', href: '/plugins#draw-for-esri-sdk' },
|
|
109
|
-
{ text: 'Frame', href: '/plugins#frame' },
|
|
110
|
-
{ text: 'Use Location', href: '/plugins#use-location' },
|
|
111
|
-
],
|
|
112
|
-
},
|
|
97
|
+
// { text: 'Overview', href: '/plugins' },
|
|
98
|
+
// { text: 'Building a Plugin', href: '/building-a-plugin' },
|
|
99
|
+
{ text: 'Available Plugins', href: '/plugins#available-plugins' },
|
|
100
|
+
{ text: 'Coming soon', href: '/plugins#coming-soon' },
|
|
101
|
+
{ text: 'Using plugins', href: '/plugins#using-plugins' },
|
|
102
|
+
{ text: 'Plugin events', href: '/plugins#plugin-events' },
|
|
103
|
+
{ text: 'Plugin methods', href: '/plugins#plugin-methods' },
|
|
104
|
+
{ text: 'Further reading', href: '/plugins#further-reading' },
|
|
113
105
|
],
|
|
114
106
|
},
|
|
107
|
+
{
|
|
108
|
+
text: 'Architecture',
|
|
109
|
+
href: '/architecture',
|
|
110
|
+
sidebar: [
|
|
111
|
+
{ text: 'Diagrams', href: 'architecture-diagrams' },
|
|
112
|
+
{ text: 'Diagram Viewer', href: 'diagrams-viewer' },
|
|
113
|
+
],
|
|
114
|
+
}
|
|
115
115
|
],
|
|
116
116
|
|
|
117
117
|
phaseBanner: {
|
|
@@ -127,7 +127,7 @@ const config = {
|
|
|
127
127
|
|
|
128
128
|
homepage: {
|
|
129
129
|
getStartedHref: '/getting-started',
|
|
130
|
-
description: '
|
|
130
|
+
description: 'Built for developers creating public-facing services on GOV.UK. Takes care of the hard work of building an accessible, standards-compliant mapping interface, so you can focus on your data.',
|
|
131
131
|
},
|
|
132
132
|
},
|
|
133
133
|
},
|
package/jest.setup.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/interactive-map",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17-alpha",
|
|
4
4
|
"description": "An accessible map component",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
"build": "npm run clean && npm-run-all --parallel build:umd build:esm",
|
|
87
87
|
"type-check": "tsc --noEmit",
|
|
88
88
|
"lint": "npm run lint:js && npm run lint:scss",
|
|
89
|
-
"lint:js": "standard \"
|
|
89
|
+
"lint:js": "standard \"./**/*.{js,jsx,ts,tsx}\"",
|
|
90
90
|
"lint:scss": "stylelint \"src/**/*.{css,scss}\"",
|
|
91
91
|
"lint:fix": "npm run lint:js:fix && npm run lint:scss:fix",
|
|
92
|
-
"lint:js:fix": "standard \"
|
|
92
|
+
"lint:js:fix": "standard \"./**/*.{js,jsx,ts,tsx}\" --fix",
|
|
93
93
|
"lint:scss:fix": "stylelint \"src/**/*.{css,scss}\" --fix",
|
|
94
94
|
"test": "jest --color --coverage --verbose",
|
|
95
95
|
"report": "webpack --profile --json --config webpack.prod.mjs > stats.json && webpack-bundle-analyzer --host 0.0.0.0 --port 8888 ./stats.json ./public",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"@babel/plugin-transform-runtime": "^7.29.0",
|
|
128
128
|
"@babel/preset-env": "^7.28.0",
|
|
129
129
|
"@babel/preset-react": "^7.27.1",
|
|
130
|
-
"@defra/docusaurus-theme-govuk": "^0.0.
|
|
130
|
+
"@defra/docusaurus-theme-govuk": "^0.0.16-alpha",
|
|
131
131
|
"@docusaurus/core": "^3.9.2",
|
|
132
132
|
"@docusaurus/module-type-aliases": "^3.9.2",
|
|
133
133
|
"@docusaurus/plugin-content-docs": "^3.9.2",
|
|
@@ -156,6 +156,7 @@
|
|
|
156
156
|
"geodesy": "^2.4.0",
|
|
157
157
|
"jest": "^29.7.0",
|
|
158
158
|
"jest-environment-jsdom": "^30.0.4",
|
|
159
|
+
"jest-expect-message": "^1.1.3",
|
|
159
160
|
"likec4": "^1.50.0",
|
|
160
161
|
"mapbox-gl-snap": "^1.1.9",
|
|
161
162
|
"mini-css-extract-plugin": "^2.9.2",
|
|
@@ -217,7 +218,7 @@
|
|
|
217
218
|
"@turf/polygon-to-line": "^7.3.3",
|
|
218
219
|
"accessible-autocomplete": "^3.0.1",
|
|
219
220
|
"govuk-frontend": "^5.13.0",
|
|
220
|
-
"maplibre-gl": "^5.
|
|
221
|
+
"maplibre-gl": "^5.21.1",
|
|
221
222
|
"polygon-splitter": "^0.0.11",
|
|
222
223
|
"preact": "^10.27.2",
|
|
223
224
|
"tslib": "^2.8.1"
|