@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.
- package/assets/templates/add-polygons.njk +1 -1
- package/assets/templates/add-symbols.njk +4 -4
- package/assets/templates/draw-tools.njk +7 -7
- package/assets/templates/marker-panel.njk +5 -5
- package/assets/templates/place-marker.njk +8 -8
- package/assets/templates/search-control.njk +1 -1
- package/assets/templates/select-feature.njk +7 -7
- package/assets/templates/style-switcher.njk +4 -4
- package/assets/templates/toggle-marker-label.njk +3 -3
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/im-core.js.LICENSE.txt +0 -30
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.LICENSE.txt +0 -20
- package/docs/api/context.md +12 -0
- package/docs/api.md +14 -16
- package/docs/building-a-plugin.md +2 -2
- package/docs/examples/add-marker-with-panel.mdx +46 -44
- package/docs/examples/add-polygons.mdx +100 -98
- package/docs/examples/add-symbols.mdx +75 -73
- package/docs/examples/basic-map.mdx +16 -14
- package/docs/examples/button-map.mdx +16 -14
- package/docs/examples/draw-tools.mdx +119 -117
- package/docs/examples/place-marker.mdx +51 -49
- package/docs/examples/search-control.mdx +22 -20
- package/docs/examples/select-feature.mdx +107 -105
- package/docs/examples/style-switcher.mdx +47 -45
- package/docs/examples/toggle-marker-label.mdx +30 -28
- package/docs/getting-started.md +26 -24
- package/docs/plugins/datasets.md +2 -0
- package/docs/plugins/draw.md +10 -10
- package/docs/plugins/interact.md +9 -9
- package/docs/plugins/map-key.md +41 -0
- package/docs/plugins/plugin-descriptor.md +1 -1
- package/docs/plugins/search.md +3 -3
- package/docusaurus.config.cjs +23 -0
- package/package.json +3 -7
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/index.js +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/esm/index.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
- package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/esm/index.js +1 -1
- package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
- package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +3 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +1 -3
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +0 -12
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +2 -2
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +1 -2
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +3 -3
- package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
- package/plugins/datasets/src/initialise/defaults.js +12 -24
- package/plugins/datasets/src/initialise/defaults.test.js +25 -57
- package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
- package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
- package/plugins/datasets/src/registry/dataset.js +21 -16
- package/plugins/datasets/src/registry/dataset.test.js +101 -11
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
- package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/esm/index.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/map-key/dist/css/index.css +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/esm/index.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
- package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +34 -3
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +5 -5
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +4 -4
- package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
- package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
- package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
- package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
- package/plugins/map-key/src/index.js +34 -0
- package/plugins/map-key/src/utils/groupStyles.js +5 -2
- package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/esm/index.js +1 -1
- package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/umd/index.js +1 -1
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/esm/index.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/plugins/search/src/Search.jsx +0 -1
- package/plugins/search/src/components/Form/Form.jsx +3 -3
- package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
- package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
- package/plugins/search/src/defaults.js +3 -0
- package/plugins/search/src/events/formHandlers.js +3 -9
- package/plugins/search/src/events/formHandlers.test.js +6 -9
- package/plugins/search/src/events/inputHandlers.js +8 -2
- package/plugins/search/src/events/inputHandlers.test.js +20 -0
- package/plugins/search/src/events/suggestionHandlers.js +3 -5
- package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
- package/plugins/search/src/utils/showResult.js +9 -0
- package/plugins/search/src/utils/showResult.test.js +16 -0
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/index.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/index.js +27 -4
- package/providers/beta/openlayers/src/index.test.js +47 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
- package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +41 -12
- package/providers/maplibre/src/index.test.js +43 -12
- package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
- package/providers/maplibre/src/utils/spatial.js +22 -12
- package/providers/maplibre/src/utils/spatial.test.js +6 -6
- package/providers/maplibre/src/utils/workerUrl.js +15 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
- package/rollup.esm.mjs +38 -1
- package/src/App/components/Hints/Hints.module.scss +1 -1
- package/src/App/components/Viewport/Viewport.jsx +6 -4
- package/src/App/components/Viewport/Viewport.test.jsx +18 -1
- package/src/App/hooks/useMapAnnouncements.js +7 -2
- package/src/App/hooks/useMapAnnouncements.test.js +13 -2
- package/src/App/hooks/useModalPanelBehaviour.js +3 -1
- package/src/App/initialiseApp.js +1 -1
- package/src/App/store/ServiceProvider.jsx +7 -1
- package/src/App/store/ServiceProvider.test.jsx +15 -0
- package/src/InteractiveMap/InteractiveMap.js +5 -4
- package/src/InteractiveMap/InteractiveMap.test.js +9 -2
- package/src/InteractiveMap/domStateManager.js +21 -1
- package/src/InteractiveMap/domStateManager.test.js +48 -1
- package/src/InteractiveMap/polyfills.js +4 -3
- package/src/InteractiveMap/polyfills.test.js +12 -0
- package/src/services/mapFocus.js +64 -0
- package/src/services/mapFocus.test.js +76 -0
- package/src/types.js +5 -7
- package/src/utils/detectInterfaceType.js +16 -5
- package/src/utils/detectInterfaceType.test.js +32 -0
- package/webpack.dev.mjs +2 -0
- 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
|
|
25
|
-
//
|
|
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
|
-
*
|
|
33
|
-
*
|
|
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
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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: { ...
|
|
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,
|
|
54
|
+
export { datasetDefaults, hasCustomVisualStyle, applyStyleDefaults, applyDatasetDefaultsWithoutFlattening }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { datasetDefaults, hasCustomVisualStyle,
|
|
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('
|
|
58
|
-
|
|
59
|
-
|
|
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('
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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('
|
|
98
|
-
|
|
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('
|
|
104
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
const result =
|
|
112
|
-
expect(result
|
|
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('
|
|
116
|
-
|
|
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('
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
expect(result).not.toHaveProperty('
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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 =
|
|
95
|
-
expect(dataset.style
|
|
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 =
|
|
104
|
-
|
|
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
|
|
184
|
+
it('returns the default symbolDescription when the dataset has no style', () => {
|
|
156
185
|
const dataset = new Dataset({})
|
|
157
|
-
expect(dataset.symbolDescription).
|
|
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' })
|