@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
|
@@ -12,6 +12,7 @@ import { resolvePointSymbol } from '../point/pointSymbolImages.js'
|
|
|
12
12
|
import { TOLERANCES } from '../defaults.js'
|
|
13
13
|
import { ADAPTER_EVENTS } from '../../../adapterEvents.js'
|
|
14
14
|
import { STYLES_CHANGED_EVENT } from './internalEvents.js'
|
|
15
|
+
import { logger } from '../../../../../../src/services/logger.js'
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Mode machine for the OL draw plugin.
|
|
@@ -24,9 +25,19 @@ import { STYLES_CHANGED_EVENT } from './internalEvents.js'
|
|
|
24
25
|
* listening to the manager's internal events.
|
|
25
26
|
*/
|
|
26
27
|
export class OLDrawManager {
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @param {Object} map - OL map
|
|
30
|
+
* @param {Object} [pluginConfig]
|
|
31
|
+
* @param {Object} [symbols]
|
|
32
|
+
* @param {Object} [symbols.mapProvider] - registers and holds symbol images (OpenLayersProvider)
|
|
33
|
+
* @param {Object} [symbols.symbolRegistry] - the app's symbol registry (services.symbolRegistry)
|
|
34
|
+
*/
|
|
35
|
+
constructor (map, pluginConfig = {}, { mapProvider, symbolRegistry } = {}) {
|
|
28
36
|
this._map = map
|
|
29
37
|
this._pluginConfig = pluginConfig
|
|
38
|
+
this.mapProvider = mapProvider
|
|
39
|
+
this.symbolRegistry = symbolRegistry
|
|
40
|
+
this._getSymbolImage = (imageId) => this.mapProvider?.getSymbolImage(imageId)
|
|
30
41
|
this._mode = 'disabled'
|
|
31
42
|
this._modeInstance = null
|
|
32
43
|
this._listeners = new Map()
|
|
@@ -34,13 +45,13 @@ export class OLDrawManager {
|
|
|
34
45
|
this.store = createFeatureStore()
|
|
35
46
|
this.undoStack = createUndoStack((length) => this.emit(ADAPTER_EVENTS.UNDO_CHANGE, length))
|
|
36
47
|
|
|
37
|
-
// Tracked (not just derived into colors/styles) so point/pointSymbolImages.js has
|
|
38
|
-
//
|
|
39
|
-
//
|
|
48
|
+
// Tracked (not just derived into colors/styles) so point/pointSymbolImages.js has a map
|
|
49
|
+
// style to register a point's icon against on demand, independent of whatever triggered
|
|
50
|
+
// the resolve.
|
|
40
51
|
this.mapStyle = null
|
|
41
52
|
|
|
42
53
|
this.colors = resolveColors(null, pluginConfig)
|
|
43
|
-
this.styles = createStyles(this.colors)
|
|
54
|
+
this.styles = createStyles(this.colors, this._getSymbolImage)
|
|
44
55
|
this.snap = createSnapManager(map, pluginConfig.snapLayers ?? null, this.colors, pluginConfig.snapRadius ?? TOLERANCES.snapRadius)
|
|
45
56
|
|
|
46
57
|
this._layer = new VectorLayer({
|
|
@@ -62,7 +73,7 @@ export class OLDrawManager {
|
|
|
62
73
|
setMapStyle (mapStyle) {
|
|
63
74
|
this.mapStyle = mapStyle
|
|
64
75
|
this.colors = resolveColors(mapStyle, this._pluginConfig)
|
|
65
|
-
this.styles = createStyles(this.colors)
|
|
76
|
+
this.styles = createStyles(this.colors, this._getSymbolImage)
|
|
66
77
|
this._layer.setStyle(this.styles.createFeatureStyle())
|
|
67
78
|
this.store.source.changed()
|
|
68
79
|
this.snap?.updateColors(this.colors)
|
|
@@ -93,7 +104,7 @@ export class OLDrawManager {
|
|
|
93
104
|
|
|
94
105
|
// --- Mode machine ---
|
|
95
106
|
|
|
96
|
-
|
|
107
|
+
changeMode (modeName, options = {}) {
|
|
97
108
|
this._modeInstance?.destroy()
|
|
98
109
|
this._modeInstance = null
|
|
99
110
|
this._mode = modeName
|
|
@@ -110,7 +121,7 @@ export class OLDrawManager {
|
|
|
110
121
|
// ever calls options.resolvePointSymbol(...) and stays free of a direct dependency on
|
|
111
122
|
// symbolRegistry/mapProvider — mirrors the ML adapter's own state.resolvePointSymbol
|
|
112
123
|
// convention (see MaplibreDrawAdapter.js's changeMode).
|
|
113
|
-
const pointOptions = { ...modeOptions, resolvePointSymbol: (olFeature) =>
|
|
124
|
+
const pointOptions = { ...modeOptions, resolvePointSymbol: (olFeature) => this.updatePointSymbol(olFeature) }
|
|
114
125
|
this._modeInstance = createDrawPointMode({ map: this._map, manager: this, options: pointOptions })
|
|
115
126
|
} else if (modeName === 'edit_vertex') {
|
|
116
127
|
this._modeInstance = createEditMode({ map: this._map, manager: this, options: modeOptions })
|
|
@@ -182,6 +193,13 @@ export class OLDrawManager {
|
|
|
182
193
|
this.emit(ADAPTER_EVENTS.INTERFACE_TYPE_CHANGE, { interfaceType: type })
|
|
183
194
|
}
|
|
184
195
|
|
|
196
|
+
// Resolves a point's symbol icon in the background; a failure leaves the point without its
|
|
197
|
+
// icon, so it's logged rather than lost.
|
|
198
|
+
updatePointSymbol (olFeature) {
|
|
199
|
+
resolvePointSymbol({ manager: this, mapProvider: this.mapProvider, olFeature })
|
|
200
|
+
.catch((error) => logger.error('[draw] failed to resolve point symbol', olFeature.getId(), error))
|
|
201
|
+
}
|
|
202
|
+
|
|
185
203
|
// --- Feature store delegation ---
|
|
186
204
|
|
|
187
205
|
get (id) {
|
|
@@ -8,7 +8,11 @@ import { resolvePointSymbol } from '../point/pointSymbolImages.js'
|
|
|
8
8
|
import { createSnapManager } from '../snap/snapManager.js'
|
|
9
9
|
import { ADAPTER_EVENTS } from '../../../adapterEvents.js'
|
|
10
10
|
import { createFakeMap } from '../__helpers__/harness.js'
|
|
11
|
+
import { logger } from '../../../../../../src/services/logger.js'
|
|
11
12
|
import { TOLERANCES } from '../defaults.js'
|
|
13
|
+
import OlFeature from 'ol/Feature.js'
|
|
14
|
+
import Point from 'ol/geom/Point.js'
|
|
15
|
+
import Icon from 'ol/style/Icon.js'
|
|
12
16
|
|
|
13
17
|
jest.mock('../draw/DrawMode.js', () => ({
|
|
14
18
|
createDrawMode: jest.fn(() => ({ destroy: jest.fn(), done: jest.fn(), cancel: jest.fn(), undo: jest.fn(), deleteVertex: jest.fn(), nudgeSelectedVertex: jest.fn(), setInterfaceType: jest.fn(), setInvalid: jest.fn(), setDrawingPreviewProperty: jest.fn() }))
|
|
@@ -35,8 +39,9 @@ jest.mock('../point/drawPointMode.js', () => ({
|
|
|
35
39
|
createDrawPointMode: jest.fn(() => ({ destroy: jest.fn(), done: jest.fn(), cancel: jest.fn(), undo: jest.fn(), setInterfaceType: jest.fn() }))
|
|
36
40
|
}))
|
|
37
41
|
jest.mock('../point/pointSymbolImages.js', () => ({
|
|
38
|
-
resolvePointSymbol: jest.fn()
|
|
42
|
+
resolvePointSymbol: jest.fn(() => Promise.resolve())
|
|
39
43
|
}))
|
|
44
|
+
jest.mock('../../../../../../src/services/logger.js', () => ({ logger: { error: jest.fn() } }))
|
|
40
45
|
jest.mock('../snap/snapManager.js', () => ({
|
|
41
46
|
createSnapManager: jest.fn(() => ({ setIndicatorActive: jest.fn(), reattach: jest.fn(), updateColors: jest.fn(), destroy: jest.fn() }))
|
|
42
47
|
}))
|
|
@@ -60,6 +65,23 @@ test('sets up the draw layer and the snap manager from the plugin config', () =>
|
|
|
60
65
|
expect(createSnapManager).toHaveBeenLastCalledWith(expect.anything(), null, expect.any(Object), TOLERANCES.snapRadius)
|
|
61
66
|
})
|
|
62
67
|
|
|
68
|
+
test('draws point symbols with images from the map provider, before and after a map style change', () => {
|
|
69
|
+
const canvas = document.createElement('canvas')
|
|
70
|
+
const mapProvider = { getSymbolImage: jest.fn((imageId) => imageId === 'symbol-pin' ? canvas : undefined) }
|
|
71
|
+
const symbolRegistry = { id: 'app-symbol-registry' }
|
|
72
|
+
const manager = new OLDrawManager(createFakeMap(), {}, { mapProvider, symbolRegistry })
|
|
73
|
+
expect(manager.symbolRegistry).toBe(symbolRegistry)
|
|
74
|
+
|
|
75
|
+
const point = new OlFeature({ geometry: new Point([5, 5]), symbol: 'pin', symbolImageId: 'symbol-pin', symbolImageAnchor: [0.5, 1] })
|
|
76
|
+
const iconOf = () => manager.styles.createFeatureStyle()(point)[0].getImage()
|
|
77
|
+
expect(iconOf()).toBeInstanceOf(Icon)
|
|
78
|
+
expect(iconOf().getImage(1)).toBe(canvas)
|
|
79
|
+
|
|
80
|
+
manager.setMapStyle({ id: 'dark', mapColorScheme: 'dark' })
|
|
81
|
+
expect(iconOf().getImage(1)).toBe(canvas)
|
|
82
|
+
expect(mapProvider.getSymbolImage).toHaveBeenCalledWith('symbol-pin')
|
|
83
|
+
})
|
|
84
|
+
|
|
63
85
|
test('map style changes rebuild the styles and notify modes and snap', () => {
|
|
64
86
|
const { map, manager } = setup()
|
|
65
87
|
const onStyles = jest.fn()
|
|
@@ -80,7 +102,7 @@ describe('mode machine', () => {
|
|
|
80
102
|
['edit_point', createEditPointMode]
|
|
81
103
|
])('%s creates its mode with snap injected, activates the indicator and reattaches snap last', async (name, factory) => {
|
|
82
104
|
const { map, manager } = setup()
|
|
83
|
-
|
|
105
|
+
manager.changeMode(name, { featureId: 'f1' })
|
|
84
106
|
expect(manager.getMode()).toBe(name)
|
|
85
107
|
expect(factory).toHaveBeenCalledWith({ map, manager, options: { featureId: 'f1', snap: manager.snap } })
|
|
86
108
|
expect(manager.snap.setIndicatorActive).toHaveBeenCalledWith(true)
|
|
@@ -90,41 +112,41 @@ describe('mode machine', () => {
|
|
|
90
112
|
// draw_point gets an extra options key (resolvePointSymbol) the other modes don't — see
|
|
91
113
|
// OLDrawManager.js's changeMode comment — so it's asserted separately rather than folded
|
|
92
114
|
// into the table above.
|
|
93
|
-
test('draw_point creates its mode with snap and resolvePointSymbol injected, activates the indicator and reattaches snap last',
|
|
115
|
+
test('draw_point creates its mode with snap and resolvePointSymbol injected, activates the indicator and reattaches snap last', () => {
|
|
94
116
|
const { map, manager } = setup()
|
|
95
117
|
const mapProvider = { drawScale: 2 }
|
|
96
|
-
|
|
118
|
+
manager.changeMode('draw_point', { featureId: 'f1', mapProvider })
|
|
97
119
|
expect(manager.getMode()).toBe('draw_point')
|
|
98
120
|
expect(createDrawPointMode).toHaveBeenCalledWith({ map, manager, options: { featureId: 'f1', mapProvider, snap: manager.snap, resolvePointSymbol: expect.any(Function) } })
|
|
99
121
|
expect(manager.snap.setIndicatorActive).toHaveBeenCalledWith(true)
|
|
100
122
|
expect(manager.snap.reattach).toHaveBeenCalled()
|
|
101
123
|
|
|
102
|
-
// The injected hook
|
|
103
|
-
|
|
124
|
+
// The injected hook resolves the point's symbol through the manager
|
|
125
|
+
const updatePointSymbol = jest.spyOn(manager, 'updatePointSymbol').mockImplementation(() => {})
|
|
104
126
|
const injected = createDrawPointMode.mock.calls.at(-1)[0].options.resolvePointSymbol
|
|
105
127
|
const olFeature = { id: 'point-1' }
|
|
106
128
|
injected(olFeature)
|
|
107
|
-
expect(
|
|
129
|
+
expect(updatePointSymbol).toHaveBeenCalledWith(olFeature)
|
|
108
130
|
})
|
|
109
131
|
|
|
110
|
-
test('disabled destroys the previous mode and deactivates the indicator',
|
|
132
|
+
test('disabled destroys the previous mode and deactivates the indicator', () => {
|
|
111
133
|
const { manager } = setup()
|
|
112
|
-
|
|
134
|
+
manager.changeMode('draw_polygon')
|
|
113
135
|
const instance = createDrawMode.mock.results[0].value
|
|
114
|
-
|
|
136
|
+
manager.changeMode('disabled')
|
|
115
137
|
expect(instance.destroy).toHaveBeenCalled()
|
|
116
138
|
expect(manager.getMode()).toBe('disabled')
|
|
117
139
|
expect(manager.snap.setIndicatorActive).toHaveBeenLastCalledWith(false)
|
|
118
140
|
})
|
|
119
141
|
|
|
120
|
-
test('operations delegate to the current mode instance and are safe without one',
|
|
142
|
+
test('operations delegate to the current mode instance and are safe without one', () => {
|
|
121
143
|
const { manager } = setup()
|
|
122
144
|
manager.done(); manager.undo(); manager.deleteVertex(); manager.nudgeSelectedVertex(1, 0, true); manager.setInterfaceType('touch'); manager.setInvalid(true) // no mode — no throw
|
|
123
145
|
manager.setDrawingPreviewProperty('splitter', 'valid') // no mode — no throw
|
|
124
146
|
expect(manager.getVertexItems()).toEqual({ vertices: [], midpoints: [] }) // no mode — safe default
|
|
125
147
|
manager.selectVertex(1); manager.insertVertexAtMidpoint(1) // no mode — no throw
|
|
126
148
|
|
|
127
|
-
|
|
149
|
+
manager.changeMode('draw_polygon')
|
|
128
150
|
const instance = createDrawMode.mock.results[0].value
|
|
129
151
|
manager.done()
|
|
130
152
|
manager.undo()
|
|
@@ -150,9 +172,9 @@ describe('mode machine', () => {
|
|
|
150
172
|
expect(manager.getMode()).toBe('disabled')
|
|
151
173
|
})
|
|
152
174
|
|
|
153
|
-
test('getVertexItems/selectVertex/insertVertexAtMidpoint delegate to the edit_vertex mode instance',
|
|
175
|
+
test('getVertexItems/selectVertex/insertVertexAtMidpoint delegate to the edit_vertex mode instance', () => {
|
|
154
176
|
const { manager } = setup()
|
|
155
|
-
|
|
177
|
+
manager.changeMode('edit_vertex', { featureId: 'f1' })
|
|
156
178
|
const instance = createEditMode.mock.results[0].value
|
|
157
179
|
|
|
158
180
|
expect(manager.getVertexItems()).toEqual({ vertices: [[0, 0]], midpoints: [] })
|
|
@@ -196,9 +218,9 @@ test('feature store delegation works with GeoJSON in and out', () => {
|
|
|
196
218
|
expect(manager.get('f1')).toBeNull()
|
|
197
219
|
})
|
|
198
220
|
|
|
199
|
-
test('remove tears everything down and silences the bus',
|
|
221
|
+
test('remove tears everything down and silences the bus', () => {
|
|
200
222
|
const { map, manager } = setup()
|
|
201
|
-
|
|
223
|
+
manager.changeMode('draw_polygon')
|
|
202
224
|
const instance = createDrawMode.mock.results[0].value
|
|
203
225
|
const snap = manager.snap
|
|
204
226
|
const listener = jest.fn()
|
|
@@ -210,3 +232,23 @@ test('remove tears everything down and silences the bus', async () => {
|
|
|
210
232
|
manager.emit(STYLES_CHANGED_EVENT, {})
|
|
211
233
|
expect(listener).not.toHaveBeenCalled()
|
|
212
234
|
})
|
|
235
|
+
|
|
236
|
+
describe('updatePointSymbol', () => {
|
|
237
|
+
test('resolves the point\'s symbol with this manager and its map provider', () => {
|
|
238
|
+
const mapProvider = { map: {} }
|
|
239
|
+
const manager = new OLDrawManager(createFakeMap(), {}, { mapProvider })
|
|
240
|
+
const olFeature = { getId: () => 'p1' }
|
|
241
|
+
manager.updatePointSymbol(olFeature)
|
|
242
|
+
expect(resolvePointSymbol).toHaveBeenCalledWith({ manager, mapProvider, olFeature })
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
test('logs a failure rather than leaving the rejection unhandled', async () => {
|
|
246
|
+
const error = new Error('rasterise failed')
|
|
247
|
+
resolvePointSymbol.mockRejectedValueOnce(error)
|
|
248
|
+
const manager = new OLDrawManager(createFakeMap(), {}, { mapProvider: { map: {} } })
|
|
249
|
+
manager.updatePointSymbol({ getId: () => 'p1' })
|
|
250
|
+
await Promise.resolve()
|
|
251
|
+
await Promise.resolve()
|
|
252
|
+
expect(logger.error).toHaveBeenCalledWith('[draw] failed to resolve point symbol', 'p1', error)
|
|
253
|
+
})
|
|
254
|
+
})
|
|
@@ -6,18 +6,21 @@ import Icon from 'ol/style/Icon.js'
|
|
|
6
6
|
import MultiPoint from 'ol/geom/MultiPoint.js'
|
|
7
7
|
import { SIZES } from '../defaults.js'
|
|
8
8
|
import { getPlacedSketchCoords } from '../utils/sketchHelpers.js'
|
|
9
|
-
import { getCachedSymbolImage } from '../../../../../../providers/beta/openlayers/src/utils/symbolImages.js'
|
|
10
|
-
import { symbolRegistry } from '../../../../../../src/services/symbolRegistry.js'
|
|
11
|
-
import { getSymbolAnchor } from '../../../../../../src/utils/symbolUtils.js'
|
|
12
9
|
|
|
13
10
|
const HALO_RADIUS_OFFSET = 3
|
|
14
11
|
|
|
15
12
|
const selectedVertexRadii = { outer: SIZES.vertexHaloRadius + HALO_RADIUS_OFFSET, mid: SIZES.vertexHaloRadius, inner: SIZES.vertexRadius }
|
|
16
13
|
const selectedMidpointRadii = { outer: SIZES.midpointHaloRadius + HALO_RADIUS_OFFSET, mid: SIZES.midpointHaloRadius, inner: SIZES.midpointRadius }
|
|
17
14
|
|
|
15
|
+
const FULL_CIRCLE = Math.PI + Math.PI // radians
|
|
16
|
+
// Dashed outline for an invalid shape: dash and gap lengths
|
|
17
|
+
const INVALID_DASH = 2
|
|
18
|
+
const INVALID_GAP = 4
|
|
19
|
+
const INVALID_LINE_DASH = [INVALID_DASH, INVALID_GAP]
|
|
20
|
+
|
|
18
21
|
const fillArc = (ctx, cx, cy, radius, fillStyle) => {
|
|
19
22
|
ctx.beginPath()
|
|
20
|
-
ctx.arc(cx, cy, radius, 0,
|
|
23
|
+
ctx.arc(cx, cy, radius, 0, FULL_CIRCLE)
|
|
21
24
|
ctx.fillStyle = fillStyle
|
|
22
25
|
ctx.fill()
|
|
23
26
|
}
|
|
@@ -68,13 +71,13 @@ const createSketchLineStyles = (colors) => ({
|
|
|
68
71
|
fill: new Fill({ color: colors.editFill })
|
|
69
72
|
}),
|
|
70
73
|
invalid: new Style({
|
|
71
|
-
stroke: new Stroke({ color: colors.invalidStroke, width: 2, lineDash:
|
|
74
|
+
stroke: new Stroke({ color: colors.invalidStroke, width: 2, lineDash: INVALID_LINE_DASH })
|
|
72
75
|
}),
|
|
73
76
|
splitValid: new Style({
|
|
74
77
|
stroke: new Stroke({ color: colors.splitValid, width: 2 })
|
|
75
78
|
}),
|
|
76
79
|
splitInvalid: new Style({
|
|
77
|
-
stroke: new Stroke({ color: colors.splitInvalid, width: 2, lineDash:
|
|
80
|
+
stroke: new Stroke({ color: colors.splitInvalid, width: 2, lineDash: INVALID_LINE_DASH })
|
|
78
81
|
})
|
|
79
82
|
})
|
|
80
83
|
|
|
@@ -96,11 +99,12 @@ const createPointPlaceholderStyle = (colors) => new Style({
|
|
|
96
99
|
// already match symbolAnchor's own [x,y]-fraction-from-top-left convention, so unlike the
|
|
97
100
|
// MapLibre adapter (whose icon-anchor only has 9 discrete positions) no offset compensation
|
|
98
101
|
// is needed here — the raw anchor is usable as-is. Icon style instances are cached per
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
+
// image+anchor+pixelRatio so a style function running every render frame doesn't rebuild one
|
|
103
|
+
// each time. Keyed weakly by the image's canvas, so a cached style goes once the OL provider
|
|
104
|
+
// drops that image.
|
|
105
|
+
const createPointStyles = (colors, getSymbolImage) => {
|
|
102
106
|
const pointStyle = createPointPlaceholderStyle(colors)
|
|
103
|
-
const iconStyleCache = new
|
|
107
|
+
const iconStyleCache = new WeakMap() // canvas → Map of anchor|pixelRatio → Style
|
|
104
108
|
|
|
105
109
|
// imageIdProp lets edit_point's own per-feature style override (point/editPointMode.js)
|
|
106
110
|
// ask for the precomputed "selected" (black ring) variant instead of the normal one — the
|
|
@@ -108,23 +112,27 @@ const createPointStyles = (colors) => {
|
|
|
108
112
|
// symbolSelectedImageId point/pointSymbolImages.js resolves for every point.
|
|
109
113
|
const getPointIconStyle = (properties, imageIdProp = 'symbolImageId') => {
|
|
110
114
|
const imageId = properties[imageIdProp]
|
|
111
|
-
const canvas = imageId &&
|
|
112
|
-
if (!canvas) {
|
|
115
|
+
const canvas = imageId && getSymbolImage?.(imageId)
|
|
116
|
+
if (!canvas || !properties.symbolImageAnchor) {
|
|
113
117
|
return null
|
|
114
118
|
}
|
|
115
|
-
|
|
116
|
-
const [anchorX, anchorY] =
|
|
119
|
+
// Resolved alongside the image by point/pointSymbolImages.js
|
|
120
|
+
const [anchorX, anchorY] = properties.symbolImageAnchor
|
|
117
121
|
// The cached canvas was rasterised at viewBox × pixelRatio device pixels for crispness
|
|
118
122
|
// (point/pointSymbolImages.js) — unlike MapLibre's map.addImage(id, data, {pixelRatio}),
|
|
119
123
|
// which uses the registered pixelRatio to auto-derive the displayed CSS size, ol/style/
|
|
120
124
|
// Icon draws its source at native pixel size by default, so `scale` has to cancel that
|
|
121
125
|
// back out here or the icon renders pixelRatio× too big.
|
|
122
126
|
const pixelRatio = properties.symbolPixelRatio || 1
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
if (!iconStyleCache.has(canvas)) {
|
|
128
|
+
iconStyleCache.set(canvas, new Map())
|
|
129
|
+
}
|
|
130
|
+
const canvasStyles = iconStyleCache.get(canvas)
|
|
131
|
+
const cacheKey = `${anchorX}|${anchorY}|${pixelRatio}`
|
|
132
|
+
let iconStyle = canvasStyles.get(cacheKey)
|
|
125
133
|
if (!iconStyle) {
|
|
126
134
|
iconStyle = new Style({ image: new Icon({ img: canvas, anchor: [anchorX, anchorY], scale: 1 / pixelRatio }) })
|
|
127
|
-
|
|
135
|
+
canvasStyles.set(cacheKey, iconStyle)
|
|
128
136
|
}
|
|
129
137
|
return iconStyle
|
|
130
138
|
}
|
|
@@ -147,7 +155,12 @@ const createPointStyles = (colors) => {
|
|
|
147
155
|
* @returns {{ vertexStyle, selectedVertexStyle, midpointStyle, selectedMidpointStyle,
|
|
148
156
|
* editFeatureStyle, selectedPointStyleFor, createSketchStyle, createFeatureStyle }}
|
|
149
157
|
*/
|
|
150
|
-
|
|
158
|
+
/**
|
|
159
|
+
* @param {Object} colors - resolved draw colours
|
|
160
|
+
* @param {Function} [getSymbolImage] - imageId → canvas, for drawn points' symbol icons (the OL
|
|
161
|
+
* provider's getSymbolImage)
|
|
162
|
+
*/
|
|
163
|
+
export const createStyles = (colors, getSymbolImage) => {
|
|
151
164
|
const { vertexImage, vertexStyle, selectedVertexStyle } = createVertexStyles(colors)
|
|
152
165
|
const { midpointStyle, selectedMidpointStyle } = createMidpointStyles(colors)
|
|
153
166
|
|
|
@@ -159,7 +172,7 @@ export const createStyles = (colors) => {
|
|
|
159
172
|
// Dashed variant shown while the edited/drawn shape is invalid — no fill, so an
|
|
160
173
|
// invalid shape reads as an outline only.
|
|
161
174
|
const editFeatureStyleInvalid = new Style({
|
|
162
|
-
stroke: new Stroke({ color: colors.invalidStroke, width: 2, lineDash:
|
|
175
|
+
stroke: new Stroke({ color: colors.invalidStroke, width: 2, lineDash: INVALID_LINE_DASH })
|
|
163
176
|
})
|
|
164
177
|
|
|
165
178
|
const sketchLineStyles = createSketchLineStyles(colors)
|
|
@@ -196,7 +209,7 @@ export const createStyles = (colors) => {
|
|
|
196
209
|
return type === geometryType ? [lineStyle, sketchVertexStyle] : [lineStyle]
|
|
197
210
|
}
|
|
198
211
|
|
|
199
|
-
const { pointStyleFor, selectedPointStyleFor } = createPointStyles(colors)
|
|
212
|
+
const { pointStyleFor, selectedPointStyleFor } = createPointStyles(colors, getSymbolImage)
|
|
200
213
|
|
|
201
214
|
const createFeatureStyle = () => (feature) => {
|
|
202
215
|
if (feature.getGeometry().getType() === 'Point') {
|
|
@@ -5,7 +5,7 @@ import Icon from 'ol/style/Icon.js'
|
|
|
5
5
|
import { createStyles } from './styles.js'
|
|
6
6
|
import { SIZES } from '../defaults.js'
|
|
7
7
|
import { polygonFeature, lineFeature, pointFeature } from '../__helpers__/harness.js'
|
|
8
|
-
import {
|
|
8
|
+
import { SymbolImageCache } from '../../../../../../providers/beta/openlayers/src/utils/symbolImages.js'
|
|
9
9
|
|
|
10
10
|
const colors = {
|
|
11
11
|
editStroke: '#e5',
|
|
@@ -23,7 +23,13 @@ const colors = {
|
|
|
23
23
|
mapStyleId: 'road'
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// The OL provider's symbol images — createStyles reads drawn points' icons through this lookup
|
|
27
|
+
const symbolImages = new SymbolImageCache()
|
|
28
|
+
const addImage = (imageId, imageData) => {
|
|
29
|
+
symbolImages.addImage(imageId, imageData)
|
|
30
|
+
return symbolImages.getImage(imageId)
|
|
31
|
+
}
|
|
32
|
+
const styles = createStyles(colors, (imageId) => symbolImages.getImage(imageId))
|
|
27
33
|
|
|
28
34
|
// Records each canvas fill as { radius, fillStyle } so ring order/colours can be asserted
|
|
29
35
|
const fakeCanvas = () => {
|
|
@@ -161,11 +167,10 @@ describe('createFeatureStyle (inactive shapes)', () => {
|
|
|
161
167
|
this._ctx ??= { putImageData: jest.fn() }
|
|
162
168
|
return this._ctx
|
|
163
169
|
})
|
|
164
|
-
|
|
165
|
-
const canvas = getOrCreateSymbolImage('symbol-pin-1x', { width: 10, height: 10 })
|
|
170
|
+
const canvas = addImage('symbol-pin-1x', { width: 10, height: 10 })
|
|
166
171
|
|
|
167
172
|
const feature = pointFeature([5, 5])
|
|
168
|
-
feature.setProperties({ symbol: 'pin', symbolImageId: 'symbol-pin-1x' })
|
|
173
|
+
feature.setProperties({ symbol: 'pin', symbolImageAnchor: [0.5, 1], symbolImageId: 'symbol-pin-1x' })
|
|
169
174
|
|
|
170
175
|
const style = styles.createFeatureStyle()(feature)[0]
|
|
171
176
|
expect(style.getImage()).toBeInstanceOf(Icon)
|
|
@@ -177,11 +182,10 @@ describe('createFeatureStyle (inactive shapes)', () => {
|
|
|
177
182
|
this._ctx ??= { putImageData: jest.fn() }
|
|
178
183
|
return this._ctx
|
|
179
184
|
})
|
|
180
|
-
|
|
181
|
-
getOrCreateSymbolImage('symbol-pin-cache', { width: 10, height: 10 })
|
|
185
|
+
addImage('symbol-pin-cache', { width: 10, height: 10 })
|
|
182
186
|
|
|
183
187
|
const feature = pointFeature([5, 5])
|
|
184
|
-
feature.setProperties({ symbol: 'pin', symbolImageId: 'symbol-pin-cache' })
|
|
188
|
+
feature.setProperties({ symbol: 'pin', symbolImageAnchor: [0.5, 1], symbolImageId: 'symbol-pin-cache' })
|
|
185
189
|
|
|
186
190
|
const styleFn = styles.createFeatureStyle()
|
|
187
191
|
const first = styleFn(feature)[0]
|
|
@@ -194,11 +198,10 @@ describe('createFeatureStyle (inactive shapes)', () => {
|
|
|
194
198
|
this._ctx ??= { putImageData: jest.fn() }
|
|
195
199
|
return this._ctx
|
|
196
200
|
})
|
|
197
|
-
|
|
198
|
-
getOrCreateSymbolImage('symbol-pin-4x', { width: 176, height: 176 }) // 44 viewBox × pixelRatio 4
|
|
201
|
+
addImage('symbol-pin-4x', { width: 176, height: 176 }) // 44 viewBox × pixelRatio 4
|
|
199
202
|
|
|
200
203
|
const feature = pointFeature([5, 5])
|
|
201
|
-
feature.setProperties({ symbol: 'pin', symbolImageId: 'symbol-pin-4x', symbolPixelRatio: 4 })
|
|
204
|
+
feature.setProperties({ symbol: 'pin', symbolImageAnchor: [0.5, 1], symbolImageId: 'symbol-pin-4x', symbolPixelRatio: 4 })
|
|
202
205
|
|
|
203
206
|
const style = styles.createFeatureStyle()(feature)[0]
|
|
204
207
|
expect(style.getImage().getScale()).toBe(0.25)
|
|
@@ -209,11 +212,10 @@ describe('createFeatureStyle (inactive shapes)', () => {
|
|
|
209
212
|
this._ctx ??= { putImageData: jest.fn() }
|
|
210
213
|
return this._ctx
|
|
211
214
|
})
|
|
212
|
-
|
|
213
|
-
getOrCreateSymbolImage('symbol-pin-no-ratio', { width: 44, height: 44 })
|
|
215
|
+
addImage('symbol-pin-no-ratio', { width: 44, height: 44 })
|
|
214
216
|
|
|
215
217
|
const feature = pointFeature([5, 5])
|
|
216
|
-
feature.setProperties({ symbol: 'pin', symbolImageId: 'symbol-pin-no-ratio' })
|
|
218
|
+
feature.setProperties({ symbol: 'pin', symbolImageAnchor: [0.5, 1], symbolImageId: 'symbol-pin-no-ratio' })
|
|
217
219
|
|
|
218
220
|
const style = styles.createFeatureStyle()(feature)[0]
|
|
219
221
|
expect(style.getImage().getScale()).toBe(1)
|
|
@@ -227,19 +229,18 @@ describe('createFeatureStyle (inactive shapes)', () => {
|
|
|
227
229
|
this._ctx ??= { putImageData: jest.fn() }
|
|
228
230
|
return this._ctx
|
|
229
231
|
})
|
|
230
|
-
|
|
231
|
-
const selectedCanvas = getOrCreateSymbolImage('symbol-pin-selected', { width: 10, height: 10 })
|
|
232
|
+
const selectedCanvas = addImage('symbol-pin-selected', { width: 10, height: 10 })
|
|
232
233
|
|
|
233
234
|
const selected = pointFeature([5, 5])
|
|
234
|
-
selected.setProperties({ symbol: 'pin', symbolImageId: 'symbol-pin-normal', symbolSelectedImageId: 'symbol-pin-selected' })
|
|
235
|
+
selected.setProperties({ symbol: 'pin', symbolImageAnchor: [0.5, 1], symbolImageId: 'symbol-pin-normal', symbolSelectedImageId: 'symbol-pin-selected' })
|
|
235
236
|
const selectedStyle = styles.selectedPointStyleFor(selected)
|
|
236
237
|
expect(selectedStyle.getImage()).toBeInstanceOf(Icon)
|
|
237
238
|
expect(selectedStyle.getImage().getImage(1)).toBe(selectedCanvas)
|
|
238
239
|
|
|
239
240
|
// No selected variant resolved yet → falls back to the normal icon
|
|
240
|
-
const normalCanvas =
|
|
241
|
+
const normalCanvas = addImage('symbol-pin-normal-only', { width: 10, height: 10 })
|
|
241
242
|
const normalOnly = pointFeature([5, 5])
|
|
242
|
-
normalOnly.setProperties({ symbol: 'pin', symbolImageId: 'symbol-pin-normal-only' })
|
|
243
|
+
normalOnly.setProperties({ symbol: 'pin', symbolImageAnchor: [0.5, 1], symbolImageId: 'symbol-pin-normal-only' })
|
|
243
244
|
const fallbackStyle = styles.selectedPointStyleFor(normalOnly)
|
|
244
245
|
expect(fallbackStyle.getImage().getImage(1)).toBe(normalCanvas)
|
|
245
246
|
|
|
@@ -249,10 +250,35 @@ describe('createFeatureStyle (inactive shapes)', () => {
|
|
|
249
250
|
expect(placeholderStyle.getImage()).not.toBeInstanceOf(Icon)
|
|
250
251
|
})
|
|
251
252
|
|
|
253
|
+
test('uses the anchor resolved alongside the image', () => {
|
|
254
|
+
HTMLCanvasElement.prototype.getContext = jest.fn(function () {
|
|
255
|
+
this._ctx ??= { putImageData: jest.fn() }
|
|
256
|
+
return this._ctx
|
|
257
|
+
})
|
|
258
|
+
addImage('symbol-anchor', { width: 40, height: 40 })
|
|
259
|
+
const feature = pointFeature([5, 5])
|
|
260
|
+
feature.setProperties({ symbol: 'pin', symbolImageAnchor: [0.25, 0.75], symbolImageId: 'symbol-anchor' })
|
|
261
|
+
|
|
262
|
+
const style = styles.createFeatureStyle()(feature)[0]
|
|
263
|
+
expect(style.getImage().getAnchor()).toEqual([10, 30])
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
test('falls back to the placeholder until the anchor has been resolved', () => {
|
|
267
|
+
HTMLCanvasElement.prototype.getContext = jest.fn(function () {
|
|
268
|
+
this._ctx ??= { putImageData: jest.fn() }
|
|
269
|
+
return this._ctx
|
|
270
|
+
})
|
|
271
|
+
addImage('symbol-no-anchor', { width: 10, height: 10 })
|
|
272
|
+
const feature = pointFeature([5, 5])
|
|
273
|
+
feature.setProperties({ symbol: 'pin', symbolImageId: 'symbol-no-anchor' })
|
|
274
|
+
|
|
275
|
+
const style = styles.createFeatureStyle()(feature)[0]
|
|
276
|
+
expect(style.getImage()).not.toBeInstanceOf(Icon)
|
|
277
|
+
})
|
|
278
|
+
|
|
252
279
|
test('a Point feature whose symbolImageId has not been rasterised/cached yet falls back to the placeholder', () => {
|
|
253
|
-
clearSymbolImageCache()
|
|
254
280
|
const feature = pointFeature([5, 5])
|
|
255
|
-
feature.setProperties({ symbol: 'pin', symbolImageId: 'symbol-not-cached' })
|
|
281
|
+
feature.setProperties({ symbol: 'pin', symbolImageAnchor: [0.5, 1], symbolImageId: 'symbol-not-cached' })
|
|
256
282
|
|
|
257
283
|
const style = styles.createFeatureStyle()(feature)[0]
|
|
258
284
|
expect(style.getImage()).not.toBeInstanceOf(Icon)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { OLDrawManager } from './core/OLDrawManager.js'
|
|
2
|
-
import { MAP_SIZE_SCALES } from './defaults.js'
|
|
3
2
|
import { refreshAllPointSymbols } from './point/pointSymbolImages.js'
|
|
3
|
+
import { logger } from '../../../../../src/services/logger.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates the OLDrawManager, attaches it to mapProvider, and wires app-level size/style events.
|
|
7
7
|
* @returns {{ manager: OLDrawManager, remove: () => void }}
|
|
8
8
|
*/
|
|
9
|
-
export const createOLDraw = ({ mapProvider, events, eventBus, pluginConfig = {}, mapStyle = null }) => {
|
|
9
|
+
export const createOLDraw = ({ mapProvider, symbolRegistry, events, eventBus, pluginConfig = {}, mapStyle = null }) => {
|
|
10
10
|
const { map } = mapProvider
|
|
11
|
-
const manager = new OLDrawManager(map, pluginConfig)
|
|
11
|
+
const manager = new OLDrawManager(map, pluginConfig, { mapProvider, symbolRegistry })
|
|
12
12
|
|
|
13
13
|
if (mapStyle) {
|
|
14
14
|
manager.setMapStyle(mapStyle)
|
|
@@ -16,29 +16,33 @@ export const createOLDraw = ({ mapProvider, events, eventBus, pluginConfig = {},
|
|
|
16
16
|
|
|
17
17
|
mapProvider.draw = manager
|
|
18
18
|
|
|
19
|
-
// Seed drawScale from the provider's own starting size — MAP_SET_SIZE only fires on a later runtime change, not the initial one.
|
|
20
|
-
mapProvider.drawScale = MAP_SIZE_SCALES[mapProvider.mapSize] ?? 1
|
|
21
|
-
|
|
22
19
|
// Nudges useHighlightSync to re-apply the highlight overlay — OL's own MAP_DATA_CHANGE is driven purely by basemap 'tileloadend', unrelated to the draw source.
|
|
23
20
|
const notifyPointSymbolsRefreshed = () => eventBus.emit(events.MAP_DATA_CHANGE)
|
|
21
|
+
const refreshPointSymbols = (pixelRatioOverride) => {
|
|
22
|
+
refreshAllPointSymbols({ manager, mapProvider, pixelRatioOverride })
|
|
23
|
+
.then(notifyPointSymbolsRefreshed)
|
|
24
|
+
.catch((error) => logger.error('[draw] failed to refresh point symbols', error))
|
|
25
|
+
}
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
// Point symbols are rasterised at the map's pixelRatio, so re-resolve them when it changes (on a
|
|
28
|
+
// map-size change). The event carries the new value, so this doesn't depend on whether the OL
|
|
29
|
+
// provider's own MAP_SET_PIXEL_RATIO listener has applied it to the map yet.
|
|
30
|
+
const handleSetPixelRatio = (pixelRatio) => {
|
|
31
|
+
refreshPointSymbols(pixelRatio)
|
|
28
32
|
}
|
|
29
|
-
eventBus.on(events.
|
|
33
|
+
eventBus.on(events.MAP_SET_PIXEL_RATIO, handleSetPixelRatio)
|
|
30
34
|
|
|
31
35
|
const handleSetMapStyle = (newMapStyle) => {
|
|
32
36
|
manager.setMapStyle(newMapStyle)
|
|
33
37
|
// Rasterised point symbol images are style-scoped (colours resolve per map style).
|
|
34
|
-
|
|
38
|
+
refreshPointSymbols()
|
|
35
39
|
}
|
|
36
40
|
eventBus.on(events.MAP_SET_STYLE, handleSetMapStyle)
|
|
37
41
|
|
|
38
42
|
return {
|
|
39
43
|
manager,
|
|
40
44
|
remove () {
|
|
41
|
-
eventBus.off(events.
|
|
45
|
+
eventBus.off(events.MAP_SET_PIXEL_RATIO, handleSetPixelRatio)
|
|
42
46
|
eventBus.off(events.MAP_SET_STYLE, handleSetMapStyle)
|
|
43
47
|
manager.remove()
|
|
44
48
|
mapProvider.draw = null
|