@defra/interactive-map 0.0.59-alpha → 0.0.61-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 (125) hide show
  1. package/assets/templates/add-polygons.njk +2 -2
  2. package/assets/templates/add-symbols.njk +2 -2
  3. package/dist/css/index.css +1 -1
  4. package/dist/esm/im-core.js +1 -1
  5. package/dist/esm/im-shell.js +1 -1
  6. package/dist/umd/im-core.js +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/docs/api/button-definition.md +11 -0
  9. package/docs/api/context.md +2 -0
  10. package/docs/api/panel-definition.md +30 -0
  11. package/docs/api/symbol-config.md +12 -0
  12. package/docs/api.md +21 -2
  13. package/docs/assets/images/slot-map.svg +3 -3
  14. package/docs/plugins/datasets.md +11 -1
  15. package/docs/plugins/draw.md +26 -0
  16. package/package.json +1 -1
  17. package/plugins/datasets/dist/esm/index.js +1 -1
  18. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  19. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  20. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  21. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  22. package/plugins/datasets/dist/umd/index.js +1 -1
  23. package/plugins/datasets/src/index.js +0 -1
  24. package/plugins/datasets/src/index.test.js +2 -8
  25. package/plugins/datasets/src/registry/dataset.test.js +9 -0
  26. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  27. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  28. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  29. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  30. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  31. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  32. package/plugins/draw/dist/umd/index.js +1 -1
  33. package/plugins/draw/src/DrawInit.jsx +3 -0
  34. package/plugins/draw/src/DrawInit.test.jsx +16 -0
  35. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
  36. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
  37. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
  38. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
  39. package/plugins/draw/src/defaults.js +4 -0
  40. package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
  41. package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
  42. package/plugins/draw/src/manifest.js +4 -1
  43. package/plugins/draw/src/manifest.test.js +15 -2
  44. package/plugins/draw/src/utils/snapMinZoom.js +8 -0
  45. package/plugins/draw/src/utils/snapMinZoom.test.js +22 -0
  46. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  47. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  48. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  49. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  50. package/plugins/map-key/src/manifest.js +1 -1
  51. package/plugins/search/dist/css/index.css +1 -1
  52. package/plugins/search/src/components/Form/Form.module.scss +1 -0
  53. package/providers/esri/dist/esm/im-esri-provider.js +1 -1
  54. package/providers/esri/src/esriProvider.js +10 -21
  55. package/providers/esri/src/utils/coords.js +37 -7
  56. package/providers/esri/src/utils/coords.test.js +22 -1
  57. package/providers/esri/src/utils/spatial.js +1 -47
  58. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  59. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  60. package/providers/maplibre/src/maplibreProvider.js +5 -14
  61. package/providers/maplibre/src/maplibreProvider.test.js +143 -146
  62. package/providers/maplibre/src/utils/spatial.js +0 -40
  63. package/providers/maplibre/src/utils/spatial.test.js +0 -35
  64. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  65. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  66. package/providers/openlayers/src/openlayersProvider.js +5 -14
  67. package/providers/openlayers/src/openlayersProvider.test.js +12 -10
  68. package/providers/openlayers/src/utils/spatial.js +0 -39
  69. package/providers/openlayers/src/utils/spatial.test.js +1 -26
  70. package/src/App/components/Hints/Hints.jsx +9 -21
  71. package/src/App/components/Hints/Hints.test.jsx +20 -33
  72. package/src/App/components/MapButton/MapButton.jsx +20 -2
  73. package/src/App/components/MapButton/MapButton.module.scss +15 -1
  74. package/src/App/components/MapButton/MapButton.test.jsx +21 -3
  75. package/src/App/components/Panel/Panel.jsx +16 -1
  76. package/src/App/components/Panel/Panel.test.jsx +44 -0
  77. package/src/App/components/Tooltip/Tooltip.jsx +29 -11
  78. package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
  79. package/src/App/components/Viewport/MapController.jsx +2 -0
  80. package/src/App/components/Viewport/MapController.test.jsx +3 -0
  81. package/src/App/hooks/useCrossHairAPI.js +27 -28
  82. package/src/App/hooks/useCrossHairAPI.test.js +64 -7
  83. package/src/App/hooks/useLayoutMeasurements.js +175 -131
  84. package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
  85. package/src/App/hooks/useMapProviderOverrides.js +114 -35
  86. package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
  87. package/src/App/hooks/useModalPanelBehaviour.js +18 -32
  88. package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
  89. package/src/App/hooks/useUserMoveTracking.js +65 -0
  90. package/src/App/hooks/useUserMoveTracking.test.js +99 -0
  91. package/src/App/hooks/useVisibleGeometry.js +35 -45
  92. package/src/App/hooks/useVisibleGeometry.test.js +149 -121
  93. package/src/App/layout/Layout.jsx +4 -4
  94. package/src/App/layout/layout.module.scss +124 -61
  95. package/src/App/renderer/mapButtons.js +1 -0
  96. package/src/App/renderer/mapButtons.test.js +8 -0
  97. package/src/App/store/AppProvider.jsx +3 -0
  98. package/src/App/store/appDispatchMiddleware.js +18 -10
  99. package/src/App/store/appDispatchMiddleware.test.js +42 -4
  100. package/src/App/store/mapActionsMap.js +2 -1
  101. package/src/App/store/mapActionsMap.test.js +6 -0
  102. package/src/App/store/mapReducer.js +2 -0
  103. package/src/App/store/mapReducer.test.js +1 -0
  104. package/src/InteractiveMap/InteractiveMap.js +3 -2
  105. package/src/InteractiveMap/InteractiveMap.test.js +2 -2
  106. package/src/config/events.js +1 -1
  107. package/src/config/mapPanelSlots.js +8 -0
  108. package/src/config/symbolConfig.js +1 -1
  109. package/src/scss/settings/_colors.scss +4 -0
  110. package/src/services/symbolRegistry.js +1 -1
  111. package/src/services/symbolRegistry.test.js +19 -0
  112. package/src/types.js +33 -8
  113. package/src/utils/getFitMove.js +73 -0
  114. package/src/utils/getFitMove.test.js +114 -0
  115. package/src/utils/getSafeZoneInset.js +122 -77
  116. package/src/utils/getSafeZoneInset.test.js +241 -54
  117. package/src/utils/getValueForStyle.js +10 -5
  118. package/src/utils/getValueForStyle.test.js +13 -2
  119. package/src/utils/renderedBoxes.js +25 -0
  120. package/src/utils/renderedBoxes.test.js +61 -0
  121. package/src/utils/screenBox.js +70 -0
  122. package/src/utils/screenBox.test.js +69 -0
  123. package/src/utils/symbolUtils.js +9 -9
  124. package/src/utils/symbolUtils.test.js +21 -0
  125. 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
+ })
@@ -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 that carry token values.
9
- // These use the 'symbol' prefix to distinguish them from fill/stroke props at the same level.
10
- // The prefix is stripped before passing tokens to the registry (e.g. symbolBackgroundColor → backgroundColor).
11
- const SYMBOL_STYLE_PROPS = new Set([
12
- 'symbolBackgroundColor', 'symbolForegroundColor',
13
- 'symbolHaloWidth', 'symbolGraphic'
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
- SYMBOL_STYLE_PROPS.forEach(key => {
53
- if (dataset[key] != null) {
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] = dataset[key]
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
- })