@defra/interactive-map 0.0.18-alpha → 0.0.19-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 (73) hide show
  1. package/assets/css/docusaurus.css +58 -34
  2. package/dist/css/index.css +1 -1
  3. package/dist/esm/im-core.js +1 -1
  4. package/dist/esm/im-shell.js +1 -1
  5. package/dist/umd/im-core.js +1 -1
  6. package/dist/umd/index.js +1 -1
  7. package/docs/api/panel-definition.md +16 -0
  8. package/docs/api.md +28 -4
  9. package/docs/assets/basic-map.jpg +0 -0
  10. package/docs/assets/button-first.jpg +0 -0
  11. package/docs/assets/maker-panel.jpg +0 -0
  12. package/docs/examples/add-marker-with-panel.mdx +59 -0
  13. package/docs/examples/basic-map.mdx +24 -0
  14. package/docs/examples/button-map.mdx +24 -0
  15. package/docs/examples/index.mdx +49 -0
  16. package/docs/index.mdx +1 -1
  17. package/docs/plugins/interact.md +32 -1
  18. package/docs/plugins.md +1 -1
  19. package/docusaurus.config.cjs +9 -1
  20. package/package.json +1 -1
  21. package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
  22. package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
  23. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  24. package/plugins/beta/draw-ml/dist/css/index.css +2 -19
  25. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  26. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  27. package/plugins/beta/scale-bar/dist/css/index.css +1 -1
  28. package/plugins/beta/scale-bar/src/scaleBar.scss +1 -0
  29. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  30. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  31. package/plugins/interact/dist/umd/index.js +1 -1
  32. package/plugins/interact/src/InteractInit.jsx +5 -3
  33. package/plugins/interact/src/api/clear.js +1 -1
  34. package/plugins/interact/src/api/selectMarker.js +14 -0
  35. package/plugins/interact/src/api/selectMarker.test.js +25 -0
  36. package/plugins/interact/src/api/unselectMarker.js +14 -0
  37. package/plugins/interact/src/api/unselectMarker.test.js +14 -0
  38. package/plugins/interact/src/events.js +18 -30
  39. package/plugins/interact/src/events.test.js +113 -108
  40. package/plugins/interact/src/manifest.js +10 -2
  41. package/plugins/interact/src/reducer.js +36 -1
  42. package/plugins/interact/src/reducer.test.js +40 -1
  43. package/plugins/interact/src/utils/interactionModes.js +12 -0
  44. package/src/App/components/Panel/Panel.jsx +6 -6
  45. package/src/App/components/Panel/Panel.test.jsx +37 -0
  46. package/src/App/components/Viewport/Viewport.jsx +5 -15
  47. package/src/App/components/Viewport/Viewport.module.scss +2 -0
  48. package/src/App/components/Viewport/Viewport.test.jsx +16 -33
  49. package/src/App/hooks/useInterfaceAPI.js +7 -7
  50. package/src/App/hooks/useInterfaceAPI.test.js +15 -9
  51. package/src/App/hooks/useLayoutMeasurements.js +64 -72
  52. package/src/App/layout/Layout.jsx +1 -1
  53. package/src/App/layout/layout.module.scss +1 -8
  54. package/src/App/renderer/HtmlElementHost.jsx +10 -5
  55. package/src/App/renderer/mapPanels.js +2 -1
  56. package/src/App/store/appActionsMap.js +4 -4
  57. package/src/App/store/appActionsMap.test.js +10 -0
  58. package/src/InteractiveMap/InteractiveMap.js +59 -11
  59. package/src/InteractiveMap/InteractiveMap.test.js +126 -4
  60. package/src/InteractiveMap/domStateManager.js +18 -6
  61. package/src/InteractiveMap/domStateManager.test.js +21 -0
  62. package/src/InteractiveMap/historyManager.js +28 -16
  63. package/src/InteractiveMap/historyManager.test.js +17 -0
  64. package/src/config/appConfig.js +2 -1
  65. package/src/config/appConfig.test.js +3 -13
  66. package/src/config/defaults.js +2 -1
  67. package/src/config/events.js +20 -21
  68. package/src/services/closeApp.js +1 -10
  69. package/src/services/closeApp.test.js +3 -43
  70. package/src/types.js +6 -1
  71. package/src/utils/mapStateSync.js +48 -10
  72. package/src/utils/mapStateSync.test.js +29 -9
  73. package/docs/examples.mdx +0 -70
@@ -33,11 +33,10 @@ describe('mapStateSync utilities', () => {
33
33
  })
34
34
 
35
35
  describe('setMapStateInURL', () => {
36
- it('preserves history state and filters params (Line 28)', () => {
36
+ it('writes center and zoom into the URL', () => {
37
37
  const mockHref = 'http://test.com/path?existing=true'
38
38
  setMapStateInURL('map1', { center: [10, 20], zoom: 5 }, mockHref)
39
39
 
40
- // Verification of Line 28: First arg must be global history state
41
40
  expect(globalThis.history.replaceState).toHaveBeenCalledWith(
42
41
  globalThis.history.state,
43
42
  '',
@@ -45,21 +44,42 @@ describe('mapStateSync utilities', () => {
45
44
  )
46
45
  })
47
46
 
48
- it('uses fallback localhost URL (Line 17)', () => {
47
+ it('replaces existing map params when already present in the URL', () => {
48
+ setMapStateInURL('map1', { center: [10, 20], zoom: 5 }, 'http://test.com?map1:center=1,2&map1:zoom=3')
49
+ const url = globalThis.history.replaceState.mock.calls[0][2]
50
+ expect(url).toContain('map1:center=10,20')
51
+ expect(url).toContain('map1:zoom=5')
52
+ expect(url).not.toContain('map1:center=1,2')
53
+ })
54
+
55
+ it('preserves unrelated existing params (e.g. mv)', () => {
56
+ setMapStateInURL('map1', { center: [10, 20], zoom: 5 }, 'http://test.com/path?mv=map1')
57
+ const url = globalThis.history.replaceState.mock.calls[0][2]
58
+ expect(url).toContain('mv=map1')
59
+ expect(url).toContain('map1:center=10,20')
60
+ })
61
+
62
+ it('uses fallback localhost URL when href is null', () => {
49
63
  setMapStateInURL('map1', { zoom: 10 }, null)
50
- const lastCall = globalThis.history.replaceState.mock.calls[0][2]
51
- expect(lastCall).toContain('http://localhost')
64
+ const url = globalThis.history.replaceState.mock.calls[0][2]
65
+ expect(url).toContain('http://localhost')
52
66
  })
53
67
 
54
- it('handles state where zoom is nullish (Line 24)', () => {
68
+ it('omits zoom when zoom is null', () => {
55
69
  setMapStateInURL('map1', { center: [0, 0], zoom: null }, 'http://test.com')
56
- const lastCall = globalThis.history.replaceState.mock.calls[0][2]
57
- expect(lastCall).not.toContain('zoom')
70
+ const url = globalThis.history.replaceState.mock.calls[0][2]
71
+ expect(url).not.toContain('zoom')
58
72
  })
59
73
 
60
- it('triggers the default href parameter', () => {
74
+ it('uses window.location.href when no href is provided', () => {
61
75
  setMapStateInURL('map1', { zoom: 10 })
62
76
  expect(globalThis.history.replaceState).toHaveBeenCalled()
63
77
  })
78
+
79
+ it('produces a URL with no search string when state is empty and no existing params', () => {
80
+ setMapStateInURL('map1', {}, 'http://test.com/path')
81
+ const url = globalThis.history.replaceState.mock.calls[0][2]
82
+ expect(url).toBe('http://test.com/path')
83
+ })
64
84
  })
65
85
  })
package/docs/examples.mdx DELETED
@@ -1,70 +0,0 @@
1
- import DemoMapInline from '../demo/DemoMapInline.js'
2
- import DemoMapButton from '../demo/DemoMapButton.js'
3
-
4
- # Examples
5
-
6
- See [Getting started](getting-started) for installation and full configuration options.
7
-
8
- ## Inline map
9
-
10
- Embed an interactive map directly on the page, allowing users to explore and interact with the map without leaving the current context.
11
-
12
- <DemoMapInline />
13
-
14
- ```js
15
- import InteractiveMap from '@defra/interactive-map'
16
- import maplibreProvider from '@defra/interactive-map/providers/maplibre'
17
- import searchPlugin from '@defra/interactive-map/plugins/search'
18
- import scaleBarPlugin from '@defra/interactive-map/plugins/scale-bar'
19
- import mapStylesPlugin from '@defra/interactive-map/plugins/map-styles'
20
-
21
- new InteractiveMap('my-map', {
22
- behaviour: 'inline',
23
- mapProvider: maplibreProvider(),
24
- mapStyle: {
25
- url: '/assets/my-map-style.json',
26
- attribution: '© OpenStreetMap contributors'
27
- },
28
- center: [-1.6, 53.1],
29
- zoom: 6,
30
- containerHeight: '500px',
31
- enableZoomControls: true,
32
- plugins: [
33
- searchPlugin({ customDatasets: [nominatimDataset], showMarker: true }),
34
- scaleBarPlugin({ units: 'metric' }),
35
- mapStylesPlugin({ mapStyles: [...] })
36
- ]
37
- })
38
- ```
39
-
40
- ## Button-triggered map
41
-
42
- Trigger the map to show on button press, allowing users to access the map when needed without it taking up space on the page by default.
43
-
44
- <DemoMapButton />
45
-
46
- ```js
47
- import InteractiveMap from '@defra/interactive-map'
48
- import maplibreProvider from '@defra/interactive-map/providers/maplibre'
49
- import searchPlugin from '@defra/interactive-map/plugins/search'
50
- import scaleBarPlugin from '@defra/interactive-map/plugins/scale-bar'
51
- import mapStylesPlugin from '@defra/interactive-map/plugins/map-styles'
52
-
53
- new InteractiveMap('my-map', {
54
- behaviour: 'buttonFirst',
55
- mapProvider: maplibreProvider(),
56
- mapStyle: {
57
- url: '/assets/my-map-style.json',
58
- attribution: '© OpenStreetMap contributors'
59
- },
60
- center: [-1.6, 53.1],
61
- zoom: 6,
62
- containerHeight: '500px',
63
- enableZoomControls: true,
64
- plugins: [
65
- searchPlugin({ customDatasets: [nominatimDataset], showMarker: true }),
66
- scaleBarPlugin({ units: 'metric' }),
67
- mapStylesPlugin({ mapStyles: [...] })
68
- ]
69
- })
70
- ```