@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.
- package/assets/css/docusaurus.css +58 -34
- 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 +16 -0
- package/docs/api.md +28 -4
- package/docs/assets/basic-map.jpg +0 -0
- package/docs/assets/button-first.jpg +0 -0
- package/docs/assets/maker-panel.jpg +0 -0
- package/docs/examples/add-marker-with-panel.mdx +59 -0
- package/docs/examples/basic-map.mdx +24 -0
- package/docs/examples/button-map.mdx +24 -0
- package/docs/examples/index.mdx +49 -0
- package/docs/index.mdx +1 -1
- package/docs/plugins/interact.md +32 -1
- package/docs/plugins.md +1 -1
- package/docusaurus.config.cjs +9 -1
- package/package.json +1 -1
- package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/css/index.css +2 -19
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/css/index.css +1 -1
- package/plugins/beta/scale-bar/src/scaleBar.scss +1 -0
- 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/interact/src/InteractInit.jsx +5 -3
- package/plugins/interact/src/api/clear.js +1 -1
- package/plugins/interact/src/api/selectMarker.js +14 -0
- package/plugins/interact/src/api/selectMarker.test.js +25 -0
- package/plugins/interact/src/api/unselectMarker.js +14 -0
- package/plugins/interact/src/api/unselectMarker.test.js +14 -0
- package/plugins/interact/src/events.js +18 -30
- package/plugins/interact/src/events.test.js +113 -108
- package/plugins/interact/src/manifest.js +10 -2
- package/plugins/interact/src/reducer.js +36 -1
- package/plugins/interact/src/reducer.test.js +40 -1
- package/plugins/interact/src/utils/interactionModes.js +12 -0
- package/src/App/components/Panel/Panel.jsx +6 -6
- package/src/App/components/Panel/Panel.test.jsx +37 -0
- package/src/App/components/Viewport/Viewport.jsx +5 -15
- package/src/App/components/Viewport/Viewport.module.scss +2 -0
- package/src/App/components/Viewport/Viewport.test.jsx +16 -33
- package/src/App/hooks/useInterfaceAPI.js +7 -7
- package/src/App/hooks/useInterfaceAPI.test.js +15 -9
- package/src/App/hooks/useLayoutMeasurements.js +64 -72
- package/src/App/layout/Layout.jsx +1 -1
- package/src/App/layout/layout.module.scss +1 -8
- package/src/App/renderer/HtmlElementHost.jsx +10 -5
- package/src/App/renderer/mapPanels.js +2 -1
- package/src/App/store/appActionsMap.js +4 -4
- package/src/App/store/appActionsMap.test.js +10 -0
- package/src/InteractiveMap/InteractiveMap.js +59 -11
- package/src/InteractiveMap/InteractiveMap.test.js +126 -4
- package/src/InteractiveMap/domStateManager.js +18 -6
- package/src/InteractiveMap/domStateManager.test.js +21 -0
- package/src/InteractiveMap/historyManager.js +28 -16
- package/src/InteractiveMap/historyManager.test.js +17 -0
- package/src/config/appConfig.js +2 -1
- package/src/config/appConfig.test.js +3 -13
- package/src/config/defaults.js +2 -1
- package/src/config/events.js +20 -21
- package/src/services/closeApp.js +1 -10
- package/src/services/closeApp.test.js +3 -43
- package/src/types.js +6 -1
- package/src/utils/mapStateSync.js +48 -10
- package/src/utils/mapStateSync.test.js +29 -9
- package/docs/examples.mdx +0 -70
|
@@ -33,11 +33,10 @@ describe('mapStateSync utilities', () => {
|
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
describe('setMapStateInURL', () => {
|
|
36
|
-
it('
|
|
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('
|
|
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
|
|
51
|
-
expect(
|
|
64
|
+
const url = globalThis.history.replaceState.mock.calls[0][2]
|
|
65
|
+
expect(url).toContain('http://localhost')
|
|
52
66
|
})
|
|
53
67
|
|
|
54
|
-
it('
|
|
68
|
+
it('omits zoom when zoom is null', () => {
|
|
55
69
|
setMapStateInURL('map1', { center: [0, 0], zoom: null }, 'http://test.com')
|
|
56
|
-
const
|
|
57
|
-
expect(
|
|
70
|
+
const url = globalThis.history.replaceState.mock.calls[0][2]
|
|
71
|
+
expect(url).not.toContain('zoom')
|
|
58
72
|
})
|
|
59
73
|
|
|
60
|
-
it('
|
|
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
|
-
```
|