@defra/interactive-map 0.0.16-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/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 +16 -15
- package/docs/api.md +3 -3
- package/docs/getting-started.md +4 -1
- package/docs/plugins/datasets.md +561 -0
- package/docs/plugins.md +1 -1
- package/package.json +2 -2
- 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 +23 -8
- 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 +2 -8
- 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 +2 -44
- 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 +29 -55
- package/plugins/beta/datasets/src/defaults.js +42 -8
- package/plugins/beta/datasets/src/fetch/createDynamicSource.js +34 -25
- package/plugins/beta/datasets/src/fetch/fetchGeoJSON.js +2 -2
- package/plugins/beta/datasets/src/manifest.js +24 -16
- package/plugins/beta/datasets/src/panels/Key.jsx +128 -50
- package/plugins/beta/datasets/src/panels/Key.module.scss +48 -9
- package/plugins/beta/datasets/src/panels/Layers.jsx +132 -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 +7 -5
- package/plugins/beta/datasets/src/utils/filters.js +5 -2
- package/plugins/beta/datasets/src/utils/mergeSublayer.js +78 -0
- 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/draw.scss +0 -7
- package/plugins/beta/draw-ml/src/manifest.js +16 -16
- 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 +5 -5
- 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/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/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/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/interact.scss +0 -7
- package/plugins/interact/src/manifest.js +14 -18
- package/plugins/interact/src/manifest.test.js +3 -1
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/src/components/Form/Form.module.scss +2 -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/utils/highlightFeatures.js +1 -0
- package/providers/maplibre/src/utils/highlightFeatures.test.js +1 -0
- 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 +1 -1
- package/src/App/renderer/HtmlElementHost.jsx +2 -1
- package/src/App/renderer/HtmlElementHost.test.jsx +7 -7
- package/src/App/renderer/mapButtons.js +1 -1
- 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 +1 -1
- package/src/App/store/appDispatchMiddleware.test.js +2 -2
- package/src/App/store/appReducer.js +2 -0
- package/src/InteractiveMap/InteractiveMap.js +4 -0
- package/src/config/appConfig.js +5 -2
- package/src/config/events.js +28 -0
- package/src/scss/main.scss +1 -0
- package/src/scss/settings/_dimensions.scss +0 -1
- package/src/utils/getSafeZoneInset.js +9 -7
- package/src/utils/getSafeZoneInset.test.js +10 -10
- package/webpack.dev.mjs +1 -1
- package/docs/api/slot-map.svg +0 -1
- 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 -164
- /package/src/{utils → services}/logger.js +0 -0
- /package/src/{utils → services}/logger.test.js +0 -0
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
# Datasets Plugin
|
|
2
|
+
|
|
3
|
+
The datasets plugin renders GeoJSON and vector tile datasets on the map, with support for sublayer style rules, layer visibility toggling, a key panel, and runtime style and data updates.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import createDatasetsPlugin from '@defra/interactive-map/plugins/beta/datasets'
|
|
9
|
+
import { maplibreLayerAdapter } from '@defra/interactive-map/plugins/beta/datasets/adapters/maplibre'
|
|
10
|
+
|
|
11
|
+
const datasetsPlugin = createDatasetsPlugin({
|
|
12
|
+
layerAdapter: maplibreLayerAdapter,
|
|
13
|
+
datasets: [
|
|
14
|
+
{
|
|
15
|
+
id: 'my-parcels',
|
|
16
|
+
label: 'My parcels',
|
|
17
|
+
geojson: 'https://example.com/api/parcels',
|
|
18
|
+
minZoom: 10,
|
|
19
|
+
maxZoom: 24,
|
|
20
|
+
showInKey: true,
|
|
21
|
+
toggleVisibility: true,
|
|
22
|
+
style: {
|
|
23
|
+
stroke: '#d4351c',
|
|
24
|
+
strokeWidth: 2,
|
|
25
|
+
fill: 'transparent'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const interactiveMap = new InteractiveMap({
|
|
32
|
+
plugins: [datasetsPlugin]
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Options
|
|
37
|
+
|
|
38
|
+
Options are passed to the factory function when creating the plugin.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
### `layerAdapter`
|
|
43
|
+
|
|
44
|
+
**Type:** `LayerAdapter`
|
|
45
|
+
**Required**
|
|
46
|
+
|
|
47
|
+
The map provider adapter responsible for rendering datasets. Import `maplibreLayerAdapter` for MapLibre GL JS, or supply a custom adapter.
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { maplibreLayerAdapter } from '@defra/interactive-map/plugins/beta/datasets/adapters/maplibre'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### `datasets`
|
|
56
|
+
|
|
57
|
+
**Type:** `Dataset[]`
|
|
58
|
+
**Required**
|
|
59
|
+
|
|
60
|
+
Array of dataset configurations to render on the map. See [Dataset configuration](#dataset-configuration) below.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### `includeModes`
|
|
65
|
+
|
|
66
|
+
**Type:** `string[]`
|
|
67
|
+
|
|
68
|
+
When set, the plugin only initialises when the app is in one of the specified modes.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### `excludeModes`
|
|
73
|
+
|
|
74
|
+
**Type:** `string[]`
|
|
75
|
+
|
|
76
|
+
When set, the plugin does not initialise when the app is in one of the specified modes.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Dataset configuration
|
|
81
|
+
|
|
82
|
+
Each entry in the `datasets` array describes one data source and how it should be rendered.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### `id`
|
|
87
|
+
|
|
88
|
+
**Type:** `string`
|
|
89
|
+
**Required**
|
|
90
|
+
|
|
91
|
+
Unique identifier for the dataset. Used in all API method calls.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### `label`
|
|
96
|
+
|
|
97
|
+
**Type:** `string`
|
|
98
|
+
|
|
99
|
+
Human-readable name shown in the Layers panel and Key panel.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### `geojson`
|
|
104
|
+
|
|
105
|
+
**Type:** `string | GeoJSON.FeatureCollection`
|
|
106
|
+
|
|
107
|
+
GeoJSON source. Provide a URL string for remote data, or a GeoJSON object for inline data. Use alongside `transformRequest` to add authentication or append bbox parameters to the request.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### `tiles`
|
|
112
|
+
|
|
113
|
+
**Type:** `string[]`
|
|
114
|
+
|
|
115
|
+
Array of vector tile URL templates (e.g. `https://example.com/tiles/{z}/{x}/{y}`). When set, the dataset uses a vector tile source instead of GeoJSON.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### `sourceLayer`
|
|
120
|
+
|
|
121
|
+
**Type:** `string`
|
|
122
|
+
|
|
123
|
+
The layer name within the vector tile source to render. Required when using `tiles`.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### `transformRequest`
|
|
128
|
+
|
|
129
|
+
**Type:** `Function`
|
|
130
|
+
|
|
131
|
+
A function called before each fetch to transform the request. Its primary purpose is to attach authentication credentials — API keys, OAuth tokens, or other headers. It also receives the current viewport context so you can append bbox or zoom parameters to the URL if your API supports spatial filtering.
|
|
132
|
+
|
|
133
|
+
The plugin handles all dynamic fetching concerns (viewport tracking, debouncing, deduplication, caching, request cancellation) — `transformRequest` only needs to return the final URL and any headers.
|
|
134
|
+
|
|
135
|
+
**Signature:** `transformRequest(url, { bbox, zoom, dataset })`
|
|
136
|
+
|
|
137
|
+
| Argument | Type | Description |
|
|
138
|
+
|----------|------|-------------|
|
|
139
|
+
| `url` | `string` | The base URL from `geojson` |
|
|
140
|
+
| `bbox` | `number[]` | Current viewport bounds as `[west, south, east, north]` |
|
|
141
|
+
| `zoom` | `number` | Current map zoom level |
|
|
142
|
+
| `dataset` | `Object` | The full dataset configuration |
|
|
143
|
+
|
|
144
|
+
Return either a plain URL string or an object `{ url, headers }`. The object form is needed when attaching auth headers.
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
// Auth headers only (no bbox filtering)
|
|
148
|
+
transformRequest: (url) => ({
|
|
149
|
+
url,
|
|
150
|
+
headers: { Authorization: `Bearer ${getToken()}` }
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
// Append bbox to URL for server-side spatial filtering
|
|
154
|
+
transformRequest: (url, { bbox }) => {
|
|
155
|
+
const separator = url.includes('?') ? '&' : '?'
|
|
156
|
+
return { url: `${url}${separator}bbox=${bbox.join(',')}` }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Both — auth + bbox
|
|
160
|
+
transformRequest: (url, { bbox }) => {
|
|
161
|
+
const separator = url.includes('?') ? '&' : '?'
|
|
162
|
+
return {
|
|
163
|
+
url: `${url}${separator}bbox=${bbox.join(',')}`,
|
|
164
|
+
headers: { Authorization: `Bearer ${getToken()}` }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### `idProperty`
|
|
172
|
+
|
|
173
|
+
**Type:** `string`
|
|
174
|
+
|
|
175
|
+
Property name used to uniquely identify features. Required alongside `transformRequest` to enable dynamic bbox-based fetching — the plugin uses it internally to deduplicate features across successive viewport fetches.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### `filter`
|
|
180
|
+
|
|
181
|
+
**Type:** `FilterExpression`
|
|
182
|
+
|
|
183
|
+
A MapLibre filter expression applied to the dataset's map layers. Features not matching the filter are not rendered.
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
filter: ['==', ['get', 'status'], 'active']
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
### `minZoom`
|
|
192
|
+
|
|
193
|
+
**Type:** `number`
|
|
194
|
+
**Default:** `6`
|
|
195
|
+
|
|
196
|
+
Minimum zoom level at which the dataset is visible.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
### `maxZoom`
|
|
201
|
+
|
|
202
|
+
**Type:** `number`
|
|
203
|
+
**Default:** `24`
|
|
204
|
+
|
|
205
|
+
Maximum zoom level at which the dataset is visible.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### `maxFeatures`
|
|
210
|
+
|
|
211
|
+
**Type:** `number`
|
|
212
|
+
|
|
213
|
+
Only applies to dynamic sources (those using `transformRequest`). Caps the number of features held in memory across all viewport fetches — older out-of-viewport features are evicted when the limit is exceeded. Omit for small or bounded datasets; set it when users are likely to pan extensively over a large dataset.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
### `visibility`
|
|
218
|
+
|
|
219
|
+
**Type:** `'visible' | 'hidden'`
|
|
220
|
+
**Default:** `'visible'`
|
|
221
|
+
|
|
222
|
+
Initial visibility of the dataset.
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### `showInKey`
|
|
227
|
+
|
|
228
|
+
**Type:** `boolean`
|
|
229
|
+
**Default:** `false`
|
|
230
|
+
|
|
231
|
+
When `true`, the dataset appears in the Key panel with its style symbol and label.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### `toggleVisibility`
|
|
236
|
+
|
|
237
|
+
**Type:** `boolean`
|
|
238
|
+
**Default:** `false`
|
|
239
|
+
|
|
240
|
+
When `true`, the dataset appears in the Layers panel and can be toggled on and off by the user.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
### `groupLabel`
|
|
245
|
+
|
|
246
|
+
**Type:** `string`
|
|
247
|
+
|
|
248
|
+
Groups this dataset with others sharing the same `groupLabel` in the Layers panel, rendering them as a single collapsible group.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
### `keySymbolShape`
|
|
253
|
+
|
|
254
|
+
**Type:** `'polygon' | 'line'`
|
|
255
|
+
|
|
256
|
+
Overrides the shape used to render the key symbol for this dataset. Defaults to a polygon shape.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
### `style`
|
|
261
|
+
|
|
262
|
+
**Type:** `Object`
|
|
263
|
+
|
|
264
|
+
Visual style for the dataset. All style properties must be nested within this object.
|
|
265
|
+
|
|
266
|
+
| Property | Type | Description |
|
|
267
|
+
|----------|------|-------------|
|
|
268
|
+
| `stroke` | `string \| Record<string, string>` | Stroke (outline) colour. Accepts a plain colour string or a map-style-keyed object e.g. `{ outdoor: '#ff0000', dark: '#ffffff' }` |
|
|
269
|
+
| `strokeWidth` | `number` | Stroke width in pixels. **Default:** `2` |
|
|
270
|
+
| `strokeDashArray` | `number[]` | Dash pattern for the stroke e.g. `[4, 2]` |
|
|
271
|
+
| `fill` | `string \| Record<string, string>` | Fill colour. Use `'transparent'` for no fill |
|
|
272
|
+
| `fillPattern` | `string` | Named fill pattern e.g. `'diagonal-cross-hatch'`, `'horizontal-hatch'`, `'dot'`, `'vertical-hatch'` |
|
|
273
|
+
| `fillPatternSvgContent` | `string` | Raw SVG content for a custom fill pattern |
|
|
274
|
+
| `fillPatternForegroundColor` | `string \| Record<string, string>` | Foreground colour for the fill pattern |
|
|
275
|
+
| `fillPatternBackgroundColor` | `string \| Record<string, string>` | Background colour for the fill pattern |
|
|
276
|
+
| `opacity` | `number` | Layer opacity from `0` to `1` |
|
|
277
|
+
| `symbolDescription` | `string \| Record<string, string>` | Accessible description of the symbol shown in the key |
|
|
278
|
+
| `keySymbolShape` | `'polygon' \| 'line'` | Shape used for the key symbol |
|
|
279
|
+
|
|
280
|
+
```js
|
|
281
|
+
style: {
|
|
282
|
+
stroke: { outdoor: '#d4351c', dark: '#ffffff' },
|
|
283
|
+
strokeWidth: 2,
|
|
284
|
+
fill: 'rgba(212,53,28,0.1)',
|
|
285
|
+
symbolDescription: { outdoor: 'Red outline' }
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### `sublayers`
|
|
292
|
+
|
|
293
|
+
**Type:** `Sublayer[]`
|
|
294
|
+
|
|
295
|
+
Array of sublayer rules that partition the dataset into visually distinct groups based on feature filters. Each sublayer is rendered as a separate pair of map layers.
|
|
296
|
+
|
|
297
|
+
Sublayers inherit the parent dataset's style and only override what they specify. Fill precedence (highest to lowest): sublayer's own `fillPattern` → sublayer's own `fill` → parent's `fillPattern` → parent's `fill`.
|
|
298
|
+
|
|
299
|
+
#### `Sublayer` properties
|
|
300
|
+
|
|
301
|
+
| Property | Type | Description |
|
|
302
|
+
|----------|------|-------------|
|
|
303
|
+
| `id` | `string` | **Required.** Unique identifier within the dataset |
|
|
304
|
+
| `label` | `string` | Human-readable name shown in the Layers and Key panels |
|
|
305
|
+
| `filter` | `FilterExpression` | MapLibre filter expression to match features for this sublayer |
|
|
306
|
+
| `style` | `Object` | Style overrides for this sublayer. Accepts the same properties as the dataset `style` object |
|
|
307
|
+
| `showInKey` | `boolean` | Shows this sublayer in the Key panel. Inherits from dataset if not set |
|
|
308
|
+
| `toggleVisibility` | `boolean` | Shows this sublayer in the Layers panel. **Default:** `false` |
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
sublayers: [
|
|
312
|
+
{
|
|
313
|
+
id: 'active',
|
|
314
|
+
label: 'Active parcels',
|
|
315
|
+
filter: ['==', ['get', 'status'], 'active'],
|
|
316
|
+
toggleVisibility: true,
|
|
317
|
+
style: {
|
|
318
|
+
stroke: '#00703c',
|
|
319
|
+
fill: 'rgba(0,112,60,0.1)',
|
|
320
|
+
symbolDescription: 'Green outline'
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
id: 'inactive',
|
|
325
|
+
label: 'Inactive parcels',
|
|
326
|
+
filter: ['==', ['get', 'status'], 'inactive'],
|
|
327
|
+
toggleVisibility: true,
|
|
328
|
+
style: {
|
|
329
|
+
stroke: '#d4351c',
|
|
330
|
+
fillPattern: 'diagonal-cross-hatch',
|
|
331
|
+
fillPatternForegroundColor: '#d4351c'
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
]
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Methods
|
|
340
|
+
|
|
341
|
+
Methods are called on the plugin instance after the `datasets:ready` event.
|
|
342
|
+
|
|
343
|
+
The API follows a consistent pattern: the primary value is the first argument, with an optional scope object as the second argument. Omitting the scope applies the operation globally where supported.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
### `addDataset(dataset)`
|
|
348
|
+
|
|
349
|
+
Add a new dataset to the map at runtime.
|
|
350
|
+
|
|
351
|
+
| Argument | Type | Description |
|
|
352
|
+
|----------|------|-------------|
|
|
353
|
+
| `dataset` | `Dataset` | Dataset configuration object. Accepts the same properties as `datasets` array entries |
|
|
354
|
+
|
|
355
|
+
```js
|
|
356
|
+
interactiveMap.on('datasets:ready', () => {
|
|
357
|
+
datasetsPlugin.addDataset({
|
|
358
|
+
id: 'new-layer',
|
|
359
|
+
geojson: 'https://example.com/api/features',
|
|
360
|
+
minZoom: 10,
|
|
361
|
+
style: { stroke: '#0000ff' }
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
### `removeDataset(datasetId)`
|
|
369
|
+
|
|
370
|
+
Remove a dataset from the map.
|
|
371
|
+
|
|
372
|
+
| Argument | Type | Description |
|
|
373
|
+
|----------|------|-------------|
|
|
374
|
+
| `datasetId` | `string` | ID of the dataset to remove |
|
|
375
|
+
|
|
376
|
+
```js
|
|
377
|
+
datasetsPlugin.removeDataset('my-parcels')
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
### `setDatasetVisibility(visible, scope?)`
|
|
383
|
+
|
|
384
|
+
Set the visibility of datasets or sublayers. Omit `scope` to apply to all datasets globally.
|
|
385
|
+
|
|
386
|
+
When showing a dataset that has sublayers, any sublayers that were individually hidden before the dataset was hidden will remain hidden — their individual visibility state is preserved.
|
|
387
|
+
|
|
388
|
+
| Argument | Type | Description |
|
|
389
|
+
|----------|------|-------------|
|
|
390
|
+
| `visible` | `boolean` | `true` to show, `false` to hide |
|
|
391
|
+
| `scope.datasetId` | `string` | Optional. When omitted, applies to all datasets |
|
|
392
|
+
| `scope.sublayerId` | `string` | Optional. When provided alongside `datasetId`, targets a single sublayer |
|
|
393
|
+
|
|
394
|
+
```js
|
|
395
|
+
// Global — all datasets
|
|
396
|
+
datasetsPlugin.setDatasetVisibility(false)
|
|
397
|
+
datasetsPlugin.setDatasetVisibility(true)
|
|
398
|
+
|
|
399
|
+
// Single dataset
|
|
400
|
+
datasetsPlugin.setDatasetVisibility(false, { datasetId: 'my-parcels' })
|
|
401
|
+
|
|
402
|
+
// Single sublayer
|
|
403
|
+
datasetsPlugin.setDatasetVisibility(false, { datasetId: 'my-parcels', sublayerId: 'active' })
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
### `setFeatureVisibility(visible, featureIds, scope)`
|
|
409
|
+
|
|
410
|
+
Show or hide specific features within a dataset without removing them from the source.
|
|
411
|
+
|
|
412
|
+
| Argument | Type | Description |
|
|
413
|
+
|----------|------|-------------|
|
|
414
|
+
| `visible` | `boolean` | `true` to show, `false` to hide |
|
|
415
|
+
| `featureIds` | `(string \| number)[]` | IDs of the features to target |
|
|
416
|
+
| `scope.datasetId` | `string` | ID of the dataset |
|
|
417
|
+
| `scope.idProperty` | `string \| null` | Property name to match features on. Pass `null` to match against the top-level `feature.id` |
|
|
418
|
+
|
|
419
|
+
```js
|
|
420
|
+
// Hide by a feature property
|
|
421
|
+
datasetsPlugin.setFeatureVisibility(false, [123, 456], {
|
|
422
|
+
datasetId: 'my-parcels',
|
|
423
|
+
idProperty: 'parcel_id'
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
// Show using feature.id
|
|
427
|
+
datasetsPlugin.setFeatureVisibility(true, [123, 456], {
|
|
428
|
+
datasetId: 'my-parcels',
|
|
429
|
+
idProperty: null
|
|
430
|
+
})
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
### `setStyle(style, scope)`
|
|
436
|
+
|
|
437
|
+
Update the visual style of a dataset or sublayer at runtime. When targeting a sublayer, only the properties specified are overridden — the sublayer inherits all other styles from the parent dataset.
|
|
438
|
+
|
|
439
|
+
| Argument | Type | Description |
|
|
440
|
+
|----------|------|-------------|
|
|
441
|
+
| `style` | `Object` | Style properties to apply. Accepts the same properties as `dataset.style` |
|
|
442
|
+
| `scope.datasetId` | `string` | ID of the dataset |
|
|
443
|
+
| `scope.sublayerId` | `string` | Optional. When provided, targets a single sublayer |
|
|
444
|
+
|
|
445
|
+
```js
|
|
446
|
+
// Dataset level
|
|
447
|
+
datasetsPlugin.setStyle(
|
|
448
|
+
{ stroke: '#0000ff', strokeWidth: 3 },
|
|
449
|
+
{ datasetId: 'my-parcels' }
|
|
450
|
+
)
|
|
451
|
+
|
|
452
|
+
// Sublayer level
|
|
453
|
+
datasetsPlugin.setStyle(
|
|
454
|
+
{ stroke: '#00703c', fillPattern: 'diagonal-cross-hatch', fillPatternForegroundColor: '#00703c' },
|
|
455
|
+
{ datasetId: 'my-parcels', sublayerId: 'active' }
|
|
456
|
+
)
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
### `getStyle(scope)`
|
|
462
|
+
|
|
463
|
+
Returns the current style object for a dataset or sublayer, or `null` if not found.
|
|
464
|
+
|
|
465
|
+
| Argument | Type | Description |
|
|
466
|
+
|----------|------|-------------|
|
|
467
|
+
| `scope.datasetId` | `string` | ID of the dataset |
|
|
468
|
+
| `scope.sublayerId` | `string` | Optional. When provided, returns the sublayer's style |
|
|
469
|
+
|
|
470
|
+
```js
|
|
471
|
+
// Dataset style
|
|
472
|
+
const style = datasetsPlugin.getStyle({ datasetId: 'my-parcels' })
|
|
473
|
+
|
|
474
|
+
// Sublayer style
|
|
475
|
+
const style = datasetsPlugin.getStyle({ datasetId: 'my-parcels', sublayerId: 'active' })
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
480
|
+
### `setOpacity(opacity, scope?)`
|
|
481
|
+
|
|
482
|
+
Set the opacity of datasets or a sublayer. Safe to call on every tick from a slider — uses `setPaintProperty` internally rather than removing and re-adding layers. Omit `scope` to apply globally.
|
|
483
|
+
|
|
484
|
+
| Argument | Type | Description |
|
|
485
|
+
|----------|------|-------------|
|
|
486
|
+
| `opacity` | `number` | Opacity from `0` (transparent) to `1` (fully opaque) |
|
|
487
|
+
| `scope.datasetId` | `string` | Optional. When omitted, applies to all datasets |
|
|
488
|
+
| `scope.sublayerId` | `string` | Optional. When provided alongside `datasetId`, targets a single sublayer |
|
|
489
|
+
|
|
490
|
+
```js
|
|
491
|
+
// Global — all datasets
|
|
492
|
+
datasetsPlugin.setOpacity(0.5)
|
|
493
|
+
|
|
494
|
+
// Single dataset
|
|
495
|
+
datasetsPlugin.setOpacity(0.5, { datasetId: 'my-parcels' })
|
|
496
|
+
|
|
497
|
+
// Single sublayer
|
|
498
|
+
datasetsPlugin.setOpacity(0.5, { datasetId: 'my-parcels', sublayerId: 'active' })
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
### `getOpacity(scope?)`
|
|
504
|
+
|
|
505
|
+
Returns the current opacity for a dataset or sublayer. When called without arguments, returns the first dataset's opacity — useful for initialising a global slider. Returns `null` if not found.
|
|
506
|
+
|
|
507
|
+
| Argument | Type | Description |
|
|
508
|
+
|----------|------|-------------|
|
|
509
|
+
| `scope.datasetId` | `string` | Optional. When omitted, returns the first dataset's opacity |
|
|
510
|
+
| `scope.sublayerId` | `string` | Optional. When provided alongside `datasetId`, returns the sublayer's opacity |
|
|
511
|
+
|
|
512
|
+
```js
|
|
513
|
+
// Global — read back after setOpacity() for slider initialisation
|
|
514
|
+
const opacity = datasetsPlugin.getOpacity()
|
|
515
|
+
|
|
516
|
+
// Single dataset
|
|
517
|
+
const opacity = datasetsPlugin.getOpacity({ datasetId: 'my-parcels' })
|
|
518
|
+
|
|
519
|
+
// Single sublayer
|
|
520
|
+
const opacity = datasetsPlugin.getOpacity({ datasetId: 'my-parcels', sublayerId: 'active' })
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
### `setData(geojson, scope)`
|
|
526
|
+
|
|
527
|
+
Replace the GeoJSON data for a dataset source. Has no effect on vector tile datasets.
|
|
528
|
+
|
|
529
|
+
| Argument | Type | Description |
|
|
530
|
+
|----------|------|-------------|
|
|
531
|
+
| `geojson` | `GeoJSON.FeatureCollection` | New GeoJSON data |
|
|
532
|
+
| `scope.datasetId` | `string` | ID of the dataset |
|
|
533
|
+
|
|
534
|
+
```js
|
|
535
|
+
datasetsPlugin.setData(
|
|
536
|
+
{ type: 'FeatureCollection', features: [...] },
|
|
537
|
+
{ datasetId: 'my-parcels' }
|
|
538
|
+
)
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
## Events
|
|
544
|
+
|
|
545
|
+
Subscribe to events using `interactiveMap.on()`.
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
### `datasets:ready`
|
|
550
|
+
|
|
551
|
+
Emitted once all datasets have been initialised and rendered on the map.
|
|
552
|
+
|
|
553
|
+
**Payload:** None
|
|
554
|
+
|
|
555
|
+
```js
|
|
556
|
+
interactiveMap.on('datasets:ready', () => {
|
|
557
|
+
console.log('Datasets are ready')
|
|
558
|
+
// Safe to call API methods from here
|
|
559
|
+
const style = datasetsPlugin.getStyle({ datasetId: 'my-parcels' }) // unchanged — scope object
|
|
560
|
+
})
|
|
561
|
+
```
|
package/docs/plugins.md
CHANGED
|
@@ -28,7 +28,7 @@ Location search plugin with autocomplete functionality. Include custom datasets
|
|
|
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
|
|
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",
|
|
@@ -218,7 +218,7 @@
|
|
|
218
218
|
"@turf/polygon-to-line": "^7.3.3",
|
|
219
219
|
"accessible-autocomplete": "^3.0.1",
|
|
220
220
|
"govuk-frontend": "^5.13.0",
|
|
221
|
-
"maplibre-gl": "^5.
|
|
221
|
+
"maplibre-gl": "^5.21.1",
|
|
222
222
|
"polygon-splitter": "^0.0.11",
|
|
223
223
|
"preact": "^10.27.2",
|
|
224
224
|
"tslib": "^2.8.1"
|
|
@@ -1,25 +1,83 @@
|
|
|
1
|
-
.im-c-datasets-
|
|
1
|
+
.im-c-datasets-key--has-groups > * {
|
|
2
|
+
border-top: 1px solid var(--button-hover-color);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.im-c-datasets-key:not(.im-c-datasets-key--has-groups) > *:first-child {
|
|
6
|
+
border-top: 1px solid var(--button-hover-color);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.im-c-datasets-key__group:not(:last-child) {
|
|
10
|
+
padding-bottom: 5px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.im-c-datasets-key__group-heading {
|
|
14
|
+
padding-top: 15px;
|
|
15
|
+
padding-bottom: 10px;
|
|
16
|
+
margin: 0;
|
|
17
|
+
font-size: 1rem;
|
|
18
|
+
font-weight: bold;
|
|
19
|
+
color: var(--foreground-color);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.im-c-datasets-key__item {
|
|
2
23
|
display: flex;
|
|
3
24
|
align-items: start;
|
|
4
|
-
padding-top:
|
|
5
|
-
padding-bottom:
|
|
6
|
-
align-self: auto;
|
|
25
|
+
padding-top: 10px;
|
|
26
|
+
padding-bottom: 10px;
|
|
7
27
|
font-size: 1rem;
|
|
8
|
-
|
|
28
|
+
}
|
|
29
|
+
.im-c-datasets-key--has-groups > .im-c-datasets-key__item {
|
|
30
|
+
padding-top: 15px;
|
|
31
|
+
padding-bottom: 15px;
|
|
32
|
+
}
|
|
33
|
+
.im-c-datasets-key__group .im-c-datasets-key__item:first-child {
|
|
34
|
+
padding-top: 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.im-c-datasets-key:not(.im-c-datasets-key--has-groups) > .im-c-datasets-key__item:first-child {
|
|
38
|
+
padding-top: 15px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.im-c-datasets-key > .im-c-datasets-key__item:last-child,
|
|
42
|
+
.im-c-datasets-key__group:last-child .im-c-datasets-key__item:last-child {
|
|
43
|
+
padding-bottom: 5px;
|
|
9
44
|
}
|
|
10
45
|
|
|
11
|
-
.im-c-datasets-key__item
|
|
46
|
+
.im-c-datasets-key__item svg {
|
|
12
47
|
position: relative;
|
|
13
48
|
flex-shrink: 0;
|
|
14
|
-
margin:
|
|
49
|
+
margin: 0 13px 0 2px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.im-c-datasets-layers--has-groups > * {
|
|
53
|
+
border-top: 1px solid var(--button-hover-color);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.im-c-datasets-layers:not(.im-c-datasets-layers--has-groups) > *:first-child {
|
|
57
|
+
border-top: 1px solid var(--button-hover-color);
|
|
58
|
+
padding-top: 10px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.im-c-datasets-layers > *:last-child {
|
|
62
|
+
margin-bottom: -5px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.im-c-datasets-layers-group:not(:last-child) {
|
|
66
|
+
padding-bottom: 5px;
|
|
15
67
|
}
|
|
16
68
|
|
|
17
69
|
.im-c-datasets-layers__item {
|
|
18
|
-
|
|
19
|
-
|
|
70
|
+
padding-bottom: 5px;
|
|
71
|
+
}
|
|
72
|
+
.im-c-datasets-layers--has-groups > .im-c-datasets-layers__item {
|
|
73
|
+
padding-top: 5px;
|
|
20
74
|
}
|
|
21
|
-
.im-c-datasets-
|
|
22
|
-
|
|
75
|
+
.im-c-datasets-layers-group .im-c-datasets-layers__item {
|
|
76
|
+
padding-top: 0;
|
|
77
|
+
padding-bottom: 0;
|
|
78
|
+
}
|
|
79
|
+
.im-c-datasets-layers-group .im-c-datasets-layers__item:not(:last-child) {
|
|
80
|
+
margin-bottom: 0;
|
|
23
81
|
}
|
|
24
82
|
|
|
25
83
|
.im-c-datasets-layers__item-label {
|
|
@@ -34,10 +92,6 @@
|
|
|
34
92
|
color: var(--foreground-color);
|
|
35
93
|
}
|
|
36
94
|
|
|
37
|
-
.im-c-datasets-layers__item--checked {
|
|
38
|
-
border-color: var(--app-border-color);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
95
|
.im-c-datasets-layers__item .govuk-checkboxes__item {
|
|
42
96
|
flex-wrap: nowrap;
|
|
43
97
|
}
|
|
@@ -45,6 +99,22 @@
|
|
|
45
99
|
margin-left: -3px;
|
|
46
100
|
}
|
|
47
101
|
|
|
102
|
+
.im-c-datasets-layers-group__fieldset {
|
|
103
|
+
border: none;
|
|
104
|
+
padding: 0;
|
|
105
|
+
margin: 0;
|
|
106
|
+
min-width: 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.im-c-datasets-layers-group__legend {
|
|
110
|
+
padding-top: 15px;
|
|
111
|
+
padding-bottom: 10px;
|
|
112
|
+
padding-inline: 0;
|
|
113
|
+
font-size: 1rem;
|
|
114
|
+
font-weight: bold;
|
|
115
|
+
color: var(--foreground-color);
|
|
116
|
+
}
|
|
117
|
+
|
|
48
118
|
.im-c-datasets {
|
|
49
119
|
display: block;
|
|
50
120
|
}
|