@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.
- 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/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/context.md +30 -12
- package/docs/api/marker-config.md +16 -8
- package/docs/api/symbol-config.md +24 -9
- package/docs/api/symbol-registry.md +49 -14
- package/docs/api.md +11 -3
- package/docs/plugins/datasets.md +6 -10
- package/docs/plugins/draw.md +2 -1
- package/docs/plugins/map-key.md +47 -4
- package/package.json +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.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/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/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/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 +10 -10
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +22 -6
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +20 -27
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +16 -70
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +30 -115
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +101 -13
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +27 -28
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +51 -32
- 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 +16 -27
- package/plugins/datasets/src/initialise/defaults.test.js +25 -57
- package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
- package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
- package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
- package/plugins/datasets/src/registry/dataset.js +23 -17
- package/plugins/datasets/src/registry/dataset.test.js +114 -11
- package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
- package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
- 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/DrawInit.jsx +7 -5
- package/plugins/draw/src/DrawInit.test.jsx +18 -2
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
- package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
- package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
- package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
- package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
- package/plugins/draw/src/defaults.js +2 -6
- package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
- package/plugins/draw/src/utils/symbolKeys.js +3 -4
- package/plugins/interact/dist/esm/im-interact-plugin.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/umd/im-map-key-plugin.js +1 -2
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/map-key/src/components/Key/Key.jsx +8 -4
- package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
- package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +36 -3
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
- package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +19 -18
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +25 -18
- package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
- package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
- 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/KeySvgSymbol.jsx +26 -12
- package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
- package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
- package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
- 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/reducers/mergeKeyGroupItems.test.js +15 -0
- package/plugins/map-key/src/registry/index.js +0 -2
- package/plugins/map-key/src/registry/index.test.js +1 -9
- package/plugins/map-key/src/utils/groupStyles.js +5 -2
- package/plugins/menu/src/registry/index.js +0 -2
- package/plugins/menu/src/registry/index.test.js +1 -9
- package/plugins/search/dist/esm/im-search-plugin.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/openlayers/dist/esm/im-openlayers-provider.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/openlayersProvider.js +102 -2
- package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
- package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
- package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
- package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
- package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
- package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
- package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
- package/providers/mapProvider.js +53 -1
- package/providers/mapProvider.test.js +6 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +50 -17
- package/providers/maplibre/src/maplibreProvider.test.js +74 -20
- package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
- package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
- package/providers/maplibre/src/utils/patternImages.js +46 -29
- package/providers/maplibre/src/utils/patternImages.test.js +52 -4
- package/providers/maplibre/src/utils/symbolImages.js +80 -39
- package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
- package/src/App/components/Hints/Hints.module.scss +1 -1
- package/src/App/components/Markers/Markers.jsx +16 -25
- package/src/App/components/Markers/Markers.test.jsx +34 -48
- package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
- package/src/App/components/Markers/SymbolMarker.jsx +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 +12 -3
- package/src/App/store/ServiceProvider.test.jsx +39 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -3
- package/src/config/appConfig.js +1 -5
- package/src/config/mapSizeScales.js +8 -0
- package/src/config/symbolConfig.js +101 -25
- package/src/services/mapFocus.js +64 -0
- package/src/services/mapFocus.test.js +76 -0
- package/src/services/patternRegistry.js +97 -76
- package/src/services/patternRegistry.test.js +19 -1
- package/src/services/symbolComposer.js +184 -0
- package/src/services/symbolComposer.test.js +132 -0
- package/src/services/symbolRegistry.js +326 -155
- package/src/services/symbolRegistry.test.js +334 -32
- package/src/types.js +11 -5
- package/src/utils/detectInterfaceType.js +16 -5
- package/src/utils/detectInterfaceType.test.js +32 -0
- package/src/utils/hashString.js +23 -0
- package/src/utils/hashString.test.js +29 -0
- package/src/utils/imageDataCache.js +43 -0
- package/src/utils/imageDataCache.test.js +38 -0
- package/src/utils/pathBounds.js +330 -0
- package/src/utils/pathBounds.test.js +145 -0
- package/src/utils/patternUtils.js +0 -8
- package/src/utils/patternUtils.test.js +0 -25
- package/src/utils/recentImageSets.js +35 -0
- package/src/utils/recentImageSets.test.js +46 -0
- package/src/utils/symbolUtils.js +26 -29
- package/src/utils/symbolUtils.test.js +27 -41
- package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
composeSymbolDef, applyAnchorOverride, scaleSvgSymbolDef, getGraphicTransform, renderComposed, renderTemplate
|
|
3
|
+
} from './symbolComposer.js'
|
|
4
|
+
import { circle, pin, graphics, SYMBOL_PADDING } from '../config/symbolConfig.js'
|
|
5
|
+
import { logger } from './logger.js'
|
|
6
|
+
|
|
7
|
+
jest.mock('./logger.js', () => ({ logger: { warn: jest.fn() } }))
|
|
8
|
+
|
|
9
|
+
const dims = (viewBox) => viewBox.split(' ').map(Number).slice(2)
|
|
10
|
+
const values = {
|
|
11
|
+
backgroundColor: '#ca3535',
|
|
12
|
+
foregroundColor: '#ffffff',
|
|
13
|
+
haloColor: '#ffffff',
|
|
14
|
+
selectedColor: 'none',
|
|
15
|
+
activeColor: 'none',
|
|
16
|
+
graphic: graphics.dot
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('composeSymbolDef', () => {
|
|
20
|
+
it('pads the scaled body by SYMBOL_PADDING on every side, rounded up to a multiple of 4', () => {
|
|
21
|
+
const [width, height] = dims(composeSymbolDef(circle, 1.25).viewBox)
|
|
22
|
+
// 26 × 1.25 + 16 = 48.5, rounded up to 52
|
|
23
|
+
expect(26 * 1.25 + SYMBOL_PADDING * 2).toBe(48.5)
|
|
24
|
+
expect(width).toBe(52)
|
|
25
|
+
expect(height).toBe(width)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('returns the same object for the same def and scale', () => {
|
|
29
|
+
expect(composeSymbolDef(pin, 0.75)).toBe(composeSymbolDef(pin, 0.75))
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('records the body\'s box within the viewBox', () => {
|
|
33
|
+
const { bodyBox, viewBox } = composeSymbolDef(circle, 1)
|
|
34
|
+
expect(bodyBox).toEqual([9, 9, 26, 26])
|
|
35
|
+
expect(dims(viewBox)).toEqual([44, 44])
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
describe('applyAnchorOverride', () => {
|
|
40
|
+
it('returns the def unchanged when there\'s no override', () => {
|
|
41
|
+
const sized = composeSymbolDef(circle, 1)
|
|
42
|
+
expect(applyAnchorOverride(sized, undefined)).toBe(sized)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('treats a built-in shape\'s override as a fraction of the shape, at every size', () => {
|
|
46
|
+
[0.75, 1, 1.25].forEach((scale) => {
|
|
47
|
+
const sized = composeSymbolDef(circle, scale)
|
|
48
|
+
const { anchor, viewBox } = applyAnchorOverride(sized, [0.5, 1])
|
|
49
|
+
const [width, height] = dims(viewBox)
|
|
50
|
+
const [x, y, w, h] = sized.bodyBox
|
|
51
|
+
// lands on the bottom-centre of the circle itself, not of its padded viewBox
|
|
52
|
+
expect(anchor[0] * width).toBeCloseTo(x + w / 2)
|
|
53
|
+
expect(anchor[1] * height).toBeCloseTo(y + h)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it.each([[[0.5]], [['0.5', '1']], [[0.5, Number.NaN]], ['bottom']])('ignores an invalid override %j, warning once', (anchor) => {
|
|
58
|
+
const sized = composeSymbolDef(circle, 1)
|
|
59
|
+
logger.warn.mockClear()
|
|
60
|
+
expect(applyAnchorOverride(sized, anchor)).toBe(sized)
|
|
61
|
+
expect(applyAnchorOverride(sized, anchor)).toBe(sized)
|
|
62
|
+
expect(logger.warn).toHaveBeenCalledTimes(1)
|
|
63
|
+
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Invalid symbolAnchor'))
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('uses an SVG-template symbol\'s override as given — a fraction of its own viewBox', () => {
|
|
67
|
+
const sized = scaleSvgSymbolDef({ svg: '<rect/>' }, '0 0 20 20', 1)
|
|
68
|
+
expect(applyAnchorOverride(sized, [0.1, 0.9]).anchor).toEqual([0.1, 0.9])
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('scaleSvgSymbolDef', () => {
|
|
73
|
+
it('leaves the svg as it is at scale 1', () => {
|
|
74
|
+
expect(scaleSvgSymbolDef({ svg: '<rect/>' }, '0 0 20 10', 1)).toEqual({ svg: '<rect/>', viewBox: '0 0 20 10', anchor: [0.5, 0.5] })
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('keeps the symbol\'s own anchor', () => {
|
|
78
|
+
expect(scaleSvgSymbolDef({ svg: '<rect/>', anchor: [0.5, 1] }, '0 0 20 10', 2).anchor).toEqual([0.5, 1])
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('scales the viewBox, origin included, and wraps the svg in a scale transform', () => {
|
|
82
|
+
expect(scaleSvgSymbolDef({ svg: '<rect/>' }, '2 4 20 10', 1.5)).toEqual({ svg: '<g transform="scale(1.5)"><rect/></g>', viewBox: '3 6 30 15', anchor: [0.5, 0.5] })
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('getGraphicTransform', () => {
|
|
87
|
+
it('leaves a graphic already centred in the 16×16 space where it is, at 0.8', () => {
|
|
88
|
+
Object.values(graphics).forEach((graphic) => {
|
|
89
|
+
expect(getGraphicTransform(graphic, 22, 20)).toBe('translate(22, 20) scale(0.8) translate(-8, -8)')
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('centres and shrinks a graphic drawn in a bigger space (e.g. a 24×24 icon)', () => {
|
|
94
|
+
// a square filling 0–24: centred on its middle (12, 12) and shrunk by 16/24
|
|
95
|
+
expect(getGraphicTransform('M0 0H24V24H0Z', 22, 22)).toBe('translate(22, 22) scale(0.533) translate(-12, -12)')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('centres a small off-centre graphic without enlarging it', () => {
|
|
99
|
+
expect(getGraphicTransform('M0 0H4V4H0Z', 22, 22)).toBe('translate(22, 22) scale(0.8) translate(-2, -2)')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('falls back to the 16×16 space\'s centre, with a warning, for a graphic it can\'t measure', () => {
|
|
103
|
+
expect(getGraphicTransform('not a path', 22, 22)).toBe('translate(22, 22) scale(0.8) translate(-8, -8)')
|
|
104
|
+
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('could not be measured'))
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('falls back to the 16×16 space\'s centre for no graphic', () => {
|
|
108
|
+
expect(getGraphicTransform('', 22, 22)).toBe('translate(22, 22) scale(0.8) translate(-8, -8)')
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
describe('renderComposed', () => {
|
|
113
|
+
const countPaths = (svg) => svg.match(/<path /g).length
|
|
114
|
+
|
|
115
|
+
it('emits only the body and graphic when no ring is showing', () => {
|
|
116
|
+
expect(countPaths(renderComposed(composeSymbolDef(circle, 1), values))).toBe(2)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('emits the selected ring, then the active ring, when their colours are set', () => {
|
|
120
|
+
const selected = renderComposed(composeSymbolDef(circle, 1), { ...values, selectedColor: '#0b0c0c' })
|
|
121
|
+
expect(countPaths(selected)).toBe(3)
|
|
122
|
+
const active = renderComposed(composeSymbolDef(circle, 1), { ...values, selectedColor: '#0b0c0c', activeColor: '#ffdd00' })
|
|
123
|
+
expect(countPaths(active)).toBe(4)
|
|
124
|
+
expect(active.indexOf('#ffdd00')).toBeLessThan(active.indexOf('#0b0c0c')) // active ring is drawn underneath
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe('renderTemplate', () => {
|
|
129
|
+
it('substitutes every occurrence of each token', () => {
|
|
130
|
+
expect(renderTemplate('<a fill="{{c}}"/><b fill="{{c}}"/>', { c: 'red' })).toBe('<a fill="red"/><b fill="red"/>')
|
|
131
|
+
})
|
|
132
|
+
})
|