@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
@@ -1,3 +1,5 @@
1
+ import { SYMBOL_STYLE_KEYS } from '../../../../src/config/symbolConfig.js'
2
+
1
3
  const datasetDefaults = {
2
4
  minZoom: 6,
3
5
  maxZoom: 24,
@@ -15,51 +17,38 @@ const datasetDefaults = {
15
17
  const STYLE_PROPS = [
16
18
  'stroke', 'strokeWidth', 'strokeDashArray',
17
19
  'fill', 'fillPattern', 'fillPatternSvgContent', 'fillPatternForegroundColor', 'fillPatternBackgroundColor',
18
- 'opacity', 'symbolDescription', 'keySymbolShape',
19
- 'symbol', 'symbolSvgContent', 'symbolViewBox', 'symbolAnchor',
20
- 'symbolBackgroundColor', 'symbolForegroundColor', 'symbolHaloWidth', 'symbolGraphic'
20
+ 'opacity', 'symbolDescription',
21
+ ...SYMBOL_STYLE_KEYS
21
22
  ]
22
23
 
23
- // Props whose presence in a style object indicates a custom visual style.
24
- // When any are set, the default symbolDescription is not appropriate.
24
+ // Props that set what a style draws. Their presence, even with an empty value such as
25
+ // `stroke: null` or `fill: 'transparent'`, indicates a custom visual style.
25
26
  const VISUAL_STYLE_PROPS = ['stroke', 'fill', 'fillPattern', 'fillPatternSvgContent', 'symbol', 'symbolSvgContent']
26
27
 
27
28
  const hasCustomVisualStyle = (style) =>
28
29
  VISUAL_STYLE_PROPS.some(prop => prop in style)
29
30
 
30
31
  /**
31
- * Merge a dataset config with defaults, flattening the nested `style` object.
32
- * Style properties must be provided via dataset.style — top-level occurrences are ignored.
33
- * symbolDescription from defaults.style is dropped when custom visual styles
34
- * are present and the dataset doesn't explicitly set its own symbolDescription.
32
+ * Apply the default style to a style. The default stroke and symbolDescription apply only when
33
+ * the style has no custom visual style; the default strokeWidth always applies.
35
34
  */
36
- const applyDatasetDefaults = (dataset, defaults) => {
37
- const style = dataset.style || {}
38
- const mergedStyle = { ...defaults.style, ...style }
39
- if (!('symbolDescription' in style) && hasCustomVisualStyle(style)) {
40
- delete mergedStyle.symbolDescription
35
+ const applyStyleDefaults = (style = {}) => {
36
+ if (!hasCustomVisualStyle(style)) {
37
+ return { ...datasetDefaults.style, ...style }
41
38
  }
42
- const topLevel = { ...dataset }
43
- delete topLevel.style
44
- STYLE_PROPS.forEach(prop => delete topLevel[prop])
45
- const topLevelDefaults = { ...defaults }
46
- delete topLevelDefaults.style
47
- return { ...topLevelDefaults, ...topLevel, ...mergedStyle }
39
+ return { strokeWidth: datasetDefaults.style.strokeWidth, ...style }
48
40
  }
49
41
 
42
+ // The dataset's own style is kept as given. Style defaults are applied by Dataset.style, after a
43
+ // sublayer's style is merged with its parent's, so a sublayer can inherit any style prop.
50
44
  const applyDatasetDefaultsWithoutFlattening = (dataset) => {
51
45
  // Allow for existing configs that use visibility instead of visible, but default to visible if neither is set
52
46
  if (dataset.visible !== true && dataset.visible !== false) {
53
47
  dataset.visible = dataset.visibility !== 'hidden'
54
48
  }
55
- const datasetWithDefaults = { ...datasetDefaults, ...dataset, style: { ...datasetDefaults.style, ...dataset.style } }
56
-
57
- const style = dataset.style || {}
58
- if (!('symbolDescription' in style) && hasCustomVisualStyle(style)) {
59
- delete datasetWithDefaults.style.symbolDescription
60
- }
49
+ const datasetWithDefaults = { ...datasetDefaults, ...dataset, style: { ...dataset.style } }
61
50
  STYLE_PROPS.forEach(prop => delete datasetWithDefaults[prop])
62
51
  return datasetWithDefaults
63
52
  }
64
53
 
65
- export { datasetDefaults, hasCustomVisualStyle, applyDatasetDefaults, applyDatasetDefaultsWithoutFlattening }
54
+ export { datasetDefaults, hasCustomVisualStyle, applyStyleDefaults, applyDatasetDefaultsWithoutFlattening }
@@ -1,4 +1,4 @@
1
- import { datasetDefaults, hasCustomVisualStyle, applyDatasetDefaults } from './defaults'
1
+ import { datasetDefaults, hasCustomVisualStyle, applyStyleDefaults, applyDatasetDefaultsWithoutFlattening } from './defaults'
2
2
 
3
3
  describe('datasetDefaults', () => {
4
4
  it('has expected top-level defaults', () => {
@@ -54,73 +54,41 @@ describe('hasCustomVisualStyle', () => {
54
54
  })
55
55
  })
56
56
 
57
- describe('applyDatasetDefaults', () => {
58
- const defaults = {
59
- minZoom: 6,
60
- maxZoom: 24,
61
- showInKey: false,
62
- style: {
63
- stroke: '#d4351c',
64
- strokeWidth: 2,
65
- symbolDescription: 'red outline'
66
- }
67
- }
68
-
69
- it('merges top-level dataset properties over defaults', () => {
70
- const dataset = { id: 'test', minZoom: 10 }
71
- const result = applyDatasetDefaults(dataset, defaults)
72
- expect(result.minZoom).toBe(10)
73
- expect(result.maxZoom).toBe(24)
74
- expect(result.showInKey).toBe(false)
75
- })
76
-
77
- it('flattens style properties into the result', () => {
78
- const dataset = { id: 'test', style: { fill: 'transparent' } }
79
- const result = applyDatasetDefaults(dataset, defaults)
80
- expect(result.fill).toBe('transparent')
81
- expect(result.stroke).toBe('#d4351c')
82
- expect(result.style).toBeUndefined()
83
- })
84
-
85
- it('dataset style properties override default style properties', () => {
86
- const dataset = { id: 'test', style: { stroke: '#0000ff' } }
87
- const result = applyDatasetDefaults(dataset, defaults)
88
- expect(result.stroke).toBe('#0000ff')
57
+ describe('applyStyleDefaults', () => {
58
+ it('applies the whole default style when there is no style', () => {
59
+ expect(applyStyleDefaults()).toEqual({ stroke: '#d4351c', strokeWidth: 2, symbolDescription: 'red outline' })
89
60
  })
90
61
 
91
- it('drops symbolDescription from defaults when custom visual style is present and no explicit symbolDescription', () => {
92
- const dataset = { id: 'test', style: { stroke: '#0000ff' } }
93
- const result = applyDatasetDefaults(dataset, defaults)
94
- expect(result.symbolDescription).toBeUndefined()
62
+ it('applies the whole default style under a style without a custom visual style', () => {
63
+ expect(applyStyleDefaults({ strokeWidth: 4, opacity: 0.5 })).toEqual({
64
+ stroke: '#d4351c', strokeWidth: 4, symbolDescription: 'red outline', opacity: 0.5
65
+ })
95
66
  })
96
67
 
97
- it('keeps symbolDescription when dataset provides its own, even with custom visual style', () => {
98
- const dataset = { id: 'test', style: { stroke: '#0000ff', symbolDescription: 'blue outline' } }
99
- const result = applyDatasetDefaults(dataset, defaults)
100
- expect(result.symbolDescription).toBe('blue outline')
68
+ it('applies only the default strokeWidth under a custom visual style', () => {
69
+ expect(applyStyleDefaults({ fill: 'blue' })).toEqual({ fill: 'blue', strokeWidth: 2 })
101
70
  })
102
71
 
103
- it('keeps symbolDescription from defaults when no custom visual style is present', () => {
104
- const dataset = { id: 'test', style: { strokeWidth: 4 } }
105
- const result = applyDatasetDefaults(dataset, defaults)
106
- expect(result.symbolDescription).toBe('red outline')
72
+ it('treats an explicitly empty stroke as a custom visual style', () => {
73
+ expect(applyStyleDefaults({ stroke: null })).toEqual({ stroke: null, strokeWidth: 2 })
107
74
  })
75
+ })
108
76
 
109
- it('keeps symbolDescription from defaults when dataset has no style', () => {
110
- const dataset = { id: 'test' }
111
- const result = applyDatasetDefaults(dataset, defaults)
112
- expect(result.symbolDescription).toBe('red outline')
77
+ describe('applyDatasetDefaultsWithoutFlattening', () => {
78
+ it('applies top-level defaults but keeps the style as given', () => {
79
+ const result = applyDatasetDefaultsWithoutFlattening({ id: 'test', style: { fill: 'blue' } })
80
+ expect(result).toMatchObject({ id: 'test', minZoom: 6, maxZoom: 24, visible: true })
81
+ expect(result.style).toEqual({ fill: 'blue' })
113
82
  })
114
83
 
115
- it('ignores style properties set at top level of dataset', () => {
116
- const dataset = { id: 'test', stroke: '#ignored' }
117
- const result = applyDatasetDefaults(dataset, defaults)
118
- expect(result.stroke).toBe('#d4351c')
84
+ it('gives a dataset without a style an empty style', () => {
85
+ expect(applyDatasetDefaultsWithoutFlattening({ id: 'test' }).style).toEqual({})
119
86
  })
120
87
 
121
- it('does not include style key in the result', () => {
122
- const dataset = { id: 'test', style: { fill: 'blue' } }
123
- const result = applyDatasetDefaults(dataset, defaults)
124
- expect(result).not.toHaveProperty('style')
88
+ it('ignores style properties set at the top level of the dataset', () => {
89
+ const result = applyDatasetDefaultsWithoutFlattening({ id: 'test', stroke: '#ignored', fill: '#ignored' })
90
+ expect(result).not.toHaveProperty('stroke')
91
+ expect(result).not.toHaveProperty('fill')
92
+ expect(result.style).toEqual({})
125
93
  })
126
94
  })
@@ -1,6 +1,4 @@
1
1
  import { createDynamicSource } from '../fetch/createDynamicSource.js'
2
- // NOSONAR: applyDatasetDefaults and datasetDefaults are used in processedDatasets.map
3
- import { applyDatasetDefaults, datasetDefaults } from './defaults.js'
4
2
  import { mappedDatasetsReducer } from '../reducers/mappedDatasetsReducer.js'
5
3
  import { datasetRegistry } from '../registry/datasetRegistry.js'
6
4
  import { attachMenuStateRef } from '../registry/isVisibleWhen.js'
@@ -23,13 +21,12 @@ export const initialiseDatasets = ({
23
21
  }
24
22
 
25
23
  // Initialise all datasets via the adapter, then set up dynamic sources
26
- const processedDatasets = datasets.map(d => applyDatasetDefaults(d, datasetDefaults))
27
24
  const { mappedDatasets, orderedDatasets } = mappedDatasetsReducer({ datasets })
28
25
  if (adapter.createDataset) {
29
26
  datasetRegistry.attachCreateDataset(adapter.createDataset)
30
27
  }
31
28
  datasetRegistry.attach(mappedDatasets, orderedDatasets, mapStyle)
32
- const menu = datasetsToMenu({ datasets: processedDatasets })
29
+ const menu = datasetsToMenu({ datasets })
33
30
 
34
31
  eventBus.requestOnce('menu:state', attachMenuStateRef) // Request the menu state from the menu plugin
35
32
 
@@ -168,10 +168,8 @@ export const datasets = [
168
168
  visible: false,
169
169
  style: {
170
170
  stroke: '#b58840',
171
- fill: 'transparent',
172
171
  strokeWidth: 4,
173
- symbolDescription: { outdoor: 'blue outline' },
174
- keySymbolShape: 'line'
172
+ symbolDescription: { outdoor: 'blue outline' }
175
173
  }
176
174
  }
177
175
  ]
@@ -20,7 +20,7 @@ describe('mappedDatasetsReducer', () => {
20
20
  }
21
21
  const result = mappedDatasetsReducer(state)
22
22
  expect(result.mappedDatasets).toEqual({
23
- roads: { ...datasetDefaults, id: 'roads', label: 'Roads', minZoom: 10 }
23
+ roads: { ...datasetDefaults, id: 'roads', label: 'Roads', minZoom: 10, style: {} }
24
24
  })
25
25
  expect(result.orderedDatasets).toEqual(['roads'])
26
26
  })
@@ -1,7 +1,8 @@
1
1
  import { datasetRegistry } from './datasetRegistry.js'
2
2
  import { isVisibleWhen } from './isVisibleWhen.js'
3
- import { hasCustomVisualStyle } from '../initialise/defaults.js'
3
+ import { datasetDefaults, hasCustomVisualStyle, applyStyleDefaults } from '../initialise/defaults.js'
4
4
  import { hasPattern } from '../../../../src/utils/patternUtils.js'
5
+ import { hasSymbol } from '../../../../src/utils/symbolUtils.js'
5
6
  import { DynamicGeoJson } from './dynamicGeoJson.js'
6
7
  import { calculateOpacity, getGlobalVisibility } from './globalDataset.js'
7
8
 
@@ -12,7 +13,7 @@ export class Dataset {
12
13
 
13
14
  get id () { return this._datasetDefinition.id }
14
15
  get label () { return this._datasetDefinition.label }
15
- get hasSymbol () { return !this.hasSublayers && Boolean(this.style?.symbol) }
16
+ get hasSymbol () { return !this.hasSublayers && hasSymbol(this.style) }
16
17
  get hasPattern () { return !this.hasSublayers && !this.hasSymbol && hasPattern(this.style) }
17
18
  get hasFill () { return !this.hasSublayers && !this.hasSymbol && (this.hasPattern || (this.style?.fill && this.style?.fill !== 'transparent')) }
18
19
  get hasStroke () { return !this.hasSublayers && !this.hasSymbol && Boolean(this.style?.stroke) }
@@ -163,21 +164,26 @@ export class Dataset {
163
164
  return undefined
164
165
  }
165
166
 
167
+ // The style as configured, merged with the parent's for a sublayer, before defaults are applied
168
+ get inheritedStyle () {
169
+ const ownStyle = this._datasetDefinition.style || {}
170
+ const parent = this.parent
171
+ if (!parent) {
172
+ return ownStyle
173
+ }
174
+ // Here - we must set the merge styles opacity to undefined before the specific child opacity
175
+ // so that we can correctly calculate opacity in the Dataset.opacity getter
176
+ // - otherwise if opacity mode multiply is set,
177
+ // any child with a parent opacity only would be multiplied by itself
178
+ return {
179
+ ...parent.inheritedStyle,
180
+ opacity: undefined, // NOSONAR - we need to set this to undefined so that the opacity getter can calculate the correct opacity
181
+ ...ownStyle
182
+ }
183
+ }
184
+
166
185
  get style () {
167
- const parentStyle = this.parent?.style
168
- if (parentStyle) {
169
- // Here - we must set the merge styles opacity to undefined before the specific child opacity
170
- // so that we can correctly calculate opacity in the Dataset.opacity getter
171
- // - otherwise if opacity mode multiply is set,
172
- // any child with a parent opacity only would be multiplied by itself
173
- return {
174
- ...parentStyle,
175
- opacity: undefined, // NOSONAR - we need to set this to undefined so that the opacity getter can calculate the correct opacity
176
- ...this._datasetDefinition.style,
177
- symbolDescription: this.symbolDescription
178
- }
179
- }
180
- return this._datasetDefinition.style || {}
186
+ return { ...applyStyleDefaults(this.inheritedStyle), symbolDescription: this.symbolDescription }
181
187
  }
182
188
 
183
189
  get hasCustomVisualStyle () {
@@ -191,7 +197,7 @@ export class Dataset {
191
197
  if (this.hasCustomVisualStyle) {
192
198
  return undefined
193
199
  }
194
- return this.parent?.symbolDescription
200
+ return this.parent ? this.parent.symbolDescription : datasetDefaults.style.symbolDescription
195
201
  }
196
202
 
197
203
  get patternConfigs () {
@@ -72,18 +72,34 @@ describe('Dataset class', () => {
72
72
  })
73
73
 
74
74
  describe('style', () => {
75
- it('returns the dataset style directly when there is no parent', () => {
75
+ it('returns a default style object when none are provided', () => {
76
+ const dataset = new Dataset({ id: 'dataset' })
77
+ expect(dataset.style).toEqual({
78
+ stroke: '#d4351c',
79
+ strokeWidth: 2,
80
+ symbolDescription: 'red outline'
81
+ })
82
+ })
83
+
84
+ it('returns the style object when one are provided', () => {
85
+ const dataset = new Dataset({ id: 'dataset', style: { stroke: '#0000ff' } })
86
+ expect(dataset.style).toEqual({
87
+ stroke: '#0000ff',
88
+ strokeWidth: 2
89
+ })
90
+ })
91
+
92
+ it('returns the dataset style, with the default strokeWidth, when there is no parent', () => {
76
93
  const dataset = new Dataset({ style: { stroke: '#ff0000', fill: 'transparent' } })
77
- expect(dataset.style).toEqual({ stroke: '#ff0000', fill: 'transparent' })
94
+ expect(dataset.style).toEqual({ stroke: '#ff0000', fill: 'transparent', strokeWidth: 2 })
78
95
  })
79
96
 
80
97
  it('merges parent style with the sublayer style', () => {
81
98
  const parentDef = { id: 'parent', style: { stroke: '#ff0000', strokeWidth: 2 } }
82
99
  const childDef = { id: 'child', parentId: 'parent', style: { fill: 'blue' } }
83
100
  datasetRegistry.attach({ parent: parentDef, child: childDef })
84
-
85
- const dataset = new Dataset(childDef)
86
- expect(dataset.style).toMatchObject({ stroke: '#ff0000', strokeWidth: 2, fill: 'blue' })
101
+ const dataset = datasetRegistry.getDataset('child')
102
+ expect(dataset.style).toEqual({ stroke: '#ff0000', strokeWidth: 2, fill: 'blue' })
87
103
  })
88
104
 
89
105
  it('overrides parent style properties with the sublayer own style', () => {
@@ -91,8 +107,11 @@ describe('Dataset class', () => {
91
107
  const childDef = { id: 'child', parentId: 'parent', style: { stroke: '#00ff00' } }
92
108
  datasetRegistry.attach({ parent: parentDef, child: childDef })
93
109
 
94
- const dataset = new Dataset(childDef)
95
- expect(dataset.style.stroke).toBe('#00ff00')
110
+ const dataset = datasetRegistry.getDataset('child')
111
+ expect(dataset.style).toEqual({
112
+ stroke: '#00ff00',
113
+ strokeWidth: 2
114
+ })
96
115
  })
97
116
 
98
117
  it('includes symbolDescription in the merged sublayer style', () => {
@@ -100,8 +119,26 @@ describe('Dataset class', () => {
100
119
  const childDef = { id: 'child', parentId: 'parent', style: { symbolDescription: 'custom' } }
101
120
  datasetRegistry.attach({ parent: parentDef, child: childDef })
102
121
 
103
- const dataset = new Dataset(childDef)
104
- expect(dataset.style.symbolDescription).toBe('custom')
122
+ const dataset = datasetRegistry.getDataset('child')
123
+
124
+ expect(dataset.style).toEqual({
125
+ stroke: '#ff0000',
126
+ strokeWidth: 2,
127
+ symbolDescription: 'custom'
128
+ })
129
+ })
130
+ })
131
+
132
+ describe('hasSymbol', () => {
133
+ it.each([
134
+ ['a symbol id', { symbol: 'pin' }],
135
+ ['inline symbolSvgContent', { symbolSvgContent: '<circle r="4"/>' }]
136
+ ])('is a symbol dataset when its style has %s', (_, style) => {
137
+ expect(new Dataset({ style }).hasSymbol).toBe(true)
138
+ })
139
+
140
+ it('is not a symbol dataset with neither', () => {
141
+ expect(new Dataset({ style: { fill: '#ff0000' } }).hasSymbol).toBe(false)
105
142
  })
106
143
  })
107
144
 
@@ -134,14 +171,19 @@ describe('Dataset class', () => {
134
171
  expect(dataset.symbolDescription).toBe('a circle')
135
172
  })
136
173
 
174
+ it("returns the dataset's own symbolDescription alongside a custom visual style", () => {
175
+ const dataset = new Dataset({ style: { stroke: '#0000ff', symbolDescription: 'blue outline' } })
176
+ expect(dataset.symbolDescription).toBe('blue outline')
177
+ })
178
+
137
179
  it('returns undefined when the dataset has a custom visual style but no symbolDescription', () => {
138
180
  const dataset = new Dataset({ style: { stroke: '#ff0000' } })
139
181
  expect(dataset.symbolDescription).toBeUndefined()
140
182
  })
141
183
 
142
- it('returns undefined when the dataset has no style', () => {
184
+ it('returns the default symbolDescription when the dataset has no style', () => {
143
185
  const dataset = new Dataset({})
144
- expect(dataset.symbolDescription).toBeUndefined()
186
+ expect(dataset.symbolDescription).toBe('red outline')
145
187
  })
146
188
 
147
189
  it("inherits the parent's symbolDescription when the sublayer has no custom visual style", () => {
@@ -165,6 +207,67 @@ describe('Dataset class', () => {
165
207
  })
166
208
  })
167
209
 
210
+ describe('style defaults', () => {
211
+ const attachChild = (parentStyle, childStyle) => {
212
+ const parentDef = { id: 'parent', sublayerIds: ['child'], style: parentStyle }
213
+ const childDef = { id: 'child', parentId: 'parent', style: childStyle }
214
+ datasetRegistry.attach({ parent: parentDef, child: childDef })
215
+ return new Dataset(childDef)
216
+ }
217
+
218
+ it('applies the default stroke when there is no style', () => {
219
+ expect(new Dataset({}).style).toMatchObject({ stroke: '#d4351c', strokeWidth: 2, symbolDescription: 'red outline' })
220
+ })
221
+
222
+ it('applies the whole default style when the style only sets opacity', () => {
223
+ expect(new Dataset({ style: { opacity: 0.5 } }).style).toEqual({
224
+ opacity: 0.5,
225
+ stroke: '#d4351c',
226
+ strokeWidth: 2,
227
+ symbolDescription: 'red outline'
228
+ })
229
+ })
230
+
231
+ it('applies the default stroke when the style only adjusts it', () => {
232
+ expect(new Dataset({ style: { strokeWidth: 4, opacity: 0.5 } }).style).toMatchObject({ stroke: '#d4351c', strokeWidth: 4, opacity: 0.5 })
233
+ })
234
+
235
+ it.each([
236
+ ['a fill', { fill: '#00ff00' }],
237
+ ['a fill pattern', { fillPattern: 'dot' }],
238
+ ['custom fill pattern content', { fillPatternSvgContent: '<path/>' }],
239
+ ['a symbol', { symbol: 'pin' }],
240
+ ['custom symbol content', { symbolSvgContent: '<path/>' }],
241
+ ['an explicitly empty stroke', { stroke: null }]
242
+ ])('does not apply the default stroke to a style with %s', (_, style) => {
243
+ const dataset = new Dataset({ style })
244
+ expect(dataset.style.stroke ?? null).toBeNull()
245
+ expect(dataset.hasStroke).toBe(false)
246
+ expect(dataset.symbolDescription).toBeUndefined()
247
+ })
248
+
249
+ it('applies the default strokeWidth to a custom stroke', () => {
250
+ expect(new Dataset({ style: { stroke: '#0000ff' } }).style.strokeWidth).toBe(2)
251
+ })
252
+
253
+ it('does not apply the default stroke to a sublayer with a fill when the parent has no style', () => {
254
+ const dataset = attachChild(undefined, { fill: '#00ff00' })
255
+ expect(dataset.style.fill).toBe('#00ff00')
256
+ expect(dataset.hasStroke).toBe(false)
257
+ })
258
+
259
+ it("lets a sublayer inherit the parent's stroke and strokeWidth", () => {
260
+ const dataset = attachChild({ stroke: '#0000ff', strokeWidth: 4 }, { fill: '#00ff00' })
261
+ expect(dataset.style).toMatchObject({ stroke: '#0000ff', strokeWidth: 4, fill: '#00ff00' })
262
+ })
263
+
264
+ it('applies the default stroke to a sublayer when neither it nor its parent has a visual style', () => {
265
+ const dataset = attachChild({ strokeWidth: 4 }, {})
266
+ expect(dataset.style).toMatchObject({ stroke: '#d4351c', strokeWidth: 4 })
267
+ expect(dataset.symbolDescription).toBe('red outline')
268
+ })
269
+ })
270
+
168
271
  describe('label', () => {
169
272
  it('returns the dataset label', () => {
170
273
  const dataset = new Dataset({ label: 'My dataset' })
@@ -1,5 +1,5 @@
1
1
  import { Dataset } from './dataset.js'
2
- import { hashString } from '../../../../src/utils/patternUtils.js'
2
+ import { hashString } from '../../../../src/utils/hashString.js'
3
3
 
4
4
  /**
5
5
  * Adds the Mapbox Style Spec's declarative model on top of Dataset: filter expressions,
@@ -2,7 +2,7 @@ import { Dataset } from './dataset.js'
2
2
  import { MapboxStyleDataset } from './mapboxStyleDataset.js'
3
3
  import { datasetRegistry } from './datasetRegistry.js'
4
4
  import { attachGlobalState } from './globalDataset.js'
5
- import { hashString } from '../../../../src/utils/patternUtils.js'
5
+ import { hashString } from '../../../../src/utils/hashString.js'
6
6
  // Use the mock datasetRegistry with the demo datasets attached before each test
7
7
  jest.mock('./datasetRegistry.js')
8
8