@defra/interactive-map 0.0.52-alpha → 0.0.53-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/esm/im-core.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/context.md +18 -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/plugins/datasets.md +4 -10
- package/docs/plugins/draw.md +2 -1
- package/docs/plugins/map-key.md +6 -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/maplibre/layerBuilders.js +9 -9
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +19 -3
- 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 +19 -26
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +15 -67
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +32 -105
- 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 +99 -11
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +26 -26
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +48 -29
- package/plugins/datasets/src/initialise/defaults.js +4 -3
- package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
- package/plugins/datasets/src/registry/dataset.js +2 -1
- package/plugins/datasets/src/registry/dataset.test.js +13 -0
- 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/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/KeyGroupItem.jsx +3 -1
- package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +15 -14
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +21 -14
- 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/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/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/menu/src/registry/index.js +0 -2
- package/plugins/menu/src/registry/index.test.js +1 -9
- 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/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/store/ServiceProvider.jsx +6 -3
- package/src/App/store/ServiceProvider.test.jsx +24 -0
- package/src/config/appConfig.js +1 -5
- package/src/config/mapSizeScales.js +8 -0
- package/src/config/symbolConfig.js +101 -25
- 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 +9 -3
- 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
|
@@ -1,91 +1,41 @@
|
|
|
1
1
|
import { render } from '@testing-library/react'
|
|
2
2
|
import { KeySvgSymbol } from './KeySvgSymbol'
|
|
3
|
-
import { getSymbolStyleColors, getSymbolViewBox } from '../../../../../src/utils/symbolUtils.js'
|
|
4
|
-
import { symbolRegistry } from '../../registry/index.js'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
getSymbolStyleColors: jest.fn(() => ({ foreground: '#000', background: '#fff' })),
|
|
8
|
-
getSymbolViewBox: jest.fn(() => '0 0 38 38')
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
|
-
const mockResolve = jest.spyOn(symbolRegistry, 'resolve')
|
|
12
|
-
|
|
13
|
-
const defaultProps = {
|
|
14
|
-
symbolDef: { id: 'marker' },
|
|
15
|
-
keyDefinition: {
|
|
16
|
-
style: {
|
|
17
|
-
stroke: '#000000'
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
mapStyle: { id: 'default' }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
mockResolve.mockClear()
|
|
25
|
-
mockResolve.mockReturnValue('<path d="M0 0"/>')
|
|
26
|
-
getSymbolStyleColors.mockReturnValue({ foreground: '#000', background: '#fff' })
|
|
27
|
-
getSymbolViewBox.mockReturnValue('0 0 38 38')
|
|
28
|
-
})
|
|
4
|
+
const keySymbol = (viewBox, svg = '<path d="M0 0"/>') => ({ svg, viewBox })
|
|
29
5
|
|
|
30
6
|
describe('KeySvgSymbol', () => {
|
|
31
|
-
it('
|
|
32
|
-
const { container } = render(<KeySvgSymbol {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(
|
|
39
|
-
|
|
40
|
-
{ foreground: '#000', background: '#fff' },
|
|
41
|
-
expect.objectContaining({ id: 'default' })
|
|
42
|
-
)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('calls getSymbolStyleColors with the dataset props', () => {
|
|
46
|
-
render(<KeySvgSymbol {...defaultProps} />)
|
|
47
|
-
expect(getSymbolStyleColors).toHaveBeenCalledWith(defaultProps.keyDefinition.style)
|
|
7
|
+
it('draws the symbol 1:1, centred in a fixed 44×44 box it may overflow', () => {
|
|
8
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('0 0 42 48')} />)
|
|
9
|
+
const [outer, inner] = container.querySelectorAll('svg')
|
|
10
|
+
expect(outer.getAttribute('width')).toBe('44')
|
|
11
|
+
expect(outer.getAttribute('height')).toBe('44')
|
|
12
|
+
expect(outer.getAttribute('viewBox')).toBe('0 0 44 44')
|
|
13
|
+
expect(outer.getAttribute('overflow')).toBe('visible')
|
|
14
|
+
expect([inner.getAttribute('x'), inner.getAttribute('y')]).toEqual(['1', '-2'])
|
|
15
|
+
expect([inner.getAttribute('width'), inner.getAttribute('height')]).toEqual(['42', '48'])
|
|
48
16
|
})
|
|
49
17
|
|
|
50
|
-
it('
|
|
51
|
-
render(<KeySvgSymbol {
|
|
52
|
-
|
|
18
|
+
it('clips the symbol to its own viewBox, as on the map', () => {
|
|
19
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('10 10 30 30')} />)
|
|
20
|
+
const inner = container.querySelectorAll('svg')[1]
|
|
21
|
+
expect(inner.getAttribute('viewBox')).toBe('10 10 30 30')
|
|
22
|
+
expect(inner.getAttribute('overflow')).toBe('hidden')
|
|
53
23
|
})
|
|
54
24
|
|
|
55
|
-
it('
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
expect(
|
|
25
|
+
it('scales a symbol bigger than the key maximum down to fit it', () => {
|
|
26
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('0 0 112 56')} />)
|
|
27
|
+
const inner = container.querySelectorAll('svg')[1]
|
|
28
|
+
expect([inner.getAttribute('width'), inner.getAttribute('height')]).toEqual(['56', '28'])
|
|
29
|
+
expect([inner.getAttribute('x'), inner.getAttribute('y')]).toEqual(['-6', '8'])
|
|
59
30
|
})
|
|
60
31
|
|
|
61
|
-
it('renders the
|
|
62
|
-
|
|
63
|
-
const { container } = render(<KeySvgSymbol {...defaultProps} />)
|
|
32
|
+
it('renders the symbol\'s svg inside a g element', () => {
|
|
33
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('0 0 38 38', '<circle id="sym-el"/>')} />)
|
|
64
34
|
expect(container.querySelector('#sym-el')).toBeTruthy()
|
|
65
35
|
})
|
|
66
36
|
|
|
67
|
-
it('
|
|
68
|
-
render(<KeySvgSymbol {
|
|
69
|
-
const callArg = mockResolve.mock.calls[0][2]
|
|
70
|
-
expect(callArg.mapColorScheme).toBe('light')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('uses the mapStyle appColorScheme when provided', () => {
|
|
74
|
-
const props = { ...defaultProps, mapStyle: { id: 'dark', appColorScheme: 'dark' } }
|
|
75
|
-
render(<KeySvgSymbol {...props} />)
|
|
76
|
-
const callArg = mockResolve.mock.calls[0][2]
|
|
77
|
-
expect(callArg.mapColorScheme).toBe('dark')
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('renders nothing when resolve returns falsy', () => {
|
|
81
|
-
mockResolve.mockReturnValue(null)
|
|
82
|
-
const { container } = render(<KeySvgSymbol {...defaultProps} />)
|
|
83
|
-
expect(container.firstChild).toBeNull()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('renders nothing when getSymbolViewBox returns falsy', () => {
|
|
87
|
-
getSymbolViewBox.mockReturnValue(null)
|
|
88
|
-
const { container } = render(<KeySvgSymbol {...defaultProps} />)
|
|
37
|
+
it('renders nothing without a key symbol', () => {
|
|
38
|
+
const { container } = render(<KeySvgSymbol keySymbol={null} />)
|
|
89
39
|
expect(container.firstChild).toBeNull()
|
|
90
40
|
})
|
|
91
41
|
})
|
|
@@ -7,7 +7,7 @@ export function MapKey ({
|
|
|
7
7
|
mapState: { mapStyle },
|
|
8
8
|
pluginConfig: { noKeyItemText },
|
|
9
9
|
pluginState,
|
|
10
|
-
services: { eventBus }
|
|
10
|
+
services: { eventBus, symbolRegistry, patternRegistry }
|
|
11
11
|
}) {
|
|
12
12
|
const [datasetRegistry, setDatasetRegistry] = useState(getDatasetRegistry())
|
|
13
13
|
// Lazily seed from the registry (already populated whenever the key is opened after
|
|
@@ -58,6 +58,8 @@ export function MapKey ({
|
|
|
58
58
|
keyGroups={keyGroups}
|
|
59
59
|
hasGroups={hasGroups}
|
|
60
60
|
mapStyle={mapStyle}
|
|
61
|
+
symbolRegistry={symbolRegistry}
|
|
62
|
+
patternRegistry={patternRegistry}
|
|
61
63
|
/>
|
|
62
64
|
)
|
|
63
65
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
const HALF = 0.5
|
|
2
|
+
|
|
1
3
|
export const SVG_SIZE = 20 // Width and height attributes of the svg element
|
|
2
|
-
export const SVG_CENTER = SVG_SIZE
|
|
3
|
-
const SVG_SYMBOL_SIZE = 44 // Width and height attributes of the svg element if its a marker or point feature symbol
|
|
4
|
+
export const SVG_CENTER = SVG_SIZE * HALF
|
|
5
|
+
export const SVG_SYMBOL_SIZE = 44 // Width and height attributes of the svg element if its a marker or point feature symbol
|
|
6
|
+
// Largest a symbol is drawn in the key: built-in symbols top out at 49 at medium and draw 1:1;
|
|
7
|
+
// a bigger custom symbol is scaled down to this so it can't spill far past its row
|
|
8
|
+
export const KEY_SYMBOL_MAX_SIZE = 56
|
|
4
9
|
|
|
5
10
|
export const svgProps = {
|
|
6
11
|
xmlns: 'http://www.w3.org/2000/svg',
|
|
@@ -16,5 +21,6 @@ export const svgSymbolProps = {
|
|
|
16
21
|
...svgProps,
|
|
17
22
|
width: SVG_SYMBOL_SIZE,
|
|
18
23
|
height: SVG_SYMBOL_SIZE,
|
|
24
|
+
viewBox: `0 0 ${SVG_SYMBOL_SIZE} ${SVG_SYMBOL_SIZE}`,
|
|
19
25
|
className: 'im-c-map-key-symbol im-c-map-key-symbol--point'
|
|
20
26
|
}
|
|
@@ -40,6 +40,21 @@ describe('mergeKeyGroupItems', () => {
|
|
|
40
40
|
])
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
+
it('merges a matched group even when the incoming item has no keyDefinitions array', () => {
|
|
44
|
+
attachPluginStateRef({
|
|
45
|
+
current: {
|
|
46
|
+
groups: [{ id: 'group-1', type: 'group', groupLabel: 'Group 1' }],
|
|
47
|
+
keyDefinitions: [{ id: 'k1', groupId: 'group-1' }]
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const items = [{ id: 'group-1' }]
|
|
52
|
+
|
|
53
|
+
expect(mergeKeyGroupItems(items)).toEqual([
|
|
54
|
+
{ id: 'group-1', type: 'group', groupLabel: 'Group 1', keyDefinitions: [{ id: 'k1', groupId: 'group-1' }] }
|
|
55
|
+
])
|
|
56
|
+
})
|
|
57
|
+
|
|
43
58
|
it('reuses the cached plugin-state groups when the ref object is unchanged', () => {
|
|
44
59
|
const ref = { current: { groups: [{ id: 'group-1', type: 'group', groupLabel: 'Group 1' }], keyDefinitions: [{ id: 'k1', groupId: 'group-1' }] } }
|
|
45
60
|
attachPluginStateRef(ref)
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { getDatasetRegistry
|
|
1
|
+
import { getDatasetRegistry } from './index.js'
|
|
2
2
|
|
|
3
3
|
describe('registry/index', () => {
|
|
4
4
|
it('exports getDatasetRegistry as a function', () => {
|
|
5
5
|
expect(typeof getDatasetRegistry).toBe('function')
|
|
6
6
|
})
|
|
7
|
-
|
|
8
|
-
it('exports patternRegistry', () => {
|
|
9
|
-
expect(patternRegistry).toBeDefined()
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('exports symbolRegistry', () => {
|
|
13
|
-
expect(symbolRegistry).toBeDefined()
|
|
14
|
-
})
|
|
15
7
|
})
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { getDatasetRegistry
|
|
1
|
+
import { getDatasetRegistry } from './index.js'
|
|
2
2
|
|
|
3
3
|
describe('registry/index', () => {
|
|
4
4
|
it('exports getDatasetRegistry as a function', () => {
|
|
5
5
|
expect(typeof getDatasetRegistry).toBe('function')
|
|
6
6
|
})
|
|
7
|
-
|
|
8
|
-
it('exports patternRegistry', () => {
|
|
9
|
-
expect(patternRegistry).toBeDefined()
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('exports symbolRegistry', () => {
|
|
13
|
-
expect(symbolRegistry).toBeDefined()
|
|
14
|
-
})
|
|
15
7
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";import r from"@arcgis/core/config.js";import n from"@arcgis/core/layers/support/TileInfo.js";import a from"@arcgis/core/Map.js";import
|
|
1
|
+
import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";import r from"@arcgis/core/config.js";import n from"@arcgis/core/layers/support/TileInfo.js";import a from"@arcgis/core/Map.js";import o from"@arcgis/core/views/MapView.js";import i from"@arcgis/core/layers/VectorTileLayer.js";import s from"@arcgis/core/geometry/Point.js";import{when as m,once as l,watch as p}from"@arcgis/core/core/reactiveUtils.js";import c from"@arcgis/core/geometry/Extent.js";class u{_notImplemented(e){throw new Error("".concat(this.name," must implement ").concat(e,"()"))}isBaseMapReady(){this._notImplemented("isBaseMapReady")}addSymbolsToMap(){this._notImplemented("addSymbolsToMap")}addPatternsToMap(){this._notImplemented("addPatternsToMap")}getActiveSymbolImageId(){this._notImplemented("getActiveSymbolImageId")}getSelectedSymbolImageId(){this._notImplemented("getSelectedSymbolImageId")}}var v={animationDuration:200},d=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom"];var y=(e,t)=>{var r=null,n=function(){for(var n=arguments.length,a=new Array(n),o=0;o<n;o++)a[o]=arguments[o];clearTimeout(r),r=setTimeout(()=>{e(...a)},t)};return n.cancel=()=>{r&&(clearTimeout(r),r=null)},n};function h(e){var{mapProvider:t,view:r,baseTileLayer:n,events:a,eventBus:o,getZoom:i,getCenter:s,getBounds:c,getResolution:u}=e,v=!1,d=[],h=[],f=e=>{var t=(()=>{if(v||!r||r.destroyed||!r.extent)return null;var{maxZoom:e,minZoom:t}=r.constraints;return{center:s(),bounds:c(),resolution:u(),zoom:i(),isAtMaxZoom:r.zoom+.01>=e,isAtMinZoom:r.zoom-.01<=t}})();t&&o.emit(e,t)};m(()=>n.loaded&&r.resolution>0,()=>f(a.MAP_LOADED)),l(()=>r.ready).then(()=>{v||(t.setBaseMapReady(!0),o.emit(a.MAP_READY,{map:t.map,view:t.view,mapStyleId:t.mapStyleId,mapSize:t.mapSize,crs:t.crs}))}),l(()=>r.stationary).then(()=>f(a.MAP_FIRST_IDLE));var g=y(()=>f(a.MAP_MOVE_END),500);h.push(g),d.push(p(()=>[r.interacting,r.animation],e=>{var[t,r]=e;(t||r)&&o.emit(a.MAP_MOVE_START),t||r||g()}));var w,x,b,M=(w=()=>f(a.MAP_MOVE),x=10,b=0,function(){var e=Date.now();e-b>=x&&(b=e,w(...arguments))});h.push(M),d.push(p(()=>r.zoom,M)),d.push(p(()=>r.extent,()=>o.emit(a.MAP_RENDER),{initial:!1}));var E=y(()=>f(a.MAP_DATA_CHANGE),500);h.push(E),d.push(p(()=>r.updating,e=>!e&&E()));var S=null,T=null;return d.push(r.on("pointer-down",e=>{S=e.x,T=e.y})),d.push(r.on("pointer-up",e=>{var n;if(0===e.button&&!(Math.hypot(e.x-S,e.y-T)>6)&&"active"!==(null===(n=t.sketchViewModel)||void 0===n?void 0:n.state)){var i={x:e.x,y:e.y},s=r.toMap(i);s&&o.emit(a.MAP_CLICK,{point:i,coords:[s.x,s.y]})}})),{remove(){v=!0,h.forEach(e=>e.cancel()),d.forEach(e=>e.remove())}}}var f=e=>e?new c({xmin:e[0],ymin:e[1],xmax:e[2],ymax:e[3],spatialReference:{wkid:27700}}):void 0,g=e=>e?new s({x:e[0],y:e[1],spatialReference:{wkid:27700}}):void 0,w=(e,t)=>{if(e)if("FeatureCollection"===e.type)e.features.forEach(e=>w(e,t));else if("Feature"===e.type)w(e.geometry,t);else if("GeometryCollection"===e.type)e.geometries.forEach(e=>w(e,t));else{var r=e=>{Array.isArray(e)&&("number"==typeof e[0]?t.push(e):e.forEach(r))};r(e.coordinates)}},x=e=>{var t=[];w(e,t);var r=t.map(e=>e[0]),n=t.map(e=>e[1]);return f([Math.min(...r),Math.min(...n),Math.max(...r),Math.max(...n)])},b=e=>{var t=1609.344,r=e/t;if(r<.5/t){var n=Math.round(e),a=1===n?"metre":"metres";return"".concat(n," ").concat(a)}if(r<10){var o=Number.parseFloat(r.toFixed(1)),i=1===o?"mile":"miles";return"".concat(o," ").concat(i)}var s=Math.round(r),m=1===s?"mile":"miles";return"".concat(s," ").concat(m)};var M={top:0,right:0,bottom:0,left:0};function E(){return(E=e(function*(e,t){if(!e||!t)return[];var r=e.map.layers.filter(e=>e instanceof i);return r.length?(yield e.hitTest(t,{include:r.toArray()})).results.map(e=>({layerId:e.layer.id,layerTitle:e.layer.title||e.layer.id,type:e.layer.type,geometry:e.graphic.geometry,symbol:e.graphic.symbol})):[]})).apply(this,arguments)}function S(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function T(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?S(Object(n),!0).forEach(function(r){t(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):S(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}class A extends u{constructor(e){var{mapProviderConfig:r={},events:n,eventBus:a}=e;super(),t(this,"_isBaseMapReady",!1),this.events=n,this.eventBus=a,this.capabilities={supportedShortcuts:d,supportsMapSizes:!1},Object.assign(this,r),this.mapEventHandles=[],this.appEventHandles=[]}get name(){return"EsriProvider"}initMap(t){var s=this;return e(function*(){var{container:e,padding:m,mapStyle:l,mapSize:p,maxExtent:c}=t;s.mapStyleId=null==l?void 0:l.id,s.mapSize=p;var{events:u,eventBus:v}=s;s.setupConfig&&(yield s.setupConfig(r));var d=new i({id:"baselayer",url:l.url,visible:!0}),y=new a({layers:[d]}),w=c?f(c):null,x=new o({spatialReference:27700,container:e,map:y,zoom:t.zoom,center:g(t.center),maxExtent:c,constraints:{lods:n.create({spatialReference:{wkid:27700}}).lods,snapToZoom:!1,minZoom:t.minZoom,maxZoom:t.maxZoom,maxScale:0,geometry:w,rotationEnabled:!1},ui:{components:[]},popupEnabled:!1});(e=>{if(e){var t=e.querySelector(".esri-view-surface");t.removeAttribute("role"),t.tabIndex=-1,t.style["outline-color"]="transparent",t.style.touchAction="none"}})(x.container),x.padding=m,t.bounds&&x.when(()=>x.goTo(f(t.bounds),{duration:0})),s.mapEventHandles=h({mapProvider:s,view:x,baseTileLayer:d,events:u,eventBus:v,getZoom:s.getZoom.bind(s),getCenter:s.getCenter.bind(s),getBounds:s.getBounds.bind(s),getResolution:s.getResolution.bind(s)}),s.appEventHandles=function(e){var{baseTileLayer:t,events:r,eventBus:n}=e,a=e=>{t.loadStyle(e.url).then(()=>{n.emit(r.MAP_STYLE_CHANGE,{mapStyleId:e.id})})};return n.on(r.MAP_SET_STYLE,a),{remove(){n.off(r.MAP_SET_STYLE,a)}}}({baseTileLayer:d,events:u,eventBus:v})||[],s.map=y,s.view=x,s.baseTileLayer=d})()}setBaseMapReady(e){this._isBaseMapReady=e}isBaseMapReady(){return this._isBaseMapReady}destroyMap(){var e,t;null===(e=this.mapEvents)||void 0===e||e.remove(),null===(t=this.appEvents)||void 0===t||t.remove(),this.mapEvents=null,this.appEvents=null,this.view&&(this.view.container=null,this.view.destroy(),this.view=null),this.map&&(this.map.removeAll(),this.map=null)}setView(e){var t,{center:r,zoom:n}=e;null===(t=this.view.animation)||void 0===t||t.destroy();var a={center:r?new s({x:r[0],y:r[1],spatialReference:{wkid:27700}}):this.view.center,zoom:null!=n?n:this.view.zoom};this.view.goTo(T(T({},a),{},{duration:v.animationDuration}))}zoomIn(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom+e,duration:v.animationDuration})}zoomOut(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom-e,duration:v.animationDuration})}panBy(e){var{x:t,y:r}=this.view.toScreen(this.view.center),n={x:t+e[0],y:r+e[1]},a=this.view.toMap(n);this.view.goTo({center:a,duration:v.animationDuration})}fitToBounds(e){var t=Array.isArray(e)?f(e):x(e);this.view.goTo(t,{duration:v.DELAY})}setPadding(e){this.view.padding=e}getCenter(){var e=this.view.center;return[e.x,e.y].map(e=>Math.round(100*e)/100)}getZoom(){return this.view.zoom}getBounds(){var{xmin:e,ymin:t,xmax:r,ymax:n}=this.view.extent;return[e,t,r,n].map(e=>Math.round(100*e)/100)}getFeaturesAtPoint(e,t){return function(e,t){return E.apply(this,arguments)}(this.view,e)}getVisibleFeatures(e){return[]}getAreaDimensions(){return(e=>{if(!(e&&e instanceof c))return"";var t=e.xmin,r=e.ymin,n=e.xmax,a=e.ymax-r,o=b(n-t),i=b(a);return"".concat(i," by ").concat(o)})(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:M;if(!e.container)return null;var{width:r,height:n}=e.container.getBoundingClientRect(),a={x:t.left,y:n-t.bottom},o={x:r-t.right,y:t.top},i=e.toMap(a),s=e.toMap(o);return new c({xmin:i.x,ymin:i.y,xmax:s.x,ymax:s.y,spatialReference:i.spatialReference})}(this.view))}getCardinalMove(e,t){return function(e,t){var[r,n]=e,[a,o]=t,i=a-r,s=o-n,m=[];return Math.abs(s)>.1&&m.push("".concat(s>0?"north":"south"," ").concat(b(Math.abs(s)))),Math.abs(i)>.1&&m.push("".concat(i>0?"east":"west"," ").concat(b(Math.abs(i)))),m.join(", ")}(e,t)}getResolution(){return this.view.resolution}mapToScreen(e){var t=g(e),r=this.view.toScreen(t);return{x:r.x,y:r.y}}screenToMap(e){var t=this.view.toMap(e);return[t.x,t.y]}isGeometryObscured(e,t){return((e,t,r)=>{if(null==r||!r.container)return!1;var n=r.container.getBoundingClientRect(),a=x(e),o=[r.toScreen(new s({x:a.xmin,y:a.ymin,spatialReference:a.spatialReference})),r.toScreen(new s({x:a.xmin,y:a.ymax,spatialReference:a.spatialReference})),r.toScreen(new s({x:a.xmax,y:a.ymin,spatialReference:a.spatialReference})),r.toScreen(new s({x:a.xmax,y:a.ymax,spatialReference:a.spatialReference}))],i=Math.min(...o.map(e=>e.x)),m=Math.max(...o.map(e=>e.x)),l=Math.min(...o.map(e=>e.y)),p=Math.max(...o.map(e=>e.y)),c=t.left-n.left,u=t.top-n.top,v=t.right-n.left,d=t.bottom-n.top;return i<v&&m>c&&l<d&&p>u})(e,t,this.view)}}export{A as default};
|