@defra/interactive-map 0.0.53-alpha → 0.0.55-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 (199) hide show
  1. package/assets/templates/add-polygons.njk +1 -1
  2. package/assets/templates/add-symbols.njk +4 -4
  3. package/assets/templates/draw-tools.njk +7 -7
  4. package/assets/templates/marker-panel.njk +5 -5
  5. package/assets/templates/place-marker.njk +8 -8
  6. package/assets/templates/search-control.njk +1 -1
  7. package/assets/templates/select-feature.njk +7 -7
  8. package/assets/templates/style-switcher.njk +4 -4
  9. package/assets/templates/toggle-marker-label.njk +3 -3
  10. package/dist/css/index.css +1 -1
  11. package/dist/esm/im-core.js +1 -1
  12. package/dist/esm/im-shell.js +1 -1
  13. package/dist/esm/index.js +1 -1
  14. package/dist/umd/im-core.js +1 -1
  15. package/dist/umd/im-core.js.LICENSE.txt +0 -30
  16. package/dist/umd/index.js +1 -1
  17. package/dist/umd/index.js.LICENSE.txt +0 -20
  18. package/docs/api/context.md +12 -0
  19. package/docs/api.md +14 -16
  20. package/docs/building-a-plugin.md +2 -2
  21. package/docs/examples/add-marker-with-panel.mdx +46 -44
  22. package/docs/examples/add-polygons.mdx +100 -98
  23. package/docs/examples/add-symbols.mdx +75 -73
  24. package/docs/examples/basic-map.mdx +16 -14
  25. package/docs/examples/button-map.mdx +16 -14
  26. package/docs/examples/draw-tools.mdx +119 -117
  27. package/docs/examples/place-marker.mdx +51 -49
  28. package/docs/examples/search-control.mdx +22 -20
  29. package/docs/examples/select-feature.mdx +107 -105
  30. package/docs/examples/style-switcher.mdx +47 -45
  31. package/docs/examples/toggle-marker-label.mdx +30 -28
  32. package/docs/getting-started.md +26 -24
  33. package/docs/plugins/datasets.md +2 -0
  34. package/docs/plugins/draw.md +10 -10
  35. package/docs/plugins/interact.md +9 -9
  36. package/docs/plugins/map-key.md +41 -0
  37. package/docs/plugins/plugin-descriptor.md +1 -1
  38. package/docs/plugins/search.md +3 -3
  39. package/docusaurus.config.cjs +23 -0
  40. package/package.json +3 -7
  41. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  42. package/plugins/beta/draw-es/dist/esm/index.js +1 -1
  43. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  44. package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
  45. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  46. package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
  47. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
  48. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  49. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
  50. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  51. package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
  52. package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
  53. package/plugins/beta/frame/dist/esm/index.js +1 -1
  54. package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
  55. package/plugins/beta/frame/dist/umd/index.js +1 -1
  56. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  57. package/plugins/beta/map-styles/dist/esm/index.js +1 -1
  58. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  59. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  60. package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
  61. package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
  62. package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
  63. package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
  64. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
  65. package/plugins/beta/use-location/dist/esm/index.js +1 -1
  66. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
  67. package/plugins/beta/use-location/dist/umd/index.js +1 -1
  68. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  69. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  70. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  71. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  72. package/plugins/datasets/dist/esm/index.js +1 -1
  73. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  74. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  75. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  76. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  77. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  78. package/plugins/datasets/dist/umd/index.js +1 -1
  79. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
  80. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  81. package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +1 -1
  82. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +3 -3
  83. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
  84. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +1 -3
  85. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +0 -12
  86. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +2 -2
  87. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +1 -2
  88. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +3 -3
  89. package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
  90. package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
  91. package/plugins/datasets/src/initialise/defaults.js +12 -24
  92. package/plugins/datasets/src/initialise/defaults.test.js +25 -57
  93. package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
  94. package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
  95. package/plugins/datasets/src/registry/dataset.js +21 -16
  96. package/plugins/datasets/src/registry/dataset.test.js +101 -11
  97. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  98. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  99. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  100. package/plugins/draw/dist/esm/index.js +1 -1
  101. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  102. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  103. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  104. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  105. package/plugins/draw/dist/umd/index.js +1 -1
  106. package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
  107. package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
  108. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  109. package/plugins/interact/dist/esm/index.js +1 -1
  110. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  111. package/plugins/interact/dist/umd/index.js +1 -1
  112. package/plugins/map-key/dist/css/index.css +1 -1
  113. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  114. package/plugins/map-key/dist/esm/index.js +1 -1
  115. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  116. package/plugins/map-key/dist/umd/index.js +1 -1
  117. package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
  118. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +34 -3
  119. package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
  120. package/plugins/map-key/src/components/Key/KeySvg.jsx +5 -5
  121. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +4 -4
  122. package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
  123. package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
  124. package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
  125. package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
  126. package/plugins/map-key/src/index.js +34 -0
  127. package/plugins/map-key/src/utils/groupStyles.js +5 -2
  128. package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
  129. package/plugins/menu/dist/esm/index.js +1 -1
  130. package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
  131. package/plugins/menu/dist/umd/index.js +1 -1
  132. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  133. package/plugins/search/dist/esm/index.js +1 -1
  134. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  135. package/plugins/search/dist/umd/index.js +1 -1
  136. package/plugins/search/src/Search.jsx +0 -1
  137. package/plugins/search/src/components/Form/Form.jsx +3 -3
  138. package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
  139. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
  140. package/plugins/search/src/defaults.js +3 -0
  141. package/plugins/search/src/events/formHandlers.js +3 -9
  142. package/plugins/search/src/events/formHandlers.test.js +6 -9
  143. package/plugins/search/src/events/inputHandlers.js +8 -2
  144. package/plugins/search/src/events/inputHandlers.test.js +20 -0
  145. package/plugins/search/src/events/suggestionHandlers.js +3 -5
  146. package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
  147. package/plugins/search/src/utils/showResult.js +9 -0
  148. package/plugins/search/src/utils/showResult.test.js +16 -0
  149. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  150. package/providers/beta/esri/dist/esm/index.js +1 -1
  151. package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
  152. package/providers/beta/open-names/dist/esm/index.js +1 -1
  153. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
  154. package/providers/beta/open-names/dist/umd/index.js +1 -1
  155. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  156. package/providers/beta/openlayers/dist/esm/index.js +1 -1
  157. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  158. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  159. package/providers/beta/openlayers/src/index.js +27 -4
  160. package/providers/beta/openlayers/src/index.test.js +47 -0
  161. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  162. package/providers/maplibre/dist/esm/index.js +1 -1
  163. package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
  164. package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
  165. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  166. package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
  167. package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
  168. package/providers/maplibre/dist/umd/index.js +1 -1
  169. package/providers/maplibre/src/index.js +41 -12
  170. package/providers/maplibre/src/index.test.js +43 -12
  171. package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
  172. package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
  173. package/providers/maplibre/src/utils/spatial.js +22 -12
  174. package/providers/maplibre/src/utils/spatial.test.js +6 -6
  175. package/providers/maplibre/src/utils/workerUrl.js +15 -0
  176. package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
  177. package/rollup.esm.mjs +38 -1
  178. package/src/App/components/Hints/Hints.module.scss +1 -1
  179. package/src/App/components/Viewport/Viewport.jsx +6 -4
  180. package/src/App/components/Viewport/Viewport.test.jsx +18 -1
  181. package/src/App/hooks/useMapAnnouncements.js +7 -2
  182. package/src/App/hooks/useMapAnnouncements.test.js +13 -2
  183. package/src/App/hooks/useModalPanelBehaviour.js +3 -1
  184. package/src/App/initialiseApp.js +1 -1
  185. package/src/App/store/ServiceProvider.jsx +7 -1
  186. package/src/App/store/ServiceProvider.test.jsx +15 -0
  187. package/src/InteractiveMap/InteractiveMap.js +5 -4
  188. package/src/InteractiveMap/InteractiveMap.test.js +9 -2
  189. package/src/InteractiveMap/domStateManager.js +21 -1
  190. package/src/InteractiveMap/domStateManager.test.js +48 -1
  191. package/src/InteractiveMap/polyfills.js +4 -3
  192. package/src/InteractiveMap/polyfills.test.js +12 -0
  193. package/src/services/mapFocus.js +64 -0
  194. package/src/services/mapFocus.test.js +76 -0
  195. package/src/types.js +5 -7
  196. package/src/utils/detectInterfaceType.js +16 -5
  197. package/src/utils/detectInterfaceType.test.js +32 -0
  198. package/webpack.dev.mjs +2 -0
  199. package/webpack.umd.mjs +28 -7
@@ -56,7 +56,7 @@ export function DatasetsInit ({ pluginConfig, pluginState, mapState, mapProvider
56
56
  })
57
57
  }
58
58
 
59
- initDatasets()
59
+ initDatasets() // NOSONAR: Not changing for now as used in production
60
60
  }, [isBaseMapReady])
61
61
 
62
62
  useEffect(() => {
@@ -78,7 +78,7 @@ export function DatasetsInit ({ pluginConfig, pluginState, mapState, mapProvider
78
78
  // MAP_STYLE_CHANGE, see useHighlightSync.js) pick up the new theme's selected/active
79
79
  // symbol images, instead of a highlight staying stuck on whatever was cached moments
80
80
  // before the switch.
81
- Promise.resolve(layerAdapter.onMapStyleChange()).then(() => {
81
+ Promise.resolve(layerAdapter.onMapStyleChange()).then(() => { // NOSONAR: Not changing for now as used in production
82
82
  eventBus.emit(EVENTS.MAP_DATA_CHANGE)
83
83
  })
84
84
  }
@@ -21,46 +21,34 @@ const STYLE_PROPS = [
21
21
  ...SYMBOL_STYLE_KEYS
22
22
  ]
23
23
 
24
- // Props whose presence in a style object indicates a custom visual style.
25
- // 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.
26
26
  const VISUAL_STYLE_PROPS = ['stroke', 'fill', 'fillPattern', 'fillPatternSvgContent', 'symbol', 'symbolSvgContent']
27
27
 
28
28
  const hasCustomVisualStyle = (style) =>
29
29
  VISUAL_STYLE_PROPS.some(prop => prop in style)
30
30
 
31
31
  /**
32
- * Merge a dataset config with defaults, flattening the nested `style` object.
33
- * Style properties must be provided via dataset.style — top-level occurrences are ignored.
34
- * symbolDescription from defaults.style is dropped when custom visual styles
35
- * 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.
36
34
  */
37
- const applyDatasetDefaults = (dataset, defaults) => {
38
- const style = dataset.style || {}
39
- const mergedStyle = { ...defaults.style, ...style }
40
- if (!('symbolDescription' in style) && hasCustomVisualStyle(style)) {
41
- delete mergedStyle.symbolDescription
35
+ const applyStyleDefaults = (style = {}) => {
36
+ if (!hasCustomVisualStyle(style)) {
37
+ return { ...datasetDefaults.style, ...style }
42
38
  }
43
- const topLevel = { ...dataset }
44
- delete topLevel.style
45
- STYLE_PROPS.forEach(prop => delete topLevel[prop])
46
- const topLevelDefaults = { ...defaults }
47
- delete topLevelDefaults.style
48
- return { ...topLevelDefaults, ...topLevel, ...mergedStyle }
39
+ return { strokeWidth: datasetDefaults.style.strokeWidth, ...style }
49
40
  }
50
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.
51
44
  const applyDatasetDefaultsWithoutFlattening = (dataset) => {
52
45
  // Allow for existing configs that use visibility instead of visible, but default to visible if neither is set
53
46
  if (dataset.visible !== true && dataset.visible !== false) {
54
47
  dataset.visible = dataset.visibility !== 'hidden'
55
48
  }
56
- const datasetWithDefaults = { ...datasetDefaults, ...dataset, style: { ...datasetDefaults.style, ...dataset.style } }
57
-
58
- const style = dataset.style || {}
59
- if (!('symbolDescription' in style) && hasCustomVisualStyle(style)) {
60
- delete datasetWithDefaults.style.symbolDescription
61
- }
49
+ const datasetWithDefaults = { ...datasetDefaults, ...dataset, style: { ...dataset.style } }
62
50
  STYLE_PROPS.forEach(prop => delete datasetWithDefaults[prop])
63
51
  return datasetWithDefaults
64
52
  }
65
53
 
66
- 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
 
@@ -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,6 +1,6 @@
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
5
  import { hasSymbol } from '../../../../src/utils/symbolUtils.js'
6
6
  import { DynamicGeoJson } from './dynamicGeoJson.js'
@@ -164,21 +164,26 @@ export class Dataset {
164
164
  return undefined
165
165
  }
166
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
+
167
185
  get style () {
168
- const parentStyle = this.parent?.style
169
- if (parentStyle) {
170
- // Here - we must set the merge styles opacity to undefined before the specific child opacity
171
- // so that we can correctly calculate opacity in the Dataset.opacity getter
172
- // - otherwise if opacity mode multiply is set,
173
- // any child with a parent opacity only would be multiplied by itself
174
- return {
175
- ...parentStyle,
176
- opacity: undefined, // NOSONAR - we need to set this to undefined so that the opacity getter can calculate the correct opacity
177
- ...this._datasetDefinition.style,
178
- symbolDescription: this.symbolDescription
179
- }
180
- }
181
- return this._datasetDefinition.style || {}
186
+ return { ...applyStyleDefaults(this.inheritedStyle), symbolDescription: this.symbolDescription }
182
187
  }
183
188
 
184
189
  get hasCustomVisualStyle () {
@@ -192,7 +197,7 @@ export class Dataset {
192
197
  if (this.hasCustomVisualStyle) {
193
198
  return undefined
194
199
  }
195
- return this.parent?.symbolDescription
200
+ return this.parent ? this.parent.symbolDescription : datasetDefaults.style.symbolDescription
196
201
  }
197
202
 
198
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,13 @@ 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
+ })
105
129
  })
106
130
  })
107
131
 
@@ -147,14 +171,19 @@ describe('Dataset class', () => {
147
171
  expect(dataset.symbolDescription).toBe('a circle')
148
172
  })
149
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
+
150
179
  it('returns undefined when the dataset has a custom visual style but no symbolDescription', () => {
151
180
  const dataset = new Dataset({ style: { stroke: '#ff0000' } })
152
181
  expect(dataset.symbolDescription).toBeUndefined()
153
182
  })
154
183
 
155
- it('returns undefined when the dataset has no style', () => {
184
+ it('returns the default symbolDescription when the dataset has no style', () => {
156
185
  const dataset = new Dataset({})
157
- expect(dataset.symbolDescription).toBeUndefined()
186
+ expect(dataset.symbolDescription).toBe('red outline')
158
187
  })
159
188
 
160
189
  it("inherits the parent's symbolDescription when the sublayer has no custom visual style", () => {
@@ -178,6 +207,67 @@ describe('Dataset class', () => {
178
207
  })
179
208
  })
180
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
+
181
271
  describe('label', () => {
182
272
  it('returns the dataset label', () => {
183
273
  const dataset = new Dataset({ label: 'My dataset' })