@defra/interactive-map 0.0.52-alpha → 0.0.54-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/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/context.md +30 -12
- package/docs/api/marker-config.md +16 -8
- package/docs/api/symbol-config.md +24 -9
- package/docs/api/symbol-registry.md +49 -14
- package/docs/api.md +11 -3
- package/docs/plugins/datasets.md +6 -10
- package/docs/plugins/draw.md +2 -1
- package/docs/plugins/map-key.md +47 -4
- package/package.json +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/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
- package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +10 -10
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +22 -6
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +20 -27
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +16 -70
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +30 -115
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +101 -13
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +27 -28
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +51 -32
- package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
- package/plugins/datasets/src/initialise/defaults.js +16 -27
- package/plugins/datasets/src/initialise/defaults.test.js +25 -57
- package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
- package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
- package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
- package/plugins/datasets/src/registry/dataset.js +23 -17
- package/plugins/datasets/src/registry/dataset.test.js +114 -11
- package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
- package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +7 -5
- package/plugins/draw/src/DrawInit.test.jsx +18 -2
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
- package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
- package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
- package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
- package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
- package/plugins/draw/src/defaults.js +2 -6
- package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
- package/plugins/draw/src/utils/symbolKeys.js +3 -4
- 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/dist/umd/index.js +1 -1
- package/plugins/map-key/dist/css/index.css +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/map-key/src/components/Key/Key.jsx +8 -4
- package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
- package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +36 -3
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
- package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +19 -18
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +25 -18
- package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
- package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
- package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
- package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
- package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
- package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
- package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
- package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
- package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
- package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
- package/plugins/map-key/src/index.js +34 -0
- package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
- package/plugins/map-key/src/registry/index.js +0 -2
- package/plugins/map-key/src/registry/index.test.js +1 -9
- package/plugins/map-key/src/utils/groupStyles.js +5 -2
- package/plugins/menu/src/registry/index.js +0 -2
- package/plugins/menu/src/registry/index.test.js +1 -9
- package/plugins/search/dist/esm/im-search-plugin.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 +0 -1
- package/plugins/search/src/components/Form/Form.jsx +3 -3
- package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
- package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
- package/plugins/search/src/defaults.js +3 -0
- package/plugins/search/src/events/formHandlers.js +3 -9
- package/plugins/search/src/events/formHandlers.test.js +6 -9
- package/plugins/search/src/events/inputHandlers.js +8 -2
- package/plugins/search/src/events/inputHandlers.test.js +20 -0
- package/plugins/search/src/events/suggestionHandlers.js +3 -5
- package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
- package/plugins/search/src/utils/showResult.js +9 -0
- package/plugins/search/src/utils/showResult.test.js +16 -0
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
- package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
- package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
- package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
- package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
- package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
- package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
- package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
- package/providers/mapProvider.js +53 -1
- package/providers/mapProvider.test.js +6 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +50 -17
- package/providers/maplibre/src/maplibreProvider.test.js +74 -20
- package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
- package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
- package/providers/maplibre/src/utils/patternImages.js +46 -29
- package/providers/maplibre/src/utils/patternImages.test.js +52 -4
- package/providers/maplibre/src/utils/symbolImages.js +80 -39
- package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
- package/src/App/components/Hints/Hints.module.scss +1 -1
- package/src/App/components/Markers/Markers.jsx +16 -25
- package/src/App/components/Markers/Markers.test.jsx +34 -48
- package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
- package/src/App/components/Markers/SymbolMarker.jsx +1 -1
- package/src/App/components/Viewport/Viewport.jsx +6 -4
- package/src/App/components/Viewport/Viewport.test.jsx +18 -1
- package/src/App/hooks/useMapAnnouncements.js +7 -2
- package/src/App/hooks/useMapAnnouncements.test.js +13 -2
- package/src/App/hooks/useModalPanelBehaviour.js +3 -1
- package/src/App/initialiseApp.js +1 -1
- package/src/App/store/ServiceProvider.jsx +12 -3
- package/src/App/store/ServiceProvider.test.jsx +39 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -3
- package/src/config/appConfig.js +1 -5
- package/src/config/mapSizeScales.js +8 -0
- package/src/config/symbolConfig.js +101 -25
- package/src/services/mapFocus.js +64 -0
- package/src/services/mapFocus.test.js +76 -0
- package/src/services/patternRegistry.js +97 -76
- package/src/services/patternRegistry.test.js +19 -1
- package/src/services/symbolComposer.js +184 -0
- package/src/services/symbolComposer.test.js +132 -0
- package/src/services/symbolRegistry.js +326 -155
- package/src/services/symbolRegistry.test.js +334 -32
- package/src/types.js +11 -5
- package/src/utils/detectInterfaceType.js +16 -5
- package/src/utils/detectInterfaceType.test.js +32 -0
- package/src/utils/hashString.js +23 -0
- package/src/utils/hashString.test.js +29 -0
- package/src/utils/imageDataCache.js +43 -0
- package/src/utils/imageDataCache.test.js +38 -0
- package/src/utils/pathBounds.js +330 -0
- package/src/utils/pathBounds.test.js +145 -0
- package/src/utils/patternUtils.js +0 -8
- package/src/utils/patternUtils.test.js +0 -25
- package/src/utils/recentImageSets.js +35 -0
- package/src/utils/recentImageSets.test.js +46 -0
- package/src/utils/symbolUtils.js +26 -29
- package/src/utils/symbolUtils.test.js +27 -41
- package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
|
@@ -2,16 +2,14 @@ import { OpenLayersDataset } from './registry/openLayersDataset.js'
|
|
|
2
2
|
import { datasetRegistry } from '../../registry/datasetRegistry.js'
|
|
3
3
|
import { MapboxStyleLayerAdapter } from '../mapboxStyleLayerAdapter.js'
|
|
4
4
|
import { createDatasetSource, createDatasetLayer, resolveLayerStyle, readGeoJSONFeatures } from './layerBuilders.js'
|
|
5
|
-
import { registerSymbols, SYMBOL_RASTER_PIXEL_RATIO } from '../../../../../providers/beta/openlayers/src/utils/symbolImages.js'
|
|
6
|
-
import { registerCrispCanvasPatterns } from './canvasPatternStyle.js'
|
|
7
5
|
import { logger } from '../../../../../src/services/logger.js'
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* OpenLayers implementation of the LayerAdapter interface for the datasets plugin.
|
|
11
9
|
*
|
|
12
10
|
* GeoJSON and vector tile datasets are both supported (see layerBuilders.createDatasetSource).
|
|
13
|
-
* Pattern fills and symbols are both wired into OpenLayersDataset.
|
|
14
|
-
* of time here (see _registerPatterns/_registerSymbols) since
|
|
11
|
+
* Pattern fills and symbols are both wired into OpenLayersDataset.getFlatStyle, registered ahead
|
|
12
|
+
* of time here (see _registerPatterns/_registerSymbols) since getFlatStyle is synchronous.
|
|
15
13
|
*
|
|
16
14
|
* One OL layer per dataset/sublayer (see OpenLayersDataset's leafLayerIds), not up to three like
|
|
17
15
|
* MapLibre — an ol/style/flat spec can combine fill+stroke (or an icon) for one feature in a
|
|
@@ -40,8 +38,19 @@ export default class OpenLayersLayerAdapter extends MapboxStyleLayerAdapter {
|
|
|
40
38
|
return new OpenLayersDataset(datasetDefinition)
|
|
41
39
|
}
|
|
42
40
|
|
|
41
|
+
// What layer styles are resolved against — see layerBuilders.js's resolveLayerStyle. Symbol
|
|
42
|
+
// images live in the OL provider (registered by _registerSymbols), so a style reads them back
|
|
43
|
+
// from there rather than from a module of its own.
|
|
43
44
|
get _styleContext () {
|
|
44
|
-
return {
|
|
45
|
+
return {
|
|
46
|
+
mapStyleId: datasetRegistry.mapStyle?.id,
|
|
47
|
+
pixelRatio: this._pixelRatio,
|
|
48
|
+
patternRegistry: this._patternRegistry,
|
|
49
|
+
symbolRegistry: this._symbolRegistry,
|
|
50
|
+
getSymbolDataUri: (imageId) => this._mapProvider.getSymbolDataUri(imageId),
|
|
51
|
+
getPatternFill: (imageId) => this._mapProvider.getPatternFill(imageId),
|
|
52
|
+
buildFilterEvaluator: (filter) => this._mapProvider.buildFilterEvaluator(filter)
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
@@ -66,20 +75,37 @@ export default class OpenLayersLayerAdapter extends MapboxStyleLayerAdapter {
|
|
|
66
75
|
datasetRegistry.forEachDataset(registryDataset => this._forEachLeafDataset(registryDataset, leaf => {
|
|
67
76
|
this._setLayerStyle(leaf)
|
|
68
77
|
}))
|
|
78
|
+
this._reapplyHighlights()
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
// Plain fill-color/stroke layers don't depend on map size at all. But
|
|
72
|
-
// canvasPatternStyle.js)
|
|
81
|
+
// Plain fill-color/stroke layers don't depend on map size at all. But pattern fills (see
|
|
82
|
+
// canvasPatternStyle.js) and symbols are rasterised at the map's *actual* pixelRatio to stay
|
|
73
83
|
// genuinely crisp, so a pixelRatio change (map resize) needs a fresh rasterisation and a
|
|
74
84
|
// re-applied style, the same way MapLibreLayerAdapter.onMapSizeChange re-rasterises
|
|
75
85
|
// symbols/patterns at the new ratio.
|
|
76
86
|
async onMapSizeChange () {
|
|
77
|
-
|
|
87
|
+
const pixelRatio = this._pixelRatio
|
|
88
|
+
await Promise.all([this._registerPatterns(), this._registerSymbols()])
|
|
89
|
+
// A later size change has moved the map on to another ratio while these images were being
|
|
90
|
+
// registered — its own call applies that ratio's styles, whose images may not be ready yet
|
|
91
|
+
if (this._pixelRatio !== pixelRatio) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
78
94
|
datasetRegistry.forEachDataset(registryDataset => this._forEachLeafDataset(registryDataset, leaf => {
|
|
79
|
-
if (leaf.hasPattern) {
|
|
95
|
+
if (leaf.hasPattern || leaf.hasSymbol) {
|
|
80
96
|
this._setLayerStyle(leaf)
|
|
81
97
|
}
|
|
82
98
|
}))
|
|
99
|
+
this._reapplyHighlights()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A selected/active dataset symbol's highlight is a separate overlay built from its images at
|
|
103
|
+
// selection time (see the OL provider's highlightFeatures.js), and OL only redraws highlights
|
|
104
|
+
// on its own basemap events — not when these styles change. So once the new images are in
|
|
105
|
+
// place, redraw it from them; otherwise it keeps the old images (blurry after a map-size
|
|
106
|
+
// change, the old colours after a style change) until the selection changes.
|
|
107
|
+
_reapplyHighlights () {
|
|
108
|
+
this._mapProvider.reapplyHighlights()
|
|
83
109
|
}
|
|
84
110
|
|
|
85
111
|
// ─── Dataset operations ─────────────────────────────────────────────────────
|
|
@@ -164,11 +190,10 @@ export default class OpenLayersLayerAdapter extends MapboxStyleLayerAdapter {
|
|
|
164
190
|
|
|
165
191
|
// ─── Private ─────────────────────────────────────────────────────────────────
|
|
166
192
|
|
|
167
|
-
//
|
|
168
|
-
// resolveLayerStyle (
|
|
193
|
+
// Registers each pattern's fill with the OL provider ahead of time, at the map's current
|
|
194
|
+
// pixelRatio, so resolveLayerStyle (synchronous) can find it already resolved — mirrors
|
|
169
195
|
// MapLibreLayerAdapter's addPatternsAndSymbolsToMap, which likewise runs before _addLayers
|
|
170
|
-
// reads the dataset's style.
|
|
171
|
-
// pixelRatio-scaled pipeline — see layerBuilders.js's resolveLayerStyle.
|
|
196
|
+
// reads the dataset's style. See canvasPatternStyle.js for how the fill is used.
|
|
172
197
|
async _registerPatterns (registryDatasets = datasetRegistry.topLevelDatasets()) {
|
|
173
198
|
const styles = []
|
|
174
199
|
registryDatasets.forEach(registryDataset => this._forEachLeafDataset(registryDataset, leaf => {
|
|
@@ -176,12 +201,14 @@ export default class OpenLayersLayerAdapter extends MapboxStyleLayerAdapter {
|
|
|
176
201
|
styles.push(leaf.style)
|
|
177
202
|
}
|
|
178
203
|
}))
|
|
179
|
-
|
|
180
|
-
|
|
204
|
+
if (styles.length) {
|
|
205
|
+
await this._mapProvider.addPatternsToMap(styles, datasetRegistry.mapStyle?.id, this._patternRegistry, this._pixelRatio)
|
|
206
|
+
}
|
|
181
207
|
}
|
|
182
208
|
|
|
183
|
-
// Rasterises and caches each symbol's icon image ahead of time,
|
|
184
|
-
// (
|
|
209
|
+
// Rasterises and caches each symbol's icon image ahead of time, at the map's current
|
|
210
|
+
// pixelRatio, so OpenLayersDataset.getFlatStyle (synchronous) can find it already resolved —
|
|
211
|
+
// same convention as _registerPatterns.
|
|
185
212
|
async _registerSymbols (registryDatasets = datasetRegistry.topLevelDatasets()) {
|
|
186
213
|
const styles = []
|
|
187
214
|
registryDatasets.forEach(registryDataset => this._forEachLeafDataset(registryDataset, leaf => {
|
|
@@ -189,7 +216,9 @@ export default class OpenLayersLayerAdapter extends MapboxStyleLayerAdapter {
|
|
|
189
216
|
styles.push(leaf.style)
|
|
190
217
|
}
|
|
191
218
|
}))
|
|
192
|
-
|
|
219
|
+
if (styles.length) {
|
|
220
|
+
await this._mapProvider.addSymbolsToMap(styles, datasetRegistry.mapStyle, this._symbolRegistry, this._pixelRatio)
|
|
221
|
+
}
|
|
193
222
|
}
|
|
194
223
|
|
|
195
224
|
// ol/style/flat's expression parser is stricter than MapLibre's filter dialect in some places
|
|
@@ -210,7 +239,7 @@ export default class OpenLayersLayerAdapter extends MapboxStyleLayerAdapter {
|
|
|
210
239
|
// from a stale, pre-switch base id forever (see layerBuilders.js's createDatasetLayer,
|
|
211
240
|
// which sets this the same way when the layer is first built).
|
|
212
241
|
if (registryDataset.hasSymbol) {
|
|
213
|
-
layer.set('symbolMeta', registryDataset.
|
|
242
|
+
layer.set('symbolMeta', registryDataset.getSymbolMeta(this._styleContext))
|
|
214
243
|
}
|
|
215
244
|
} catch (error) {
|
|
216
245
|
logger.warn(`OpenLayers datasets adapter: failed to build a style for dataset "${registryDataset.id}" — ${error.message}`)
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import OpenLayersLayerAdapter from './openlayersLayerAdapter.js'
|
|
2
2
|
import { datasetRegistry } from '../../registry/datasetRegistry.js'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { createPatternRegistry } from '../../../../../src/services/patternRegistry.js'
|
|
4
|
+
import { createSymbolRegistry } from '../../../../../src/services/symbolRegistry.js'
|
|
5
5
|
import { logger } from '../../../../../src/services/logger.js'
|
|
6
|
-
import {
|
|
6
|
+
import { SymbolImageCache } from '../../../../../providers/beta/openlayers/src/utils/symbolImages.js'
|
|
7
|
+
import { PatternImageCache } from '../../../../../providers/beta/openlayers/src/utils/patternImages.js'
|
|
8
|
+
import { buildFilterEvaluator } from '../../../../../providers/beta/openlayers/src/utils/filterEvaluator.js'
|
|
9
|
+
// The OL provider registers British National Grid when it loads
|
|
10
|
+
import '../../../../../providers/beta/openlayers/src/utils/bngProjection.js'
|
|
7
11
|
import VectorLayer from 'ol/layer/Vector.js'
|
|
8
12
|
import VectorTileLayer from 'ol/layer/VectorTile.js'
|
|
9
13
|
import * as layerBuilders from './layerBuilders.js'
|
|
10
14
|
|
|
15
|
+
const patternRegistry = createPatternRegistry()
|
|
16
|
+
|
|
17
|
+
const symbolRegistry = createSymbolRegistry()
|
|
18
|
+
|
|
11
19
|
jest.mock('../../registry/datasetRegistry.js')
|
|
12
20
|
|
|
13
21
|
// The mocked datasetRegistry's beforeEach attaches full demo data alongside this file's own
|
|
@@ -15,9 +23,8 @@ jest.mock('../../registry/datasetRegistry.js')
|
|
|
15
23
|
// — so pattern registration needs the real patternRegistry singleton, not an empty stub, even
|
|
16
24
|
// though none of this file's own fixtures configure a pattern themselves.
|
|
17
25
|
beforeEach(() => {
|
|
18
|
-
clearSymbolImageCache()
|
|
19
26
|
// Covers the full pipeline exercised here: SVG -> Image -> canvas (rasteriseToImageData needs
|
|
20
|
-
// drawImage/getImageData) -> ImageData -> canvas (
|
|
27
|
+
// drawImage/getImageData) -> ImageData -> canvas (SymbolImageCache.addImage needs putImageData;
|
|
21
28
|
// canvasPatternStyle's crisp-pattern Fill needs createPattern).
|
|
22
29
|
HTMLCanvasElement.prototype.getContext = jest.fn(() => ({
|
|
23
30
|
drawImage: jest.fn(),
|
|
@@ -45,7 +52,20 @@ const makeMap = (pixelRatio = 1) => {
|
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
// Stands in for the OL provider's methods the adapter uses, with a real symbol image cache
|
|
56
|
+
const makeMapProvider = (map) => {
|
|
57
|
+
const symbolImages = new SymbolImageCache()
|
|
58
|
+
const patternImages = new PatternImageCache()
|
|
59
|
+
return {
|
|
60
|
+
map,
|
|
61
|
+
addSymbolsToMap: jest.fn((configs, mapStyle, symbolRegistry, pixelRatio) => symbolImages.registerSymbols(configs, mapStyle, symbolRegistry, pixelRatio)),
|
|
62
|
+
getSymbolDataUri: (imageId) => symbolImages.getDataUri(imageId),
|
|
63
|
+
addPatternsToMap: jest.fn((configs, mapStyleId, patternRegistry, pixelRatio) => patternImages.registerPatterns(configs, mapStyleId, patternRegistry, pixelRatio)),
|
|
64
|
+
getPatternFill: (imageId) => patternImages.getFill(imageId),
|
|
65
|
+
buildFilterEvaluator,
|
|
66
|
+
reapplyHighlights: jest.fn()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
49
69
|
|
|
50
70
|
let map, mapProvider, adapter
|
|
51
71
|
|
|
@@ -56,9 +76,9 @@ beforeEach(() => {
|
|
|
56
76
|
datasetRegistry.attachCreateDataset(adapter.createDataset)
|
|
57
77
|
datasetRegistry.mockExtend({
|
|
58
78
|
'ds-fill': { id: 'ds-fill', style: { fill: '#0000ff' }, geojson: { type: 'FeatureCollection', features: [point(1, [0, 0])] } },
|
|
59
|
-
'ds-bare': { id: 'ds-bare' },
|
|
79
|
+
'ds-bare': { id: 'ds-bare', style: { stroke: null } },
|
|
60
80
|
'ds-tiles': { id: 'ds-tiles', tiles: ['https://example.com/{z}/{x}/{y}'], style: { fill: '#0000ff' } },
|
|
61
|
-
'ds-tiles-bare': { id: 'ds-tiles-bare', tiles: ['https://example.com/{z}/{x}/{y}'] },
|
|
81
|
+
'ds-tiles-bare': { id: 'ds-tiles-bare', style: { stroke: null }, tiles: ['https://example.com/{z}/{x}/{y}'] },
|
|
62
82
|
'ds-dynamic': { id: 'ds-dynamic', style: { fill: '#0000ff' }, dynamicGeoJSON: { url: 'https://example.com', idProperty: 'ref' } },
|
|
63
83
|
'ds-parent': { id: 'ds-parent', sublayerIds: ['ds-child-a', 'ds-child-b'], geojson: { type: 'FeatureCollection', features: [point(1, [0, 0])] } },
|
|
64
84
|
'ds-child-a': { id: 'ds-child-a', parentId: 'ds-parent', style: { fill: '#ff0000' }, filter: ['==', ['get', 'cat'], 'a'] },
|
|
@@ -237,12 +257,12 @@ describe('visibility', () => {
|
|
|
237
257
|
})
|
|
238
258
|
|
|
239
259
|
describe('applyFeatureFilter', () => {
|
|
240
|
-
it('re-derives
|
|
260
|
+
it('re-derives the flat style to reflect newly hidden features', async () => {
|
|
241
261
|
await adapter.addDataset('ds-fill')
|
|
242
262
|
datasetRegistry.mockExtend({ 'ds-fill': { id: 'ds-fill', style: { fill: '#0000ff' }, hiddenFeatures: [1], geojson: { type: 'FeatureCollection', features: [] } } })
|
|
243
263
|
adapter.applyFeatureFilter('ds-fill')
|
|
244
|
-
//
|
|
245
|
-
// checking the underlying style was re-set to the dataset's current (filtered)
|
|
264
|
+
// the flat style now wraps in a filter rule — confirm the layer's style function reflects it by
|
|
265
|
+
// checking the underlying style was re-set to the dataset's current (filtered) flat style.
|
|
246
266
|
const registryDataset = datasetRegistry.getDataset('ds-fill')
|
|
247
267
|
expect(getLayer('ds-fill').getStyle()).toBeDefined()
|
|
248
268
|
expect(registryDataset.filter).not.toBeNull()
|
|
@@ -369,6 +389,51 @@ describe('pattern registration', () => {
|
|
|
369
389
|
expect(setStyleSpy).toHaveBeenCalledWith(expect.any(Function))
|
|
370
390
|
})
|
|
371
391
|
|
|
392
|
+
it('onMapSizeChange() re-rasterises symbols at the new pixelRatio so they stay drawn 1:1', async () => {
|
|
393
|
+
await adapter.addDataset('ds-symbol')
|
|
394
|
+
const layer = getLayer('ds-symbol')
|
|
395
|
+
expect(layer.getStyle()).toMatchObject({ 'icon-scale': 1 })
|
|
396
|
+
expect(layer.get('symbolMeta').pixelRatio).toBe(1)
|
|
397
|
+
|
|
398
|
+
map.getPixelRatio.mockReturnValue(2)
|
|
399
|
+
await adapter.onMapSizeChange()
|
|
400
|
+
|
|
401
|
+
expect(layer.getStyle()).toMatchObject({ 'icon-src': 'data:image/png;base64,mock', 'icon-scale': 0.5 })
|
|
402
|
+
expect(layer.get('symbolMeta').pixelRatio).toBe(2)
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
it('onMapSizeChange() leaves symbol styles alone if the pixel ratio changes again while its images are registering', async () => {
|
|
406
|
+
await adapter.addDataset('ds-symbol')
|
|
407
|
+
const layer = getLayer('ds-symbol')
|
|
408
|
+
const setStyleSpy = jest.spyOn(layer, 'setStyle')
|
|
409
|
+
// a second map-size change lands mid-registration — its own call will apply the newer ratio
|
|
410
|
+
const registering = adapter.onMapSizeChange()
|
|
411
|
+
map.getPixelRatio.mockReturnValue(2)
|
|
412
|
+
await registering
|
|
413
|
+
expect(setStyleSpy).not.toHaveBeenCalled()
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
it('onMapSizeChange() redraws highlights once the new images are in place, so a selected symbol isn\'t left blurry', async () => {
|
|
417
|
+
await adapter.addDataset('ds-symbol')
|
|
418
|
+
const layer = getLayer('ds-symbol')
|
|
419
|
+
const setStyleSpy = jest.spyOn(layer, 'setStyle')
|
|
420
|
+
map.getPixelRatio.mockReturnValue(2)
|
|
421
|
+
mapProvider.reapplyHighlights.mockImplementation(() => {
|
|
422
|
+
// by now the layer has been restyled with the new ratio's images
|
|
423
|
+
expect(setStyleSpy).toHaveBeenCalled()
|
|
424
|
+
})
|
|
425
|
+
await adapter.onMapSizeChange()
|
|
426
|
+
expect(mapProvider.reapplyHighlights).toHaveBeenCalledTimes(1)
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
it('onMapSizeChange() leaves highlights to the newer call when the pixel ratio has moved on', async () => {
|
|
430
|
+
await adapter.addDataset('ds-symbol')
|
|
431
|
+
const registering = adapter.onMapSizeChange()
|
|
432
|
+
map.getPixelRatio.mockReturnValue(2)
|
|
433
|
+
await registering
|
|
434
|
+
expect(mapProvider.reapplyHighlights).not.toHaveBeenCalled()
|
|
435
|
+
})
|
|
436
|
+
|
|
372
437
|
it('onMapSizeChange() does not touch a plain fill/stroke dataset\'s style', async () => {
|
|
373
438
|
await adapter.addDataset('ds-fill')
|
|
374
439
|
const layer = getLayer('ds-fill')
|
|
@@ -379,7 +444,20 @@ describe('pattern registration', () => {
|
|
|
379
444
|
})
|
|
380
445
|
|
|
381
446
|
describe('symbol registration', () => {
|
|
382
|
-
it('registers
|
|
447
|
+
it('registers symbol images with the OL provider, using the adapter\'s registry at the map\'s pixel ratio', async () => {
|
|
448
|
+
map.getPixelRatio.mockReturnValue(2)
|
|
449
|
+
await adapter.addDataset('ds-symbol')
|
|
450
|
+
expect(mapProvider.addSymbolsToMap).toHaveBeenCalledWith(
|
|
451
|
+
[expect.objectContaining({ symbol: 'pin' })], datasetRegistry.mapStyle, symbolRegistry, 2
|
|
452
|
+
)
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
it('doesn\'t call the provider when there are no symbols to register', async () => {
|
|
456
|
+
await adapter.addDataset('ds-fill')
|
|
457
|
+
expect(mapProvider.addSymbolsToMap).not.toHaveBeenCalled()
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
it('registers a symbol before init() adds its layer, so getFlatStyle already resolves it', async () => {
|
|
383
461
|
await adapter.init()
|
|
384
462
|
expect(getLayer('ds-symbol').getStyle()).toMatchObject({ 'icon-src': 'data:image/png;base64,mock' })
|
|
385
463
|
})
|
|
@@ -408,9 +486,19 @@ describe('symbol registration', () => {
|
|
|
408
486
|
})
|
|
409
487
|
|
|
410
488
|
// symbolMeta.imageId is only ever resolved for the 'normal' variant, but that's still
|
|
411
|
-
// mapStyle-dependent (see registerSymbol's resolve() call) — so a stale, pre-switch id left
|
|
489
|
+
// mapStyle-dependent (see SymbolImageCache.registerSymbol's resolve() call) — so a stale, pre-switch id left
|
|
412
490
|
// on the layer would make highlightFeatures.js's reverse-map keep resolving the OLD theme's
|
|
413
491
|
// selected/active image forever, regardless of how many times the map style actually changes.
|
|
492
|
+
it('redraws highlights after onMapStyleChange() has re-registered and restyled, so a selected symbol takes the new colours', async () => {
|
|
493
|
+
await adapter.addDataset('ds-symbol')
|
|
494
|
+
const setStyleSpy = jest.spyOn(getLayer('ds-symbol'), 'setStyle')
|
|
495
|
+
mapProvider.reapplyHighlights.mockImplementation(() => {
|
|
496
|
+
expect(setStyleSpy).toHaveBeenCalled()
|
|
497
|
+
})
|
|
498
|
+
await adapter.onMapStyleChange()
|
|
499
|
+
expect(mapProvider.reapplyHighlights).toHaveBeenCalledTimes(1)
|
|
500
|
+
})
|
|
501
|
+
|
|
414
502
|
it('refreshes symbolMeta on onMapStyleChange(), not just the layer\'s own style', async () => {
|
|
415
503
|
await adapter.addDataset('ds-symbol')
|
|
416
504
|
const layer = getLayer('ds-symbol')
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { MapboxStyleDataset } from '../../../registry/mapboxStyleDataset.js'
|
|
2
2
|
import { datasetRegistry } from '../../../registry/datasetRegistry.js'
|
|
3
3
|
import { getValueForStyle } from '../../../../../../src/utils/getValueForStyle.js'
|
|
4
|
-
import { getSymbolAnchor } from '../../../../../../src/utils/symbolUtils.js'
|
|
5
|
-
import { symbolRegistry } from '../../../../../../src/services/symbolRegistry.js'
|
|
6
|
-
import { getCachedSymbolDataUri, SYMBOL_RASTER_PIXEL_RATIO } from '../../../../../../providers/beta/openlayers/src/utils/symbolImages.js'
|
|
7
4
|
|
|
8
5
|
const MAX_TILE_ZOOM = 22
|
|
9
|
-
const DEFAULT_STROKE_WIDTH = 1
|
|
10
6
|
|
|
11
7
|
/**
|
|
12
8
|
* OpenLayers implementation of the shared Dataset registry model.
|
|
@@ -102,40 +98,41 @@ export class OpenLayersDataset extends MapboxStyleDataset {
|
|
|
102
98
|
|
|
103
99
|
/**
|
|
104
100
|
* The resolved base (normal) symbol imageId + anchor for this dataset — layerBuilders.js tags
|
|
105
|
-
* the OL layer with this so highlightFeatures.js can resolve a select/active
|
|
106
|
-
* for it
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* @
|
|
101
|
+
* the OL layer with this so the OL provider's highlightFeatures.js can resolve a select/active
|
|
102
|
+
* highlight image for it without reaching back into the datasets plugin's own registries, the
|
|
103
|
+
* same way MapLibre's highlight code reads icon-image/icon-anchor straight off the rendered
|
|
104
|
+
* style layer instead of re-deriving them.
|
|
105
|
+
* @param {Object} context - the adapter's style context
|
|
106
|
+
* @param {number} context.pixelRatio - the map's current pixelRatio, which the image is rasterised at
|
|
107
|
+
* @param {Object} context.symbolRegistry
|
|
108
|
+
* @returns {{ imageId: string, anchor: number[], pixelRatio: number }|null}
|
|
111
109
|
*/
|
|
112
|
-
|
|
110
|
+
getSymbolMeta ({ pixelRatio, symbolRegistry }) {
|
|
113
111
|
if (!this.hasSymbol) {
|
|
114
112
|
return null
|
|
115
113
|
}
|
|
116
|
-
const imageId = symbolRegistry.getSymbolImageId(this.style, datasetRegistry.mapStyle,
|
|
114
|
+
const imageId = symbolRegistry.getSymbolImageId(this.style, datasetRegistry.mapStyle, 'normal', pixelRatio)
|
|
117
115
|
if (!imageId) {
|
|
118
116
|
return null
|
|
119
117
|
}
|
|
120
|
-
return { imageId, anchor:
|
|
118
|
+
return { imageId, anchor: symbolRegistry.getSymbolDef(this.style).anchor, pixelRatio }
|
|
121
119
|
}
|
|
122
120
|
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
// free (colour resolution + hashing)
|
|
130
|
-
|
|
131
|
-
_symbolStyle () {
|
|
121
|
+
// The image is rasterised at the map's own pixelRatio and drawn at 1 / pixelRatio, i.e. one
|
|
122
|
+
// image pixel per device pixel — any other ratio makes the browser resample it, which Chrome
|
|
123
|
+
// does with visible aliasing. So, like patterns, symbols are re-registered on resize. Falls
|
|
124
|
+
// back to an empty style (no icon at all) until the image has been rasterised ahead of time by
|
|
125
|
+
// the adapter (image registration is async; this must stay synchronous). Reuses getSymbolMeta
|
|
126
|
+
// rather than re-resolving getSymbolImageId/getSymbolDef itself — symbolRegistry.resolve()/
|
|
127
|
+
// getSymbolDef() aren't free (colour resolution + hashing).
|
|
128
|
+
_symbolStyle (context) {
|
|
132
129
|
const style = {}
|
|
133
|
-
const meta = this.
|
|
134
|
-
const dataUri = meta &&
|
|
130
|
+
const meta = this.getSymbolMeta(context)
|
|
131
|
+
const dataUri = meta && context.getSymbolDataUri(meta.imageId)
|
|
135
132
|
if (dataUri) {
|
|
136
133
|
style['icon-src'] = dataUri
|
|
137
134
|
style['icon-anchor'] = meta.anchor
|
|
138
|
-
style['icon-scale'] = 1 /
|
|
135
|
+
style['icon-scale'] = 1 / context.pixelRatio
|
|
139
136
|
}
|
|
140
137
|
return this._wrapWithFilter(style)
|
|
141
138
|
}
|
|
@@ -149,11 +146,13 @@ export class OpenLayersDataset extends MapboxStyleDataset {
|
|
|
149
146
|
* this getter knows nothing about. hasFill is also true for a pattern dataset (see base
|
|
150
147
|
* Dataset.hasFill), so that's explicitly excluded here rather than emitting a meaningless
|
|
151
148
|
* fill-color for it.
|
|
149
|
+
* @param {Object} context - the adapter's style context; symbol datasets use its pixelRatio,
|
|
150
|
+
* symbolRegistry and getSymbolDataUri (the OL provider's registered image lookup)
|
|
152
151
|
* @returns {Object|Array<Object>}
|
|
153
152
|
*/
|
|
154
|
-
|
|
153
|
+
getFlatStyle (context) {
|
|
155
154
|
if (this.hasSymbol) {
|
|
156
|
-
return this._symbolStyle()
|
|
155
|
+
return this._symbolStyle(context)
|
|
157
156
|
}
|
|
158
157
|
const mapStyleId = datasetRegistry.mapStyle?.id
|
|
159
158
|
const style = {}
|
|
@@ -162,7 +161,7 @@ export class OpenLayersDataset extends MapboxStyleDataset {
|
|
|
162
161
|
}
|
|
163
162
|
if (this.hasStroke) {
|
|
164
163
|
style['stroke-color'] = getValueForStyle(this.style.stroke, mapStyleId)
|
|
165
|
-
style['stroke-width'] = this.style.strokeWidth
|
|
164
|
+
style['stroke-width'] = this.style.strokeWidth
|
|
166
165
|
if (this.style.strokeDashArray) {
|
|
167
166
|
style['stroke-line-dash'] = this.style.strokeDashArray
|
|
168
167
|
}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { OpenLayersDataset } from './openLayersDataset.js'
|
|
2
2
|
import { datasetRegistry } from '../../../registry/datasetRegistry.js'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { createSymbolRegistry } from '../../../../../../src/services/symbolRegistry.js'
|
|
4
|
+
import { SymbolImageCache } from '../../../../../../providers/beta/openlayers/src/utils/symbolImages.js'
|
|
5
|
+
|
|
6
|
+
const symbolRegistry = createSymbolRegistry()
|
|
5
7
|
// Use the mock datasetRegistry with the demo datasets attached before each test
|
|
6
8
|
// so we can test Dataset methods that depend on parent/sublayer relationships and styles
|
|
7
9
|
jest.mock('../../../registry/datasetRegistry.js')
|
|
8
10
|
|
|
11
|
+
// The map's own pixelRatio — symbols are rasterised at it and drawn 1:1 (icon-scale 1 / ratio)
|
|
12
|
+
const PIXEL_RATIO = 2
|
|
13
|
+
// pin at medium: its default anchor (just below the tip), and [0.5, 1] — the bottom of the pin shape itself
|
|
14
|
+
const PIN_ANCHOR = symbolRegistry.getSymbolDef({ symbol: 'pin' }).anchor
|
|
15
|
+
const PIN_BOTTOM_ANCHOR = symbolRegistry.getSymbolDef({ symbol: 'pin', symbolAnchor: [0.5, 1] }).anchor
|
|
16
|
+
|
|
17
|
+
// The OL provider's symbol images, and the style context the adapter resolves styles against
|
|
18
|
+
let symbolImages
|
|
19
|
+
const context = (pixelRatio = PIXEL_RATIO) => ({ pixelRatio, symbolRegistry, getSymbolDataUri: (imageId) => symbolImages.getDataUri(imageId) })
|
|
20
|
+
|
|
9
21
|
beforeAll(() => {
|
|
10
22
|
globalThis.Image = class {
|
|
11
23
|
constructor (w, h) { this.width = w; this.height = h; this._src = '' }
|
|
@@ -28,7 +40,7 @@ describe('OpenLayersDataset', () => {
|
|
|
28
40
|
'ds-stroke-only': { id: 'ds-stroke-only', style: { stroke: 'red', strokeWidth: 2 } },
|
|
29
41
|
'ds-dashed-stroke': { id: 'ds-dashed-stroke', style: { stroke: 'red', strokeDashArray: [4, 2] } },
|
|
30
42
|
'ds-transparent-fill': { id: 'ds-transparent-fill', style: { fill: 'transparent' } },
|
|
31
|
-
'ds-bare': { id: 'ds-bare' },
|
|
43
|
+
'ds-bare': { id: 'ds-bare', style: { stroke: null } },
|
|
32
44
|
'ds-tiles': { id: 'ds-tiles', tiles: ['https://example.com/{z}/{x}/{y}'], minZoom: 5, maxZoom: 15 },
|
|
33
45
|
'ds-tiles-no-zoom': { id: 'ds-tiles-no-zoom', tiles: ['https://example.com/{z}/{x}/{y}'] },
|
|
34
46
|
'ds-static-geojson': { id: 'ds-static-geojson', geojson: { type: 'FeatureCollection', features: [] }, style: { fill: 'green' } },
|
|
@@ -40,7 +52,7 @@ describe('OpenLayersDataset', () => {
|
|
|
40
52
|
'ds-symbol-anchor': { id: 'ds-symbol-anchor', style: { symbol: 'pin', symbolAnchor: [0.5, 1] } },
|
|
41
53
|
'ds-symbol-filter': { id: 'ds-symbol-filter', style: { symbol: 'pin' }, filter: ['==', ['get', 'type'], 'a'] }
|
|
42
54
|
})
|
|
43
|
-
|
|
55
|
+
symbolImages = new SymbolImageCache()
|
|
44
56
|
})
|
|
45
57
|
|
|
46
58
|
describe('leafLayerIds', () => {
|
|
@@ -164,50 +176,51 @@ describe('OpenLayersDataset', () => {
|
|
|
164
176
|
})
|
|
165
177
|
})
|
|
166
178
|
|
|
167
|
-
describe('
|
|
179
|
+
describe('getSymbolMeta', () => {
|
|
168
180
|
it('returns null for a dataset with no symbol', () => {
|
|
169
|
-
expect(datasetRegistry.getDataset('ds-fill-only').
|
|
181
|
+
expect(datasetRegistry.getDataset('ds-fill-only').getSymbolMeta(context())).toBeNull()
|
|
170
182
|
})
|
|
171
183
|
|
|
172
184
|
it('returns null when the style\'s symbol name has no known symbol definition', () => {
|
|
173
|
-
expect(datasetRegistry.getDataset('ds-symbol-unknown').
|
|
185
|
+
expect(datasetRegistry.getDataset('ds-symbol-unknown').getSymbolMeta(context())).toBeNull()
|
|
174
186
|
})
|
|
175
187
|
|
|
176
188
|
it('returns the resolved imageId and anchor for a known symbol, with no registration needed', () => {
|
|
177
|
-
expect(datasetRegistry.getDataset('ds-symbol').
|
|
189
|
+
expect(datasetRegistry.getDataset('ds-symbol').getSymbolMeta(context())).toEqual({
|
|
178
190
|
imageId: expect.any(String),
|
|
179
|
-
anchor:
|
|
191
|
+
anchor: PIN_ANCHOR,
|
|
192
|
+
pixelRatio: PIXEL_RATIO
|
|
180
193
|
})
|
|
181
194
|
})
|
|
182
195
|
|
|
183
196
|
it('uses the dataset\'s own symbolAnchor over the symbol definition\'s default', () => {
|
|
184
|
-
expect(datasetRegistry.getDataset('ds-symbol-anchor').
|
|
197
|
+
expect(datasetRegistry.getDataset('ds-symbol-anchor').getSymbolMeta(context()).anchor).toEqual(PIN_BOTTOM_ANCHOR)
|
|
185
198
|
})
|
|
186
199
|
})
|
|
187
200
|
|
|
188
|
-
describe('
|
|
201
|
+
describe('getFlatStyle', () => {
|
|
189
202
|
it('returns fill-color for a fill-only dataset', () => {
|
|
190
|
-
expect(datasetRegistry.getDataset('ds-fill-only').
|
|
203
|
+
expect(datasetRegistry.getDataset('ds-fill-only').getFlatStyle(context())).toEqual({ 'fill-color': 'blue' })
|
|
191
204
|
})
|
|
192
205
|
|
|
193
|
-
it('returns stroke-color and stroke-width
|
|
194
|
-
expect(datasetRegistry.getDataset('ds-stroke-only').
|
|
206
|
+
it('returns stroke-color and stroke-width', () => {
|
|
207
|
+
expect(datasetRegistry.getDataset('ds-stroke-only').getFlatStyle(context())).toEqual({ 'stroke-color': 'red', 'stroke-width': 2 })
|
|
195
208
|
})
|
|
196
209
|
|
|
197
210
|
it('includes stroke-line-dash when strokeDashArray is set', () => {
|
|
198
|
-
expect(datasetRegistry.getDataset('ds-dashed-stroke').
|
|
211
|
+
expect(datasetRegistry.getDataset('ds-dashed-stroke').getFlatStyle(context())).toEqual({
|
|
199
212
|
'stroke-color': 'red',
|
|
200
|
-
'stroke-width':
|
|
213
|
+
'stroke-width': 2,
|
|
201
214
|
'stroke-line-dash': [4, 2]
|
|
202
215
|
})
|
|
203
216
|
})
|
|
204
217
|
|
|
205
218
|
it('returns an empty style object for a bare dataset', () => {
|
|
206
|
-
expect(datasetRegistry.getDataset('ds-bare').
|
|
219
|
+
expect(datasetRegistry.getDataset('ds-bare').getFlatStyle(context())).toEqual({})
|
|
207
220
|
})
|
|
208
221
|
|
|
209
222
|
it('wraps the style in a filter rule when the dataset has hidden features', () => {
|
|
210
|
-
expect(datasetRegistry.getDataset('ds-hf').
|
|
223
|
+
expect(datasetRegistry.getDataset('ds-hf').getFlatStyle(context())).toEqual([{
|
|
211
224
|
filter: ['!', ['in', ['to-string', ['id']], ['literal', ['1', '2']]]],
|
|
212
225
|
style: { 'fill-color': 'blue' }
|
|
213
226
|
}])
|
|
@@ -215,45 +228,51 @@ describe('OpenLayersDataset', () => {
|
|
|
215
228
|
|
|
216
229
|
describe('pattern fills', () => {
|
|
217
230
|
// A pattern fill is built by canvasPatternStyle.js's crisp CanvasPattern-based style
|
|
218
|
-
// instead (see layerBuilders.js's resolveLayerStyle) —
|
|
231
|
+
// instead (see layerBuilders.js's resolveLayerStyle) — getFlatStyle never resolves one, and
|
|
219
232
|
// must not fall back to a meaningless fill-color either (see base Dataset.hasFill, which
|
|
220
233
|
// is also true for a pattern dataset).
|
|
221
234
|
it('never sets fill-color or fill-pattern-src for a pattern dataset', () => {
|
|
222
|
-
expect(datasetRegistry.getDataset('ds-pattern').
|
|
235
|
+
expect(datasetRegistry.getDataset('ds-pattern').getFlatStyle(context())).toEqual({})
|
|
223
236
|
})
|
|
224
237
|
})
|
|
225
238
|
|
|
226
239
|
describe('symbols', () => {
|
|
227
240
|
it('has no icon-src before the symbol is registered', () => {
|
|
228
|
-
//
|
|
229
|
-
expect(datasetRegistry.getDataset('ds-symbol').
|
|
241
|
+
// image registration is async and hasn't run yet — getFlatStyle must never block on it.
|
|
242
|
+
expect(datasetRegistry.getDataset('ds-symbol').getFlatStyle(context())).toEqual({})
|
|
230
243
|
})
|
|
231
244
|
|
|
232
245
|
it('uses icon-src, icon-anchor and icon-scale once the symbol is registered', async () => {
|
|
233
246
|
const dataset = datasetRegistry.getDataset('ds-symbol')
|
|
234
|
-
await registerSymbol(dataset.style, undefined, symbolRegistry,
|
|
235
|
-
expect(dataset.
|
|
247
|
+
await symbolImages.registerSymbol(dataset.style, undefined, symbolRegistry, PIXEL_RATIO)
|
|
248
|
+
expect(dataset.getFlatStyle(context())).toEqual({
|
|
236
249
|
'icon-src': 'data:image/png;base64,mock',
|
|
237
|
-
'icon-anchor':
|
|
238
|
-
'icon-scale': 1 /
|
|
250
|
+
'icon-anchor': PIN_ANCHOR,
|
|
251
|
+
'icon-scale': 1 / PIXEL_RATIO
|
|
239
252
|
})
|
|
240
253
|
})
|
|
241
254
|
|
|
242
255
|
it('uses the dataset\'s own symbolAnchor over the symbol definition\'s default', async () => {
|
|
243
256
|
const dataset = datasetRegistry.getDataset('ds-symbol-anchor')
|
|
244
|
-
await registerSymbol(dataset.style, undefined, symbolRegistry,
|
|
245
|
-
expect(dataset.
|
|
257
|
+
await symbolImages.registerSymbol(dataset.style, undefined, symbolRegistry, PIXEL_RATIO)
|
|
258
|
+
expect(dataset.getFlatStyle(context())['icon-anchor']).toEqual(PIN_BOTTOM_ANCHOR)
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('only finds the image registered at the same pixelRatio', async () => {
|
|
262
|
+
const dataset = datasetRegistry.getDataset('ds-symbol')
|
|
263
|
+
await symbolImages.registerSymbol(dataset.style, undefined, symbolRegistry, PIXEL_RATIO)
|
|
264
|
+
expect(dataset.getFlatStyle(context(PIXEL_RATIO + 1))).toEqual({})
|
|
246
265
|
})
|
|
247
266
|
|
|
248
267
|
it('wraps icon style in a filter rule when the dataset has one', async () => {
|
|
249
268
|
const dataset = datasetRegistry.getDataset('ds-symbol-filter')
|
|
250
|
-
await registerSymbol(dataset.style, undefined, symbolRegistry,
|
|
251
|
-
expect(dataset.
|
|
269
|
+
await symbolImages.registerSymbol(dataset.style, undefined, symbolRegistry, PIXEL_RATIO)
|
|
270
|
+
expect(dataset.getFlatStyle(context())).toEqual([{
|
|
252
271
|
filter: ['==', ['get', 'type'], 'a'],
|
|
253
272
|
style: {
|
|
254
273
|
'icon-src': 'data:image/png;base64,mock',
|
|
255
|
-
'icon-anchor':
|
|
256
|
-
'icon-scale': 1 /
|
|
274
|
+
'icon-anchor': PIN_ANCHOR,
|
|
275
|
+
'icon-scale': 1 / PIXEL_RATIO
|
|
257
276
|
}
|
|
258
277
|
}])
|
|
259
278
|
})
|
|
@@ -174,7 +174,7 @@ export const createDynamicSource = ({ dynamicGeoJSON, mapProvider, onUpdate }) =
|
|
|
174
174
|
mapProvider.map.on('moveend', handleMoveEnd)
|
|
175
175
|
|
|
176
176
|
// Initial fetch
|
|
177
|
-
fetchData()
|
|
177
|
+
fetchData() // NOSONAR: Not changing for now as used in production
|
|
178
178
|
|
|
179
179
|
return {
|
|
180
180
|
/**
|
|
@@ -203,7 +203,7 @@ export const createDynamicSource = ({ dynamicGeoJSON, mapProvider, onUpdate }) =
|
|
|
203
203
|
refresh () {
|
|
204
204
|
state.features.clear()
|
|
205
205
|
state.fetchedBbox = null
|
|
206
|
-
fetchData()
|
|
206
|
+
fetchData() // NOSONAR: Not changing for now as used in production
|
|
207
207
|
},
|
|
208
208
|
|
|
209
209
|
/**
|
|
@@ -56,7 +56,7 @@ export function DatasetsInit ({ pluginConfig, pluginState, mapState, mapProvider
|
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
initDatasets()
|
|
59
|
+
initDatasets() // NOSONAR: Not changing for now as used in production
|
|
60
60
|
}, [isBaseMapReady])
|
|
61
61
|
|
|
62
62
|
useEffect(() => {
|
|
@@ -78,7 +78,7 @@ export function DatasetsInit ({ pluginConfig, pluginState, mapState, mapProvider
|
|
|
78
78
|
// MAP_STYLE_CHANGE, see useHighlightSync.js) pick up the new theme's selected/active
|
|
79
79
|
// symbol images, instead of a highlight staying stuck on whatever was cached moments
|
|
80
80
|
// before the switch.
|
|
81
|
-
Promise.resolve(layerAdapter.onMapStyleChange()).then(() => {
|
|
81
|
+
Promise.resolve(layerAdapter.onMapStyleChange()).then(() => { // NOSONAR: Not changing for now as used in production
|
|
82
82
|
eventBus.emit(EVENTS.MAP_DATA_CHANGE)
|
|
83
83
|
})
|
|
84
84
|
}
|