@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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MapboxStyleDataset } from '../../../registry/mapboxStyleDataset.js'
|
|
2
|
-
import { anchorToMaplibre } from '../../../../../../providers/maplibre/src/utils/symbolImages.js'
|
|
3
2
|
import { logger } from '../../../../../../src/services/logger.js'
|
|
4
3
|
const MAX_TILE_ZOOM = 22
|
|
5
4
|
|
|
@@ -73,7 +72,8 @@ export class MapLibreDataset extends MapboxStyleDataset {
|
|
|
73
72
|
return null
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
// iconLayout: icon-anchor/icon-offset from MapLibreProvider.getSymbolIconLayout
|
|
76
|
+
getSymbolSource (imageId, iconLayout) {
|
|
77
77
|
return {
|
|
78
78
|
id: this.symbolLayerId,
|
|
79
79
|
type: 'symbol',
|
|
@@ -84,7 +84,7 @@ export class MapLibreDataset extends MapboxStyleDataset {
|
|
|
84
84
|
layout: {
|
|
85
85
|
visibility: this.visibility,
|
|
86
86
|
'icon-image': imageId,
|
|
87
|
-
|
|
87
|
+
...iconLayout,
|
|
88
88
|
'icon-allow-overlap': true
|
|
89
89
|
},
|
|
90
90
|
...(this.filter ? { filter: this.filter } : {})
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { MapLibreDataset } from './mapLibreDataset.js'
|
|
2
2
|
import { datasetRegistry } from '../../../registry/datasetRegistry.js'
|
|
3
3
|
import { logger } from '../../../../../../src/services/logger.js'
|
|
4
|
+
import { hashString } from '../../../../../../src/utils/hashString.js'
|
|
4
5
|
// Use the mock datasetRegistry with the demo datasets attached before each test
|
|
5
6
|
// so we can test Dataset methods that depend on parent/sublayer relationships and styles
|
|
6
7
|
jest.mock('../../../registry/datasetRegistry.js')
|
|
7
8
|
jest.mock('../../../../../../src/services/logger.js')
|
|
8
9
|
|
|
10
|
+
// The demo existing-fields tiles URL and static geojson URL, as sourceId hashes them
|
|
11
|
+
const EXISTING_FIELDS_SOURCE_ID = `tiles-${hashString('https://farming-tiles-702a60f45633.herokuapp.com/field_parcels_with_hedges_wgs84/{z}/{x}/{y}')}`
|
|
12
|
+
const STATIC_GEOJSON_SOURCE_ID = `geojson-${hashString('https://example.com/static.geojson')}`
|
|
13
|
+
|
|
9
14
|
describe('MapLibreDataset', () => {
|
|
10
15
|
beforeEach(() => {
|
|
11
16
|
logger.warn.mockClear()
|
|
@@ -17,7 +22,7 @@ describe('MapLibreDataset', () => {
|
|
|
17
22
|
'ds-transparent-fill': { id: 'ds-transparent-fill', style: { fill: 'transparent' } },
|
|
18
23
|
// shared: no special properties — used by layerIds, sourceId, source, visibility,
|
|
19
24
|
// _hiddenFeaturesIdExpression, _hiddenFeaturesFilter, and filter tests
|
|
20
|
-
'ds-bare': { id: 'ds-bare' },
|
|
25
|
+
'ds-bare': { id: 'ds-bare', style: { stroke: null } },
|
|
21
26
|
'ds-no-id-prop': { id: 'ds-no-id-prop', geojson: 'https://example.com/data', transformRequest: () => {} },
|
|
22
27
|
'ds-no-transform': { id: 'ds-no-transform', geojson: 'https://example.com/data', idProperty: 'id' },
|
|
23
28
|
'ds-static-url': { id: 'ds-static-url', geojson: 'https://example.com/static.geojson' },
|
|
@@ -212,12 +217,12 @@ describe('MapLibreDataset', () => {
|
|
|
212
217
|
|
|
213
218
|
it('returns a tiles-based id for a tile dataset (array tiles)', () => {
|
|
214
219
|
const dataset = datasetRegistry.getDataset('existing-fields')
|
|
215
|
-
expect(dataset.sourceId).toBe(
|
|
220
|
+
expect(dataset.sourceId).toBe(EXISTING_FIELDS_SOURCE_ID)
|
|
216
221
|
})
|
|
217
222
|
|
|
218
223
|
it('returns a tiles-based id when tiles is a plain string (line 76 non-array branch)', () => {
|
|
219
224
|
const dataset = datasetRegistry.getDataset('existing-fields')
|
|
220
|
-
expect(dataset.sourceId).toBe(
|
|
225
|
+
expect(dataset.sourceId).toBe(EXISTING_FIELDS_SOURCE_ID)
|
|
221
226
|
})
|
|
222
227
|
|
|
223
228
|
it('returns geojson-dynamic-{id} for a dynamic geojson source', () => {
|
|
@@ -225,7 +230,7 @@ describe('MapLibreDataset', () => {
|
|
|
225
230
|
})
|
|
226
231
|
|
|
227
232
|
it('returns geojson-{hash} for a static string geojson url', () => {
|
|
228
|
-
expect(datasetRegistry.getDataset('ds-static-url').sourceId).toBe(
|
|
233
|
+
expect(datasetRegistry.getDataset('ds-static-url').sourceId).toBe(STATIC_GEOJSON_SOURCE_ID)
|
|
229
234
|
})
|
|
230
235
|
|
|
231
236
|
it('returns geojson-{id} for an object geojson source', () => {
|
|
@@ -328,43 +333,31 @@ describe('MapLibreDataset', () => {
|
|
|
328
333
|
filter: ['in', ['get', 'category'], 'prehistoric']
|
|
329
334
|
}
|
|
330
335
|
|
|
331
|
-
|
|
332
|
-
expect(datasetRegistry.getDataset('historic-monuments-prehistoric').getSymbolSource('my-icon', null, null)).toEqual({
|
|
333
|
-
...prehistoricBase,
|
|
334
|
-
layout: { visibility: 'visible', 'icon-image': 'my-icon', 'icon-anchor': 'center', 'icon-allow-overlap': true }
|
|
335
|
-
})
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
it('uses the provided anchor when given', () => {
|
|
339
|
-
expect(datasetRegistry.getDataset('historic-monuments-prehistoric').getSymbolSource('icon', [0.1, 0.9], null)).toEqual({
|
|
340
|
-
...prehistoricBase,
|
|
341
|
-
layout: { visibility: 'visible', 'icon-image': 'icon', 'icon-anchor': 'bottom-left', 'icon-allow-overlap': true }
|
|
342
|
-
})
|
|
343
|
-
})
|
|
336
|
+
const ICON_LAYOUT = { 'icon-anchor': 'bottom', 'icon-offset': [0, 4.7] }
|
|
344
337
|
|
|
345
|
-
it('
|
|
346
|
-
expect(datasetRegistry.getDataset('historic-monuments-prehistoric').getSymbolSource('icon',
|
|
338
|
+
it('returns a symbol layer spec with the correct shape', () => {
|
|
339
|
+
expect(datasetRegistry.getDataset('historic-monuments-prehistoric').getSymbolSource('my-icon', ICON_LAYOUT)).toEqual({
|
|
347
340
|
...prehistoricBase,
|
|
348
|
-
layout: { visibility: 'visible', 'icon-image': 'icon',
|
|
341
|
+
layout: { visibility: 'visible', 'icon-image': 'my-icon', ...ICON_LAYOUT, 'icon-allow-overlap': true }
|
|
349
342
|
})
|
|
350
343
|
})
|
|
351
344
|
|
|
352
345
|
it('does not include a filter property when filter is null', () => {
|
|
353
|
-
expect(datasetRegistry.getDataset('historic-monuments').getSymbolSource('icon',
|
|
346
|
+
expect(datasetRegistry.getDataset('historic-monuments').getSymbolSource('icon', ICON_LAYOUT)).toEqual({
|
|
354
347
|
id: null,
|
|
355
348
|
type: 'symbol',
|
|
356
349
|
source: 'geojson-historic-monuments',
|
|
357
350
|
'source-layer': undefined,
|
|
358
351
|
minzoom: 10,
|
|
359
352
|
maxzoom: 24,
|
|
360
|
-
layout: { visibility: 'visible', 'icon-image': 'icon',
|
|
353
|
+
layout: { visibility: 'visible', 'icon-image': 'icon', ...ICON_LAYOUT, 'icon-allow-overlap': true }
|
|
361
354
|
})
|
|
362
355
|
})
|
|
363
356
|
|
|
364
357
|
it('includes a filter property when the dataset has a filter', () => {
|
|
365
|
-
expect(datasetRegistry.getDataset('historic-monuments-prehistoric').getSymbolSource('icon',
|
|
358
|
+
expect(datasetRegistry.getDataset('historic-monuments-prehistoric').getSymbolSource('icon', ICON_LAYOUT)).toEqual({
|
|
366
359
|
...prehistoricBase,
|
|
367
|
-
layout: { visibility: 'visible', 'icon-image': 'icon',
|
|
360
|
+
layout: { visibility: 'visible', 'icon-image': 'icon', ...ICON_LAYOUT, 'icon-allow-overlap': true }
|
|
368
361
|
})
|
|
369
362
|
})
|
|
370
363
|
})
|
|
@@ -395,7 +388,7 @@ describe('MapLibreDataset', () => {
|
|
|
395
388
|
expect(datasetRegistry.getDataset('existing-fields').getFillSource({})).toEqual({
|
|
396
389
|
id: 'existing-fields',
|
|
397
390
|
type: 'fill',
|
|
398
|
-
source:
|
|
391
|
+
source: EXISTING_FIELDS_SOURCE_ID,
|
|
399
392
|
'source-layer': 'field_parcels_wgs84',
|
|
400
393
|
minzoom: 10,
|
|
401
394
|
maxzoom: 24,
|
|
@@ -413,7 +406,7 @@ describe('MapLibreDataset', () => {
|
|
|
413
406
|
.toEqual({
|
|
414
407
|
id: 'hedge-control',
|
|
415
408
|
type: 'line',
|
|
416
|
-
source:
|
|
409
|
+
source: EXISTING_FIELDS_SOURCE_ID,
|
|
417
410
|
'source-layer': 'hedge_control',
|
|
418
411
|
minzoom: 10,
|
|
419
412
|
maxzoom: 24,
|
|
@@ -428,7 +421,7 @@ describe('MapLibreDataset', () => {
|
|
|
428
421
|
.toEqual({
|
|
429
422
|
id: 'existing-fields-stroke',
|
|
430
423
|
type: 'line',
|
|
431
|
-
source:
|
|
424
|
+
source: EXISTING_FIELDS_SOURCE_ID,
|
|
432
425
|
'source-layer': 'field_parcels_wgs84',
|
|
433
426
|
minzoom: 10,
|
|
434
427
|
maxzoom: 24,
|
|
@@ -1,101 +1,47 @@
|
|
|
1
1
|
import Style from 'ol/style/Style.js'
|
|
2
|
-
import Fill from 'ol/style/Fill.js'
|
|
3
2
|
import Stroke from 'ol/style/Stroke.js'
|
|
4
3
|
import { getValueForStyle } from '../../../../../src/utils/getValueForStyle.js'
|
|
5
|
-
import { buildFilterEvaluator } from '../../../../../providers/beta/openlayers/src/utils/filterEvaluator.js'
|
|
6
|
-
|
|
7
|
-
const DEFAULT_STROKE_WIDTH = 1
|
|
8
4
|
|
|
9
5
|
/**
|
|
10
|
-
* The Canvas-only
|
|
6
|
+
* The Canvas-only style for genuinely crisp fill patterns, at any pixelRatio.
|
|
11
7
|
*
|
|
12
|
-
* ol/style/flat's declarative fill-pattern-src
|
|
13
|
-
*
|
|
14
|
-
* ol/style/Fill
|
|
15
|
-
* pixelRatio-scaled
|
|
16
|
-
*
|
|
8
|
+
* ol/style/flat's declarative fill-pattern-src crops a pattern to its display size rather than
|
|
9
|
+
* scaling it, so it can't hold more source detail than it shows on screen. The OL provider instead
|
|
10
|
+
* caches each pattern as an ol/style/Fill whose colour is a CanvasPattern built from the
|
|
11
|
+
* pixelRatio-scaled image (see its addPatternsToMap/getPatternFill), and this builds a style
|
|
12
|
+
* function around that fill.
|
|
17
13
|
*
|
|
18
14
|
* Building actual ol/style/Style objects only works on Canvas — WebGLVector requires flat-style
|
|
19
15
|
* JSON (compiled to GLSL ahead of time), so this module is Canvas-only. See layerBuilders.js's
|
|
20
16
|
* resolveLayerStyle for where this is picked over the shared flatStyle path.
|
|
21
17
|
*/
|
|
22
18
|
|
|
23
|
-
const crispPatternCache = new Map() // imageId (already pixelRatio-scoped, see patternRegistry) → Fill
|
|
24
|
-
|
|
25
|
-
const cacheKey = (imageId) => imageId
|
|
26
|
-
|
|
27
|
-
export const getCachedCrispPatternFill = (imageId) => crispPatternCache.get(cacheKey(imageId))
|
|
28
|
-
|
|
29
|
-
const buildPatternFill = (imageData) => {
|
|
30
|
-
const source = document.createElement('canvas')
|
|
31
|
-
source.width = imageData.width
|
|
32
|
-
source.height = imageData.height
|
|
33
|
-
source.getContext('2d').putImageData(imageData, 0, 0)
|
|
34
|
-
const scratch = document.createElement('canvas')
|
|
35
|
-
const pattern = scratch.getContext('2d').createPattern(source, 'repeat')
|
|
36
|
-
return new Fill({ color: pattern })
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Rasterise-once-cache-forever — a synchronous cache lookup at style-build time needs this
|
|
41
|
-
* already resolved.
|
|
42
|
-
* @param {Object} style - Dataset style with fillPattern* properties
|
|
43
|
-
* @param {string} mapStyleId
|
|
44
|
-
* @param {Object} patternRegistry
|
|
45
|
-
* @param {number} pixelRatio - the map's current pixelRatio; re-called on resize
|
|
46
|
-
* @returns {Promise<void>}
|
|
47
|
-
*/
|
|
48
|
-
export const registerCrispCanvasPattern = async (style, mapStyleId, patternRegistry, pixelRatio) => {
|
|
49
|
-
const imageId = patternRegistry.getPatternImageId(style, mapStyleId, pixelRatio)
|
|
50
|
-
if (!imageId || crispPatternCache.has(cacheKey(imageId))) {
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
const result = await patternRegistry.rasterisePatternImage(style, mapStyleId, pixelRatio)
|
|
54
|
-
if (!result) {
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
const key = cacheKey(result.imageId)
|
|
58
|
-
if (!crispPatternCache.has(key)) {
|
|
59
|
-
crispPatternCache.set(key, buildPatternFill(result.imageData))
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Register every pattern style in the given array, in parallel. */
|
|
64
|
-
export const registerCrispCanvasPatterns = async (styleArray, mapStyleId, patternRegistry, pixelRatio) => {
|
|
65
|
-
if (!styleArray.length) {
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
await Promise.all(styleArray.map(style => registerCrispCanvasPattern(style, mapStyleId, patternRegistry, pixelRatio)))
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Mainly for testing — clears every cached Fill. */
|
|
72
|
-
export const clearCrispPatternCache = () => {
|
|
73
|
-
crispPatternCache.clear()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
19
|
const buildStroke = (registryDataset, mapStyleId) => {
|
|
77
20
|
if (!registryDataset.hasStroke) {
|
|
78
21
|
return undefined
|
|
79
22
|
}
|
|
80
23
|
return new Stroke({
|
|
81
24
|
color: getValueForStyle(registryDataset.style.stroke, mapStyleId),
|
|
82
|
-
width: registryDataset.style.strokeWidth
|
|
25
|
+
width: registryDataset.style.strokeWidth,
|
|
83
26
|
lineDash: registryDataset.style.strokeDashArray
|
|
84
27
|
})
|
|
85
28
|
}
|
|
86
29
|
|
|
87
30
|
/**
|
|
88
31
|
* Builds an OL style function for a Canvas-rendered, pattern-bearing dataset/sublayer — uses a
|
|
89
|
-
* real CanvasPattern (see module doc), bypassing OpenLayersDataset.
|
|
32
|
+
* real CanvasPattern (see module doc), bypassing OpenLayersDataset.getFlatStyle for this one case.
|
|
90
33
|
* @param {Object} registryDataset - an OpenLayersDataset with hasPattern true
|
|
91
|
-
* @param {
|
|
92
|
-
* @param {
|
|
93
|
-
* @param {
|
|
34
|
+
* @param {Object} context - the adapter's style context
|
|
35
|
+
* @param {string} context.mapStyleId
|
|
36
|
+
* @param {number} context.pixelRatio - the ratio the adapter last registered patterns at
|
|
37
|
+
* @param {Object} context.patternRegistry
|
|
38
|
+
* @param {Function} context.getPatternFill - the OL provider's registered pattern fill lookup
|
|
39
|
+
* @param {Function} context.buildFilterEvaluator - the OL provider's filter compiler
|
|
94
40
|
* @returns {import('ol/style/Style.js').StyleFunction}
|
|
95
41
|
*/
|
|
96
|
-
export const buildCanvasPatternStyle = (registryDataset, mapStyleId, pixelRatio, patternRegistry) => {
|
|
42
|
+
export const buildCanvasPatternStyle = (registryDataset, { mapStyleId, pixelRatio, patternRegistry, getPatternFill, buildFilterEvaluator }) => {
|
|
97
43
|
const imageId = patternRegistry.getPatternImageId(registryDataset.style, mapStyleId, pixelRatio)
|
|
98
|
-
const fill = imageId &&
|
|
44
|
+
const fill = imageId && getPatternFill(imageId)
|
|
99
45
|
const style = fill ? new Style({ fill, stroke: buildStroke(registryDataset, mapStyleId) }) : undefined
|
|
100
46
|
const matchesFilter = buildFilterEvaluator(registryDataset.filter)
|
|
101
47
|
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import Style from 'ol/style/Style.js'
|
|
2
2
|
import Feature from 'ol/Feature.js'
|
|
3
3
|
import Point from 'ol/geom/Point.js'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
getCachedCrispPatternFill,
|
|
8
|
-
clearCrispPatternCache,
|
|
9
|
-
buildCanvasPatternStyle
|
|
10
|
-
} from './canvasPatternStyle.js'
|
|
4
|
+
import { buildCanvasPatternStyle } from './canvasPatternStyle.js'
|
|
5
|
+
import { buildFilterEvaluator } from '../../../../../providers/beta/openlayers/src/utils/filterEvaluator.js'
|
|
6
|
+
import { PatternImageCache } from '../../../../../providers/beta/openlayers/src/utils/patternImages.js'
|
|
11
7
|
|
|
12
8
|
const OUTDOOR = 'outdoor'
|
|
13
9
|
|
|
10
|
+
// Stands in for the OL provider's pattern fills
|
|
11
|
+
let patternImages
|
|
12
|
+
|
|
13
|
+
// The adapter's style context, with the OL provider's real filter compiler and pattern fills
|
|
14
|
+
const styleContext = (patternRegistry) => ({
|
|
15
|
+
mapStyleId: OUTDOOR,
|
|
16
|
+
pixelRatio: 1,
|
|
17
|
+
patternRegistry,
|
|
18
|
+
getPatternFill: (imageId) => patternImages.getFill(imageId),
|
|
19
|
+
buildFilterEvaluator
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const registerPattern = (style, patternRegistry) => patternImages.registerPatterns([style], OUTDOOR, patternRegistry, 1)
|
|
23
|
+
|
|
14
24
|
const makePatternRegistry = () => ({
|
|
15
25
|
getPatternImageId: jest.fn((style, mapStyleId, pixelRatio) => `pattern-${style.fillPattern}-${mapStyleId}-${pixelRatio}`),
|
|
16
26
|
rasterisePatternImage: jest.fn(async (style, mapStyleId, pixelRatio) => ({
|
|
@@ -19,115 +29,32 @@ const makePatternRegistry = () => ({
|
|
|
19
29
|
}))
|
|
20
30
|
})
|
|
21
31
|
|
|
22
|
-
let createPatternCalls
|
|
23
32
|
beforeEach(() => {
|
|
24
|
-
|
|
25
|
-
createPatternCalls = []
|
|
33
|
+
patternImages = new PatternImageCache()
|
|
26
34
|
HTMLCanvasElement.prototype.getContext = jest.fn(function () {
|
|
27
35
|
this._ctx ??= {
|
|
28
36
|
putImageData: jest.fn(),
|
|
29
|
-
createPattern: jest.fn((source, repetition) => {
|
|
30
|
-
const pattern = { source, repetition }
|
|
31
|
-
createPatternCalls.push(pattern)
|
|
32
|
-
return pattern
|
|
33
|
-
})
|
|
37
|
+
createPattern: jest.fn((source, repetition) => ({ source, repetition }))
|
|
34
38
|
}
|
|
35
39
|
return this._ctx
|
|
36
40
|
})
|
|
37
41
|
})
|
|
38
42
|
|
|
39
|
-
describe('registerCrispCanvasPattern', () => {
|
|
40
|
-
it('caches a Fill built from a real CanvasPattern for a valid pattern config', async () => {
|
|
41
|
-
const patternRegistry = makePatternRegistry()
|
|
42
|
-
const style = { fillPattern: 'dot' }
|
|
43
|
-
await registerCrispCanvasPattern(style, OUTDOOR, patternRegistry, 2)
|
|
44
|
-
const imageId = patternRegistry.getPatternImageId(style, OUTDOOR, 2)
|
|
45
|
-
const fill = getCachedCrispPatternFill(imageId)
|
|
46
|
-
expect(fill.getColor()).toEqual(expect.objectContaining({ repetition: 'repeat' }))
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('rasterises at the given pixelRatio, not a fixed constant', async () => {
|
|
50
|
-
const patternRegistry = makePatternRegistry()
|
|
51
|
-
await registerCrispCanvasPattern({ fillPattern: 'dot' }, OUTDOOR, patternRegistry, 3)
|
|
52
|
-
expect(patternRegistry.rasterisePatternImage).toHaveBeenCalledWith({ fillPattern: 'dot' }, OUTDOOR, 3)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('does nothing when getPatternImageId returns null', async () => {
|
|
56
|
-
const patternRegistry = makePatternRegistry()
|
|
57
|
-
patternRegistry.getPatternImageId.mockReturnValue(null)
|
|
58
|
-
await registerCrispCanvasPattern({ fillPattern: 'unknown' }, OUTDOOR, patternRegistry, 1)
|
|
59
|
-
expect(patternRegistry.rasterisePatternImage).not.toHaveBeenCalled()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('does nothing when rasterisePatternImage returns null', async () => {
|
|
63
|
-
const patternRegistry = makePatternRegistry()
|
|
64
|
-
patternRegistry.rasterisePatternImage.mockResolvedValue(null)
|
|
65
|
-
const style = { fillPattern: 'dot' }
|
|
66
|
-
await registerCrispCanvasPattern(style, OUTDOOR, patternRegistry, 1)
|
|
67
|
-
const imageId = patternRegistry.getPatternImageId(style, OUTDOOR, 1)
|
|
68
|
-
expect(getCachedCrispPatternFill(imageId)).toBeUndefined()
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('skips rasterising again once cached for the same imageId', async () => {
|
|
72
|
-
const patternRegistry = makePatternRegistry()
|
|
73
|
-
const style = { fillPattern: 'dot' }
|
|
74
|
-
await registerCrispCanvasPattern(style, OUTDOOR, patternRegistry, 1)
|
|
75
|
-
await registerCrispCanvasPattern(style, OUTDOOR, patternRegistry, 1)
|
|
76
|
-
expect(patternRegistry.rasterisePatternImage).toHaveBeenCalledTimes(1)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('building the same pattern config twice concurrently still leaves exactly one cached Fill', async () => {
|
|
80
|
-
// registerCrispCanvasPatterns (plural) can be handed two different dataset styles that
|
|
81
|
-
// happen to resolve to the same imageId (identical pattern/colours) — both start rasterising
|
|
82
|
-
// before either has cached its result, so the second one back must skip re-caching rather
|
|
83
|
-
// than clobbering the first.
|
|
84
|
-
const patternRegistry = makePatternRegistry()
|
|
85
|
-
const style = { fillPattern: 'dot' }
|
|
86
|
-
await registerCrispCanvasPatterns([style, { ...style }], OUTDOOR, patternRegistry, 1)
|
|
87
|
-
const imageId = patternRegistry.getPatternImageId(style, OUTDOOR, 1)
|
|
88
|
-
expect(getCachedCrispPatternFill(imageId)).toBeDefined()
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('caches separately per pixelRatio, since imageId is pixelRatio-scoped', async () => {
|
|
92
|
-
const patternRegistry = makePatternRegistry()
|
|
93
|
-
const style = { fillPattern: 'dot' }
|
|
94
|
-
await registerCrispCanvasPattern(style, OUTDOOR, patternRegistry, 1)
|
|
95
|
-
await registerCrispCanvasPattern(style, OUTDOOR, patternRegistry, 4)
|
|
96
|
-
expect(patternRegistry.rasterisePatternImage).toHaveBeenCalledTimes(2)
|
|
97
|
-
expect(getCachedCrispPatternFill(patternRegistry.getPatternImageId(style, OUTDOOR, 1))).toBeDefined()
|
|
98
|
-
expect(getCachedCrispPatternFill(patternRegistry.getPatternImageId(style, OUTDOOR, 4))).toBeDefined()
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
describe('registerCrispCanvasPatterns', () => {
|
|
103
|
-
it('registers every config in parallel', async () => {
|
|
104
|
-
const patternRegistry = makePatternRegistry()
|
|
105
|
-
await registerCrispCanvasPatterns([{ fillPattern: 'dot' }, { fillPattern: 'stripes' }], OUTDOOR, patternRegistry, 1)
|
|
106
|
-
expect(patternRegistry.rasterisePatternImage).toHaveBeenCalledTimes(2)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('is a no-op for an empty array', async () => {
|
|
110
|
-
const patternRegistry = makePatternRegistry()
|
|
111
|
-
await registerCrispCanvasPatterns([], OUTDOOR, patternRegistry, 1)
|
|
112
|
-
expect(patternRegistry.rasterisePatternImage).not.toHaveBeenCalled()
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
43
|
describe('buildCanvasPatternStyle', () => {
|
|
117
44
|
const feature = (props) => new Feature({ geometry: new Point([0, 0]), ...props })
|
|
118
45
|
|
|
119
46
|
it('returns undefined when the pattern has not been registered yet', () => {
|
|
120
47
|
const patternRegistry = makePatternRegistry()
|
|
121
48
|
const registryDataset = { style: { fillPattern: 'dot' }, filter: null }
|
|
122
|
-
const styleFn = buildCanvasPatternStyle(registryDataset,
|
|
49
|
+
const styleFn = buildCanvasPatternStyle(registryDataset, styleContext(patternRegistry))
|
|
123
50
|
expect(styleFn(feature())).toBeUndefined()
|
|
124
51
|
})
|
|
125
52
|
|
|
126
53
|
it('returns a Style with the cached pattern Fill once registered, for an unfiltered dataset', async () => {
|
|
127
54
|
const patternRegistry = makePatternRegistry()
|
|
128
|
-
await
|
|
55
|
+
await registerPattern({ fillPattern: 'dot' }, patternRegistry)
|
|
129
56
|
const registryDataset = { style: { fillPattern: 'dot' }, filter: null, hasStroke: false }
|
|
130
|
-
const styleFn = buildCanvasPatternStyle(registryDataset,
|
|
57
|
+
const styleFn = buildCanvasPatternStyle(registryDataset, styleContext(patternRegistry))
|
|
131
58
|
const style = styleFn(feature())
|
|
132
59
|
expect(style).toBeInstanceOf(Style)
|
|
133
60
|
expect(style.getFill().getColor()).toEqual(expect.objectContaining({ repetition: 'repeat' }))
|
|
@@ -135,64 +62,52 @@ describe('buildCanvasPatternStyle', () => {
|
|
|
135
62
|
|
|
136
63
|
it('includes a Stroke when the dataset has one', async () => {
|
|
137
64
|
const patternRegistry = makePatternRegistry()
|
|
138
|
-
await
|
|
65
|
+
await registerPattern({ fillPattern: 'dot' }, patternRegistry)
|
|
139
66
|
const registryDataset = {
|
|
140
67
|
style: { fillPattern: 'dot', stroke: '#ff0000', strokeWidth: 3 },
|
|
141
68
|
filter: null,
|
|
142
69
|
hasStroke: true
|
|
143
70
|
}
|
|
144
|
-
const styleFn = buildCanvasPatternStyle(registryDataset,
|
|
71
|
+
const styleFn = buildCanvasPatternStyle(registryDataset, styleContext(patternRegistry))
|
|
145
72
|
const style = styleFn(feature())
|
|
146
73
|
expect(style.getStroke().getColor()).toBe('#ff0000')
|
|
147
74
|
expect(style.getStroke().getWidth()).toBe(3)
|
|
148
75
|
})
|
|
149
76
|
|
|
150
|
-
it('defaults the Stroke width to 1 when strokeWidth is not set', async () => {
|
|
151
|
-
const patternRegistry = makePatternRegistry()
|
|
152
|
-
await registerCrispCanvasPattern({ fillPattern: 'dot' }, OUTDOOR, patternRegistry, 1)
|
|
153
|
-
const registryDataset = {
|
|
154
|
-
style: { fillPattern: 'dot', stroke: '#ff0000' },
|
|
155
|
-
filter: null,
|
|
156
|
-
hasStroke: true
|
|
157
|
-
}
|
|
158
|
-
const styleFn = buildCanvasPatternStyle(registryDataset, OUTDOOR, 1, patternRegistry)
|
|
159
|
-
expect(styleFn(feature()).getStroke().getWidth()).toBe(1)
|
|
160
|
-
})
|
|
161
|
-
|
|
162
77
|
it('evaluates a filter correctly for a feature with no geometry', async () => {
|
|
163
78
|
const patternRegistry = makePatternRegistry()
|
|
164
|
-
await
|
|
79
|
+
await registerPattern({ fillPattern: 'dot' }, patternRegistry)
|
|
165
80
|
const registryDataset = {
|
|
166
81
|
style: { fillPattern: 'dot' },
|
|
167
82
|
filter: ['==', ['get', 'category'], 'a'],
|
|
168
83
|
hasStroke: false
|
|
169
84
|
}
|
|
170
|
-
const styleFn = buildCanvasPatternStyle(registryDataset,
|
|
85
|
+
const styleFn = buildCanvasPatternStyle(registryDataset, styleContext(patternRegistry))
|
|
171
86
|
const featureWithNoGeometry = new Feature({ category: 'a' })
|
|
172
87
|
expect(styleFn(featureWithNoGeometry)).toBeInstanceOf(Style)
|
|
173
88
|
})
|
|
174
89
|
|
|
175
90
|
it('hides a feature that does not match the dataset filter', async () => {
|
|
176
91
|
const patternRegistry = makePatternRegistry()
|
|
177
|
-
await
|
|
92
|
+
await registerPattern({ fillPattern: 'dot' }, patternRegistry)
|
|
178
93
|
const registryDataset = {
|
|
179
94
|
style: { fillPattern: 'dot' },
|
|
180
95
|
filter: ['==', ['get', 'category'], 'a'],
|
|
181
96
|
hasStroke: false
|
|
182
97
|
}
|
|
183
|
-
const styleFn = buildCanvasPatternStyle(registryDataset,
|
|
98
|
+
const styleFn = buildCanvasPatternStyle(registryDataset, styleContext(patternRegistry))
|
|
184
99
|
expect(styleFn(feature({ category: 'b' }))).toBeUndefined()
|
|
185
100
|
})
|
|
186
101
|
|
|
187
102
|
it('shows a feature that matches the dataset filter', async () => {
|
|
188
103
|
const patternRegistry = makePatternRegistry()
|
|
189
|
-
await
|
|
104
|
+
await registerPattern({ fillPattern: 'dot' }, patternRegistry)
|
|
190
105
|
const registryDataset = {
|
|
191
106
|
style: { fillPattern: 'dot' },
|
|
192
107
|
filter: ['==', ['get', 'category'], 'a'],
|
|
193
108
|
hasStroke: false
|
|
194
109
|
}
|
|
195
|
-
const styleFn = buildCanvasPatternStyle(registryDataset,
|
|
110
|
+
const styleFn = buildCanvasPatternStyle(registryDataset, styleContext(patternRegistry))
|
|
196
111
|
expect(styleFn(feature({ category: 'a' }))).toBeInstanceOf(Style)
|
|
197
112
|
})
|
|
198
113
|
})
|
|
@@ -7,13 +7,11 @@ import MVT from 'ol/format/MVT.js'
|
|
|
7
7
|
import Feature from 'ol/Feature.js'
|
|
8
8
|
import TileGrid from 'ol/tilegrid/TileGrid.js'
|
|
9
9
|
import { logger } from '../../../../../src/services/logger.js'
|
|
10
|
-
import { BNG_CRS } from '../../../../../providers/beta/openlayers/src/utils/bngProjection.js'
|
|
11
10
|
import { buildCanvasPatternStyle } from './canvasPatternStyle.js'
|
|
12
11
|
|
|
13
|
-
// Data and map both use
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
const PROJECTION = BNG_CRS
|
|
12
|
+
// Data and map both use British National Grid, so no coordinate transformation is needed. The
|
|
13
|
+
// OpenLayers provider registers the projection with OL.
|
|
14
|
+
const PROJECTION = 'EPSG:27700'
|
|
17
15
|
const format = new GeoJSON({ dataProjection: PROJECTION, featureProjection: PROJECTION })
|
|
18
16
|
|
|
19
17
|
// The Mapbox style spec's minzoom/maxzoom are inclusive-min, exclusive-max; OL's own semantics
|
|
@@ -135,18 +133,18 @@ export const createDatasetSource = (registryDataset) => {
|
|
|
135
133
|
|
|
136
134
|
/**
|
|
137
135
|
* The style value to hand to layer.setStyle()/the layer constructor: registryDataset's own
|
|
138
|
-
*
|
|
136
|
+
* flat style, except for a pattern fill, which needs the genuinely crisp, CanvasPattern-based
|
|
139
137
|
* style function from canvasPatternStyle.js instead — see that module's doc for why flat-style's
|
|
140
138
|
* fill-pattern-src can't achieve this.
|
|
141
139
|
* @param {Object} registryDataset - an OpenLayersDataset
|
|
142
|
-
* @param {{ mapStyleId: string, pixelRatio: number, patternRegistry: Object }} context
|
|
140
|
+
* @param {{ mapStyleId: string, pixelRatio: number, patternRegistry: Object, symbolRegistry: Object, getSymbolDataUri: Function, getPatternFill: Function, buildFilterEvaluator: Function }} context
|
|
143
141
|
* @returns {Object|Array<Object>|import('ol/style/Style.js').StyleFunction}
|
|
144
142
|
*/
|
|
145
|
-
export const resolveLayerStyle = (registryDataset,
|
|
143
|
+
export const resolveLayerStyle = (registryDataset, context = {}) => {
|
|
146
144
|
if (registryDataset.hasPattern) {
|
|
147
|
-
return buildCanvasPatternStyle(registryDataset,
|
|
145
|
+
return buildCanvasPatternStyle(registryDataset, context)
|
|
148
146
|
}
|
|
149
|
-
return registryDataset.
|
|
147
|
+
return registryDataset.getFlatStyle(context)
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
/**
|
|
@@ -155,7 +153,7 @@ export const resolveLayerStyle = (registryDataset, { mapStyleId, pixelRatio, pat
|
|
|
155
153
|
* style pipeline (see resolveLayerStyle).
|
|
156
154
|
* @param {Object} registryDataset - an OpenLayersDataset
|
|
157
155
|
* @param {import('ol/source/Vector.js').default} olSource
|
|
158
|
-
* @param {{ mapStyleId: string, pixelRatio: number, patternRegistry: Object }} context
|
|
156
|
+
* @param {{ mapStyleId: string, pixelRatio: number, patternRegistry: Object, symbolRegistry: Object, getSymbolDataUri: Function, getPatternFill: Function, buildFilterEvaluator: Function }} context
|
|
159
157
|
* @returns {import('ol/layer/Layer.js').default}
|
|
160
158
|
*/
|
|
161
159
|
export const createDatasetLayer = (registryDataset, olSource, context) => {
|
|
@@ -197,9 +195,9 @@ export const createDatasetLayer = (registryDataset, olSource, context) => {
|
|
|
197
195
|
layer.set('filter', registryDataset.filter)
|
|
198
196
|
}
|
|
199
197
|
// Lets highlightFeatures.js build a select/active highlight for a dataset symbol point —
|
|
200
|
-
// see OpenLayersDataset.
|
|
198
|
+
// see OpenLayersDataset.getSymbolMeta's doc.
|
|
201
199
|
if (registryDataset.hasSymbol) {
|
|
202
|
-
layer.set('symbolMeta', registryDataset.
|
|
200
|
+
layer.set('symbolMeta', registryDataset.getSymbolMeta(context))
|
|
203
201
|
}
|
|
204
202
|
return layer
|
|
205
203
|
}
|
|
@@ -4,6 +4,8 @@ import VectorTileSource from 'ol/source/VectorTile.js'
|
|
|
4
4
|
import VectorTileLayer from 'ol/layer/VectorTile.js'
|
|
5
5
|
import { createDatasetSource, createDatasetLayer, readGeoJSONFeatures } from './layerBuilders.js'
|
|
6
6
|
import { logger } from '../../../../../src/services/logger.js'
|
|
7
|
+
// The OL provider registers British National Grid when it loads
|
|
8
|
+
import '../../../../../providers/beta/openlayers/src/utils/bngProjection.js'
|
|
7
9
|
|
|
8
10
|
jest.mock('../../../../../src/services/logger.js', () => ({ logger: { warn: jest.fn() } }))
|
|
9
11
|
|
|
@@ -140,7 +142,7 @@ describe('createDatasetLayer', () => {
|
|
|
140
142
|
// canvas 2D context, which jsdom returns null for without the `canvas` npm package. Hex
|
|
141
143
|
// colours take OL's fast lane and skip that path entirely (see ol/color.js#parseRgba).
|
|
142
144
|
// Named colours work fine in a real browser; this is a test-environment gap only.
|
|
143
|
-
const registryDataset = {
|
|
145
|
+
const registryDataset = { getFlatStyle: () => ({ 'fill-color': '#0000ff' }), opacity: 0.5, visibility: 'visible', minZoom: 1, maxZoom: 10, hasPattern: false }
|
|
144
146
|
|
|
145
147
|
it('builds a Canvas VectorLayer', () => {
|
|
146
148
|
const layer = createDatasetLayer(registryDataset, new VectorSource())
|
|
@@ -203,13 +205,19 @@ describe('createDatasetLayer', () => {
|
|
|
203
205
|
})
|
|
204
206
|
|
|
205
207
|
it('gives a symbol dataset a higher zIndex, so it always renders above fill/stroke layers', () => {
|
|
206
|
-
const layer = createDatasetLayer({ ...registryDataset, hasSymbol: true }, new VectorSource())
|
|
208
|
+
const layer = createDatasetLayer({ ...registryDataset, hasSymbol: true, getSymbolMeta: () => null }, new VectorSource())
|
|
207
209
|
expect(layer.getZIndex()).toBeGreaterThan(0)
|
|
208
210
|
})
|
|
211
|
+
|
|
212
|
+
it('tags a symbol layer with its symbolMeta at the context pixelRatio, for highlightFeatures.js', () => {
|
|
213
|
+
const getSymbolMeta = jest.fn(({ pixelRatio }) => ({ imageId: 'img', anchor: [0.5, 0.5], pixelRatio }))
|
|
214
|
+
const layer = createDatasetLayer({ ...registryDataset, hasSymbol: true, getSymbolMeta }, new VectorSource(), { pixelRatio: 3 })
|
|
215
|
+
expect(layer.get('symbolMeta')).toEqual({ imageId: 'img', anchor: [0.5, 0.5], pixelRatio: 3 })
|
|
216
|
+
})
|
|
209
217
|
})
|
|
210
218
|
|
|
211
219
|
describe('tile-backed dataset', () => {
|
|
212
|
-
const tileRegistryDataset = {
|
|
220
|
+
const tileRegistryDataset = { getFlatStyle: () => ({ 'stroke-color': '#0000ff' }), opacity: 1, visibility: 'visible', hasPattern: false, id: 'existing-fields' }
|
|
213
221
|
// A real VectorTileSource, built the same way createDatasetSource does — a bare
|
|
214
222
|
// `new VectorTileSource()` throws without a resolved projection.
|
|
215
223
|
const tileSource = () => createDatasetSource({ id: 'existing-fields', idStrategy: null, source: { type: 'vector', tiles: ['https://example.com/{z}/{x}/{y}'] } })
|