@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
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getPixelRatio, resolvePointSymbol, refreshAllPointSymbols } from './pointSymbolImages.js'
|
|
2
|
+
import { createSymbolRegistry } from '../../../../../src/services/symbolRegistry.js'
|
|
3
|
+
import { logger } from '../../../../../src/services/logger.js'
|
|
4
|
+
import { getSymbolIconLayout } from '../../../../../providers/maplibre/src/utils/symbolImages.js'
|
|
5
|
+
|
|
6
|
+
const symbolRegistry = createSymbolRegistry()
|
|
3
7
|
|
|
4
8
|
const mapStyle = { id: 'outdoor', mapColorScheme: 'light' }
|
|
5
9
|
|
|
@@ -12,8 +16,14 @@ const createMap = ({ pixelRatio = 2 } = {}) => ({
|
|
|
12
16
|
setLayoutProperty: jest.fn()
|
|
13
17
|
})
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
// The provider's symbol methods: addSymbolsToMap is a no-op unless overridden, nothing is
|
|
20
|
+
// registered as an active/selected variant, and icon placement is the provider's own
|
|
21
|
+
const createMapProvider = (overrides = {}) => ({
|
|
22
|
+
addSymbolsToMap: jest.fn(() => Promise.resolve()),
|
|
23
|
+
getActiveSymbolImageId: jest.fn(() => null),
|
|
24
|
+
getSelectedSymbolImageId: jest.fn(() => null),
|
|
25
|
+
getSymbolIconLayout: jest.fn(getSymbolIconLayout),
|
|
26
|
+
...overrides
|
|
17
27
|
})
|
|
18
28
|
|
|
19
29
|
const createDraw = (features = []) => ({
|
|
@@ -25,21 +35,6 @@ const createDraw = (features = []) => ({
|
|
|
25
35
|
const point = (id, properties, coordinates = [1, 2]) =>
|
|
26
36
|
({ id, type: 'Feature', geometry: { type: 'Point', coordinates }, properties })
|
|
27
37
|
|
|
28
|
-
describe('hasSymbolStyle', () => {
|
|
29
|
-
it('is true when symbol is set', () => {
|
|
30
|
-
expect(hasSymbolStyle({ symbol: 'pin' })).toBe(true)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('is true when symbolSvgContent is set', () => {
|
|
34
|
-
expect(hasSymbolStyle({ symbolSvgContent: '<path/>' })).toBe(true)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('is false with neither, or no properties at all', () => {
|
|
38
|
-
expect(hasSymbolStyle({})).toBe(false)
|
|
39
|
-
expect(hasSymbolStyle(undefined)).toBe(false)
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
38
|
describe('getPixelRatio', () => {
|
|
44
39
|
it('reads map.getPixelRatio()', () => {
|
|
45
40
|
expect(getPixelRatio(createMap({ pixelRatio: 3 }))).toBe(3)
|
|
@@ -56,7 +51,7 @@ describe('resolvePointSymbol', () => {
|
|
|
56
51
|
const map = createMap()
|
|
57
52
|
const mapProvider = createMapProvider()
|
|
58
53
|
const draw = createDraw()
|
|
59
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties: {} })
|
|
54
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties: {} })
|
|
60
55
|
expect(mapProvider.addSymbolsToMap).not.toHaveBeenCalled()
|
|
61
56
|
expect(draw.add).not.toHaveBeenCalled()
|
|
62
57
|
})
|
|
@@ -67,10 +62,10 @@ describe('resolvePointSymbol', () => {
|
|
|
67
62
|
const properties = { symbol: 'pin', label: 'a point' }
|
|
68
63
|
const draw = createDraw([point('p1', properties)])
|
|
69
64
|
|
|
70
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
65
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
71
66
|
|
|
72
|
-
expect(mapProvider.addSymbolsToMap).toHaveBeenCalledWith([properties], mapStyle, symbolRegistry)
|
|
73
|
-
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle,
|
|
67
|
+
expect(mapProvider.addSymbolsToMap).toHaveBeenCalledWith([properties], mapStyle, symbolRegistry, 2)
|
|
68
|
+
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, 'normal', 2)
|
|
74
69
|
expect(draw.add).toHaveBeenCalledWith({
|
|
75
70
|
id: 'p1',
|
|
76
71
|
type: 'Feature',
|
|
@@ -79,22 +74,21 @@ describe('resolvePointSymbol', () => {
|
|
|
79
74
|
...properties,
|
|
80
75
|
symbolImageId: expectedImageId,
|
|
81
76
|
symbolIconAnchor: 'bottom', // pin's default anchor [0.5, 0.9] snaps to icon-anchor 'bottom'
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
// for the case where it actually populates them.
|
|
77
|
+
// The provider has no active/selected variants registered in this test — see the
|
|
78
|
+
// dedicated test below for the case where it does.
|
|
85
79
|
symbolActiveImageId: null,
|
|
86
80
|
symbolSelectedImageId: null
|
|
87
81
|
}
|
|
88
82
|
})
|
|
89
|
-
// icon-offset corrects the precision lost snapping 0.
|
|
83
|
+
// icon-offset corrects the precision lost snapping pin's ~0.832 anchor to 1.0 against its 52px-tall viewBox —
|
|
90
84
|
// registered into the point-symbol layers' icon-offset match expression instead of onto
|
|
91
85
|
// the feature (see registerSymbolIconOffset's comment for why).
|
|
92
|
-
expect(map._symbolIconOffsetMap[expectedImageId]).toEqual([0,
|
|
86
|
+
expect(map._symbolIconOffsetMap[expectedImageId]).toEqual([0, 8.75])
|
|
93
87
|
expect(map.setLayoutProperty).toHaveBeenCalledWith('point-symbol.hot', 'icon-offset', [
|
|
94
|
-
'match', ['get', 'user_symbolImageId'], expectedImageId, ['literal', [0,
|
|
88
|
+
'match', ['get', 'user_symbolImageId'], expectedImageId, ['literal', [0, 8.75]], ['literal', [0, 0]]
|
|
95
89
|
])
|
|
96
90
|
expect(map.setLayoutProperty).toHaveBeenCalledWith('point-symbol.cold', 'icon-offset', [
|
|
97
|
-
'match', ['get', 'user_symbolImageId'], expectedImageId, ['literal', [0,
|
|
91
|
+
'match', ['get', 'user_symbolImageId'], expectedImageId, ['literal', [0, 8.75]], ['literal', [0, 0]]
|
|
98
92
|
])
|
|
99
93
|
})
|
|
100
94
|
|
|
@@ -105,42 +99,61 @@ describe('resolvePointSymbol', () => {
|
|
|
105
99
|
const properties = { symbol: 'pin' }
|
|
106
100
|
const draw = createDraw([point('p1', properties)])
|
|
107
101
|
|
|
108
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
102
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
109
103
|
|
|
110
104
|
expect(map.setLayoutProperty).toHaveBeenCalledWith('point-symbol.cold', 'icon-offset', expect.anything())
|
|
111
105
|
expect(map.setLayoutProperty).not.toHaveBeenCalledWith('point-symbol.hot', 'icon-offset', expect.anything())
|
|
112
106
|
})
|
|
113
107
|
|
|
108
|
+
it('writes the icon-offset expression into draw.options.styles so re-added layers keep it', async () => {
|
|
109
|
+
const map = createMap()
|
|
110
|
+
map.getLayer.mockReturnValue(false) // layers not on the map yet (or wiped by a style change)
|
|
111
|
+
const mapProvider = createMapProvider()
|
|
112
|
+
const properties = { symbol: 'pin' }
|
|
113
|
+
const draw = createDraw([point('p1', properties)])
|
|
114
|
+
draw.options = {
|
|
115
|
+
styles: [
|
|
116
|
+
{ id: 'point-symbol.cold', layout: { 'icon-anchor': 'x' } },
|
|
117
|
+
{ id: 'point-symbol.hot', layout: {} },
|
|
118
|
+
{ id: 'polygon-fill.cold', layout: {} }
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
123
|
+
|
|
124
|
+
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, 'normal', 2)
|
|
125
|
+
const expression = ['match', ['get', 'user_symbolImageId'], expectedImageId, ['literal', [0, 8.75]], ['literal', [0, 0]]]
|
|
126
|
+
expect(draw.options.styles[0].layout).toEqual({ 'icon-anchor': 'x', 'icon-offset': expression })
|
|
127
|
+
expect(draw.options.styles[1].layout).toEqual({ 'icon-offset': expression })
|
|
128
|
+
expect(draw.options.styles[2].layout).toEqual({})
|
|
129
|
+
expect(map.setLayoutProperty).not.toHaveBeenCalled()
|
|
130
|
+
})
|
|
131
|
+
|
|
114
132
|
it('does not re-register or re-apply icon-offset for a symbolImageId already known (offset is deterministic per id)', async () => {
|
|
115
133
|
const map = createMap()
|
|
116
134
|
const mapProvider = createMapProvider()
|
|
117
135
|
const properties = { symbol: 'pin' }
|
|
118
136
|
const draw = createDraw([point('p1', properties), point('p2', properties)])
|
|
119
137
|
|
|
120
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
138
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
121
139
|
map.setLayoutProperty.mockClear()
|
|
122
140
|
|
|
123
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p2', properties })
|
|
141
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p2', properties })
|
|
124
142
|
|
|
125
143
|
expect(map.setLayoutProperty).not.toHaveBeenCalled()
|
|
126
144
|
})
|
|
127
145
|
|
|
128
|
-
it('reads the active/selected variant ids back from
|
|
146
|
+
it('reads the active/selected variant ids back from the provider once addSymbolsToMap has registered them', async () => {
|
|
129
147
|
const map = createMap()
|
|
130
148
|
const properties = { symbol: 'pin' }
|
|
131
149
|
const draw = createDraw([point('p1', properties)])
|
|
132
|
-
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
map._activeSymbolImageMap = { [expectedImageId]: 'symbol-act-xyz' }
|
|
138
|
-
map._selectedSymbolImageMap = { [expectedImageId]: 'symbol-sel-xyz' }
|
|
139
|
-
return Promise.resolve()
|
|
140
|
-
})
|
|
141
|
-
}
|
|
150
|
+
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, 'normal', 2)
|
|
151
|
+
const mapProvider = createMapProvider({
|
|
152
|
+
getActiveSymbolImageId: jest.fn((imageId) => imageId === expectedImageId ? 'symbol-act-xyz' : null),
|
|
153
|
+
getSelectedSymbolImageId: jest.fn((imageId) => imageId === expectedImageId ? 'symbol-sel-xyz' : null)
|
|
154
|
+
})
|
|
142
155
|
|
|
143
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
156
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
144
157
|
|
|
145
158
|
expect(draw.add).toHaveBeenCalledWith(expect.objectContaining({
|
|
146
159
|
properties: expect.objectContaining({
|
|
@@ -157,7 +170,7 @@ describe('resolvePointSymbol', () => {
|
|
|
157
170
|
const draw = createDraw([point('p1', properties)])
|
|
158
171
|
const spy = jest.spyOn(symbolRegistry, 'getSymbolImageId').mockReturnValueOnce(null)
|
|
159
172
|
|
|
160
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
173
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
161
174
|
|
|
162
175
|
expect(draw.add).not.toHaveBeenCalled()
|
|
163
176
|
spy.mockRestore()
|
|
@@ -167,72 +180,72 @@ describe('resolvePointSymbol', () => {
|
|
|
167
180
|
const map = createMap()
|
|
168
181
|
const properties = { symbol: 'pin' }
|
|
169
182
|
let resolveRegistration
|
|
170
|
-
const mapProvider = { addSymbolsToMap: jest.fn(() => new Promise((resolve) => { resolveRegistration = resolve })) }
|
|
183
|
+
const mapProvider = createMapProvider({ addSymbolsToMap: jest.fn(() => new Promise((resolve) => { resolveRegistration = resolve })) })
|
|
171
184
|
const draw = createDraw() // empty — feature already gone
|
|
172
185
|
|
|
173
|
-
const pending = resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
186
|
+
const pending = resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
174
187
|
resolveRegistration()
|
|
175
188
|
await pending
|
|
176
189
|
|
|
177
190
|
expect(draw.add).not.toHaveBeenCalled()
|
|
178
191
|
})
|
|
179
192
|
|
|
180
|
-
it('
|
|
193
|
+
it('anchors a built-in shape\'s symbolAnchor override to the shape itself, not its padded viewBox', async () => {
|
|
181
194
|
const map = createMap()
|
|
182
195
|
const mapProvider = createMapProvider()
|
|
183
196
|
const properties = { symbol: 'circle', symbolAnchor: [0, 0] }
|
|
184
197
|
const draw = createDraw([point('p1', properties)])
|
|
185
198
|
|
|
186
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
199
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
187
200
|
|
|
201
|
+
// [0, 0] is the circle's own top-left — 9px in from the 44×44 viewBox's corner (the ring
|
|
202
|
+
// padding) — so it snaps to 'top-left' and the offset moves it the remaining 9px
|
|
188
203
|
expect(draw.add).toHaveBeenCalledWith(expect.objectContaining({
|
|
189
204
|
properties: expect.objectContaining({ symbolIconAnchor: 'top-left' })
|
|
190
205
|
}))
|
|
191
|
-
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle,
|
|
192
|
-
expect(map._symbolIconOffsetMap[expectedImageId]).toEqual([
|
|
206
|
+
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, 'normal', 2)
|
|
207
|
+
expect(map._symbolIconOffsetMap[expectedImageId]).toEqual([-9, -9])
|
|
193
208
|
})
|
|
194
209
|
|
|
195
210
|
it('computes a non-zero icon-offset for an off-grid custom symbolAnchor', async () => {
|
|
196
211
|
const map = createMap()
|
|
197
212
|
const mapProvider = createMapProvider()
|
|
198
|
-
const properties = { symbol: 'circle', symbolAnchor: [0.5,
|
|
213
|
+
const properties = { symbol: 'circle', symbolAnchor: [0.5, 1] }
|
|
199
214
|
const draw = createDraw([point('p1', properties)])
|
|
200
215
|
|
|
201
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
216
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
202
217
|
|
|
203
|
-
// circle's
|
|
218
|
+
// the circle's bottom edge sits 9px above its 44×44 viewBox's — off the grid, so it snaps to
|
|
219
|
+
// icon-anchor 'bottom' (the viewBox edge) and the offset moves it back up those 9px
|
|
204
220
|
expect(draw.add).toHaveBeenCalledWith(expect.objectContaining({
|
|
205
221
|
properties: expect.objectContaining({ symbolIconAnchor: 'bottom' })
|
|
206
222
|
}))
|
|
207
|
-
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle,
|
|
208
|
-
expect(map._symbolIconOffsetMap[expectedImageId]).toEqual([0,
|
|
223
|
+
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, 'normal', 2)
|
|
224
|
+
expect(map._symbolIconOffsetMap[expectedImageId]).toEqual([0, 9])
|
|
209
225
|
})
|
|
210
226
|
|
|
211
227
|
it('respects a custom symbolViewBox when computing the offset', async () => {
|
|
212
228
|
const map = createMap()
|
|
213
229
|
const mapProvider = createMapProvider()
|
|
214
|
-
const properties = {
|
|
230
|
+
const properties = { symbolSvgContent: '<circle/>', symbolViewBox: '0 0 100 100', symbolAnchor: [0.5, 0.9] }
|
|
215
231
|
const draw = createDraw([point('p1', properties)])
|
|
216
232
|
|
|
217
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
233
|
+
await resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })
|
|
218
234
|
|
|
219
|
-
//
|
|
220
|
-
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle,
|
|
235
|
+
// anchor [0.5, 0.9] against the custom 100×100 viewBox
|
|
236
|
+
const expectedImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, 'normal', 2)
|
|
221
237
|
expect(map._symbolIconOffsetMap[expectedImageId]).toEqual([0, 10])
|
|
222
238
|
})
|
|
223
239
|
|
|
224
|
-
it('
|
|
240
|
+
it('rejects, without writing to the feature, when registration fails', async () => {
|
|
225
241
|
const map = createMap()
|
|
226
242
|
const properties = { symbol: 'pin' }
|
|
227
|
-
const
|
|
243
|
+
const error = new Error('rasterise failed')
|
|
244
|
+
const mapProvider = createMapProvider({ addSymbolsToMap: jest.fn(() => Promise.reject(error)) })
|
|
228
245
|
const draw = createDraw([point('p1', properties)])
|
|
229
|
-
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
230
|
-
|
|
231
|
-
await resolvePointSymbol({ draw, mapProvider, map, featureId: 'p1', properties })
|
|
232
246
|
|
|
247
|
+
await expect(resolvePointSymbol({ draw, mapProvider, map, symbolRegistry, featureId: 'p1', properties })).rejects.toBe(error)
|
|
233
248
|
expect(draw.add).not.toHaveBeenCalled()
|
|
234
|
-
expect(consoleError).toHaveBeenCalledWith('[draw] failed to resolve point symbol', 'p1', expect.any(Error))
|
|
235
|
-
consoleError.mockRestore()
|
|
236
249
|
})
|
|
237
250
|
})
|
|
238
251
|
|
|
@@ -245,20 +258,76 @@ describe('refreshAllPointSymbols', () => {
|
|
|
245
258
|
const polygon = { id: 'poly1', geometry: { type: 'Polygon' }, properties: { symbol: 'pin' } }
|
|
246
259
|
const draw = createDraw([pointWithSymbol, pointWithoutSymbol, polygon])
|
|
247
260
|
|
|
248
|
-
await refreshAllPointSymbols({ draw, mapProvider, map })
|
|
261
|
+
await refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry })
|
|
249
262
|
|
|
250
263
|
expect(mapProvider.addSymbolsToMap).toHaveBeenCalledTimes(1)
|
|
251
|
-
expect(mapProvider.addSymbolsToMap).toHaveBeenCalledWith([pointWithSymbol.properties], mapStyle, symbolRegistry)
|
|
264
|
+
expect(mapProvider.addSymbolsToMap).toHaveBeenCalledWith([pointWithSymbol.properties], mapStyle, symbolRegistry, 2)
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
it('registers images at pixelRatioOverride, so they match the ids worked out at it', async () => {
|
|
268
|
+
const map = createMap({ pixelRatio: 2 })
|
|
269
|
+
const mapProvider = createMapProvider()
|
|
270
|
+
const draw = createDraw([point('p1', { symbol: 'pin' })])
|
|
271
|
+
|
|
272
|
+
await refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry, pixelRatioOverride: 3 })
|
|
273
|
+
|
|
274
|
+
expect(mapProvider.addSymbolsToMap).toHaveBeenCalledWith([expect.objectContaining({ symbol: 'pin' })], mapStyle, symbolRegistry, 3)
|
|
275
|
+
const [{ features: [written] }] = draw.add.mock.calls[0]
|
|
276
|
+
expect(written.properties.symbolImageId).toBe(symbolRegistry.getSymbolImageId({ symbol: 'pin' }, mapStyle, 'normal', 3))
|
|
252
277
|
})
|
|
253
278
|
|
|
254
279
|
it('does nothing when there are no drawn points', async () => {
|
|
255
280
|
const map = createMap()
|
|
256
281
|
const mapProvider = createMapProvider()
|
|
257
282
|
const draw = createDraw([])
|
|
258
|
-
await refreshAllPointSymbols({ draw, mapProvider, map })
|
|
283
|
+
await refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry })
|
|
259
284
|
expect(mapProvider.addSymbolsToMap).not.toHaveBeenCalled()
|
|
260
285
|
})
|
|
261
286
|
|
|
287
|
+
it('drops an older refresh\'s results when a newer one has started since', async () => {
|
|
288
|
+
const map = createMap()
|
|
289
|
+
const draw = createDraw([point('p1', { symbol: 'pin' })])
|
|
290
|
+
// the first refresh's image registration is held until after the second has finished
|
|
291
|
+
let releaseFirst
|
|
292
|
+
const held = new Promise((resolve) => { releaseFirst = resolve })
|
|
293
|
+
const mapProvider = createMapProvider({ addSymbolsToMap: jest.fn().mockImplementationOnce(() => held).mockResolvedValue(undefined) })
|
|
294
|
+
|
|
295
|
+
const first = refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry, pixelRatioOverride: 1 })
|
|
296
|
+
await refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry, pixelRatioOverride: 2 })
|
|
297
|
+
releaseFirst()
|
|
298
|
+
await first
|
|
299
|
+
|
|
300
|
+
expect(draw.add).toHaveBeenCalledTimes(1)
|
|
301
|
+
const [{ features: [written] }] = draw.add.mock.calls[0]
|
|
302
|
+
expect(written.properties.symbolImageId).toBe(symbolRegistry.getSymbolImageId({ symbol: 'pin' }, mapStyle, 'normal', 2))
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
it('drops icon offsets for image ids no drawn point uses any more, keeping the rest', async () => {
|
|
306
|
+
const map = createMap()
|
|
307
|
+
const mapProvider = createMapProvider()
|
|
308
|
+
let features = [point('p1', { symbol: 'pin', symbolImageId: 'symbol-stale-1x' })]
|
|
309
|
+
// a draw whose add() really replaces the stored features, as mapbox-gl-draw's does
|
|
310
|
+
const draw = {
|
|
311
|
+
getAll: jest.fn(() => ({ features })),
|
|
312
|
+
get: jest.fn((id) => features.find((f) => f.id === id) ?? null),
|
|
313
|
+
add: jest.fn(({ features: added }) => { features = added })
|
|
314
|
+
}
|
|
315
|
+
map._symbolIconOffsetMap = { 'symbol-stale-1x': [0, 4] }
|
|
316
|
+
|
|
317
|
+
await refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry, pixelRatioOverride: 2 })
|
|
318
|
+
|
|
319
|
+
const freshId = symbolRegistry.getSymbolImageId({ symbol: 'pin' }, mapStyle, 'normal', 2)
|
|
320
|
+
expect(Object.keys(map._symbolIconOffsetMap)).toEqual([freshId])
|
|
321
|
+
|
|
322
|
+
// a second refresh at the same ratio has nothing new to register or prune
|
|
323
|
+
const calls = map.setLayoutProperty.mock.calls.length
|
|
324
|
+
await refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry, pixelRatioOverride: 2 })
|
|
325
|
+
expect(map.setLayoutProperty.mock.calls.length).toBe(calls)
|
|
326
|
+
expect(map.setLayoutProperty).toHaveBeenLastCalledWith('point-symbol.cold', 'icon-offset', [
|
|
327
|
+
'match', ['get', 'user_symbolImageId'], freshId, ['literal', [0, 8.75]], ['literal', [0, 0]]
|
|
328
|
+
])
|
|
329
|
+
})
|
|
330
|
+
|
|
262
331
|
// A style change re-resolves every point concurrently; each one's addSymbolsToMap()
|
|
263
332
|
// settles on its own schedule. A single combined draw.add() (rather than one call per
|
|
264
333
|
// point) is what keeps mapbox-gl-draw's debounced render from ever painting one point's
|
|
@@ -272,14 +341,14 @@ describe('refreshAllPointSymbols', () => {
|
|
|
272
341
|
// Stagger completion — p2 resolves after p1 to simulate genuinely concurrent, unevenly
|
|
273
342
|
// timed rasterisation.
|
|
274
343
|
let resolveP1, resolveP2
|
|
275
|
-
const mapProvider = {
|
|
344
|
+
const mapProvider = createMapProvider({
|
|
276
345
|
addSymbolsToMap: jest.fn((configs) => new Promise((resolve) => {
|
|
277
346
|
const target = configs[0].symbol === 'pin' ? (v) => { resolveP1 = v } : (v) => { resolveP2 = v }
|
|
278
347
|
target(resolve)
|
|
279
348
|
}))
|
|
280
|
-
}
|
|
349
|
+
})
|
|
281
350
|
|
|
282
|
-
const pending = refreshAllPointSymbols({ draw, mapProvider, map })
|
|
351
|
+
const pending = refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry })
|
|
283
352
|
resolveP2()
|
|
284
353
|
await Promise.resolve()
|
|
285
354
|
resolveP1()
|
|
@@ -296,19 +365,19 @@ describe('refreshAllPointSymbols', () => {
|
|
|
296
365
|
const p1 = point('p1', { symbol: 'pin' })
|
|
297
366
|
const p2 = point('p2', { symbol: 'not-a-real-symbol' })
|
|
298
367
|
const draw = createDraw([p1, p2])
|
|
299
|
-
const mapProvider = {
|
|
368
|
+
const mapProvider = createMapProvider({
|
|
300
369
|
addSymbolsToMap: jest.fn((configs) =>
|
|
301
370
|
configs[0].symbol === 'not-a-real-symbol' ? Promise.reject(new Error('rasterise failed')) : Promise.resolve()
|
|
302
371
|
)
|
|
303
|
-
}
|
|
304
|
-
const
|
|
372
|
+
})
|
|
373
|
+
const loggerError = jest.spyOn(logger, 'error').mockImplementation(() => {})
|
|
305
374
|
|
|
306
|
-
await refreshAllPointSymbols({ draw, mapProvider, map })
|
|
375
|
+
await refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry })
|
|
307
376
|
|
|
308
|
-
expect(
|
|
377
|
+
expect(loggerError).toHaveBeenCalledWith('[draw] failed to resolve point symbol', expect.any(Error))
|
|
309
378
|
expect(draw.add).toHaveBeenCalledTimes(1)
|
|
310
379
|
const [{ features }] = draw.add.mock.calls[0]
|
|
311
380
|
expect(features.map((f) => f.id)).toEqual(['p1'])
|
|
312
|
-
|
|
381
|
+
loggerError.mockRestore()
|
|
313
382
|
})
|
|
314
383
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createOLDraw } from './olDraw.js'
|
|
2
|
-
import {
|
|
2
|
+
import { hasSymbol } from '../../../../../src/utils/symbolUtils.js'
|
|
3
3
|
|
|
4
4
|
// split.js passes this literal — MapLibre's own always-present "already-drawn
|
|
5
5
|
// shapes" style layer id — as a snapLayers entry so the split line snaps to the
|
|
@@ -39,6 +39,7 @@ export class OLDrawAdapter {
|
|
|
39
39
|
constructor (mapProvider, options) {
|
|
40
40
|
const { manager, remove } = createOLDraw({
|
|
41
41
|
mapProvider,
|
|
42
|
+
symbolRegistry: options.symbolRegistry,
|
|
42
43
|
events: options.events,
|
|
43
44
|
eventBus: options.eventBus,
|
|
44
45
|
// The full pluginConfig, not just snapLayers — OLDrawManager also reads
|
|
@@ -101,8 +102,8 @@ export class OLDrawAdapter {
|
|
|
101
102
|
// drawend handler, so it must be resolved here instead — mirrors MaplibreDrawAdapter.js.
|
|
102
103
|
add (feature) {
|
|
103
104
|
const olFeature = this._manager.add(feature)
|
|
104
|
-
if (feature.geometry?.type === 'Point' &&
|
|
105
|
-
|
|
105
|
+
if (feature.geometry?.type === 'Point' && hasSymbol(feature.properties)) {
|
|
106
|
+
this._manager.updatePointSymbol(olFeature)
|
|
106
107
|
}
|
|
107
108
|
return olFeature
|
|
108
109
|
}
|
|
@@ -116,8 +117,8 @@ export class OLDrawAdapter {
|
|
|
116
117
|
return
|
|
117
118
|
}
|
|
118
119
|
olFeature.setProperties(properties)
|
|
119
|
-
if (olFeature.getGeometry()?.getType() === 'Point' &&
|
|
120
|
-
|
|
120
|
+
if (olFeature.getGeometry()?.getType() === 'Point' && hasSymbol(olFeature.getProperties())) {
|
|
121
|
+
this._manager.updatePointSymbol(olFeature)
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
@@ -130,7 +131,7 @@ export class OLDrawAdapter {
|
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
setSnapLayers (layers) {
|
|
133
|
-
const translated = layers?.map((
|
|
134
|
+
const translated = layers?.map((layer) => (layer === DRAW_OUTLINE_STYLE_LAYER ? this._manager._layer : layer))
|
|
134
135
|
this._manager.snap?.setSnapLayers(translated)
|
|
135
136
|
}
|
|
136
137
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { OLDrawAdapter } from './OLDrawAdapter.js'
|
|
2
2
|
import { createOLDraw } from './olDraw.js'
|
|
3
|
-
import { resolvePointSymbol, hasSymbolStyle } from './point/pointSymbolImages.js'
|
|
4
3
|
|
|
5
4
|
// The literal split.js passes — see OLDrawAdapter.js's DRAW_OUTLINE_STYLE_LAYER comment.
|
|
6
5
|
const DRAW_OUTLINE_STYLE_LAYER = 'stroke-inactive.cold'
|
|
@@ -24,6 +23,7 @@ const fakeManager = () => ({
|
|
|
24
23
|
setDrawingPreviewProperty: jest.fn(),
|
|
25
24
|
get: jest.fn(() => 'feature'),
|
|
26
25
|
add: jest.fn(),
|
|
26
|
+
updatePointSymbol: jest.fn(),
|
|
27
27
|
store: { getOL: jest.fn() },
|
|
28
28
|
delete: jest.fn(),
|
|
29
29
|
deleteAll: jest.fn(),
|
|
@@ -36,19 +36,15 @@ const fakeManager = () => ({
|
|
|
36
36
|
jest.mock('./olDraw.js', () => ({
|
|
37
37
|
createOLDraw: jest.fn(({ mapProvider }) => ({ manager: mapProvider._testManager, remove: jest.fn() }))
|
|
38
38
|
}))
|
|
39
|
-
|
|
40
|
-
resolvePointSymbol: jest.fn(),
|
|
41
|
-
hasSymbolStyle: jest.fn()
|
|
42
|
-
}))
|
|
43
|
-
|
|
44
|
-
const setup = () => {
|
|
39
|
+
const setup = (extraOptions = {}) => {
|
|
45
40
|
const manager = fakeManager()
|
|
46
41
|
const mapProvider = { _testManager: manager }
|
|
47
42
|
const adapter = new OLDrawAdapter(mapProvider, {
|
|
48
43
|
events: { MAP_SET_STYLE: 's' },
|
|
49
44
|
eventBus: {},
|
|
50
45
|
snapLayers: ['boundaries'],
|
|
51
|
-
mapStyle: { id: 'default' }
|
|
46
|
+
mapStyle: { id: 'default' },
|
|
47
|
+
...extraOptions
|
|
52
48
|
})
|
|
53
49
|
return { manager, mapProvider, adapter }
|
|
54
50
|
}
|
|
@@ -65,6 +61,12 @@ test('wires olDraw with the plugin options and uses the returned manager', () =>
|
|
|
65
61
|
expect(manager.getMode).toHaveBeenCalled()
|
|
66
62
|
})
|
|
67
63
|
|
|
64
|
+
test('passes the app\'s symbol registry through to olDraw', () => {
|
|
65
|
+
const symbolRegistry = { id: 'app-symbol-registry' }
|
|
66
|
+
setup({ symbolRegistry })
|
|
67
|
+
expect(createOLDraw).toHaveBeenCalledWith(expect.objectContaining({ symbolRegistry }))
|
|
68
|
+
})
|
|
69
|
+
|
|
68
70
|
test('forwards the full pluginConfig (colour/size overrides too), not just snapLayers', () => {
|
|
69
71
|
const manager = fakeManager()
|
|
70
72
|
const mapProvider = { _testManager: manager }
|
|
@@ -150,49 +152,45 @@ test('remaining calls delegate straight through; setFeatureProperty is a deliber
|
|
|
150
152
|
// A directly-added Point skips draw_point's own icon-resolving drawend handler.
|
|
151
153
|
describe('add() and point symbol resolution', () => {
|
|
152
154
|
test('resolves the symbol for a Point feature with symbol properties', () => {
|
|
153
|
-
const { manager,
|
|
155
|
+
const { manager, adapter } = setup()
|
|
154
156
|
const olFeature = {}
|
|
155
157
|
manager.add.mockReturnValue(olFeature)
|
|
156
|
-
hasSymbolStyle.mockReturnValue(true)
|
|
157
158
|
const feature = { geometry: { type: 'Point', coordinates: [0, 0] }, properties: { symbol: 'pin' } }
|
|
158
159
|
|
|
159
160
|
const result = adapter.add(feature)
|
|
160
161
|
|
|
161
162
|
expect(manager.add).toHaveBeenCalledWith(feature)
|
|
162
|
-
expect(
|
|
163
|
-
expect(resolvePointSymbol).toHaveBeenCalledWith({ manager, mapProvider, olFeature })
|
|
163
|
+
expect(manager.updatePointSymbol).toHaveBeenCalledWith(olFeature)
|
|
164
164
|
expect(result).toBe(olFeature)
|
|
165
165
|
})
|
|
166
166
|
|
|
167
167
|
test('does not attempt resolution for a Point with no symbol properties', () => {
|
|
168
168
|
const { manager, adapter } = setup()
|
|
169
169
|
manager.add.mockReturnValue({})
|
|
170
|
-
hasSymbolStyle.mockReturnValue(false)
|
|
171
170
|
adapter.add({ geometry: { type: 'Point', coordinates: [0, 0] }, properties: {} })
|
|
172
|
-
expect(
|
|
171
|
+
expect(manager.updatePointSymbol).not.toHaveBeenCalled()
|
|
173
172
|
})
|
|
174
173
|
|
|
175
174
|
test('does not attempt resolution for a non-Point geometry', () => {
|
|
176
175
|
const { manager, adapter } = setup()
|
|
177
176
|
manager.add.mockReturnValue({})
|
|
178
177
|
adapter.add({ geometry: { type: 'Polygon', coordinates: [[]] }, properties: { symbol: 'pin' } })
|
|
179
|
-
expect(
|
|
180
|
-
expect(resolvePointSymbol).not.toHaveBeenCalled()
|
|
178
|
+
expect(manager.updatePointSymbol).not.toHaveBeenCalled()
|
|
181
179
|
})
|
|
182
180
|
|
|
183
181
|
test('does not attempt resolution for a feature with no geometry', () => {
|
|
184
182
|
const { manager, adapter } = setup()
|
|
185
183
|
manager.add.mockReturnValue({})
|
|
186
184
|
adapter.add({ id: 'b' })
|
|
187
|
-
expect(
|
|
185
|
+
expect(manager.updatePointSymbol).not.toHaveBeenCalled()
|
|
188
186
|
})
|
|
189
187
|
})
|
|
190
188
|
|
|
191
189
|
describe('setStyle()', () => {
|
|
192
|
-
const fakeOLFeature = (geometryType) => ({
|
|
190
|
+
const fakeOLFeature = (geometryType, properties = {}) => ({
|
|
193
191
|
setProperties: jest.fn(),
|
|
194
192
|
getGeometry: jest.fn(() => ({ getType: () => geometryType })),
|
|
195
|
-
getProperties: jest.fn(() =>
|
|
193
|
+
getProperties: jest.fn(() => properties)
|
|
196
194
|
})
|
|
197
195
|
|
|
198
196
|
test('patches the feature\'s properties (not silently, so VectorSource still redraws)', () => {
|
|
@@ -208,14 +206,13 @@ describe('setStyle()', () => {
|
|
|
208
206
|
|
|
209
207
|
// setStyle re-resolves a Point's icon the same way add() does for a directly-added one.
|
|
210
208
|
test('re-resolves the icon for a Point patched with symbol properties', () => {
|
|
211
|
-
const { manager,
|
|
212
|
-
const olFeature = fakeOLFeature('Point')
|
|
209
|
+
const { manager, adapter } = setup()
|
|
210
|
+
const olFeature = fakeOLFeature('Point', { symbol: 'pin' })
|
|
213
211
|
manager.store.getOL.mockReturnValue(olFeature)
|
|
214
|
-
hasSymbolStyle.mockReturnValue(true)
|
|
215
212
|
|
|
216
213
|
adapter.setStyle('p1', { symbolBackgroundColor: '#ca3535' })
|
|
217
214
|
|
|
218
|
-
expect(
|
|
215
|
+
expect(manager.updatePointSymbol).toHaveBeenCalledWith(olFeature)
|
|
219
216
|
})
|
|
220
217
|
|
|
221
218
|
test('does not attempt resolution for a non-Point geometry', () => {
|
|
@@ -223,14 +220,14 @@ describe('setStyle()', () => {
|
|
|
223
220
|
const olFeature = fakeOLFeature('Polygon')
|
|
224
221
|
manager.store.getOL.mockReturnValue(olFeature)
|
|
225
222
|
adapter.setStyle('a', { stroke: 'blue' })
|
|
226
|
-
expect(
|
|
223
|
+
expect(manager.updatePointSymbol).not.toHaveBeenCalled()
|
|
227
224
|
})
|
|
228
225
|
|
|
229
226
|
test('does nothing for an id with no existing feature', () => {
|
|
230
227
|
const { manager, adapter } = setup()
|
|
231
228
|
manager.store.getOL.mockReturnValue(null)
|
|
232
229
|
expect(() => adapter.setStyle('missing', { stroke: 'blue' })).not.toThrow()
|
|
233
|
-
expect(
|
|
230
|
+
expect(manager.updatePointSymbol).not.toHaveBeenCalled()
|
|
234
231
|
})
|
|
235
232
|
})
|
|
236
233
|
|