@defra/interactive-map 0.0.52-alpha → 0.0.53-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/esm/im-core.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/context.md +18 -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/plugins/datasets.md +4 -10
- package/docs/plugins/draw.md +2 -1
- package/docs/plugins/map-key.md +6 -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/maplibre/layerBuilders.js +9 -9
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +19 -3
- 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 +19 -26
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +15 -67
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +32 -105
- 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 +99 -11
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +26 -26
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +48 -29
- package/plugins/datasets/src/initialise/defaults.js +4 -3
- package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
- package/plugins/datasets/src/registry/dataset.js +2 -1
- package/plugins/datasets/src/registry/dataset.test.js +13 -0
- 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/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/KeyGroupItem.jsx +3 -1
- package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +15 -14
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +21 -14
- 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/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/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/menu/src/registry/index.js +0 -2
- package/plugins/menu/src/registry/index.test.js +1 -9
- 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/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/store/ServiceProvider.jsx +6 -3
- package/src/App/store/ServiceProvider.test.jsx +24 -0
- package/src/config/appConfig.js +1 -5
- package/src/config/mapSizeScales.js +8 -0
- package/src/config/symbolConfig.js +101 -25
- 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 +9 -3
- 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
|
@@ -4,10 +4,12 @@ import { attachAppEvents } from './appEvents.js'
|
|
|
4
4
|
import { createMapLabelNavigator } from './utils/labels.js'
|
|
5
5
|
import { updateHighlightedFeatures } from './utils/highlightFeatures.js'
|
|
6
6
|
import { queryFeatures } from './utils/queryFeatures.js'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { SymbolImageVariants, getSymbolIconLayout } from './utils/symbolImages.js'
|
|
8
|
+
import { PatternImages } from './utils/patternImages.js'
|
|
9
9
|
import { getAreaDimensions, getCardinalMove, getResolution, getPaddedBounds, isGeometryObscured } from './utils/spatial.js'
|
|
10
|
-
import {
|
|
10
|
+
import { createSymbolRegistry } from '../../../src/services/symbolRegistry.js'
|
|
11
|
+
|
|
12
|
+
const symbolRegistry = createSymbolRegistry()
|
|
11
13
|
|
|
12
14
|
jest.mock('./defaults.js', () => ({
|
|
13
15
|
DEFAULTS: { animationDuration: 400, coordinatePrecision: 7 },
|
|
@@ -36,8 +38,10 @@ jest.mock('./utils/labels.js', () => ({
|
|
|
36
38
|
}))
|
|
37
39
|
jest.mock('./utils/highlightFeatures.js', () => ({ updateHighlightedFeatures: jest.fn(() => []) }))
|
|
38
40
|
jest.mock('./utils/queryFeatures.js', () => ({ queryFeatures: jest.fn(() => []) }))
|
|
39
|
-
jest.mock('./utils/symbolImages.js', () => ({
|
|
40
|
-
jest.
|
|
41
|
+
jest.mock('./utils/symbolImages.js', () => ({
|
|
42
|
+
...jest.requireActual('./utils/symbolImages.js'),
|
|
43
|
+
getSymbolIconLayout: jest.fn(() => ({ 'icon-anchor': 'bottom', 'icon-offset': [0, 2] }))
|
|
44
|
+
}))
|
|
41
45
|
|
|
42
46
|
describe('MapLibreProvider', () => {
|
|
43
47
|
let map, eventBus, maplibreModule, loadCallback
|
|
@@ -275,7 +279,7 @@ describe('MapLibreProvider', () => {
|
|
|
275
279
|
expect(queryFeatures).toHaveBeenCalledWith(map, { x: 10, y: 20 }, { radius: 5 })
|
|
276
280
|
p.updateHighlightedFeatures(['feat'], null, { style: 1 })
|
|
277
281
|
expect(updateHighlightedFeatures).toHaveBeenCalledWith({
|
|
278
|
-
LngLatBounds: maplibreModule.LngLatBounds, map, selectedFeatures: ['feat'], activeFeatures: null, stylesMap: { style: 1 }
|
|
282
|
+
LngLatBounds: maplibreModule.LngLatBounds, map, selectedFeatures: ['feat'], activeFeatures: null, stylesMap: { style: 1 }, symbolImages: p.symbolImages
|
|
279
283
|
})
|
|
280
284
|
})
|
|
281
285
|
|
|
@@ -297,51 +301,101 @@ describe('MapLibreProvider', () => {
|
|
|
297
301
|
expect(map.queryRenderedFeatures).toHaveBeenCalledWith(undefined, { layers: ['l1'] })
|
|
298
302
|
})
|
|
299
303
|
|
|
300
|
-
|
|
304
|
+
// The provider's own record of registered symbol images, created with its map
|
|
305
|
+
const initWithSymbolImages = async () => {
|
|
301
306
|
const p = makeProvider()
|
|
302
307
|
await doInitMap(p)
|
|
308
|
+
const registerSymbols = jest.spyOn(p.symbolImages, 'registerSymbols').mockResolvedValue()
|
|
309
|
+
return { p, registerSymbols }
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
test('owns a SymbolImageVariants for its map', async () => {
|
|
313
|
+
const p = makeProvider()
|
|
314
|
+
await doInitMap(p)
|
|
315
|
+
expect(p.symbolImages).toBeInstanceOf(SymbolImageVariants)
|
|
316
|
+
expect(p.symbolImages.map).toBe(map)
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
test('addSymbolsToMap registers the symbols with its symbol images', async () => {
|
|
320
|
+
const { p, registerSymbols } = await initWithSymbolImages()
|
|
303
321
|
const configs = [{ symbol: 'pin' }]
|
|
304
322
|
const mapStyle = { id: 'test', selectedColor: '#0b0c0c' }
|
|
305
323
|
await p.addSymbolsToMap(configs, mapStyle, symbolRegistry)
|
|
306
|
-
expect(
|
|
324
|
+
expect(registerSymbols).toHaveBeenCalledWith(configs, mapStyle, symbolRegistry, expect.any(Number))
|
|
307
325
|
})
|
|
308
326
|
|
|
309
327
|
test('addSymbolsToMap computes pixelRatio from getPixelRatio and mapSize scale factor', async () => {
|
|
310
|
-
const p =
|
|
311
|
-
await doInitMap(p)
|
|
328
|
+
const { p, registerSymbols } = await initWithSymbolImages()
|
|
312
329
|
map.getPixelRatio.mockReturnValue(2)
|
|
313
330
|
p.mapSize = 'medium'
|
|
314
331
|
await p.addSymbolsToMap([], { id: 'test' }, symbolRegistry)
|
|
315
|
-
expect(
|
|
332
|
+
expect(registerSymbols).toHaveBeenCalledWith([], { id: 'test' }, symbolRegistry, 2)
|
|
316
333
|
})
|
|
317
334
|
|
|
318
|
-
test('addSymbolsToMap
|
|
335
|
+
test('addSymbolsToMap registers at a given pixelRatio instead of the map\'s', async () => {
|
|
336
|
+
const { p, registerSymbols } = await initWithSymbolImages()
|
|
337
|
+
map.getPixelRatio.mockReturnValue(2)
|
|
338
|
+
await p.addSymbolsToMap([], { id: 'test' }, symbolRegistry, 3)
|
|
339
|
+
expect(registerSymbols).toHaveBeenCalledWith([], { id: 'test' }, symbolRegistry, 3)
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
test('getSymbolIconLayout delegates to the symbol image utility', () => {
|
|
343
|
+
const symbolDef = { anchor: [0.5, 0.9], viewBox: '0 0 44 44' }
|
|
344
|
+
expect(makeProvider().getSymbolIconLayout(symbolDef)).toEqual({ 'icon-anchor': 'bottom', 'icon-offset': [0, 2] })
|
|
345
|
+
expect(getSymbolIconLayout).toHaveBeenCalledWith(symbolDef)
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
test('looks up a registered symbol\'s active and selected variants', async () => {
|
|
319
349
|
const p = makeProvider()
|
|
320
350
|
await doInitMap(p)
|
|
351
|
+
expect(p.getActiveSymbolImageId('img')).toBeNull()
|
|
352
|
+
expect(p.getSelectedSymbolImageId('img')).toBeNull()
|
|
353
|
+
p.symbolImages.activeImageIds.set('img', 'img-active')
|
|
354
|
+
p.symbolImages.selectedImageIds.set('img', 'img-selected')
|
|
355
|
+
expect(p.getActiveSymbolImageId('img')).toBe('img-active')
|
|
356
|
+
expect(p.getSelectedSymbolImageId('img')).toBe('img-selected')
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
test('addSymbolsToMap falls back to pixelRatio 1 when getPixelRatio returns 0', async () => {
|
|
360
|
+
const { p, registerSymbols } = await initWithSymbolImages()
|
|
321
361
|
map.getPixelRatio.mockReturnValue(0)
|
|
322
362
|
p.mapSize = 'small' // scaleFactor['small'] = 1
|
|
323
363
|
await p.addSymbolsToMap([], { id: 'test' }, symbolRegistry)
|
|
324
|
-
expect(
|
|
364
|
+
expect(registerSymbols).toHaveBeenCalledWith([], { id: 'test' }, symbolRegistry, 1)
|
|
325
365
|
})
|
|
326
366
|
|
|
327
|
-
|
|
367
|
+
// The provider's own pattern images, created with its map
|
|
368
|
+
const initWithPatternImages = async () => {
|
|
369
|
+
const p = makeProvider()
|
|
370
|
+
await doInitMap(p)
|
|
371
|
+
const registerPatterns = jest.spyOn(p.patternImages, 'registerPatterns').mockResolvedValue()
|
|
372
|
+
return { p, registerPatterns }
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
test('owns a PatternImages for its map', async () => {
|
|
328
376
|
const p = makeProvider()
|
|
329
377
|
await doInitMap(p)
|
|
378
|
+
expect(p.patternImages).toBeInstanceOf(PatternImages)
|
|
379
|
+
expect(p.patternImages.map).toBe(map)
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
test('addPatternsToMap falls back to pixelRatio 1 when getPixelRatio returns 0', async () => {
|
|
383
|
+
const { p, registerPatterns } = await initWithPatternImages()
|
|
330
384
|
map.getPixelRatio.mockReturnValue(0)
|
|
331
385
|
const configs = [{ fillPattern: 'dot' }]
|
|
332
386
|
const registry = {}
|
|
333
387
|
await p.addPatternsToMap(configs, 'test', registry)
|
|
334
|
-
expect(
|
|
388
|
+
expect(registerPatterns).toHaveBeenCalledWith(configs, 'test', registry, 1)
|
|
335
389
|
})
|
|
336
390
|
|
|
337
|
-
test('addPatternsToMap
|
|
338
|
-
const p =
|
|
339
|
-
await doInitMap(p)
|
|
391
|
+
test('addPatternsToMap registers at the map\'s pixel ratio, or a given one', async () => {
|
|
392
|
+
const { p, registerPatterns } = await initWithPatternImages()
|
|
340
393
|
map.getPixelRatio.mockReturnValue(2)
|
|
341
|
-
p.mapSize = 'medium'
|
|
342
394
|
const registry = {}
|
|
343
395
|
await p.addPatternsToMap([], 'test', registry)
|
|
344
|
-
expect(
|
|
396
|
+
expect(registerPatterns).toHaveBeenLastCalledWith([], 'test', registry, 2)
|
|
397
|
+
await p.addPatternsToMap([], 'test', registry, 3)
|
|
398
|
+
expect(registerPatterns).toHaveBeenLastCalledWith([], 'test', registry, 3)
|
|
345
399
|
})
|
|
346
400
|
|
|
347
401
|
describe('setHoverCursor', () => {
|
|
@@ -9,8 +9,11 @@ const SELECTED_PREFIX = 'selected-highlight'
|
|
|
9
9
|
// Inner and selected both use the selected colour/width (black, thin)
|
|
10
10
|
const usesSelectedStyle = (prefix) => prefix === SELECTED_PREFIX || prefix === ACTIVE_INNER_PREFIX
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// Which variant of a symbol a highlight shows: its image id lookup on the provider's
|
|
13
|
+
// symbolImages, and draw's per-feature property holding the same id
|
|
14
|
+
const symbolVariant = (symbolImages, variant) => variant === 'active'
|
|
15
|
+
? { property: 'user_symbolActiveImageId', getImageId: (imageId) => symbolImages?.getActiveImageId(imageId) ?? null }
|
|
16
|
+
: { property: 'user_symbolSelectedImageId', getImageId: (imageId) => symbolImages?.getSelectedImageId(imageId) ?? null }
|
|
14
17
|
|
|
15
18
|
// Grouped by layerId, not sourceId: mapbox-gl-draw stores every geometry type in the same
|
|
16
19
|
// cold/hot sources, so a point (symbol layer) and a polygon (fill layer) selected together
|
|
@@ -138,14 +141,13 @@ const calculateBounds = (LngLatBounds, renderedFeatures) => {
|
|
|
138
141
|
// Draw's point-symbol layer has a per-feature data-driven icon-image, so there's no single
|
|
139
142
|
// shared image id to reverse-map — pointSymbolImages.js precomputes each point's own active/
|
|
140
143
|
// selected variant as a property, and the highlight layer just reads that directly.
|
|
141
|
-
const applySymbolGeomHighlight = (map, base, sourceId, srcLayer, layerId, filter,
|
|
144
|
+
const applySymbolGeomHighlight = (map, base, sourceId, srcLayer, layerId, filter, variant) => {
|
|
142
145
|
const imageId = map.getLayoutProperty(layerId, ICON_IMAGE)
|
|
143
146
|
if (Array.isArray(imageId)) {
|
|
144
|
-
|
|
145
|
-
applySymbolHighlightLayer(map, `${base}-symbol`, sourceId, srcLayer, layerId, ['get', property], filter)
|
|
147
|
+
applySymbolHighlightLayer(map, `${base}-symbol`, sourceId, srcLayer, layerId, ['get', variant.property], filter)
|
|
146
148
|
return
|
|
147
149
|
}
|
|
148
|
-
const symbolImageId =
|
|
150
|
+
const symbolImageId = variant.getImageId(imageId)
|
|
149
151
|
if (symbolImageId) {
|
|
150
152
|
applySymbolHighlightLayer(map, `${base}-symbol`, sourceId, srcLayer, layerId, symbolImageId, filter)
|
|
151
153
|
}
|
|
@@ -193,7 +195,7 @@ const applyLineHighlight = (map, base, sourceId, srcLayer, lineColor, lineWidth,
|
|
|
193
195
|
// active-highlight → yellow active ring (stroke only)
|
|
194
196
|
// active-highlight-inner → black thin ring drawn on top of active
|
|
195
197
|
// selected-highlight → black thin ring + fill for polygon features
|
|
196
|
-
const applyLayerHighlight = (map, layerId, featuresByLayer, stylesMap, prefix,
|
|
198
|
+
const applyLayerHighlight = (map, layerId, featuresByLayer, stylesMap, prefix, variant) => {
|
|
197
199
|
const { ids, fillIds, idProperty, sourceId, hasFillGeometry } = featuresByLayer[layerId]
|
|
198
200
|
const baseLayer = map.getLayer(layerId)
|
|
199
201
|
// Only the recorded layerId is registered in stylesMap — falls back to its cold/hot sibling
|
|
@@ -227,14 +229,14 @@ const applyLayerHighlight = (map, layerId, featuresByLayer, stylesMap, prefix, g
|
|
|
227
229
|
applyLineHighlight(map, base, sourceId, srcLayer, lineColor, lineWidth, filter)
|
|
228
230
|
break
|
|
229
231
|
case 'symbol':
|
|
230
|
-
applySymbolGeomHighlight(map, base, sourceId, srcLayer, layerId, filter,
|
|
232
|
+
applySymbolGeomHighlight(map, base, sourceId, srcLayer, layerId, filter, variant)
|
|
231
233
|
break
|
|
232
234
|
default:
|
|
233
235
|
break
|
|
234
236
|
}
|
|
235
237
|
}
|
|
236
238
|
|
|
237
|
-
const applyFeatureHighlights = (map, features, stylesMap, prefix,
|
|
239
|
+
const applyFeatureHighlights = (map, features, stylesMap, prefix, variant) => {
|
|
238
240
|
const featuresByLayer = groupFeaturesByLayer(map, features)
|
|
239
241
|
const currentLayerIds = new Set(Object.keys(featuresByLayer))
|
|
240
242
|
const storageKey = `_${prefix.replaceAll('-', '')}Sources`
|
|
@@ -242,7 +244,7 @@ const applyFeatureHighlights = (map, features, stylesMap, prefix, getSymbolImage
|
|
|
242
244
|
|
|
243
245
|
cleanupStaleLayers(map, previousLayerIds, currentLayerIds, prefix)
|
|
244
246
|
map[storageKey] = currentLayerIds
|
|
245
|
-
currentLayerIds.forEach(layerId => applyLayerHighlight(map, layerId, featuresByLayer, stylesMap, prefix,
|
|
247
|
+
currentLayerIds.forEach(layerId => applyLayerHighlight(map, layerId, featuresByLayer, stylesMap, prefix, variant))
|
|
246
248
|
|
|
247
249
|
return featuresByLayer
|
|
248
250
|
}
|
|
@@ -260,17 +262,20 @@ const applyFeatureHighlights = (map, features, stylesMap, prefix, getSymbolImage
|
|
|
260
262
|
* @param {Array} opts.activeFeatures - keyboard-cursor features
|
|
261
263
|
* @param {object} opts.stylesMap - keyed by layerId; each value is
|
|
262
264
|
* { stroke, selectionStroke, strokeWidth, activeStrokeWidth, fill }
|
|
265
|
+
* @param {object} [opts.symbolImages] - the provider's SymbolImageVariants, for symbol highlights
|
|
263
266
|
* @returns {number[]|null} [west, south, east, north] bounds or null if nothing is selected
|
|
264
267
|
*/
|
|
265
|
-
export function updateHighlightedFeatures ({ LngLatBounds, map, selectedFeatures, activeFeatures, stylesMap }) {
|
|
268
|
+
export function updateHighlightedFeatures ({ LngLatBounds, map, selectedFeatures, activeFeatures, stylesMap, symbolImages }) {
|
|
266
269
|
if (!map) {
|
|
267
270
|
return null
|
|
268
271
|
}
|
|
272
|
+
const activeVariant = symbolVariant(symbolImages, 'active')
|
|
273
|
+
const selectedVariant = symbolVariant(symbolImages, 'selected')
|
|
269
274
|
// Active cursor features — rendered first so selected layers appear on top
|
|
270
275
|
if (activeFeatures?.length) {
|
|
271
|
-
applyFeatureHighlights(map, activeFeatures, stylesMap, ACTIVE_PREFIX,
|
|
276
|
+
applyFeatureHighlights(map, activeFeatures, stylesMap, ACTIVE_PREFIX, activeVariant)
|
|
272
277
|
// Black selected stroke on top of yellow active (mirrors resolveActive for symbols)
|
|
273
|
-
applyFeatureHighlights(map, activeFeatures, stylesMap, ACTIVE_INNER_PREFIX,
|
|
278
|
+
applyFeatureHighlights(map, activeFeatures, stylesMap, ACTIVE_INNER_PREFIX, selectedVariant)
|
|
274
279
|
} else {
|
|
275
280
|
clearPrefixLayers(map, ACTIVE_PREFIX)
|
|
276
281
|
clearPrefixLayers(map, ACTIVE_INNER_PREFIX)
|
|
@@ -279,7 +284,7 @@ export function updateHighlightedFeatures ({ LngLatBounds, map, selectedFeatures
|
|
|
279
284
|
// Selection features
|
|
280
285
|
let featuresByLayer = {}
|
|
281
286
|
if (selectedFeatures?.length) {
|
|
282
|
-
featuresByLayer = applyFeatureHighlights(map, selectedFeatures, stylesMap, SELECTED_PREFIX,
|
|
287
|
+
featuresByLayer = applyFeatureHighlights(map, selectedFeatures, stylesMap, SELECTED_PREFIX, selectedVariant)
|
|
283
288
|
} else {
|
|
284
289
|
clearPrefixLayers(map, SELECTED_PREFIX)
|
|
285
290
|
}
|
|
@@ -183,6 +183,12 @@ describe('Highlighting Utils — layer management', () => {
|
|
|
183
183
|
})
|
|
184
184
|
})
|
|
185
185
|
|
|
186
|
+
// Stands in for the provider's SymbolImageVariants
|
|
187
|
+
const makeSymbolImages = ({ active = {}, selected = {} } = {}) => ({
|
|
188
|
+
getActiveImageId: (imageId) => active[imageId] ?? null,
|
|
189
|
+
getSelectedImageId: (imageId) => selected[imageId] ?? null
|
|
190
|
+
})
|
|
191
|
+
|
|
186
192
|
// ─── Symbol layers ────────────────────────────────────────────────────────────
|
|
187
193
|
|
|
188
194
|
describe('Highlighting Utils — symbol layers (active cursor)', () => {
|
|
@@ -192,17 +198,17 @@ describe('Highlighting Utils — symbol layers (active cursor)', () => {
|
|
|
192
198
|
const ICON_ANCHOR = 'icon-anchor'
|
|
193
199
|
const POINT_FEATURE = { featureId: 1, layerId: 'l1', geometry: { type: 'Point' } }
|
|
194
200
|
|
|
195
|
-
let map
|
|
201
|
+
let map, symbolImages
|
|
196
202
|
|
|
197
203
|
beforeEach(() => {
|
|
198
204
|
map = makeMap()
|
|
199
|
-
|
|
205
|
+
symbolImages = makeSymbolImages({ active: { [SYMBOL_IMAGE]: ACTIVE_IMAGE } })
|
|
200
206
|
map.getLayer.mockImplementation(id => id === 'l1' ? { source: 's1', type: 'symbol' } : null) // NOSONAR
|
|
201
207
|
map.getLayoutProperty.mockReturnValue(SYMBOL_IMAGE)
|
|
202
208
|
})
|
|
203
209
|
|
|
204
210
|
const run = (activeFeatures = [POINT_FEATURE]) =>
|
|
205
|
-
updateHighlightedFeatures({ LngLatBounds, map, activeFeatures, stylesMap: { l1: {} } })
|
|
211
|
+
updateHighlightedFeatures({ LngLatBounds, map, activeFeatures, stylesMap: { l1: {} }, symbolImages })
|
|
206
212
|
|
|
207
213
|
test('creates symbol highlight layer with cursor image variant', () => {
|
|
208
214
|
run()
|
|
@@ -251,9 +257,9 @@ describe('Highlighting Utils — symbol layers (active cursor)', () => {
|
|
|
251
257
|
expect(map.setLayoutProperty).toHaveBeenCalledWith(HIGHLIGHT_LAYER, ICON_IMAGE, ACTIVE_IMAGE)
|
|
252
258
|
})
|
|
253
259
|
|
|
254
|
-
test('skips highlight when icon-image has no
|
|
260
|
+
test('skips highlight when the icon-image has no registered active variant', () => {
|
|
255
261
|
map.getLayoutProperty.mockReturnValue(SYMBOL_IMAGE)
|
|
256
|
-
|
|
262
|
+
symbolImages = makeSymbolImages()
|
|
257
263
|
run()
|
|
258
264
|
expect(map.addLayer).not.toHaveBeenCalled()
|
|
259
265
|
})
|
|
@@ -307,17 +313,17 @@ describe('Highlighting Utils — symbol layers (committed selection)', () => {
|
|
|
307
313
|
const ICON_IMAGE = 'icon-image'
|
|
308
314
|
const POINT_FEATURE = { featureId: 1, layerId: 'l1', geometry: { type: 'Point' } }
|
|
309
315
|
|
|
310
|
-
let map
|
|
316
|
+
let map, symbolImages
|
|
311
317
|
|
|
312
318
|
beforeEach(() => {
|
|
313
319
|
map = makeMap()
|
|
314
|
-
|
|
320
|
+
symbolImages = makeSymbolImages({ selected: { [SYMBOL_IMAGE]: SELECTED_IMAGE } })
|
|
315
321
|
map.getLayer.mockImplementation(id => id === 'l1' ? { source: 's1', type: 'symbol' } : null) // NOSONAR
|
|
316
322
|
map.getLayoutProperty.mockReturnValue(SYMBOL_IMAGE)
|
|
317
323
|
})
|
|
318
324
|
|
|
319
325
|
const run = (selectedFeatures = [POINT_FEATURE]) =>
|
|
320
|
-
updateHighlightedFeatures({ LngLatBounds, map, selectedFeatures, stylesMap: { l1: {} } })
|
|
326
|
+
updateHighlightedFeatures({ LngLatBounds, map, selectedFeatures, stylesMap: { l1: {} }, symbolImages })
|
|
321
327
|
|
|
322
328
|
test('creates selected-highlight symbol layer with selected image variant', () => {
|
|
323
329
|
run()
|
|
@@ -328,8 +334,8 @@ describe('Highlighting Utils — symbol layers (committed selection)', () => {
|
|
|
328
334
|
}))
|
|
329
335
|
})
|
|
330
336
|
|
|
331
|
-
test('skips highlight when icon-image has no
|
|
332
|
-
|
|
337
|
+
test('skips highlight when the icon-image has no registered selected variant', () => {
|
|
338
|
+
symbolImages = makeSymbolImages()
|
|
333
339
|
run()
|
|
334
340
|
expect(map.addLayer).not.toHaveBeenCalled()
|
|
335
341
|
})
|
|
@@ -509,7 +515,6 @@ describe('Highlighting Utils — mapbox-gl-draw cold/hot sibling layers', () =>
|
|
|
509
515
|
})
|
|
510
516
|
map.getLayoutProperty.mockImplementation((id, prop) => // NOSONAR
|
|
511
517
|
prop === 'icon-image' ? SYMBOL_IMAGE : undefined)
|
|
512
|
-
map._selectedSymbolImageMap = { [SYMBOL_IMAGE]: 'symbol-sel-xyz' }
|
|
513
518
|
|
|
514
519
|
// The feature's own current geometry lives on the hot source (it moved there when its
|
|
515
520
|
// properties were last refreshed) — only stylesMap['point-symbol.cold'] is registered,
|
|
@@ -518,7 +523,8 @@ describe('Highlighting Utils — mapbox-gl-draw cold/hot sibling layers', () =>
|
|
|
518
523
|
LngLatBounds,
|
|
519
524
|
map,
|
|
520
525
|
selectedFeatures: [{ featureId: 'p1', layerId: 'point-symbol.cold', geometry: { type: 'Point' } }],
|
|
521
|
-
stylesMap: { 'point-symbol.cold': { stroke: 'red', selectionStroke: 'black', strokeWidth: 2 } }
|
|
526
|
+
stylesMap: { 'point-symbol.cold': { stroke: 'red', selectionStroke: 'black', strokeWidth: 2 } },
|
|
527
|
+
symbolImages: makeSymbolImages({ selected: { [SYMBOL_IMAGE]: 'symbol-sel-xyz' } })
|
|
522
528
|
})
|
|
523
529
|
|
|
524
530
|
// A highlight layer gets created/filtered for BOTH the recorded source and its sibling —
|
|
@@ -558,7 +564,6 @@ describe('Highlighting Utils — multi-select across geometry types sharing a so
|
|
|
558
564
|
})
|
|
559
565
|
map.getLayoutProperty.mockImplementation((id, prop) => // NOSONAR
|
|
560
566
|
prop === 'icon-image' ? SYMBOL_IMAGE : undefined)
|
|
561
|
-
map._selectedSymbolImageMap = { [SYMBOL_IMAGE]: 'symbol-sel-xyz' }
|
|
562
567
|
|
|
563
568
|
updateHighlightedFeatures({
|
|
564
569
|
LngLatBounds,
|
|
@@ -570,7 +575,8 @@ describe('Highlighting Utils — multi-select across geometry types sharing a so
|
|
|
570
575
|
stylesMap: {
|
|
571
576
|
'point-symbol.cold': { stroke: 'red', selectionStroke: 'black', strokeWidth: 2 },
|
|
572
577
|
'fill-inactive.cold': { stroke: 'red', selectionStroke: 'black', fill: 'blue', strokeWidth: 2 }
|
|
573
|
-
}
|
|
578
|
+
},
|
|
579
|
+
symbolImages: makeSymbolImages({ selected: { [SYMBOL_IMAGE]: 'symbol-sel-xyz' } })
|
|
574
580
|
})
|
|
575
581
|
|
|
576
582
|
expect(map.addLayer).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -1,37 +1,54 @@
|
|
|
1
1
|
import { getEffectivePixelRatio } from '../../../../src/utils/patternUtils.js'
|
|
2
|
+
import { RecentImageSets } from '../../../../src/utils/recentImageSets.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param {Object} map - MapLibre map instance
|
|
10
|
-
* @param {Object[]} styleArray - an array of pattern style configs
|
|
11
|
-
* @param {string} mapStyleId
|
|
12
|
-
* @param {Object} patternRegistry
|
|
13
|
-
* @param {number} pixelRatio
|
|
14
|
-
* @returns {Promise<void>}
|
|
5
|
+
* The MapLibre provider's pattern images, in the map's own image store (map.addImage). One per
|
|
6
|
+
* map, shared by every caller that registers patterns on it. Images are kept for the current and
|
|
7
|
+
* previous map size and style; ones only older sizes and styles used are removed from the map,
|
|
8
|
+
* so they don't build up as the map size or style changes.
|
|
15
9
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
export class PatternImages {
|
|
11
|
+
recentImageSets = new RecentImageSets()
|
|
12
|
+
|
|
13
|
+
/** @param {Object} map - MapLibre map instance */
|
|
14
|
+
constructor (map) {
|
|
15
|
+
this.map = map
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Rasterises and adds each pattern's image to the map. Images the map already has are reused,
|
|
20
|
+
* and styles that resolve to the same image are only rasterised once.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object[]} styleArray - pattern style configs (fillPattern/fillPatternSvgContent plus colours)
|
|
23
|
+
* @param {string} mapStyleId
|
|
24
|
+
* @param {Object} patternRegistry
|
|
25
|
+
* @param {number} pixelRatio - Device pixel ratio × map size scale factor
|
|
26
|
+
* @returns {Promise<void>}
|
|
27
|
+
*/
|
|
28
|
+
async registerPatterns (styleArray, mapStyleId, patternRegistry, pixelRatio) {
|
|
29
|
+
const { map } = this
|
|
30
|
+
const stylesByImageId = new Map()
|
|
31
|
+
styleArray.forEach((style) => {
|
|
32
|
+
const imageId = patternRegistry.getPatternImageId(style, mapStyleId, pixelRatio)
|
|
33
|
+
if (imageId && !stylesByImageId.has(imageId)) {
|
|
34
|
+
stylesByImageId.set(imageId, style)
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
const effectiveRatio = getEffectivePixelRatio(pixelRatio)
|
|
38
|
+
await Promise.all(Array.from(stylesByImageId, async ([imageId, style]) => {
|
|
39
|
+
if (map.hasImage(imageId)) {
|
|
40
|
+
return
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
const result = await patternRegistry.rasterisePatternImage(style, mapStyleId, pixelRatio)
|
|
43
|
+
if (result && !map.hasImage(result.imageId)) {
|
|
44
|
+
map.addImage(result.imageId, result.imageData, { pixelRatio: effectiveRatio })
|
|
45
|
+
}
|
|
46
|
+
}))
|
|
47
|
+
this.recentImageSets.add(`${mapStyleId}|${pixelRatio}`, Array.from(stylesByImageId.keys()))
|
|
48
|
+
.forEach((imageId) => {
|
|
49
|
+
if (map.hasImage(imageId)) {
|
|
50
|
+
map.removeImage(imageId)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
37
54
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PatternImages } from './patternImages.js'
|
|
2
|
+
import { createPatternRegistry } from '../../../../src/services/patternRegistry.js'
|
|
3
|
+
|
|
4
|
+
const patternRegistry = createPatternRegistry()
|
|
3
5
|
|
|
4
6
|
const OUTDOOR = 'outdoor'
|
|
5
7
|
|
|
@@ -31,6 +33,10 @@ const makeMap = (existingIds = []) => ({
|
|
|
31
33
|
addImage: jest.fn()
|
|
32
34
|
})
|
|
33
35
|
|
|
36
|
+
// Registers the configs with a fresh PatternImages for the map
|
|
37
|
+
const addPatternsToMap = (map, configs, mapStyleId, registry, pixelRatio = 1) =>
|
|
38
|
+
new PatternImages(map).registerPatterns(configs, mapStyleId, registry, pixelRatio)
|
|
39
|
+
|
|
34
40
|
// ─── addPatternsToMap ─────────────────────────────────────────────────────────
|
|
35
41
|
describe('addPatternsToMap', () => {
|
|
36
42
|
beforeEach(() => {
|
|
@@ -56,7 +62,7 @@ describe('addPatternsToMap', () => {
|
|
|
56
62
|
it('skips addImage when image is already registered', async () => {
|
|
57
63
|
const style = { fillPattern: 'stripes' }
|
|
58
64
|
const pixelRatio = 1
|
|
59
|
-
const map = makeMap([
|
|
65
|
+
const map = makeMap([patternRegistry.getPatternImageId(style, OUTDOOR, pixelRatio)])
|
|
60
66
|
await addPatternsToMap(map, [style], OUTDOOR, patternRegistry, pixelRatio)
|
|
61
67
|
expect(map.addImage).not.toHaveBeenCalled()
|
|
62
68
|
})
|
|
@@ -77,7 +83,6 @@ describe('addPatternsToMap', () => {
|
|
|
77
83
|
it('processes multiple configs in parallel', async () => {
|
|
78
84
|
const map = makeMap()
|
|
79
85
|
patternRegistry.register('dots', "fillPatternForegroundColor: '#aabbcc', fillPatternBackgroundColor: '#112233'")
|
|
80
|
-
console.log('patternRegistry.list', patternRegistry.list())
|
|
81
86
|
await addPatternsToMap(map, [{ fillPattern: 'stripes' }, { fillPattern: 'dots' }], OUTDOOR, patternRegistry)
|
|
82
87
|
expect(map.addImage).toHaveBeenCalledTimes(2)
|
|
83
88
|
})
|
|
@@ -188,3 +193,46 @@ describe('addPatternsToMap', () => {
|
|
|
188
193
|
})
|
|
189
194
|
})
|
|
190
195
|
})
|
|
196
|
+
|
|
197
|
+
describe('PatternImages — removing images from older map sizes and styles', () => {
|
|
198
|
+
// A map that keeps the images added to it, like MapLibre's image store
|
|
199
|
+
const makeImageStore = () => {
|
|
200
|
+
const images = new Set()
|
|
201
|
+
return {
|
|
202
|
+
images,
|
|
203
|
+
hasImage: jest.fn((id) => images.has(id)),
|
|
204
|
+
addImage: jest.fn((id) => images.add(id)),
|
|
205
|
+
removeImage: jest.fn((id) => images.delete(id))
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const style = { fillPatternSvgContent: SVG_CONTENT }
|
|
209
|
+
|
|
210
|
+
it('keeps the current and previous size, and removes an older one\'s image when a third arrives', async () => {
|
|
211
|
+
const map = makeImageStore()
|
|
212
|
+
const patternImages = new PatternImages(map)
|
|
213
|
+
await patternImages.registerPatterns([style], OUTDOOR, patternRegistry, 1)
|
|
214
|
+
const oldId = patternRegistry.getPatternImageId(style, OUTDOOR, 1)
|
|
215
|
+
await patternImages.registerPatterns([style], OUTDOOR, patternRegistry, 2)
|
|
216
|
+
expect(map.images.has(oldId)).toBe(true)
|
|
217
|
+
|
|
218
|
+
await patternImages.registerPatterns([style], OUTDOOR, patternRegistry, 3)
|
|
219
|
+
expect(map.images.has(oldId)).toBe(false)
|
|
220
|
+
expect(map.images.size).toBe(2)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('skips removing an old image the map no longer has, e.g. after a style change', async () => {
|
|
224
|
+
const map = makeImageStore()
|
|
225
|
+
const patternImages = new PatternImages(map)
|
|
226
|
+
await patternImages.registerPatterns([style], OUTDOOR, patternRegistry, 1)
|
|
227
|
+
map.images.clear()
|
|
228
|
+
await patternImages.registerPatterns([style], OUTDOOR, patternRegistry, 2)
|
|
229
|
+
await patternImages.registerPatterns([style], OUTDOOR, patternRegistry, 3)
|
|
230
|
+
expect(map.removeImage).not.toHaveBeenCalled()
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('rasterises a pattern shared by several styles once', async () => {
|
|
234
|
+
const map = makeImageStore()
|
|
235
|
+
await new PatternImages(map).registerPatterns([style, { ...style }], OUTDOOR, patternRegistry, 1)
|
|
236
|
+
expect(map.addImage).toHaveBeenCalledTimes(1)
|
|
237
|
+
})
|
|
238
|
+
})
|