@defra/interactive-map 0.0.52-alpha → 0.0.54-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/dist/css/index.css +1 -1
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api/context.md +30 -12
  7. package/docs/api/marker-config.md +16 -8
  8. package/docs/api/symbol-config.md +24 -9
  9. package/docs/api/symbol-registry.md +49 -14
  10. package/docs/api.md +11 -3
  11. package/docs/plugins/datasets.md +6 -10
  12. package/docs/plugins/draw.md +2 -1
  13. package/docs/plugins/map-key.md +47 -4
  14. package/package.json +1 -1
  15. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  16. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  17. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  18. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  19. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  20. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  21. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  22. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  23. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  24. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  25. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
  26. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  27. package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +10 -10
  28. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +22 -6
  29. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
  30. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
  31. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
  32. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +20 -27
  33. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +16 -70
  34. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +30 -115
  35. package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
  36. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
  37. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
  38. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +101 -13
  39. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +27 -28
  40. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +51 -32
  41. package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
  42. package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
  43. package/plugins/datasets/src/initialise/defaults.js +16 -27
  44. package/plugins/datasets/src/initialise/defaults.test.js +25 -57
  45. package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
  46. package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
  47. package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
  48. package/plugins/datasets/src/registry/dataset.js +23 -17
  49. package/plugins/datasets/src/registry/dataset.test.js +114 -11
  50. package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
  51. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
  52. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  53. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  54. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  55. package/plugins/draw/dist/esm/index.js +1 -1
  56. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  57. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  58. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  59. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  60. package/plugins/draw/dist/umd/index.js +1 -1
  61. package/plugins/draw/src/DrawInit.jsx +7 -5
  62. package/plugins/draw/src/DrawInit.test.jsx +18 -2
  63. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
  64. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
  65. package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
  66. package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
  67. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
  68. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
  69. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
  70. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
  71. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
  72. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
  73. package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
  74. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
  75. package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
  76. package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
  77. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
  78. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
  79. package/plugins/draw/src/defaults.js +2 -6
  80. package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
  81. package/plugins/draw/src/utils/symbolKeys.js +3 -4
  82. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  83. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  84. package/plugins/interact/dist/umd/index.js +1 -1
  85. package/plugins/map-key/dist/css/index.css +1 -1
  86. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  87. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
  88. package/plugins/map-key/dist/umd/index.js +1 -1
  89. package/plugins/map-key/src/components/Key/Key.jsx +8 -4
  90. package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
  91. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +36 -3
  92. package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
  93. package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
  94. package/plugins/map-key/src/components/Key/KeySvg.jsx +19 -18
  95. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +25 -18
  96. package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
  97. package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
  98. package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
  99. package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
  100. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
  101. package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
  102. package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
  103. package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
  104. package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
  105. package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
  106. package/plugins/map-key/src/index.js +34 -0
  107. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
  108. package/plugins/map-key/src/registry/index.js +0 -2
  109. package/plugins/map-key/src/registry/index.test.js +1 -9
  110. package/plugins/map-key/src/utils/groupStyles.js +5 -2
  111. package/plugins/menu/src/registry/index.js +0 -2
  112. package/plugins/menu/src/registry/index.test.js +1 -9
  113. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  114. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  115. package/plugins/search/dist/umd/index.js +1 -1
  116. package/plugins/search/src/Search.jsx +0 -1
  117. package/plugins/search/src/components/Form/Form.jsx +3 -3
  118. package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
  119. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
  120. package/plugins/search/src/defaults.js +3 -0
  121. package/plugins/search/src/events/formHandlers.js +3 -9
  122. package/plugins/search/src/events/formHandlers.test.js +6 -9
  123. package/plugins/search/src/events/inputHandlers.js +8 -2
  124. package/plugins/search/src/events/inputHandlers.test.js +20 -0
  125. package/plugins/search/src/events/suggestionHandlers.js +3 -5
  126. package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
  127. package/plugins/search/src/utils/showResult.js +9 -0
  128. package/plugins/search/src/utils/showResult.test.js +16 -0
  129. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  130. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  131. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  132. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  133. package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
  134. package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
  135. package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
  136. package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
  137. package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
  138. package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
  139. package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
  140. package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
  141. package/providers/mapProvider.js +53 -1
  142. package/providers/mapProvider.test.js +6 -0
  143. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  144. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  145. package/providers/maplibre/dist/umd/index.js +1 -1
  146. package/providers/maplibre/src/maplibreProvider.js +50 -17
  147. package/providers/maplibre/src/maplibreProvider.test.js +74 -20
  148. package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
  149. package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
  150. package/providers/maplibre/src/utils/patternImages.js +46 -29
  151. package/providers/maplibre/src/utils/patternImages.test.js +52 -4
  152. package/providers/maplibre/src/utils/symbolImages.js +80 -39
  153. package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
  154. package/src/App/components/Hints/Hints.module.scss +1 -1
  155. package/src/App/components/Markers/Markers.jsx +16 -25
  156. package/src/App/components/Markers/Markers.test.jsx +34 -48
  157. package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
  158. package/src/App/components/Markers/SymbolMarker.jsx +1 -1
  159. package/src/App/components/Viewport/Viewport.jsx +6 -4
  160. package/src/App/components/Viewport/Viewport.test.jsx +18 -1
  161. package/src/App/hooks/useMapAnnouncements.js +7 -2
  162. package/src/App/hooks/useMapAnnouncements.test.js +13 -2
  163. package/src/App/hooks/useModalPanelBehaviour.js +3 -1
  164. package/src/App/initialiseApp.js +1 -1
  165. package/src/App/store/ServiceProvider.jsx +12 -3
  166. package/src/App/store/ServiceProvider.test.jsx +39 -0
  167. package/src/InteractiveMap/InteractiveMap.js +3 -3
  168. package/src/config/appConfig.js +1 -5
  169. package/src/config/mapSizeScales.js +8 -0
  170. package/src/config/symbolConfig.js +101 -25
  171. package/src/services/mapFocus.js +64 -0
  172. package/src/services/mapFocus.test.js +76 -0
  173. package/src/services/patternRegistry.js +97 -76
  174. package/src/services/patternRegistry.test.js +19 -1
  175. package/src/services/symbolComposer.js +184 -0
  176. package/src/services/symbolComposer.test.js +132 -0
  177. package/src/services/symbolRegistry.js +326 -155
  178. package/src/services/symbolRegistry.test.js +334 -32
  179. package/src/types.js +11 -5
  180. package/src/utils/detectInterfaceType.js +16 -5
  181. package/src/utils/detectInterfaceType.test.js +32 -0
  182. package/src/utils/hashString.js +23 -0
  183. package/src/utils/hashString.test.js +29 -0
  184. package/src/utils/imageDataCache.js +43 -0
  185. package/src/utils/imageDataCache.test.js +38 -0
  186. package/src/utils/pathBounds.js +330 -0
  187. package/src/utils/pathBounds.test.js +145 -0
  188. package/src/utils/patternUtils.js +0 -8
  189. package/src/utils/patternUtils.test.js +0 -25
  190. package/src/utils/recentImageSets.js +35 -0
  191. package/src/utils/recentImageSets.test.js +46 -0
  192. package/src/utils/symbolUtils.js +26 -29
  193. package/src/utils/symbolUtils.test.js +27 -41
  194. 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
- constructor (map, pluginConfig = {}) {
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
- // something to pass to symbolRegistry.rasteriseSymbolImage() when resolving a point's
39
- // icon on demand, independent of whatever triggered the resolve.
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
- async changeMode (modeName, options = {}) {
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) => resolvePointSymbol({ manager: this, mapProvider: options.mapProvider, 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
- await manager.changeMode(name, { featureId: 'f1' })
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', async () => {
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
- await manager.changeMode('draw_point', { featureId: 'f1', mapProvider })
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 delegates to point/pointSymbolImages.js's resolvePointSymbol with
103
- // this manager and the mapProvider changeMode was called with.
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(resolvePointSymbol).toHaveBeenCalledWith({ manager, mapProvider, olFeature })
129
+ expect(updatePointSymbol).toHaveBeenCalledWith(olFeature)
108
130
  })
109
131
 
110
- test('disabled destroys the previous mode and deactivates the indicator', async () => {
132
+ test('disabled destroys the previous mode and deactivates the indicator', () => {
111
133
  const { manager } = setup()
112
- await manager.changeMode('draw_polygon')
134
+ manager.changeMode('draw_polygon')
113
135
  const instance = createDrawMode.mock.results[0].value
114
- await manager.changeMode('disabled')
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', async () => {
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
- await manager.changeMode('draw_polygon')
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', async () => {
175
+ test('getVertexItems/selectVertex/insertVertexAtMidpoint delegate to the edit_vertex mode instance', () => {
154
176
  const { manager } = setup()
155
- await manager.changeMode('edit_vertex', { featureId: 'f1' })
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', async () => {
221
+ test('remove tears everything down and silences the bus', () => {
200
222
  const { map, manager } = setup()
201
- await manager.changeMode('draw_polygon')
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, Math.PI * 2)
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: [2, 4] })
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: [2, 4] })
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
- // imageId+anchor+pixelRatio so a style function running every render frame doesn't rebuild
100
- // one each time.
101
- const createPointStyles = (colors) => {
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 Map()
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 && getCachedSymbolImage(imageId)
112
- if (!canvas) {
115
+ const canvas = imageId && getSymbolImage?.(imageId)
116
+ if (!canvas || !properties.symbolImageAnchor) {
113
117
  return null
114
118
  }
115
- const symbolDef = symbolRegistry.getSymbolDef(properties)
116
- const [anchorX, anchorY] = getSymbolAnchor(properties, symbolDef)
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
- const cacheKey = `${imageId}|${anchorX}|${anchorY}|${pixelRatio}`
124
- let iconStyle = iconStyleCache.get(cacheKey)
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
- iconStyleCache.set(cacheKey, iconStyle)
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
- export const createStyles = (colors) => {
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: [2, 4] })
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 { getOrCreateSymbolImage, clearSymbolImageCache } from '../../../../../../providers/beta/openlayers/src/utils/symbolImages.js'
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
- const styles = createStyles(colors)
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
- clearSymbolImageCache()
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
- clearSymbolImageCache()
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
- clearSymbolImageCache()
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
- clearSymbolImageCache()
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
- clearSymbolImageCache()
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 = getOrCreateSymbolImage('symbol-pin-normal-only', { width: 10, height: 10 })
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
- const handleSetMapSize = (size) => {
26
- mapProvider.drawScale = MAP_SIZE_SCALES[size] ?? 1
27
- refreshAllPointSymbols({ manager, mapProvider }).then(notifyPointSymbolsRefreshed)
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.MAP_SET_SIZE, handleSetMapSize)
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
- refreshAllPointSymbols({ manager, mapProvider }).then(notifyPointSymbolsRefreshed)
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.MAP_SET_SIZE, handleSetMapSize)
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