@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
@@ -0,0 +1,132 @@
1
+ import {
2
+ composeSymbolDef, applyAnchorOverride, scaleSvgSymbolDef, getGraphicTransform, renderComposed, renderTemplate
3
+ } from './symbolComposer.js'
4
+ import { circle, pin, graphics, SYMBOL_PADDING } from '../config/symbolConfig.js'
5
+ import { logger } from './logger.js'
6
+
7
+ jest.mock('./logger.js', () => ({ logger: { warn: jest.fn() } }))
8
+
9
+ const dims = (viewBox) => viewBox.split(' ').map(Number).slice(2)
10
+ const values = {
11
+ backgroundColor: '#ca3535',
12
+ foregroundColor: '#ffffff',
13
+ haloColor: '#ffffff',
14
+ selectedColor: 'none',
15
+ activeColor: 'none',
16
+ graphic: graphics.dot
17
+ }
18
+
19
+ describe('composeSymbolDef', () => {
20
+ it('pads the scaled body by SYMBOL_PADDING on every side, rounded up to a multiple of 4', () => {
21
+ const [width, height] = dims(composeSymbolDef(circle, 1.25).viewBox)
22
+ // 26 × 1.25 + 16 = 48.5, rounded up to 52
23
+ expect(26 * 1.25 + SYMBOL_PADDING * 2).toBe(48.5)
24
+ expect(width).toBe(52)
25
+ expect(height).toBe(width)
26
+ })
27
+
28
+ it('returns the same object for the same def and scale', () => {
29
+ expect(composeSymbolDef(pin, 0.75)).toBe(composeSymbolDef(pin, 0.75))
30
+ })
31
+
32
+ it('records the body\'s box within the viewBox', () => {
33
+ const { bodyBox, viewBox } = composeSymbolDef(circle, 1)
34
+ expect(bodyBox).toEqual([9, 9, 26, 26])
35
+ expect(dims(viewBox)).toEqual([44, 44])
36
+ })
37
+ })
38
+
39
+ describe('applyAnchorOverride', () => {
40
+ it('returns the def unchanged when there\'s no override', () => {
41
+ const sized = composeSymbolDef(circle, 1)
42
+ expect(applyAnchorOverride(sized, undefined)).toBe(sized)
43
+ })
44
+
45
+ it('treats a built-in shape\'s override as a fraction of the shape, at every size', () => {
46
+ [0.75, 1, 1.25].forEach((scale) => {
47
+ const sized = composeSymbolDef(circle, scale)
48
+ const { anchor, viewBox } = applyAnchorOverride(sized, [0.5, 1])
49
+ const [width, height] = dims(viewBox)
50
+ const [x, y, w, h] = sized.bodyBox
51
+ // lands on the bottom-centre of the circle itself, not of its padded viewBox
52
+ expect(anchor[0] * width).toBeCloseTo(x + w / 2)
53
+ expect(anchor[1] * height).toBeCloseTo(y + h)
54
+ })
55
+ })
56
+
57
+ it.each([[[0.5]], [['0.5', '1']], [[0.5, Number.NaN]], ['bottom']])('ignores an invalid override %j, warning once', (anchor) => {
58
+ const sized = composeSymbolDef(circle, 1)
59
+ logger.warn.mockClear()
60
+ expect(applyAnchorOverride(sized, anchor)).toBe(sized)
61
+ expect(applyAnchorOverride(sized, anchor)).toBe(sized)
62
+ expect(logger.warn).toHaveBeenCalledTimes(1)
63
+ expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Invalid symbolAnchor'))
64
+ })
65
+
66
+ it('uses an SVG-template symbol\'s override as given — a fraction of its own viewBox', () => {
67
+ const sized = scaleSvgSymbolDef({ svg: '<rect/>' }, '0 0 20 20', 1)
68
+ expect(applyAnchorOverride(sized, [0.1, 0.9]).anchor).toEqual([0.1, 0.9])
69
+ })
70
+ })
71
+
72
+ describe('scaleSvgSymbolDef', () => {
73
+ it('leaves the svg as it is at scale 1', () => {
74
+ expect(scaleSvgSymbolDef({ svg: '<rect/>' }, '0 0 20 10', 1)).toEqual({ svg: '<rect/>', viewBox: '0 0 20 10', anchor: [0.5, 0.5] })
75
+ })
76
+
77
+ it('keeps the symbol\'s own anchor', () => {
78
+ expect(scaleSvgSymbolDef({ svg: '<rect/>', anchor: [0.5, 1] }, '0 0 20 10', 2).anchor).toEqual([0.5, 1])
79
+ })
80
+
81
+ it('scales the viewBox, origin included, and wraps the svg in a scale transform', () => {
82
+ expect(scaleSvgSymbolDef({ svg: '<rect/>' }, '2 4 20 10', 1.5)).toEqual({ svg: '<g transform="scale(1.5)"><rect/></g>', viewBox: '3 6 30 15', anchor: [0.5, 0.5] })
83
+ })
84
+ })
85
+
86
+ describe('getGraphicTransform', () => {
87
+ it('leaves a graphic already centred in the 16×16 space where it is, at 0.8', () => {
88
+ Object.values(graphics).forEach((graphic) => {
89
+ expect(getGraphicTransform(graphic, 22, 20)).toBe('translate(22, 20) scale(0.8) translate(-8, -8)')
90
+ })
91
+ })
92
+
93
+ it('centres and shrinks a graphic drawn in a bigger space (e.g. a 24×24 icon)', () => {
94
+ // a square filling 0–24: centred on its middle (12, 12) and shrunk by 16/24
95
+ expect(getGraphicTransform('M0 0H24V24H0Z', 22, 22)).toBe('translate(22, 22) scale(0.533) translate(-12, -12)')
96
+ })
97
+
98
+ it('centres a small off-centre graphic without enlarging it', () => {
99
+ expect(getGraphicTransform('M0 0H4V4H0Z', 22, 22)).toBe('translate(22, 22) scale(0.8) translate(-2, -2)')
100
+ })
101
+
102
+ it('falls back to the 16×16 space\'s centre, with a warning, for a graphic it can\'t measure', () => {
103
+ expect(getGraphicTransform('not a path', 22, 22)).toBe('translate(22, 22) scale(0.8) translate(-8, -8)')
104
+ expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('could not be measured'))
105
+ })
106
+
107
+ it('falls back to the 16×16 space\'s centre for no graphic', () => {
108
+ expect(getGraphicTransform('', 22, 22)).toBe('translate(22, 22) scale(0.8) translate(-8, -8)')
109
+ })
110
+ })
111
+
112
+ describe('renderComposed', () => {
113
+ const countPaths = (svg) => svg.match(/<path /g).length
114
+
115
+ it('emits only the body and graphic when no ring is showing', () => {
116
+ expect(countPaths(renderComposed(composeSymbolDef(circle, 1), values))).toBe(2)
117
+ })
118
+
119
+ it('emits the selected ring, then the active ring, when their colours are set', () => {
120
+ const selected = renderComposed(composeSymbolDef(circle, 1), { ...values, selectedColor: '#0b0c0c' })
121
+ expect(countPaths(selected)).toBe(3)
122
+ const active = renderComposed(composeSymbolDef(circle, 1), { ...values, selectedColor: '#0b0c0c', activeColor: '#ffdd00' })
123
+ expect(countPaths(active)).toBe(4)
124
+ expect(active.indexOf('#ffdd00')).toBeLessThan(active.indexOf('#0b0c0c')) // active ring is drawn underneath
125
+ })
126
+ })
127
+
128
+ describe('renderTemplate', () => {
129
+ it('substitutes every occurrence of each token', () => {
130
+ expect(renderTemplate('<a fill="{{c}}"/><b fill="{{c}}"/>', { c: 'red' })).toBe('<a fill="red"/><b fill="red"/>')
131
+ })
132
+ })