@defra/interactive-map 0.0.59-alpha → 0.0.60-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 +2 -2
- package/assets/templates/add-symbols.njk +2 -2
- 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/panel-definition.md +30 -0
- package/docs/api/symbol-config.md +12 -0
- package/docs/api.md +21 -2
- package/docs/assets/images/slot-map.svg +3 -3
- package/docs/plugins/datasets.md +11 -1
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.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/index.js +0 -1
- package/plugins/datasets/src/index.test.js +2 -8
- package/plugins/datasets/src/registry/dataset.test.js +9 -0
- 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/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +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 -1
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/src/components/Form/Form.module.scss +1 -0
- package/providers/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/esri/src/esriProvider.js +10 -21
- package/providers/esri/src/utils/coords.js +37 -7
- package/providers/esri/src/utils/coords.test.js +22 -1
- package/providers/esri/src/utils/spatial.js +1 -47
- 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/src/maplibreProvider.js +5 -14
- package/providers/maplibre/src/maplibreProvider.test.js +143 -146
- package/providers/maplibre/src/utils/spatial.js +0 -40
- package/providers/maplibre/src/utils/spatial.test.js +0 -35
- package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/openlayers/src/openlayersProvider.js +5 -14
- package/providers/openlayers/src/openlayersProvider.test.js +12 -10
- package/providers/openlayers/src/utils/spatial.js +0 -39
- package/providers/openlayers/src/utils/spatial.test.js +1 -26
- package/src/App/components/Hints/Hints.jsx +9 -21
- package/src/App/components/Hints/Hints.test.jsx +20 -33
- package/src/App/components/Panel/Panel.jsx +16 -1
- package/src/App/components/Panel/Panel.test.jsx +44 -0
- package/src/App/hooks/useCrossHairAPI.js +27 -28
- package/src/App/hooks/useCrossHairAPI.test.js +64 -7
- package/src/App/hooks/useLayoutMeasurements.js +175 -131
- package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
- package/src/App/hooks/useMapProviderOverrides.js +114 -35
- package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
- package/src/App/hooks/useModalPanelBehaviour.js +18 -32
- package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
- package/src/App/hooks/useVisibleGeometry.js +35 -45
- package/src/App/hooks/useVisibleGeometry.test.js +149 -121
- package/src/App/layout/Layout.jsx +4 -4
- package/src/App/layout/layout.module.scss +124 -61
- package/src/App/store/AppProvider.jsx +3 -0
- package/src/App/store/appDispatchMiddleware.js +18 -10
- package/src/App/store/appDispatchMiddleware.test.js +42 -4
- package/src/InteractiveMap/InteractiveMap.js +3 -2
- package/src/InteractiveMap/InteractiveMap.test.js +2 -2
- package/src/config/events.js +1 -1
- package/src/config/mapPanelSlots.js +8 -0
- package/src/config/symbolConfig.js +1 -1
- package/src/services/symbolRegistry.js +1 -1
- package/src/services/symbolRegistry.test.js +19 -0
- package/src/types.js +29 -8
- package/src/utils/getFitMove.js +73 -0
- package/src/utils/getFitMove.test.js +114 -0
- package/src/utils/getSafeZoneInset.js +122 -77
- package/src/utils/getSafeZoneInset.test.js +241 -54
- package/src/utils/getValueForStyle.js +10 -5
- package/src/utils/getValueForStyle.test.js +13 -2
- package/src/utils/renderedBoxes.js +25 -0
- package/src/utils/renderedBoxes.test.js +61 -0
- package/src/utils/screenBox.js +70 -0
- package/src/utils/screenBox.test.js +69 -0
- package/src/utils/symbolUtils.js +9 -9
- package/src/utils/symbolUtils.test.js +21 -0
- package/providers/esri/src/utils/spatial.test.js +0 -58
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getScreenBox, getRelativeBox, getBoxCenter, isInside, isOverlapping } from './screenBox.js'
|
|
2
|
+
|
|
3
|
+
describe('getScreenBox', () => {
|
|
4
|
+
// Projects [x, y] to { x, y } with y flipped, as screens count down from the top
|
|
5
|
+
const mapToScreen = ([x, y]) => ({ x, y: -y })
|
|
6
|
+
|
|
7
|
+
test('bounds the projected corners of a flat bounds array', () => {
|
|
8
|
+
expect(getScreenBox([10, 20, 30, 40], mapToScreen)).toEqual({ left: 10, top: -40, right: 30, bottom: -20 })
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('accepts nested [[west, south], [east, north]] bounds', () => {
|
|
12
|
+
expect(getScreenBox([[10, 20], [30, 40]], mapToScreen)).toEqual({ left: 10, top: -40, right: 30, bottom: -20 })
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('works out the bounds of GeoJSON', () => {
|
|
16
|
+
const feature = { type: 'Feature', geometry: { type: 'LineString', coordinates: [[10, 40], [30, 20]] }, properties: {} }
|
|
17
|
+
expect(getScreenBox(feature, mapToScreen)).toEqual({ left: 10, top: -40, right: 30, bottom: -20 })
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('ignores heights in 3D GeoJSON', () => {
|
|
21
|
+
const feature = { type: 'Feature', geometry: { type: 'LineString', coordinates: [[10, 40, 5], [30, 20, 9]] }, properties: {} }
|
|
22
|
+
expect(getScreenBox(feature, mapToScreen)).toEqual({ left: 10, top: -40, right: 30, bottom: -20 })
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('gives a point a box with no size', () => {
|
|
26
|
+
expect(getScreenBox({ type: 'Point', coordinates: [10, 20] }, mapToScreen)).toEqual({ left: 10, top: -20, right: 10, bottom: -20 })
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('multiplies the projected pixels by the scale', () => {
|
|
30
|
+
expect(getScreenBox([10, 20, 30, 40], mapToScreen, 2)).toEqual({ left: 20, top: -80, right: 60, bottom: -40 })
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('getRelativeBox', () => {
|
|
35
|
+
test('makes a rect relative to another', () => {
|
|
36
|
+
expect(getRelativeBox({ left: 110, top: 70, right: 210, bottom: 170 }, { left: 10, top: 20 })).toEqual({ left: 100, top: 50, right: 200, bottom: 150 })
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('getBoxCenter', () => {
|
|
41
|
+
test('gives the middle of a box', () => {
|
|
42
|
+
expect(getBoxCenter({ left: 100, top: 50, right: 300, bottom: 150 })).toEqual([200, 100])
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
describe('isInside', () => {
|
|
47
|
+
const area = { left: 100, top: 50, right: 300, bottom: 150 }
|
|
48
|
+
|
|
49
|
+
test('is true for a box within the area, including one touching its edges', () => {
|
|
50
|
+
expect(isInside({ left: 150, top: 60, right: 250, bottom: 100 }, area)).toBe(true)
|
|
51
|
+
expect(isInside(area, area)).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('is false for a box that crosses an edge', () => {
|
|
55
|
+
expect(isInside({ left: 250, top: 60, right: 350, bottom: 100 }, area)).toBe(false)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('isOverlapping', () => {
|
|
60
|
+
const area = { left: 100, top: 50, right: 300, bottom: 120 }
|
|
61
|
+
|
|
62
|
+
test('is true for boxes that overlap', () => {
|
|
63
|
+
expect(isOverlapping({ left: 250, top: 100, right: 350, bottom: 200 }, area)).toBe(true)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('is false for boxes that only touch at an edge', () => {
|
|
67
|
+
expect(isOverlapping({ left: 300, top: 60, right: 350, bottom: 100 }, area)).toBe(false)
|
|
68
|
+
})
|
|
69
|
+
})
|
package/src/utils/symbolUtils.js
CHANGED
|
@@ -5,12 +5,12 @@ import { logger } from '../services/logger.js'
|
|
|
5
5
|
const reportedSizes = new Set()
|
|
6
6
|
const quoted = (text) => `'${text}'`
|
|
7
7
|
|
|
8
|
-
// Symbol style props in dataset style
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
'
|
|
8
|
+
// Symbol style props in a dataset style use the 'symbol' prefix to distinguish them from fill/stroke
|
|
9
|
+
// props at the same level. Any of them that isn't structural carries a token value, and the prefix
|
|
10
|
+
// is stripped before passing tokens to the registry (e.g. symbolAccentColor → accentColor).
|
|
11
|
+
const SYMBOL_PROP = /^symbol[A-Z]/
|
|
12
|
+
const STRUCTURAL_SYMBOL_PROPS = new Set([
|
|
13
|
+
'symbolSvgContent', 'symbolViewBox', 'symbolAnchor', 'symbolSize', 'symbolDescription'
|
|
14
14
|
])
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -49,11 +49,11 @@ export const isStandaloneLabel = (marker) => {
|
|
|
49
49
|
export const getSymbolStyleColors = (dataset) => {
|
|
50
50
|
if (!hasSymbol(dataset)) { return {} }
|
|
51
51
|
const tokens = {}
|
|
52
|
-
|
|
53
|
-
if (
|
|
52
|
+
Object.entries(dataset).forEach(([key, value]) => {
|
|
53
|
+
if (SYMBOL_PROP.test(key) && !STRUCTURAL_SYMBOL_PROPS.has(key) && value != null) {
|
|
54
54
|
// Strip 'symbol' prefix: symbolBackgroundColor → backgroundColor
|
|
55
55
|
const tokenKey = key.charAt(6).toLowerCase() + key.slice(7) // NOSONAR
|
|
56
|
-
tokens[tokenKey] =
|
|
56
|
+
tokens[tokenKey] = value
|
|
57
57
|
}
|
|
58
58
|
})
|
|
59
59
|
return tokens
|
|
@@ -98,6 +98,27 @@ describe('getSymbolStyleColors', () => {
|
|
|
98
98
|
expect(result).not.toHaveProperty('foregroundColor')
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
+
it('passes a custom symbol prop as the token named after it', () => {
|
|
102
|
+
const dataset = { symbol: 'pin', symbolAccentColor: { outdoor: '#ffdd00', dark: '#f47738' } }
|
|
103
|
+
expect(getSymbolStyleColors(dataset)).toEqual({ accentColor: { outdoor: '#ffdd00', dark: '#f47738' } })
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('does not use structural props as tokens', () => {
|
|
107
|
+
const dataset = {
|
|
108
|
+
symbol: 'pin',
|
|
109
|
+
symbolSvgContent: '<circle/>',
|
|
110
|
+
symbolViewBox: '0 0 10 10',
|
|
111
|
+
symbolAnchor: [0.5, 0.5],
|
|
112
|
+
symbolSize: 'large',
|
|
113
|
+
symbolDescription: 'A pin'
|
|
114
|
+
}
|
|
115
|
+
expect(getSymbolStyleColors(dataset)).toEqual({})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('ignores props that only start with the word symbol', () => {
|
|
119
|
+
expect(getSymbolStyleColors({ symbol: 'pin', symbolic: 'yes', stroke: '#000000' })).toEqual({})
|
|
120
|
+
})
|
|
121
|
+
|
|
101
122
|
it('supports style-keyed colour objects', () => {
|
|
102
123
|
const dataset = {
|
|
103
124
|
symbol: 'pin',
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { isGeometryObscured } from './spatial.js'
|
|
2
|
-
|
|
3
|
-
jest.mock('@arcgis/core/geometry/Extent.js', () =>
|
|
4
|
-
jest.fn().mockImplementation((opts) => ({ ...opts, type: 'extent' }))
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
jest.mock('@arcgis/core/geometry/Point.js', () =>
|
|
8
|
-
jest.fn().mockImplementation((opts) => ({ ...opts, type: 'point' }))
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
jest.mock('./coords.js', () => ({
|
|
12
|
-
getBboxFromGeoJSON: jest.fn(() => ({
|
|
13
|
-
xmin: 100,
|
|
14
|
-
ymin: 200,
|
|
15
|
-
xmax: 500,
|
|
16
|
-
ymax: 600,
|
|
17
|
-
spatialReference: { wkid: 27700 },
|
|
18
|
-
type: 'extent'
|
|
19
|
-
}))
|
|
20
|
-
}))
|
|
21
|
-
|
|
22
|
-
describe('isGeometryObscured', () => {
|
|
23
|
-
const geojson = { type: 'Feature', geometry: { type: 'Point', coordinates: [300, 400] }, properties: {} }
|
|
24
|
-
|
|
25
|
-
// Container sits at viewport origin so container-relative coords equal viewport coords
|
|
26
|
-
const makeView = (toScreenFn) => ({
|
|
27
|
-
container: {
|
|
28
|
-
getBoundingClientRect: jest.fn(() => ({ left: 0, top: 0, right: 1000, bottom: 800 }))
|
|
29
|
-
},
|
|
30
|
-
toScreen: jest.fn(toScreenFn)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
// Panel occupies the right 400px of the viewport
|
|
34
|
-
const panelRect = { left: 600, top: 0, right: 1000, bottom: 800, width: 400, height: 800 }
|
|
35
|
-
|
|
36
|
-
test('returns false when view has no container', () => {
|
|
37
|
-
expect(isGeometryObscured(geojson, panelRect, null)).toBe(false)
|
|
38
|
-
expect(isGeometryObscured(geojson, panelRect, {})).toBe(false)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
test('returns true when geometry screen bbox overlaps the panel rect', () => {
|
|
42
|
-
// Corners project into the panel (x: 650 is between panelLeft 600 and panelRight 1000)
|
|
43
|
-
const view = makeView(() => ({ x: 650, y: 400 }))
|
|
44
|
-
expect(isGeometryObscured(geojson, panelRect, view)).toBe(true)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('returns false when geometry screen bbox does not overlap the panel rect', () => {
|
|
48
|
-
// Corners project to x: 300, entirely left of panelLeft (600)
|
|
49
|
-
const view = makeView(() => ({ x: 300, y: 400 }))
|
|
50
|
-
expect(isGeometryObscured(geojson, panelRect, view)).toBe(false)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test('projects all four bbox corners', () => {
|
|
54
|
-
const view = makeView(() => ({ x: 300, y: 400 }))
|
|
55
|
-
isGeometryObscured(geojson, panelRect, view)
|
|
56
|
-
expect(view.toScreen).toHaveBeenCalledTimes(4)
|
|
57
|
-
})
|
|
58
|
-
})
|