@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.
Files changed (147) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/dist/umd/index.js +1 -1
  4. package/docs/api/context.md +18 -12
  5. package/docs/api/marker-config.md +16 -8
  6. package/docs/api/symbol-config.md +24 -9
  7. package/docs/api/symbol-registry.md +49 -14
  8. package/docs/plugins/datasets.md +4 -10
  9. package/docs/plugins/draw.md +2 -1
  10. package/docs/plugins/map-key.md +6 -4
  11. package/package.json +1 -1
  12. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  13. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  14. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  15. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  16. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  17. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  18. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  19. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  20. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  21. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  22. package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +9 -9
  23. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +19 -3
  24. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
  25. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
  26. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
  27. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +19 -26
  28. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +15 -67
  29. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +32 -105
  30. package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
  31. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
  32. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
  33. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +99 -11
  34. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +26 -26
  35. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +48 -29
  36. package/plugins/datasets/src/initialise/defaults.js +4 -3
  37. package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
  38. package/plugins/datasets/src/registry/dataset.js +2 -1
  39. package/plugins/datasets/src/registry/dataset.test.js +13 -0
  40. package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
  41. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
  42. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  43. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  44. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  45. package/plugins/draw/dist/esm/index.js +1 -1
  46. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  47. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  48. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  49. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  50. package/plugins/draw/dist/umd/index.js +1 -1
  51. package/plugins/draw/src/DrawInit.jsx +7 -5
  52. package/plugins/draw/src/DrawInit.test.jsx +18 -2
  53. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
  54. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
  55. package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
  56. package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
  57. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
  58. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
  59. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
  60. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
  61. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
  62. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
  63. package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
  64. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
  65. package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
  66. package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
  67. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
  68. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
  69. package/plugins/draw/src/defaults.js +2 -6
  70. package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
  71. package/plugins/draw/src/utils/symbolKeys.js +3 -4
  72. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  73. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  74. package/plugins/interact/dist/umd/index.js +1 -1
  75. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  76. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
  77. package/plugins/map-key/dist/umd/index.js +1 -1
  78. package/plugins/map-key/src/components/Key/Key.jsx +8 -4
  79. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +3 -1
  80. package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
  81. package/plugins/map-key/src/components/Key/KeySvg.jsx +15 -14
  82. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +21 -14
  83. package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
  84. package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
  85. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
  86. package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
  87. package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
  88. package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
  89. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
  90. package/plugins/map-key/src/registry/index.js +0 -2
  91. package/plugins/map-key/src/registry/index.test.js +1 -9
  92. package/plugins/menu/src/registry/index.js +0 -2
  93. package/plugins/menu/src/registry/index.test.js +1 -9
  94. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  95. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  96. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  97. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  98. package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
  99. package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
  100. package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
  101. package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
  102. package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
  103. package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
  104. package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
  105. package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
  106. package/providers/mapProvider.js +53 -1
  107. package/providers/mapProvider.test.js +6 -0
  108. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  109. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  110. package/providers/maplibre/dist/umd/index.js +1 -1
  111. package/providers/maplibre/src/maplibreProvider.js +50 -17
  112. package/providers/maplibre/src/maplibreProvider.test.js +74 -20
  113. package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
  114. package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
  115. package/providers/maplibre/src/utils/patternImages.js +46 -29
  116. package/providers/maplibre/src/utils/patternImages.test.js +52 -4
  117. package/providers/maplibre/src/utils/symbolImages.js +80 -39
  118. package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
  119. package/src/App/components/Markers/Markers.jsx +16 -25
  120. package/src/App/components/Markers/Markers.test.jsx +34 -48
  121. package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
  122. package/src/App/components/Markers/SymbolMarker.jsx +1 -1
  123. package/src/App/store/ServiceProvider.jsx +6 -3
  124. package/src/App/store/ServiceProvider.test.jsx +24 -0
  125. package/src/config/appConfig.js +1 -5
  126. package/src/config/mapSizeScales.js +8 -0
  127. package/src/config/symbolConfig.js +101 -25
  128. package/src/services/patternRegistry.js +97 -76
  129. package/src/services/patternRegistry.test.js +19 -1
  130. package/src/services/symbolComposer.js +184 -0
  131. package/src/services/symbolComposer.test.js +132 -0
  132. package/src/services/symbolRegistry.js +326 -155
  133. package/src/services/symbolRegistry.test.js +334 -32
  134. package/src/types.js +9 -3
  135. package/src/utils/hashString.js +23 -0
  136. package/src/utils/hashString.test.js +29 -0
  137. package/src/utils/imageDataCache.js +43 -0
  138. package/src/utils/imageDataCache.test.js +38 -0
  139. package/src/utils/pathBounds.js +330 -0
  140. package/src/utils/pathBounds.test.js +145 -0
  141. package/src/utils/patternUtils.js +0 -8
  142. package/src/utils/patternUtils.test.js +0 -25
  143. package/src/utils/recentImageSets.js +35 -0
  144. package/src/utils/recentImageSets.test.js +46 -0
  145. package/src/utils/symbolUtils.js +26 -29
  146. package/src/utils/symbolUtils.test.js +27 -41
  147. package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
@@ -1,3 +1,10 @@
1
+ import { SYMBOL_SIZES } from '../config/symbolConfig.js'
2
+ import { logger } from '../services/logger.js'
3
+
4
+ // Each unknown symbol size is reported once, rather than on every render
5
+ const reportedSizes = new Set()
6
+ const quoted = (text) => `'${text}'`
7
+
1
8
  // Symbol style props in dataset style that carry token values.
2
9
  // These use the 'symbol' prefix to distinguish them from fill/stroke props at the same level.
3
10
  // The prefix is stripped before passing tokens to the registry (e.g. symbolBackgroundColor → backgroundColor).
@@ -7,15 +14,15 @@ const SYMBOL_STYLE_PROPS = new Set([
7
14
  ])
8
15
 
9
16
  /**
10
- * Returns true if this dataset should be rendered as a symbol (point) layer.
11
- * @param {Object} dataset
17
+ * Whether a dataset or draw style draws a symbol: a `symbol` id or inline `symbolSvgContent`.
18
+ * @param {Object} [style]
12
19
  * @returns {boolean}
13
20
  */
14
- export const hasSymbol = (dataset) => !!(dataset.symbol || dataset.symbolSvgContent)
21
+ export const hasSymbol = (style) => !!(style?.symbol || style?.symbolSvgContent)
15
22
 
16
23
  /**
17
24
  * Returns true if a marker item should render as a standalone label with no symbol.
18
- * Requires label content and at least one of symbol/symbolSvgContent to be explicitly null.
25
+ * Requires label content and at least one of symbol/svgContent to be explicitly null.
19
26
  * Undefined values fall through to render-time default symbol resolution.
20
27
  *
21
28
  * @param {Object} marker
@@ -25,10 +32,10 @@ export const isStandaloneLabel = (marker) => {
25
32
  if (!marker.label) {
26
33
  return false
27
34
  }
28
- if (marker.symbol || marker.symbolSvgContent) {
35
+ if (marker.symbol || marker.svgContent) {
29
36
  return false
30
37
  }
31
- return marker.symbol === null || marker.symbolSvgContent === null
38
+ return marker.symbol === null || marker.svgContent === null
32
39
  }
33
40
 
34
41
  /**
@@ -53,31 +60,21 @@ export const getSymbolStyleColors = (dataset) => {
53
60
  }
54
61
 
55
62
  /**
56
- * Returns the viewBox string for a dataset's symbol.
57
- * Precedence: dataset.symbolViewBox → symbolDef viewBox → default.
63
+ * Returns the scale factor for a symbol size ('small' | 'medium' | 'large'). Missing means
64
+ * medium; an unknown value is warned about (once) and also treated as medium.
65
+ * The one place a size becomes a number — extend here to accept other sizes or raw factors.
58
66
  *
59
- * @param {Object} dataset
60
- * @param {Object|undefined} symbolDef
61
- * @returns {string}
67
+ * @param {string} [size]
68
+ * @returns {number}
62
69
  */
63
- export const getSymbolViewBox = (dataset, symbolDef) => {
64
- if (dataset.symbolViewBox) {
65
- return dataset.symbolViewBox
70
+ export const getSymbolScale = (size) => {
71
+ if (size == null || Object.keys(SYMBOL_SIZES).includes(size)) {
72
+ return SYMBOL_SIZES[size] ?? SYMBOL_SIZES.medium
66
73
  }
67
- return symbolDef?.viewBox ?? '0 0 38 38'
68
- }
69
-
70
- /**
71
- * Returns the anchor for a dataset's symbol as [x, y] in 0–1 space.
72
- * Precedence: dataset.symbolAnchor → symbolDef anchor → [0.5, 0.5].
73
- *
74
- * @param {Object} dataset
75
- * @param {Object|undefined} symbolDef
76
- * @returns {number[]}
77
- */
78
- export const getSymbolAnchor = (dataset, symbolDef) => {
79
- if (dataset.symbolAnchor) {
80
- return dataset.symbolAnchor
74
+ if (!reportedSizes.has(size)) {
75
+ reportedSizes.add(size)
76
+ const expected = Object.keys(SYMBOL_SIZES).map(quoted).join(', ')
77
+ logger.warn(`Unknown symbol size "${size}" — expected ${expected}. Using 'medium'.`)
81
78
  }
82
- return symbolDef?.anchor ?? [0.5, 0.5]
79
+ return SYMBOL_SIZES.medium
83
80
  }
@@ -2,9 +2,11 @@ import {
2
2
  hasSymbol,
3
3
  isStandaloneLabel,
4
4
  getSymbolStyleColors,
5
- getSymbolViewBox,
6
- getSymbolAnchor
5
+ getSymbolScale
7
6
  } from './symbolUtils.js'
7
+ import { logger } from '../services/logger.js'
8
+
9
+ jest.mock('../services/logger.js', () => ({ logger: { warn: jest.fn() } }))
8
10
 
9
11
  // ─── hasSymbol ────────────────────────────────────────────────────────────────
10
12
 
@@ -17,6 +19,10 @@ describe('hasSymbol', () => {
17
19
  expect(hasSymbol({ symbolSvgContent: '<circle/>' })).toBe(true)
18
20
  })
19
21
 
22
+ it('returns false with no style at all', () => {
23
+ expect(hasSymbol(undefined)).toBe(false)
24
+ })
25
+
20
26
  it('returns false when symbol is absent', () => {
21
27
  expect(hasSymbol({})).toBe(false)
22
28
  })
@@ -38,11 +44,11 @@ describe('isStandaloneLabel', () => {
38
44
  expect(isStandaloneLabel({ label: 'My label', symbol: 'pin' })).toBe(false)
39
45
  })
40
46
 
41
- it('returns false when marker has symbolSvgContent (line 28)', () => {
42
- expect(isStandaloneLabel({ label: 'My label', symbolSvgContent: '<circle/>' })).toBe(false)
47
+ it('returns false when marker has svgContent (line 28)', () => {
48
+ expect(isStandaloneLabel({ label: 'My label', svgContent: '<circle/>' })).toBe(false)
43
49
  })
44
50
 
45
- it('returns false when label is present but both symbol and symbolSvgContent are undefined (line 31)', () => {
51
+ it('returns false when label is present but both symbol and svgContent are undefined (line 31)', () => {
46
52
  expect(isStandaloneLabel({ label: 'My label' })).toBe(false)
47
53
  })
48
54
 
@@ -50,8 +56,8 @@ describe('isStandaloneLabel', () => {
50
56
  expect(isStandaloneLabel({ label: 'My label', symbol: null })).toBe(true)
51
57
  })
52
58
 
53
- it('returns true when label is present and symbolSvgContent is explicitly null (line 31)', () => {
54
- expect(isStandaloneLabel({ label: 'My label', symbolSvgContent: null })).toBe(true)
59
+ it('returns true when label is present and svgContent is explicitly null (line 31)', () => {
60
+ expect(isStandaloneLabel({ label: 'My label', svgContent: null })).toBe(true)
55
61
  })
56
62
  })
57
63
 
@@ -103,46 +109,26 @@ describe('getSymbolStyleColors', () => {
103
109
  })
104
110
  })
105
111
 
106
- // ─── getSymbolViewBox ─────────────────────────────────────────────────────────
107
-
108
- describe('getSymbolViewBox', () => {
109
- it('returns symbolViewBox from dataset', () => {
110
- const dataset = { symbol: 'custom', symbolViewBox: '0 0 24 24' }
111
- expect(getSymbolViewBox(dataset, undefined)).toBe('0 0 24 24')
112
- })
113
-
114
- it('falls back to symbolDef viewBox', () => {
115
- const symbolDef = { id: 'pin', viewBox: '0 0 38 38' }
116
- expect(getSymbolViewBox({ symbol: 'pin' }, symbolDef)).toBe('0 0 38 38')
117
- })
118
-
119
- it('returns default viewBox when neither source has one', () => {
120
- expect(getSymbolViewBox({ symbol: 'pin' }, {})).toBe('0 0 38 38')
121
- })
122
-
123
- it('returns default viewBox when symbolDef is undefined', () => {
124
- expect(getSymbolViewBox({ symbol: 'pin' }, undefined)).toBe('0 0 38 38')
125
- })
126
- })
127
-
128
- // ─── getSymbolAnchor ──────────────────────────────────────────────────────────
112
+ // ─── getSymbolScale ───────────────────────────────────────────────────────────
129
113
 
130
- describe('getSymbolAnchor', () => {
131
- it('returns symbolAnchor from dataset', () => {
132
- const dataset = { symbol: 'custom', symbolAnchor: [0.5, 0.9] }
133
- expect(getSymbolAnchor(dataset, undefined)).toEqual([0.5, 0.9])
114
+ describe('getSymbolScale', () => {
115
+ it.each([['small', 0.75], ['medium', 1], ['large', 1.25]])('maps %s to %s', (size, scale) => {
116
+ expect(getSymbolScale(size)).toBe(scale)
134
117
  })
135
118
 
136
- it('falls back to symbolDef anchor', () => {
137
- const symbolDef = { id: 'pin', anchor: [0.5, 0.9] }
138
- expect(getSymbolAnchor({ symbol: 'pin' }, symbolDef)).toEqual([0.5, 0.9])
119
+ it('treats a missing size as medium, without a warning', () => {
120
+ expect(getSymbolScale(undefined)).toBe(1)
121
+ expect(logger.warn).not.toHaveBeenCalled()
139
122
  })
140
123
 
141
- it('returns default [0.5, 0.5] when neither source has an anchor', () => {
142
- expect(getSymbolAnchor({ symbol: 'pin' }, {})).toEqual([0.5, 0.5])
124
+ it('warns once about an unknown size, and treats it as medium', () => {
125
+ expect(getSymbolScale('huge')).toBe(1)
126
+ expect(getSymbolScale('huge')).toBe(1)
127
+ expect(logger.warn).toHaveBeenCalledTimes(1)
128
+ expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Unknown symbol size "huge"'))
143
129
  })
144
130
 
145
- it('returns default [0.5, 0.5] when symbolDef is undefined', () => {
146
- expect(getSymbolAnchor({ symbol: 'pin' }, undefined)).toEqual([0.5, 0.5])
131
+ it('doesn\'t mistake inherited object keys for sizes', () => {
132
+ expect(getSymbolScale('toString')).toBe(1)
147
133
  })
148
134
  })
@@ -1 +0,0 @@
1
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */