@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.
Files changed (147) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/dist/umd/index.js +1 -1
  4. package/docs/api/context.md +18 -12
  5. package/docs/api/marker-config.md +16 -8
  6. package/docs/api/symbol-config.md +24 -9
  7. package/docs/api/symbol-registry.md +49 -14
  8. package/docs/plugins/datasets.md +4 -10
  9. package/docs/plugins/draw.md +2 -1
  10. package/docs/plugins/map-key.md +6 -4
  11. package/package.json +1 -1
  12. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  13. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  14. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  15. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  16. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  17. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  18. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.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/src/adapters/maplibre/layerBuilders.js +9 -9
  23. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +19 -3
  24. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
  25. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
  26. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
  27. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +19 -26
  28. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +15 -67
  29. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +32 -105
  30. package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
  31. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
  32. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
  33. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +99 -11
  34. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +26 -26
  35. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +48 -29
  36. package/plugins/datasets/src/initialise/defaults.js +4 -3
  37. package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
  38. package/plugins/datasets/src/registry/dataset.js +2 -1
  39. package/plugins/datasets/src/registry/dataset.test.js +13 -0
  40. package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
  41. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
  42. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  43. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  44. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  45. package/plugins/draw/dist/esm/index.js +1 -1
  46. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  47. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  48. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  49. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  50. package/plugins/draw/dist/umd/index.js +1 -1
  51. package/plugins/draw/src/DrawInit.jsx +7 -5
  52. package/plugins/draw/src/DrawInit.test.jsx +18 -2
  53. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
  54. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
  55. package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
  56. package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
  57. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
  58. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
  59. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
  60. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
  61. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
  62. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
  63. package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
  64. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
  65. package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
  66. package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
  67. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
  68. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
  69. package/plugins/draw/src/defaults.js +2 -6
  70. package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
  71. package/plugins/draw/src/utils/symbolKeys.js +3 -4
  72. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  73. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  74. package/plugins/interact/dist/umd/index.js +1 -1
  75. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  76. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
  77. package/plugins/map-key/dist/umd/index.js +1 -1
  78. package/plugins/map-key/src/components/Key/Key.jsx +8 -4
  79. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +3 -1
  80. package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
  81. package/plugins/map-key/src/components/Key/KeySvg.jsx +15 -14
  82. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +21 -14
  83. package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
  84. package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
  85. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
  86. package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
  87. package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
  88. package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
  89. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
  90. package/plugins/map-key/src/registry/index.js +0 -2
  91. package/plugins/map-key/src/registry/index.test.js +1 -9
  92. package/plugins/menu/src/registry/index.js +0 -2
  93. package/plugins/menu/src/registry/index.test.js +1 -9
  94. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  95. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  96. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  97. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  98. package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
  99. package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
  100. package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
  101. package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
  102. package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
  103. package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
  104. package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
  105. package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
  106. package/providers/mapProvider.js +53 -1
  107. package/providers/mapProvider.test.js +6 -0
  108. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  109. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  110. package/providers/maplibre/dist/umd/index.js +1 -1
  111. package/providers/maplibre/src/maplibreProvider.js +50 -17
  112. package/providers/maplibre/src/maplibreProvider.test.js +74 -20
  113. package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
  114. package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
  115. package/providers/maplibre/src/utils/patternImages.js +46 -29
  116. package/providers/maplibre/src/utils/patternImages.test.js +52 -4
  117. package/providers/maplibre/src/utils/symbolImages.js +80 -39
  118. package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
  119. package/src/App/components/Markers/Markers.jsx +16 -25
  120. package/src/App/components/Markers/Markers.test.jsx +34 -48
  121. package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
  122. package/src/App/components/Markers/SymbolMarker.jsx +1 -1
  123. package/src/App/store/ServiceProvider.jsx +6 -3
  124. package/src/App/store/ServiceProvider.test.jsx +24 -0
  125. package/src/config/appConfig.js +1 -5
  126. package/src/config/mapSizeScales.js +8 -0
  127. package/src/config/symbolConfig.js +101 -25
  128. package/src/services/patternRegistry.js +97 -76
  129. package/src/services/patternRegistry.test.js +19 -1
  130. package/src/services/symbolComposer.js +184 -0
  131. package/src/services/symbolComposer.test.js +132 -0
  132. package/src/services/symbolRegistry.js +326 -155
  133. package/src/services/symbolRegistry.test.js +334 -32
  134. package/src/types.js +9 -3
  135. package/src/utils/hashString.js +23 -0
  136. package/src/utils/hashString.test.js +29 -0
  137. package/src/utils/imageDataCache.js +43 -0
  138. package/src/utils/imageDataCache.test.js +38 -0
  139. package/src/utils/pathBounds.js +330 -0
  140. package/src/utils/pathBounds.test.js +145 -0
  141. package/src/utils/patternUtils.js +0 -8
  142. package/src/utils/patternUtils.test.js +0 -25
  143. package/src/utils/recentImageSets.js +35 -0
  144. package/src/utils/recentImageSets.test.js +46 -0
  145. package/src/utils/symbolUtils.js +26 -29
  146. package/src/utils/symbolUtils.test.js +27 -41
  147. package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
@@ -1,19 +1,36 @@
1
- import { getCachedSymbolImage, getOrCreateSymbolImage, clearSymbolImageCache, registerSymbol, registerSymbols, getCachedSymbolDataUri, getActiveSymbolImageId, getSelectedSymbolImageId } from './symbolImages.js'
1
+ import Icon from 'ol/style/Icon.js'
2
+ import ImageState from 'ol/ImageState.js'
3
+ import { shared as iconImageCache } from 'ol/style/IconImageCache.js'
4
+ import { SymbolImageCache } from './symbolImages.js'
2
5
 
3
6
  const MAP_STYLE = { id: 'outdoor' }
4
7
 
5
8
  const imageData = (width, height) => ({ width, height })
6
9
 
10
+ const imageIdFor = (style, variant, pixelRatio) => `symbol-${style.symbol}-${pixelRatio}x${variant === 'normal' ? '' : `-${variant}`}`
11
+
12
+ // Like the real registry, getSymbolImageIds builds on getSymbolImageId (so a test overriding
13
+ // getSymbolImageId changes both)
7
14
  const makeSymbolRegistry = () => ({
8
- getSymbolImageId: jest.fn((style, mapStyle, active, pixelRatio) => `symbol-${style.symbol}-${pixelRatio}x${active ? '-active' : ''}`),
15
+ getSymbolImageId: jest.fn((style, mapStyle, variant, pixelRatio) => imageIdFor(style, variant, pixelRatio)),
16
+ getSymbolImageIds: jest.fn(function (style, mapStyle, pixelRatio) {
17
+ const normal = this.getSymbolImageId(style, mapStyle, 'normal', pixelRatio)
18
+ return normal && {
19
+ normal,
20
+ active: this.getSymbolImageId(style, mapStyle, 'active', pixelRatio),
21
+ selected: this.getSymbolImageId(style, mapStyle, 'selected', pixelRatio)
22
+ }
23
+ }),
9
24
  rasteriseSymbolImage: jest.fn(async (style, mapStyle, variant, pixelRatio) => ({
10
- imageId: `symbol-${style.symbol}-${pixelRatio}x${variant === 'active' ? '-active' : variant === 'selected' ? '-selected' : ''}`,
25
+ imageId: imageIdFor(style, variant, pixelRatio),
11
26
  imageData: imageData(20, 20)
12
27
  }))
13
28
  })
14
29
 
30
+ let cache
31
+
15
32
  beforeEach(() => {
16
- clearSymbolImageCache()
33
+ cache = new SymbolImageCache()
17
34
  // Memoized per-canvas so `canvas.getContext()` returns the same mock object on repeat
18
35
  // calls (real canvases do the same) — needed so assertions and the code under test see
19
36
  // the same putImageData spy, not two different ones from two different mock calls.
@@ -26,143 +43,177 @@ beforeEach(() => {
26
43
  })
27
44
  })
28
45
 
29
- describe('getCachedSymbolImage', () => {
46
+ describe('getImage', () => {
30
47
  it('returns undefined for an id that has never been registered', () => {
31
- expect(getCachedSymbolImage('symbol-unseen')).toBeUndefined()
48
+ expect(cache.getImage('symbol-unseen')).toBeUndefined()
32
49
  })
33
50
 
34
- it('returns the cached canvas after getOrCreateSymbolImage has resolved it', () => {
35
- const canvas = getOrCreateSymbolImage('symbol-a', imageData(20, 30))
36
- expect(getCachedSymbolImage('symbol-a')).toBe(canvas)
51
+ it('returns the canvas addImage drew', () => {
52
+ cache.addImage('symbol-a', imageData(20, 30))
53
+ expect(cache.getImage('symbol-a')).toBeInstanceOf(HTMLCanvasElement)
37
54
  })
38
55
  })
39
56
 
40
- describe('getOrCreateSymbolImage', () => {
57
+ describe('addImage', () => {
41
58
  it('draws the ImageData onto a canvas sized to match it', () => {
42
- const canvas = getOrCreateSymbolImage('symbol-b', imageData(44, 60))
43
- expect(canvas).toBeInstanceOf(HTMLCanvasElement)
59
+ cache.addImage('symbol-b', imageData(44, 60))
60
+ const canvas = cache.getImage('symbol-b')
44
61
  expect(canvas.width).toBe(44)
45
62
  expect(canvas.height).toBe(60)
46
63
  expect(canvas.getContext().putImageData).toHaveBeenCalledWith(imageData(44, 60), 0, 0)
47
64
  })
48
65
 
49
- it('rasterises only once — a second call with the same id returns the same canvas without redrawing', () => {
50
- const first = getOrCreateSymbolImage('symbol-c', imageData(10, 10))
51
- const contextCallsAfterFirst = HTMLCanvasElement.prototype.getContext.mock.calls.length
52
- const second = getOrCreateSymbolImage('symbol-c', imageData(10, 10))
53
- expect(second).toBe(first)
54
- expect(HTMLCanvasElement.prototype.getContext.mock.calls).toHaveLength(contextCallsAfterFirst)
55
- })
56
-
57
- it('different ids get independent canvases', () => {
58
- const a = getOrCreateSymbolImage('symbol-d', imageData(10, 10))
59
- const b = getOrCreateSymbolImage('symbol-e', imageData(20, 20))
60
- expect(a).not.toBe(b)
66
+ it('only makes a data URI when asked', () => {
67
+ cache.addImage('symbol-plain', imageData(10, 10))
68
+ cache.addImage('symbol-uri', imageData(12, 12), true)
69
+ expect(cache.getDataUri('symbol-plain')).toBeUndefined()
70
+ expect(cache.getDataUri('symbol-uri')).toBe('data:image/png;base64,mock-12x12')
61
71
  })
62
72
  })
63
73
 
64
- describe('clearSymbolImageCache', () => {
65
- it('forces the next getOrCreateSymbolImage call to rasterise again', () => {
66
- const first = getOrCreateSymbolImage('symbol-f', imageData(10, 10))
67
- clearSymbolImageCache()
68
- const second = getOrCreateSymbolImage('symbol-f', imageData(10, 10))
69
- expect(second).not.toBe(first)
70
- })
71
-
72
- it('also clears the data URI cache', async () => {
73
- const symbolRegistry = makeSymbolRegistry()
74
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
75
- clearSymbolImageCache()
76
- expect(getCachedSymbolDataUri('symbol-pin-1x')).toBeUndefined()
77
- })
74
+ // Each OL provider owns its own cache, so two maps never share (or clobber) each other's images
75
+ it('keeps separate caches independent', async () => {
76
+ const other = new SymbolImageCache()
77
+ await cache.registerSymbol({ symbol: 'pin' }, MAP_STYLE, makeSymbolRegistry(), 1)
78
+ expect(cache.getImage('symbol-pin-1x')).toBeInstanceOf(HTMLCanvasElement)
79
+ expect(other.getImage('symbol-pin-1x')).toBeUndefined()
80
+ expect(other.getActiveImageId('symbol-pin-1x')).toBeNull()
78
81
  })
79
82
 
80
83
  describe('registerSymbol', () => {
81
- it('caches a data URI built from the rasterised ImageData', async () => {
84
+ // A flat style's icon-src that isn't already in OL's icon cache is loaded asynchronously, and
85
+ // OL draws nothing for the icon until it has — a flicker every time styles switch images.
86
+ it('seeds OL\'s icon cache, so an icon-src from it is loaded straight away', async () => {
82
87
  const symbolRegistry = makeSymbolRegistry()
83
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
84
- expect(getCachedSymbolDataUri('symbol-pin-1x')).toBe('data:image/png;base64,mock-20x20')
88
+ symbolRegistry.getSymbolImageId.mockReturnValue('seeded')
89
+ symbolRegistry.rasteriseSymbolImage.mockImplementation(async (style, mapStyle, variant) => ({
90
+ imageId: variant === 'normal' ? 'seeded' : `seeded-${variant}`,
91
+ imageData: imageData(31, 17)
92
+ }))
93
+ await cache.registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
94
+
95
+ const icon = new Icon({ src: cache.getDataUri('seeded') })
96
+ expect(icon.getImageState()).toBe(ImageState.LOADED)
97
+ expect(icon.getImage(1)).toBe(cache.getImage('seeded'))
98
+ })
99
+
100
+ it('caches a data URI for the normal image only', async () => {
101
+ await cache.registerSymbol({ symbol: 'pin' }, MAP_STYLE, makeSymbolRegistry(), 1)
102
+ expect(cache.getDataUri('symbol-pin-1x')).toBe('data:image/png;base64,mock-20x20')
103
+ expect(cache.getDataUri('symbol-pin-1x-active')).toBeUndefined()
85
104
  })
86
105
 
87
- it('rasterises at the given pixelRatio, not a fixed constant', async () => {
106
+ it('rasterises at the given pixelRatio', async () => {
88
107
  const symbolRegistry = makeSymbolRegistry()
89
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 3)
108
+ await cache.registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 3)
90
109
  expect(symbolRegistry.rasteriseSymbolImage).toHaveBeenCalledWith({ symbol: 'pin' }, MAP_STYLE, 'normal', 3)
91
110
  })
92
111
 
93
112
  it('does nothing when rasteriseSymbolImage returns null', async () => {
94
113
  const symbolRegistry = { ...makeSymbolRegistry(), rasteriseSymbolImage: jest.fn().mockResolvedValue(null) }
95
- await registerSymbol({ symbol: 'unknown' }, MAP_STYLE, symbolRegistry, 1)
96
- expect(getCachedSymbolDataUri('symbol-unknown-1x')).toBeUndefined()
114
+ await cache.registerSymbol({ symbol: 'unknown' }, MAP_STYLE, symbolRegistry, 1)
115
+ expect(cache.getDataUri('symbol-unknown-1x')).toBeUndefined()
97
116
  })
98
117
 
99
118
  it('does nothing when getSymbolImageId returns null', async () => {
100
119
  const symbolRegistry = { ...makeSymbolRegistry(), getSymbolImageId: jest.fn(() => null) }
101
- await registerSymbol({ symbol: 'unknown' }, MAP_STYLE, symbolRegistry, 1)
120
+ await cache.registerSymbol({ symbol: 'unknown' }, MAP_STYLE, symbolRegistry, 1)
102
121
  expect(symbolRegistry.rasteriseSymbolImage).not.toHaveBeenCalled()
103
122
  })
104
123
 
105
- it('skips re-rasterising normal/active once cached for the same imageId — selected always re-rasterises', async () => {
124
+ it('rasterises nothing for a symbol whose images are all cached', async () => {
106
125
  const symbolRegistry = makeSymbolRegistry()
107
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
126
+ await cache.registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
108
127
  expect(symbolRegistry.rasteriseSymbolImage).toHaveBeenCalledTimes(3) // normal + active + selected
109
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
110
- expect(symbolRegistry.rasteriseSymbolImage).toHaveBeenCalledTimes(4) // + selected only
128
+ const selected = cache.getImage('symbol-pin-1x-selected')
129
+ await cache.registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
130
+ expect(symbolRegistry.rasteriseSymbolImage).toHaveBeenCalledTimes(3)
131
+ expect(cache.getImage('symbol-pin-1x-selected')).toBe(selected)
111
132
  })
112
133
 
113
- it('reuses the same cached canvas getOrCreateSymbolImage builds', async () => {
114
- const symbolRegistry = makeSymbolRegistry()
115
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
116
- expect(getCachedSymbolImage('symbol-pin-1x')).toBeInstanceOf(HTMLCanvasElement)
134
+ it('maps the normal image to its active and selected variants', async () => {
135
+ await cache.registerSymbol({ symbol: 'pin' }, MAP_STYLE, makeSymbolRegistry(), 1)
136
+ expect(cache.getActiveImageId('symbol-pin-1x')).toBe('symbol-pin-1x-active')
137
+ expect(cache.getSelectedImageId('symbol-pin-1x')).toBe('symbol-pin-1x-selected')
138
+ expect(cache.getImage('symbol-pin-1x-active')).toBeInstanceOf(HTMLCanvasElement)
139
+ expect(cache.getImage('symbol-pin-1x-selected')).toBeInstanceOf(HTMLCanvasElement)
117
140
  })
141
+ })
118
142
 
119
- it('registers the active variant, resolvable via getActiveSymbolImageId', async () => {
120
- const symbolRegistry = makeSymbolRegistry()
121
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
122
- expect(getActiveSymbolImageId('symbol-pin-1x')).toBe('symbol-pin-1x-active')
123
- expect(getCachedSymbolImage('symbol-pin-1x-active')).toBeInstanceOf(HTMLCanvasElement)
143
+ describe('getActiveImageId / getSelectedImageId', () => {
144
+ it('returns null for an imageId that has never been registered', () => {
145
+ expect(cache.getActiveImageId('symbol-unseen')).toBeNull()
146
+ expect(cache.getSelectedImageId('symbol-unseen')).toBeNull()
124
147
  })
148
+ })
125
149
 
126
- it('registers the selected variant, resolvable via getSelectedSymbolImageId', async () => {
150
+ describe('registerSymbols', () => {
151
+ it('registers every config in parallel', async () => {
127
152
  const symbolRegistry = makeSymbolRegistry()
128
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
129
- expect(getSelectedSymbolImageId('symbol-pin-1x')).toBe('symbol-pin-1x-selected')
130
- expect(getCachedSymbolImage('symbol-pin-1x-selected')).toBeInstanceOf(HTMLCanvasElement)
153
+ await cache.registerSymbols([{ symbol: 'pin' }, { symbol: 'flag' }], MAP_STYLE, symbolRegistry, 1)
154
+ expect(symbolRegistry.rasteriseSymbolImage).toHaveBeenCalledTimes(6) // 2 symbols × normal/active/selected
131
155
  })
132
156
 
133
- it('does not register an active variant when getSymbolImageId returns null for active', async () => {
157
+ it('is a no-op for an empty array', async () => {
134
158
  const symbolRegistry = makeSymbolRegistry()
135
- symbolRegistry.getSymbolImageId.mockImplementation((style, mapStyle, active) => (active ? null : 'symbol-pin-1x'))
136
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
137
- expect(getActiveSymbolImageId('symbol-pin-1x')).toBeNull()
159
+ await cache.registerSymbols([], MAP_STYLE, symbolRegistry, 1)
160
+ expect(symbolRegistry.rasteriseSymbolImage).not.toHaveBeenCalled()
138
161
  })
139
162
  })
140
163
 
141
- describe('getActiveSymbolImageId / getSelectedSymbolImageId', () => {
142
- it('returns null for an imageId that has never been registered', () => {
143
- expect(getActiveSymbolImageId('symbol-unseen')).toBeNull()
144
- expect(getSelectedSymbolImageId('symbol-unseen')).toBeNull()
145
- })
164
+ describe('dropping images from older map sizes and styles', () => {
165
+ const pin = { symbol: 'pin' }
146
166
 
147
- it('is cleared by clearSymbolImageCache', async () => {
167
+ it('keeps the current and previous size, and drops an older one\'s images when a third arrives', async () => {
148
168
  const symbolRegistry = makeSymbolRegistry()
149
- await registerSymbol({ symbol: 'pin' }, MAP_STYLE, symbolRegistry, 1)
150
- clearSymbolImageCache()
151
- expect(getActiveSymbolImageId('symbol-pin-1x')).toBeNull()
152
- expect(getSelectedSymbolImageId('symbol-pin-1x')).toBeNull()
169
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 1)
170
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 2)
171
+ expect(cache.getImage('symbol-pin-1x')).toBeInstanceOf(HTMLCanvasElement)
172
+
173
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 3)
174
+ expect(cache.getImage('symbol-pin-1x')).toBeUndefined()
175
+ expect(cache.getImage('symbol-pin-1x-active')).toBeUndefined()
176
+ expect(cache.getImage('symbol-pin-1x-selected')).toBeUndefined()
177
+ expect(cache.getDataUri('symbol-pin-1x')).toBeUndefined()
178
+ expect(cache.getActiveImageId('symbol-pin-1x')).toBeNull()
179
+ expect(cache.getSelectedImageId('symbol-pin-1x')).toBeNull()
180
+ expect(cache.getImage('symbol-pin-2x')).toBeInstanceOf(HTMLCanvasElement)
181
+ expect(cache.getImage('symbol-pin-3x')).toBeInstanceOf(HTMLCanvasElement)
182
+ })
183
+
184
+ it('treats a map style change the same as a size change', async () => {
185
+ const symbolRegistry = makeSymbolRegistry()
186
+ await cache.registerSymbols([pin], { id: 'outdoor' }, symbolRegistry, 1)
187
+ await cache.registerSymbols([{ symbol: 'flag' }], { id: 'dark' }, symbolRegistry, 1)
188
+ await cache.registerSymbols([{ symbol: 'star' }], { id: 'night' }, symbolRegistry, 1)
189
+ expect(cache.getImage('symbol-pin-1x')).toBeUndefined()
190
+ expect(cache.getImage('symbol-flag-1x')).toBeInstanceOf(HTMLCanvasElement)
153
191
  })
154
- })
155
192
 
156
- describe('registerSymbols', () => {
157
- it('registers every config in parallel', async () => {
193
+ it('keeps OL\'s icon cache entry while a kept image has the same data URI', async () => {
194
+ // every mock image is 20×20, so they all share one data URI
158
195
  const symbolRegistry = makeSymbolRegistry()
159
- await registerSymbols([{ symbol: 'pin' }, { symbol: 'flag' }], MAP_STYLE, symbolRegistry, 1)
160
- expect(symbolRegistry.rasteriseSymbolImage).toHaveBeenCalledTimes(6) // 2 symbols × normal/active/selected
196
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 1)
197
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 2)
198
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 3)
199
+ expect(new Icon({ src: cache.getDataUri('symbol-pin-3x') }).getImageState()).toBe(ImageState.LOADED)
161
200
  })
162
201
 
163
- it('is a no-op for an empty array', async () => {
202
+ it('releases a dropped image from OL\'s icon cache, and seeds it again when it comes back', async () => {
203
+ // a data URI per image size, so each image's is its own
204
+ HTMLCanvasElement.prototype.toDataURL = jest.fn(function () { return `data:image/png;base64,${this.width}` })
164
205
  const symbolRegistry = makeSymbolRegistry()
165
- await registerSymbols([], MAP_STYLE, symbolRegistry, 1)
166
- expect(symbolRegistry.rasteriseSymbolImage).not.toHaveBeenCalled()
206
+ symbolRegistry.rasteriseSymbolImage.mockImplementation(async (style, mapStyle, variant, pixelRatio) => ({
207
+ imageId: `symbol-${style.symbol}-${pixelRatio}x${variant === 'normal' ? '' : `-${variant}`}`,
208
+ imageData: imageData(20 * pixelRatio, 20 * pixelRatio)
209
+ }))
210
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 1)
211
+ const dataUri = cache.getDataUri('symbol-pin-1x')
212
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 2)
213
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 3)
214
+ expect(iconImageCache.get(dataUri, null).getImageState()).toBe(ImageState.IDLE)
215
+
216
+ await cache.registerSymbols([pin], MAP_STYLE, symbolRegistry, 1)
217
+ expect(new Icon({ src: dataUri }).getImageState()).toBe(ImageState.LOADED)
167
218
  })
168
219
  })
@@ -1,5 +1,57 @@
1
1
  export class MapProvider {
2
+ _notImplemented (method) {
3
+ throw new Error(`${this.name} must implement ${method}()`)
4
+ }
5
+
2
6
  isBaseMapReady () {
3
- throw new Error(this.name + ' must implement isBaseMapReady()')
7
+ this._notImplemented('isBaseMapReady')
8
+ }
9
+
10
+ /**
11
+ * Rasterises and registers each symbol's normal, active and selected images with the map.
12
+ * Images already registered are reused.
13
+ *
14
+ * @param {Object[]} symbolConfigs - symbol styles (symbol/symbolSvgContent plus token overrides)
15
+ * @param {Object} mapStyle - current map style config
16
+ * @param {Object} symbolRegistry
17
+ * @param {number} [pixelRatio] - defaults to the map's current pixel ratio
18
+ * @returns {Promise<void>}
19
+ */
20
+ addSymbolsToMap () {
21
+ this._notImplemented('addSymbolsToMap')
22
+ }
23
+
24
+ /**
25
+ * Rasterises and registers each pattern's image with the map. Images already registered are
26
+ * reused.
27
+ *
28
+ * @param {Object[]} patternConfigs - pattern styles (fillPattern/fillPatternSvgContent plus colours)
29
+ * @param {string} mapStyleId
30
+ * @param {Object} patternRegistry
31
+ * @param {number} [pixelRatio] - defaults to the map's current pixel ratio
32
+ * @returns {Promise<void>}
33
+ */
34
+ addPatternsToMap () {
35
+ this._notImplemented('addPatternsToMap')
36
+ }
37
+
38
+ /**
39
+ * The imageId of a registered symbol's active (keyboard cursor) variant.
40
+ *
41
+ * @param {string} normalImageId
42
+ * @returns {string|null}
43
+ */
44
+ getActiveSymbolImageId () {
45
+ this._notImplemented('getActiveSymbolImageId')
46
+ }
47
+
48
+ /**
49
+ * The imageId of a registered symbol's selected variant.
50
+ *
51
+ * @param {string} normalImageId
52
+ * @returns {string|null}
53
+ */
54
+ getSelectedSymbolImageId () {
55
+ this._notImplemented('getSelectedSymbolImageId')
4
56
  }
5
57
  }
@@ -19,6 +19,12 @@ describe('MapProvider', () => {
19
19
  })
20
20
  })
21
21
 
22
+ it.each(['addSymbolsToMap', 'addPatternsToMap', 'getActiveSymbolImageId', 'getSelectedSymbolImageId'])('requires a subclass to implement %s', (method) => {
23
+ const provider = new MapProvider()
24
+ provider.name = 'TestProvider'
25
+ expect(() => provider[method]()).toThrow(`TestProvider must implement ${method}()`)
26
+ })
27
+
22
28
  it('can be subclassed with an isBaseMapReady implementation', () => {
23
29
  class ConcreteProvider extends MapProvider {
24
30
  isBaseMapReady () {
@@ -1 +1 @@
1
- import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/objectWithoutProperties";import a from"@babel/runtime/helpers/asyncToGenerator";class r{isBaseMapReady(){throw new Error(this.name+" must implement isBaseMapReady()")}}var n=400,i=7,o=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom","highlightLabelAtCenter","highlightNextLabel"];var s=(t,e)=>{var a=null,r=function(){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];clearTimeout(a),a=setTimeout(()=>{t(...n)},e)};return r.cancel=()=>{a&&(clearTimeout(a),a=null)},r};function l(t){var{map:e,events:a,eventBus:r,getCenter:n,getZoom:i,getBounds:o,getResolution:l}=t,h=[],u=[],c=()=>{var t=i();return{center:n(),bounds:o(),resolution:l(),zoom:t,isAtMaxZoom:e.getMaxZoom()<=t,isAtMinZoom:e.getMinZoom()>=t}},d=(t,e)=>r.emit(t,e),p=()=>d(a.MAP_LOADED);e.on("load",p),h.push(["load",p]);e.once("idle",()=>d(a.MAP_FIRST_IDLE,c()));var g=()=>d(a.MAP_MOVE_START);e.on("movestart",g),h.push(["movestart",g]);var f=s(()=>{d(a.MAP_MOVE_END,c())},500);e.on("moveend",f),h.push(["moveend",f]);var y,m,v,M=(y=()=>{d(a.MAP_MOVE,c())},m=10,v=0,function(){var t=Date.now();t-v>=m&&(v=t,y(...arguments))});e.on("zoom",M),h.push(["zoom",M]);var b=()=>d(a.MAP_RENDER);e.on("render",b),h.push(["render",b]);var w=s(()=>{d(a.MAP_DATA_CHANGE,c())},500),x=t=>{t.isSourceLoaded&&w()};e.on("styledata",w),e.on("sourcedata",x),h.push(["styledata",w],["sourcedata",x]);var N=()=>d(a.MAP_STYLE_CHANGE);e.on("style.load",N),h.push(["style.load",N]);var P=t=>d(a.MAP_CLICK,{point:t.point,coords:[t.lngLat.lng,t.lngLat.lat]});return e.on("click",P),h.push(["click",P]),u.push(f,M,w),{remove(){u.forEach(t=>t.cancel()),h.forEach(t=>{var[a,r]=t;return e.off(a,r)})}}}let h=" ";class u{static get separator(){return h}static set separator(t){h=t}static parse(t){if(!isNaN(parseFloat(t))&&isFinite(t))return Number(t);const e=String(t).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==e[e.length-1]&&e.splice(e.length-1),""==e)return NaN;let a=null;switch(e.length){case 3:a=e[0]/1+e[1]/60+e[2]/3600;break;case 2:a=e[0]/1+e[1]/60;break;case 1:a=e[0];break;default:return NaN}return/^-|[WS]$/i.test(t.trim())&&(a=-a),Number(a)}static toDms(t,e="d",a=void 0){if(isNaN(t))return null;if("string"==typeof t&&""==t.trim())return null;if("boolean"==typeof t)return null;if(t==1/0)return null;if(null==t)return null;if(void 0===a)switch(e){case"d":case"deg":a=4;break;case"dm":case"deg+min":a=2;break;case"dms":case"deg+min+sec":a=0;break;default:e="d",a=4}t=Math.abs(t);let r=null,n=null,i=null,o=null;switch(e){default:case"d":case"deg":n=t.toFixed(a),n<100&&(n="0"+n),n<10&&(n="0"+n),r=n+"°";break;case"dm":case"deg+min":n=Math.floor(t),i=(60*t%60).toFixed(a),60==i&&(i=(0).toFixed(a),n++),n=("000"+n).slice(-3),i<10&&(i="0"+i),r=n+"°"+u.separator+i+"′";break;case"dms":case"deg+min+sec":n=Math.floor(t),i=Math.floor(3600*t/60)%60,o=(3600*t%60).toFixed(a),60==o&&(o=(0).toFixed(a),i++),60==i&&(i=0,n++),n=("000"+n).slice(-3),i=("00"+i).slice(-2),o<10&&(o="0"+o),r=n+"°"+u.separator+i+"′"+u.separator+o+"″"}return r}static toLat(t,e,a){const r=u.toDms(u.wrap90(t),e,a);return null===r?"–":r.slice(1)+u.separator+(t<0?"S":"N")}static toLon(t,e,a){const r=u.toDms(u.wrap180(t),e,a);return null===r?"–":r+u.separator+(t<0?"W":"E")}static toBrng(t,e,a){const r=u.toDms(u.wrap360(t),e,a);return null===r?"–":r.replace("360","0")}static fromLocale(t){const e=123456.789.toLocaleString(),a={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(a.thousands,"⁜").replace(a.decimal,".").replace("⁜",",")}static toLocale(t){const e=123456.789.toLocaleString(),a={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(/,([0-9])/,"⁜$1").replace(".",a.decimal).replace("⁜",a.thousands)}static compassPoint(t,e=3){if(![1,2,3].includes(Number(e)))throw new RangeError(`invalid precision ‘${e}’`);t=u.wrap360(t);const a=4*2**(e-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(t*a/360)%a*16/a]}static wrap90(t){if(-90<=t&&t<=90)return t;const e=t,a=360;return 1*Math.abs(((e-90)%a+a)%a-180)-90}static wrap180(t){if(-180<=t&&t<=180)return t;const e=360;return((360*t/e-180)%e+e)%e-180}static wrap360(t){if(0<=t&&t<360)return t;const e=360;return(360*t/e%e+e)%e}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const c=Math.PI;class d{constructor(t,e){if(isNaN(t))throw new TypeError(`invalid lat ‘${t}’`);if(isNaN(e))throw new TypeError(`invalid lon ‘${e}’`);this._lat=u.wrap90(Number(t)),this._lon=u.wrap180(Number(e))}get lat(){return this._lat}get latitude(){return this._lat}set lat(t){if(this._lat=isNaN(t)?u.wrap90(u.parse(t)):u.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${t}’`)}set latitude(t){if(this._lat=isNaN(t)?u.wrap90(u.parse(t)):u.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${t}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(t){if(this._lon=isNaN(t)?u.wrap180(u.parse(t)):u.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${t}’`)}set lng(t){if(this._lon=isNaN(t)?u.wrap180(u.parse(t)):u.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${t}’`)}set longitude(t){if(this._lon=isNaN(t)?u.wrap180(u.parse(t)):u.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${t}’`)}static get metresToKm(){return.001}static get metresToMiles(){return 1/1609.344}static get metresToNauticalMiles(){return 1/1852}static parse(...t){if(0==t.length)throw new TypeError("invalid (empty) point");if(null===t[0]||null===t[1])throw new TypeError("invalid (null) point");let e,a;if(2==t.length&&([e,a]=t,e=u.wrap90(u.parse(e)),a=u.wrap180(u.parse(a)),isNaN(e)||isNaN(a)))throw new TypeError(`invalid point ‘${t.toString()}’`);if(1==t.length&&"string"==typeof t[0]&&([e,a]=t[0].split(","),e=u.wrap90(u.parse(e)),a=u.wrap180(u.parse(a)),isNaN(e)||isNaN(a)))throw new TypeError(`invalid point ‘${t[0]}’`);if(1==t.length&&"object"==typeof t[0]){const r=t[0];if("Point"==r.type&&Array.isArray(r.coordinates)?[a,e]=r.coordinates:(null!=r.latitude&&(e=r.latitude),null!=r.lat&&(e=r.lat),null!=r.longitude&&(a=r.longitude),null!=r.lng&&(a=r.lng),null!=r.lon&&(a=r.lon),e=u.wrap90(u.parse(e)),a=u.wrap180(u.parse(a))),isNaN(e)||isNaN(a))throw new TypeError(`invalid point ‘${JSON.stringify(t[0])}’`)}if(isNaN(e)||isNaN(a))throw new TypeError(`invalid point ‘${t.toString()}’`);return new d(e,a)}distanceTo(t,e=6371e3){if(t instanceof d||(t=d.parse(t)),isNaN(e))throw new TypeError(`invalid radius ‘${e}’`);const a=e,r=this.lat.toRadians(),n=this.lon.toRadians(),i=t.lat.toRadians(),o=i-r,s=t.lon.toRadians()-n,l=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r)*Math.cos(i)*Math.sin(s/2)*Math.sin(s/2);return a*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))}initialBearingTo(t){if(t instanceof d||(t=d.parse(t)),this.equals(t))return NaN;const e=this.lat.toRadians(),a=t.lat.toRadians(),r=(t.lon-this.lon).toRadians(),n=Math.cos(e)*Math.sin(a)-Math.sin(e)*Math.cos(a)*Math.cos(r),i=Math.sin(r)*Math.cos(a),o=Math.atan2(i,n).toDegrees();return u.wrap360(o)}finalBearingTo(t){t instanceof d||(t=d.parse(t));const e=t.initialBearingTo(this)+180;return u.wrap360(e)}midpointTo(t){t instanceof d||(t=d.parse(t));const e=this.lat.toRadians(),a=this.lon.toRadians(),r=t.lat.toRadians(),n=(t.lon-this.lon).toRadians(),i=Math.cos(e),o=0,s=Math.sin(e),l={x:i+Math.cos(r)*Math.cos(n),y:o+Math.cos(r)*Math.sin(n),z:s+Math.sin(r)},h=Math.atan2(l.z,Math.sqrt(l.x*l.x+l.y*l.y)),u=a+Math.atan2(l.y,l.x),c=h.toDegrees(),p=u.toDegrees();return new d(c,p)}intermediatePointTo(t,e){if(t instanceof d||(t=d.parse(t)),this.equals(t))return new d(this.lat,this.lon);const a=this.lat.toRadians(),r=this.lon.toRadians(),n=t.lat.toRadians(),i=t.lon.toRadians(),o=n-a,s=i-r,l=Math.sin(o/2)*Math.sin(o/2)+Math.cos(a)*Math.cos(n)*Math.sin(s/2)*Math.sin(s/2),h=2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),u=Math.sin((1-e)*h)/Math.sin(h),c=Math.sin(e*h)/Math.sin(h),p=u*Math.cos(a)*Math.cos(r)+c*Math.cos(n)*Math.cos(i),g=u*Math.cos(a)*Math.sin(r)+c*Math.cos(n)*Math.sin(i),f=u*Math.sin(a)+c*Math.sin(n),y=Math.atan2(f,Math.sqrt(p*p+g*g)),m=Math.atan2(g,p),v=y.toDegrees(),M=m.toDegrees();return new d(v,M)}destinationPoint(t,e,a=6371e3){const r=t/a,n=Number(e).toRadians(),i=this.lat.toRadians(),o=this.lon.toRadians(),s=Math.sin(i)*Math.cos(r)+Math.cos(i)*Math.sin(r)*Math.cos(n),l=Math.asin(s),h=Math.sin(n)*Math.sin(r)*Math.cos(i),u=Math.cos(r)-Math.sin(i)*s,c=o+Math.atan2(h,u),p=l.toDegrees(),g=c.toDegrees();return new d(p,g)}static intersection(t,e,a,r){if(t instanceof d||(t=d.parse(t)),a instanceof d||(a=d.parse(a)),isNaN(e))throw new TypeError(`invalid brng1 ‘${e}’`);if(isNaN(r))throw new TypeError(`invalid brng2 ‘${r}’`);const n=t.lat.toRadians(),i=t.lon.toRadians(),o=a.lat.toRadians(),s=a.lon.toRadians(),l=Number(e).toRadians(),h=Number(r).toRadians(),u=o-n,p=s-i,g=2*Math.asin(Math.sqrt(Math.sin(u/2)*Math.sin(u/2)+Math.cos(n)*Math.cos(o)*Math.sin(p/2)*Math.sin(p/2)));if(Math.abs(g)<Number.EPSILON)return new d(t.lat,t.lon);const f=(Math.sin(o)-Math.sin(n)*Math.cos(g))/(Math.sin(g)*Math.cos(n)),y=(Math.sin(n)-Math.sin(o)*Math.cos(g))/(Math.sin(g)*Math.cos(o)),m=Math.acos(Math.min(Math.max(f,-1),1)),v=Math.acos(Math.min(Math.max(y,-1),1)),M=l-(Math.sin(s-i)>0?m:2*c-m),b=(Math.sin(s-i)>0?2*c-v:v)-h;if(0==Math.sin(M)&&0==Math.sin(b))return null;if(Math.sin(M)*Math.sin(b)<0)return null;const w=-Math.cos(M)*Math.cos(b)+Math.sin(M)*Math.sin(b)*Math.cos(g),x=Math.atan2(Math.sin(g)*Math.sin(M)*Math.sin(b),Math.cos(b)+Math.cos(M)*w),N=Math.asin(Math.min(Math.max(Math.sin(n)*Math.cos(x)+Math.cos(n)*Math.sin(x)*Math.cos(l),-1),1)),P=i+Math.atan2(Math.sin(l)*Math.sin(x)*Math.cos(n),Math.cos(x)-Math.sin(n)*Math.sin(N)),S=N.toDegrees(),E=P.toDegrees();return new d(S,E)}crossTrackDistanceTo(t,e,a=6371e3){t instanceof d||(t=d.parse(t)),e instanceof d||(e=d.parse(e));const r=a;if(this.equals(t))return 0;const n=t.distanceTo(this,r)/r,i=t.initialBearingTo(this).toRadians(),o=t.initialBearingTo(e).toRadians();return Math.asin(Math.sin(n)*Math.sin(i-o))*r}alongTrackDistanceTo(t,e,a=6371e3){t instanceof d||(t=d.parse(t)),e instanceof d||(e=d.parse(e));const r=a;if(this.equals(t))return 0;const n=t.distanceTo(this,r)/r,i=t.initialBearingTo(this).toRadians(),o=t.initialBearingTo(e).toRadians(),s=Math.asin(Math.sin(n)*Math.sin(i-o));return Math.acos(Math.cos(n)/Math.abs(Math.cos(s)))*Math.sign(Math.cos(o-i))*r}maxLatitude(t){const e=Number(t).toRadians(),a=this.lat.toRadians();return Math.acos(Math.abs(Math.sin(e)*Math.cos(a))).toDegrees()}static crossingParallels(t,e,a){if(t.equals(e))return null;const r=Number(a).toRadians(),n=t.lat.toRadians(),i=t.lon.toRadians(),o=e.lat.toRadians(),s=e.lon.toRadians()-i,l=Math.sin(n)*Math.cos(o)*Math.cos(r)*Math.sin(s),h=Math.sin(n)*Math.cos(o)*Math.cos(r)*Math.cos(s)-Math.cos(n)*Math.sin(o)*Math.cos(r),c=Math.cos(n)*Math.cos(o)*Math.sin(r)*Math.sin(s);if(c*c>l*l+h*h)return null;const d=Math.atan2(-h,l),p=Math.acos(c/Math.sqrt(l*l+h*h)),g=i+d+p,f=(i+d-p).toDegrees(),y=g.toDegrees();return{lon1:u.wrap180(f),lon2:u.wrap180(y)}}rhumbDistanceTo(t,e=6371e3){t instanceof d||(t=d.parse(t));const a=e,r=this.lat.toRadians(),n=t.lat.toRadians(),i=n-r;let o=Math.abs(t.lon-this.lon).toRadians();Math.abs(o)>c&&(o=o>0?-(2*c-o):2*c+o);const s=Math.log(Math.tan(n/2+c/4)/Math.tan(r/2+c/4)),l=Math.abs(s)>1e-11?i/s:Math.cos(r);return Math.sqrt(i*i+l*l*o*o)*a}rhumbBearingTo(t){if(t instanceof d||(t=d.parse(t)),this.equals(t))return NaN;const e=this.lat.toRadians(),a=t.lat.toRadians();let r=(t.lon-this.lon).toRadians();Math.abs(r)>c&&(r=r>0?-(2*c-r):2*c+r);const n=Math.log(Math.tan(a/2+c/4)/Math.tan(e/2+c/4)),i=Math.atan2(r,n).toDegrees();return u.wrap360(i)}rhumbDestinationPoint(t,e,a=6371e3){const r=this.lat.toRadians(),n=this.lon.toRadians(),i=Number(e).toRadians(),o=t/a,s=o*Math.cos(i);let l=r+s;Math.abs(l)>c/2&&(l=l>0?c-l:-c-l);const h=Math.log(Math.tan(l/2+c/4)/Math.tan(r/2+c/4)),u=Math.abs(h)>1e-11?s/h:Math.cos(r),p=n+o*Math.sin(i)/u,g=l.toDegrees(),f=p.toDegrees();return new d(g,f)}rhumbMidpointTo(t){t instanceof d||(t=d.parse(t));const e=this.lat.toRadians();let a=this.lon.toRadians();const r=t.lat.toRadians(),n=t.lon.toRadians();Math.abs(n-a)>c&&(a+=2*c);const i=(e+r)/2,o=Math.tan(c/4+e/2),s=Math.tan(c/4+r/2),l=Math.tan(c/4+i/2);let h=((n-a)*Math.log(l)+a*Math.log(s)-n*Math.log(o))/Math.log(s/o);isFinite(h)||(h=(a+n)/2);const u=i.toDegrees(),p=h.toDegrees();return new d(u,p)}static areaOf(t,e=6371e3){const a=e,r=t[0].equals(t[t.length-1]);r||t.push(t[0]);const n=t.length-1;let i=0;for(let e=0;e<n;e++){const a=t[e].lat.toRadians(),r=t[e+1].lat.toRadians(),n=(t[e+1].lon-t[e].lon).toRadians();i+=2*Math.atan2(Math.tan(n/2)*(Math.tan(a/2)+Math.tan(r/2)),1+Math.tan(a/2)*Math.tan(r/2))}(function(t){let e=0,a=t[0].initialBearingTo(t[1]);for(let r=0;r<t.length-1;r++){const n=t[r].initialBearingTo(t[r+1]),i=t[r].finalBearingTo(t[r+1]);e+=(n-a+540)%360-180,e+=(i-n+540)%360-180,a=i}const r=t[0].initialBearingTo(t[1]);e+=(r-a+540)%360-180;return Math.abs(e)<90})(t)&&(i=Math.abs(i)-2*c);const o=Math.abs(i*a*a);return r||t.pop(),o}equals(t){return t instanceof d||(t=d.parse(t)),!(Math.abs(this.lat-t.lat)>Number.EPSILON)&&!(Math.abs(this.lon-t.lon)>Number.EPSILON)}toGeoJSON(){return{type:"Point",coordinates:[this.lon,this.lat]}}toString(t="d",e=void 0){if(!["d","dm","dms","n"].includes(t))throw new RangeError(`invalid format ‘${t}’`);if("n"==t)return null==e&&(e=4),`${this.lat.toFixed(e)},${this.lon.toFixed(e)}`;return`${u.toLat(this.lat,t,e)}, ${u.toLon(this.lon,t,e)}`}}function p(t,e,a){if(null!==t)for(var r,n,i,o,s,l,h,u,c=0,d=0,g=t.type,f="FeatureCollection"===g,y="Feature"===g,m=f?t.features.length:1,v=0;v<m;v++){s=(u=!!(h=f?t.features[v].geometry:y?t.geometry:t)&&"GeometryCollection"===h.type)?h.geometries.length:1;for(var M=0;M<s;M++){var b=0,w=0;if(null!==(o=u?h.geometries[M]:h)){l=o.coordinates;var x=o.type;switch(c=0,x){case null:break;case"Point":if(!1===e(l,d,v,b,w))return!1;d++,b++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(!1===e(l[r],d,v,b,w))return!1;d++,"MultiPoint"===x&&b++}"LineString"===x&&b++;break;case"Polygon":case"MultiLineString":for(r=0;r<l.length;r++){for(n=0;n<l[r].length-c;n++){if(!1===e(l[r][n],d,v,b,w))return!1;d++}"MultiLineString"===x&&b++,"Polygon"===x&&w++}"Polygon"===x&&b++;break;case"MultiPolygon":for(r=0;r<l.length;r++){for(w=0,n=0;n<l[r].length;n++){for(i=0;i<l[r][n].length-c;i++){if(!1===e(l[r][n][i],d,v,b,w))return!1;d++}w++}b++}break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(!1===p(o.geometries[r],e))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}var g=function(t,e={}){if(null!=t.bbox&&!0!==e.recompute)return t.bbox;const a=[1/0,1/0,-1/0,-1/0];return p(t,t=>{a[0]>t[0]&&(a[0]=t[0]),a[1]>t[1]&&(a[1]=t[1]),a[2]<t[0]&&(a[2]=t[0]),a[3]<t[1]&&(a[3]=t[1])}),a},f=(t,e)=>{var[a,r]=t,[n,i]=e,o=new d(r,a),s=new d(i,n);return o.distanceTo(s)},y=t=>{var e=t/1609.344;if(e<.5){var a=Math.round(t),r=1===a?"metre":"metres";return"".concat(a," ").concat(r)}if(e<10){var n=Number.parseFloat(e.toFixed(1)),i=1===n?"mile":"miles";return"".concat(n," ").concat(i)}var o=Math.round(e);return"".concat(o," miles")},m=t=>g(t);function v(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,r)}return a}function M(e){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?v(Object(r),!0).forEach(function(a){t(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var b="highlighted-label";function w(t,e){if("number"==typeof t)return t;if(!Array.isArray(t)||"interpolate"!==t[0])return function(t,e){var{stops:a}=t;if(a.length<2)return a.length>0?a[0][1]:0;for(var r=a[0],n=a[a.length-1],i=1;i<a.length;i++){var o=a[i];if(o[0]>e){n=o,r=a[i-1];break}r=a[i-1],n=o}var[s,l]=r,[h,u]=n;return e<=s?l:e>=h?u:l+(e-s)/(h-s)*(u-l)}(t,e);var[,,a,...r]=t;if("zoom"!==a[0])throw new Error("Only zoom-based expressions supported");for(var n=0;n<r.length-2;n+=2){var i=r[n],o=r[n+1],s=r[n+2],l=r[n+3];if(e<=i)return o;if(e<=s)return o+(e-i)/(s-i)*(l-o)}return r[r.length-1]}function x(t,e,a){return e.flatMap(e=>{var r,n=function(t){var e,a;return"string"==typeof t?null===(e=/^{(.+)}$/.exec(t))||void 0===e?void 0:e[1]:Array.isArray(t)?null===(a=t.find(t=>Array.isArray(t)&&"get"===t[0]))||void 0===a?void 0:a[1]:null}(null===(r=e.layout)||void 0===r?void 0:r["text-field"]);return n?a.filter(t=>{var a;return t.layer.id===e.id&&(null===(a=t.properties)||void 0===a?void 0:a[n])}).map(a=>function(t,e,a,r){var n=function(t){var{type:e,coordinates:a}=t;if("Point"===e)return a;if("MultiPoint"===e)return a[0];if(e.includes("LineString")){var r="LineString"===e?a:a[0];return[(r[0][0]+r[r.length-1][0])/2,(r[0][1]+r[r.length-1][1])/2]}if(e.includes("Polygon")){var n="Polygon"===e?a[0]:a[0][0],i=n.reduce((t,e)=>[t[0]+e[0],t[1]+e[1]],[0,0]);return[i[0]/n.length,i[1]/n.length]}return null}(t.geometry);if(!n)return null;var i=r.project({lng:n[0],lat:n[1]});return{text:t.properties[a],x:i.x,y:i.y,feature:t,layer:e}}(a,e,n,t)).filter(Boolean):[]})}function N(t,e){if(e.highlightLayerId&&t.getLayer(e.highlightLayerId)){try{t.removeLayer(e.highlightLayerId)}catch(t){}e.highlightLayerId=null,e.highlightedExpr=null}}function P(t,e,a){var r;if(null!=e&&null!==(r=e.feature)&&void 0!==r&&r.layer){N(t,a);var{feature:n,layer:i}=e;a.highlightLayerId="highlight-".concat(i.id);var{id:o,type:s,properties:l,geometry:h}=n;t.getSource(b).setData({id:o,type:s,properties:l,geometry:h}),a.highlightedExpr=i.layout["text-size"];var u=t.getZoom(),c=function(t,e,a){return{id:"highlight-".concat(t.id),type:t.type,source:b,layout:M(M({},t.layout),{},{"text-size":e,"text-allow-overlap":!0,"text-ignore-placement":!0,"text-max-angle":90}),paint:M(M({},t.paint),{},{"text-color":a.text,"text-halo-color":a.halo,"text-halo-width":3,"text-halo-blur":1,"text-opacity":1})}}(i,1.5*w(a.highlightedExpr,u),a.isDarkStyle?{text:"#ffffff",halo:"#000000"}:{text:"#000000",halo:"#ffffff"});t.addLayer(c),t.moveLayer(a.highlightLayerId)}}function S(t,e){if(!e.currentPixel)return null;var a=e.labels.map((t,e)=>({pixel:[t.x,t.y],index:e})).filter(t=>t.pixel[0]!==e.currentPixel.x||t.pixel[1]!==e.currentPixel.y);if(!a.length)return null;var r=a.map(t=>t.pixel),n=((t,e,a)=>{var r=(t,e)=>t[0]===e[0]&&t[1]===e[1],n=e.filter(e=>{var n=Math.abs(e[0]-t[0]),i=Math.abs(e[1]-t[1]);return("ArrowUp"===a?e[1]<=t[1]&&i>=n:"ArrowDown"===a?e[1]>t[1]&&i>=n:"ArrowLeft"===a?e[0]<=t[0]&&i<n:"ArrowRight"!==a||e[0]>t[0]&&i<n)&&!r(e,t)});n.length||n.push(t);var i=e=>Math.hypot(t[0]-e[0],t[1]-e[1]),o=n.reduce((t,e)=>i(e)<i(t)?e:t,n[0]);return e.findIndex(t=>r(t,o))})([e.currentPixel.x,e.currentPixel.y],r,t);return(null==n||n<0||n>=a.length)&&(n=0),e.labels[a[n].index]}function E(t){t.getSource(b)||t.addSource(b,{type:"geojson",data:{type:"FeatureCollection",features:[]}})}function L(t){t.getStyle().layers.filter(t=>{var e;return"line"===(null===(e=t.layout)||void 0===e?void 0:e["symbol-placement"])}).forEach(e=>t.setLayoutProperty(e.id,"symbol-placement","line-center"))}var R=t=>t.endsWith(".cold")?"".concat(t.slice(0,-5),".hot"):t.endsWith(".hot")?"".concat(t.slice(0,-4),".cold"):null;function O(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,r)}return a}function T(e){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?O(Object(r),!0).forEach(function(a){t(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):O(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var I="icon-image",A="active-highlight",D="active-highlight-inner",_="selected-highlight",j=(t,e)=>{var a,r;return null!==(a=null===(r=t._activeSymbolImageMap)||void 0===r?void 0:r[e])&&void 0!==a?a:null},C=(t,e)=>{var a,r;return null!==(a=null===(r=t._selectedSymbolImageMap)||void 0===r?void 0:r[e])&&void 0!==a?a:null},B=(t,e,a,r)=>{var{featureId:n,idProperty:i,geometry:o}=r,s=t.getLayer(a);s&&(e[a]||(e[a]={ids:new Set,fillIds:new Set,idProperty:i,sourceId:s.source,hasFillGeometry:!1}),!o||"Polygon"!==o.type&&"MultiPolygon"!==o.type||(e[a].hasFillGeometry=!0,e[a].fillIds.add(n)),e[a].ids.add(n))},F=(t,e,a,r)=>{e.forEach(e=>{if(!a.has(e)){var n="".concat(r,"-").concat(e);["".concat(n,"-fill"),"".concat(n,"-line"),"".concat(n,"-symbol")].forEach(e=>{t.getLayer(e)&&t.setFilter(e,["==","id",""])})}})},k=(t,e)=>{var a="_".concat(e.replaceAll("-",""),"Sources");F(t,t[a]||new Set,new Set,e),t[a]=new Set},z=(t,e,a,r,n,i,o)=>{!!t.getLayer(e)||t.addLayer(T(T({id:e,type:a,source:r},n&&{"source-layer":n}),{},{paint:i})),Object.entries(i).forEach(a=>{var[r,n]=a;t.setPaintProperty(e,r,n)}),t.setFilter(e,o),t.moveLayer(e)},W=(t,e,a,r,n,i,o)=>{var s,l=t.getLayoutProperty(n,"icon-offset");t.getLayer(e)||t.addLayer(T(T({id:e,type:"symbol",source:a},r&&{"source-layer":r}),{},{layout:T(T({[I]:i,"icon-anchor":null!==(s=t.getLayoutProperty(n,"icon-anchor"))&&void 0!==s?s:"center"},void 0!==l&&{"icon-offset":l}),{},{"icon-allow-overlap":!0})}));t.setLayoutProperty(e,I,i),void 0!==l&&t.setLayoutProperty(e,"icon-offset",l),t.setFilter(e,o),t.moveLayer(e)},q=(t,e,a,r,n,i)=>{var o,{ids:s,fillIds:l,idProperty:h,sourceId:u,hasFillGeometry:c}=a[e],d=t.getLayer(e),p=null!==(o=r[e])&&void 0!==o?o:r[R(e)];if(d&&p){var g=d.sourceLayer,f=c?"fill":d.type,y="".concat(n,"-").concat(e),{fill:m}=p,v=n===_,M=(t=>t===_||t===D)(n),{lineColor:b,lineWidth:w}=((t,e)=>({lineColor:e?t.selectionStroke:t.stroke,lineWidth:e?t.strokeWidth:t.activeStrokeWidth}))(p,M),x=h?["get",h]:["id"],N=["in",x,["literal",Array.from(s)]];if("fill-extrusion"!==d.type)switch(f){case"fill":((t,e,a,r,n)=>{var{isSelected:i,idExpression:o,fillIds:s,fill:l,lineColor:h,lineWidth:u,filter:c}=n;if(i){var d=[];s.forEach(t=>d.push(t));var p=["in",o,["literal",d]];z(t,"".concat(e,"-fill"),"fill",a,r,{"fill-color":l},p)}z(t,"".concat(e,"-line"),"line",a,r,{"line-color":h,"line-width":u},c)})(t,y,u,g,{isSelected:v,idExpression:x,fillIds:l,fill:m,lineColor:b,lineWidth:w,filter:N});break;case"line":((t,e,a,r,n,i,o)=>{t.getLayer("".concat(e,"-fill"))&&t.setFilter("".concat(e,"-fill"),["==","id",""]),z(t,"".concat(e,"-line"),"line",a,r,{"line-color":n,"line-width":i},o)})(t,y,u,g,b,w,N);break;case"symbol":((t,e,a,r,n,i,o)=>{var s=t.getLayoutProperty(n,I);if(Array.isArray(s)){var l=o===j?"user_symbolActiveImageId":"user_symbolSelectedImageId";W(t,"".concat(e,"-symbol"),a,r,n,["get",l],i)}else{var h=o(t,s);h&&W(t,"".concat(e,"-symbol"),a,r,n,h,i)}})(t,y,u,g,e,N,i)}else((t,e,a,r)=>{var{ids:n,lineColor:i,lineWidth:o,idExpression:s}=r,l=[];n.forEach(t=>l.push(t));var h=["in",s,["literal",l]],{source:u,sourceLayer:c}=t.getLayer(a);z(t,"".concat(e,"-line"),"line",u,c,{"line-color":i,"line-width":o},h)})(t,y,e,{ids:s,lineColor:b,lineWidth:w,idExpression:x})}},$=(t,e,a,r,n)=>{var i=((t,e)=>{var a={};return null==e||e.forEach(e=>{B(t,a,e.layerId,e);var r=R(e.layerId);r&&B(t,a,r,e)}),a})(t,e),o=new Set(Object.keys(i)),s="_".concat(r.replaceAll("-",""),"Sources"),l=t[s]||new Set;return F(t,l,o,r),t[s]=o,o.forEach(e=>q(t,e,i,a,r,n)),i};var Z=(t,e,a)=>{var r=(e.x-a.x)**2+(e.y-a.y)**2;if(0===r)return(t.x-e.x)**2+(t.y-e.y)**2;var n=((t.x-e.x)*(a.x-e.x)+(t.y-e.y)*(a.y-e.y))/r;return n=Math.max(0,Math.min(1,n)),(t.x-(e.x+n*(a.x-e.x)))**2+(t.y-(e.y+n*(a.y-e.y)))**2},G=function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{radius:r=10}=a,n=[[e.x-r,e.y-r],[e.x+r,e.y+r]],i=t.queryRenderedFeatures(n);if(0===i.length)return[];var o=new Set(t.queryRenderedFeatures([e.x,e.y]).map(t=>{var e,a=void 0===t.id?JSON.stringify(t.properties):t.id;return"".concat(null===(e=t.layer)||void 0===e?void 0:e.source,":").concat(a)})),s=[];i.forEach(t=>{!1===s.includes(t.layer.id)&&s.push(t.layer.id)});for(var l=new Set,h=[],u=i.length-1;u>=0;u--){var c,d=i[u],p=void 0===d.id?JSON.stringify(d.properties):d.id,g="".concat(null===(c=d.layer)||void 0===c?void 0:c.source,":").concat(p);!1===l.has(g)&&(l.add(g),h.push(d))}var f=t.unproject(e),y=[f.lng,f.lat],m=h.filter(t=>{var e=t.geometry.type;if(e.includes("Polygon"))return("Polygon"===e?[t.geometry.coordinates]:t.geometry.coordinates).some(t=>((t,e)=>{for(var[a,r]=t,n=!1,i=0,o=e.length-1;i<e.length;o=i,i++){var[s,l]=e[i],[h,u]=e[o];l>r!=u>r&&a<(h-s)*(r-l)/(u-l)+s&&(n=!n)}return n})(y,t[0]));if("Point"===e||"MultiPoint"===e){var a,r=void 0===t.id?JSON.stringify(t.properties):t.id;return o.has("".concat(null===(a=t.layer)||void 0===a?void 0:a.source,":").concat(r))}return!0});return m.map(a=>{var r=0,n=a.geometry.type,i=((t,e,a)=>{var{coordinates:r,type:n}=a,i=1/0,o=e=>t.project(e),s=t=>{for(var a=0;a<t.length-1;a++){var r=Z(e,o(t[a]),o(t[a+1]));r<i&&(i=r)}};if("Point"===n){var l=o(r);i=(e.x-l.x)**2+(e.y-l.y)**2}else"LineString"===n||"MultiPoint"===n?"LineString"===n?s(r):r.forEach(t=>{var a=o(t),r=(e.x-a.x)**2+(e.y-a.y)**2;r<i&&(i=r)}):"Polygon"===n||"MultiLineString"===n?r.forEach(s):"MultiPolygon"===n&&r.forEach(t=>t.forEach(s));return i})(t,e,a.geometry);return r+=1e6*s.indexOf(a.layer.id),n.includes("Polygon")&&(r-=5e5),{f:a,score:r+=i}}).sort((t,e)=>t.score-e.score).map(t=>{var{f:e}=t;return e})},H=(t,e,a)=>{var r=t.getCanvas();if(a&&t.off("mousemove",a),null==e||!e.length)return r.style.cursor="",null;var n=a=>{var n=(t=>{var e=new Set(t);return t.forEach(t=>{var a=R(t);a&&e.add(a)}),[...e]})(e).filter(e=>t.getLayer(e));if(0!==n.length){var{lineLayers:i,otherLayers:o}=((t,e)=>{var a=[],r=[];for(var n of e)if("line"===t.getLayer(n).type){var i=n.endsWith("-stroke")?n.slice(0,-7):null;null!==i&&e.includes(i)||a.push(n)}else r.push(n);return{lineLayers:a,otherLayers:r}})(t,n),{x:s,y:l}=a.point,h=[[s-10,l-10],[s+10,l+10]],u=i.length>0&&t.queryRenderedFeatures(h,{layers:i}).length>0,c=o.length>0&&t.queryRenderedFeatures(a.point,{layers:o}).length>0;r.style.cursor=u||c?"pointer":""}else r.style.cursor=""};return t.on("mousemove",n),n},J=function(){var t=a(function*(t,e,r,n){var i,o,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:2;e.length&&(null!==(i=t._activeSymbolImageMap)&&void 0!==i||(t._activeSymbolImageMap={}),null!==(o=t._selectedSymbolImageMap)&&void 0!==o||(t._selectedSymbolImageMap={}),yield Promise.all(e.flatMap(e=>{var i=n.getSymbolImageId(e,r,!1,s),o=n.getSymbolImageId(e,r,!0,s);return i&&o&&(t._activeSymbolImageMap[i]=o),["normal","active","selected"].map(function(){var l=a(function*(a){var l="active"===a?o:i;if("selected"===a||l&&!t.hasImage(l)){var h=yield n.rasteriseSymbolImage(e,r,a,s);h&&("selected"===a&&i&&(t._selectedSymbolImageMap[i]=h.imageId),t.hasImage(h.imageId)||t.addImage(h.imageId,h.imageData,{pixelRatio:s}))}});return function(t){return l.apply(this,arguments)}}())})))});return function(e,a,r,n){return t.apply(this,arguments)}}(),V=function(){var t=a(function*(t,e,r,n,i){if(e.length){var o=(t=>Math.max(2,2*t))(i),s=e.reduce((e,s)=>{var l=n.getPatternImageId(s,r,i);return!l||e[l]||t.hasImage(l)||(e[l]=a(function*(){var e=yield n.rasterisePatternImage(s,r,i);e&&!t.hasImage(e.imageId)&&t.addImage(e.imageId,e.imageData,{pixelRatio:o})})),e},{});yield Promise.all(Object.values(s).map(t=>t()))}});return function(e,a,r,n,i){return t.apply(this,arguments)}}(),Y=["container","padding","mapStyle","mapSize","center","zoom","bounds","pixelRatio"];function K(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,r)}return a}function U(e){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?K(Object(r),!0).forEach(function(a){t(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):K(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}class X extends r{constructor(t){var{mapFramework:e,mapProviderConfig:a={},events:r,eventBus:n}=t;super(),this.maplibreModule=e,this.events=r,this.eventBus=n,this.capabilities={supportedShortcuts:o,supportsMapSizes:!0},Object.assign(this,a)}get name(){return"MapLibreProvider"}initMap(t){var r=this;return a(function*(){var{container:a,padding:n,mapStyle:i,mapSize:o,center:s,zoom:h,bounds:u,pixelRatio:c}=t,d=e(t,Y);r.mapStyleId=null==i?void 0:i.id,r.mapSize=o;var{Map:p}=r.maplibreModule,{events:g,eventBus:f}=r,y=new p(U(U({},d),{},{container:a,style:null==i?void 0:i.url,pixelRatio:c,padding:n,center:s,zoom:h,fadeDuration:0,attributionControl:!1,dragRotate:!1,doubleClickZoom:!1}));y.touchZoomRotate.disableRotation(),r.map=y,r.map.setPadding(n),u&&y.fitBounds(u,{duration:0}),function(t){var e=Event.prototype.preventDefault;Event.prototype.preventDefault=function(){if(("touchmove"===this.type||"touchstart"===this.type)&&!this.cancelable){var a=t.getCanvas();if(a&&(this.target===a||a.contains(this.target)))return}e.call(this)}}(y),function(t){var e=t.getCanvas();e.removeAttribute("role"),e.setAttribute("tabindex",-1),e.removeAttribute("aria-label"),e.style.display="block",e.addEventListener("focus",t=>{e.blur(),t.relatedTarget&&t.relatedTarget.focus({preventScroll:!0})})}(y),l({map:y,events:g,eventBus:f,getCenter:r.getCenter.bind(r),getZoom:r.getZoom.bind(r),getBounds:r.getBounds.bind(r),getResolution:r.getResolution.bind(r)}),function(t){var{mapProvider:e,map:a,events:r,eventBus:n}=t,i=t=>{a.once("style.load",()=>{n.emit(r.MAP_STYLE_CHANGE,{mapStyleId:t.id})}),a.setStyle(t.url,{diff:!1})},o=t=>{a.setPixelRatio(t)},s=t=>{var{mapSize:a}=t;e.mapSize=a};n.on(r.MAP_SET_STYLE,i),n.on(r.MAP_SET_PIXEL_RATIO,o),n.on(r.MAP_SIZE_CHANGE,s)}({mapProvider:r,map:y,events:g,eventBus:f}),y.on("load",()=>{r.labelNavigator=function(t,e,a,r){var n={isDarkStyle:"dark"===e,labels:[],currentPixel:null,highlightLayerId:null,highlightedExpr:null};function i(){var e=t.getStyle().layers.filter(t=>"symbol"===t.type),a=t.queryRenderedFeatures({layers:e.map(t=>t.id)});n.labels=x(t,e,a)}function o(){if(i(),!n.labels.length)return null;var e=t.project(t.getCenter()),a=function(t,e){var a;return null===(a=t.reduce((t,a)=>{var r=(a.x-e.x)**2+(a.y-e.y)**2;return!t||r<t.dist?{label:a,dist:r}:t},null))||void 0===a?void 0:a.label}(n.labels,e);return n.currentPixel={x:a.x,y:a.y},P(t,a,n),a.text}return L(t),E(t),null==r||r.on(a.MAP_SET_STYLE,e=>{t.once("styledata",()=>t.once("idle",()=>{L(t),E(t),n.isDarkStyle="dark"===(null==e?void 0:e.mapColorScheme)}))}),t.on("zoom",()=>{if(n.highlightLayerId&&n.highlightedExpr){var e=w(n.highlightedExpr,t.getZoom());t.setLayoutProperty(n.highlightLayerId,"text-size",1.5*e)}}),function(t){t.getStyle().layers.filter(t=>"symbol"===t.type).forEach(e=>{t.setPaintProperty(e.id,"text-opacity",["case",["boolean",["feature-state","highlighted"],!1],0,1])})}(t),{refreshLabels:i,highlightNextLabel:function(e){if(i(),!n.labels.length)return null;if(!n.currentPixel)return o();var a=S(e,n);return a?(n.currentPixel={x:a.x,y:a.y},P(t,a,n),a.text):null},highlightLabelAtCenter:o,clearHighlightedLabel:()=>N(t,n)}}(y,null==i?void 0:i.mapColorScheme,g,f)}),r.eventBus.emit(g.MAP_READY,{map:r.map,mapStyleId:r.mapStyleId,mapSize:r.mapSize,crs:r.crs})})()}isBaseMapReady(){var t;return Boolean(null===(t=this.map)||void 0===t?void 0:t.getStyle())}destroyMap(){var t,e;this.setHoverCursor([]),null===(t=this.mapEvents)||void 0===t||t.remove(),null===(e=this.appEvents)||void 0===e||e.remove(),this.mapEvents=null,this.appEvents=null,this.map.remove()}setHoverCursor(t){this.map&&(this._onHoverMove=H(this.map,t,this._onHoverMove))}setView(t){var{center:e,zoom:a}=t;this.map.flyTo({center:e||this.getCenter(),zoom:a||this.getZoom(),duration:this.map.isStyleLoaded()?n:0})}zoomIn(t){this.map.easeTo({zoom:this.getZoom()+t,duration:n})}zoomOut(t){this.map.easeTo({zoom:this.getZoom()-t,duration:n})}panBy(t){this.map.panBy(t,{duration:n})}fitToBounds(t){var e=Array.isArray(t)?t:m(t),a=this.map.isStyleLoaded()?n:0;this.map.fitBounds(e,{duration:a})}setPadding(t){this.map.setPadding(t)}updateHighlightedFeatures(t,e,a){var{LngLatBounds:r}=this.maplibreModule;return function(t){var{LngLatBounds:e,map:a,selectedFeatures:r,activeFeatures:n,stylesMap:i}=t;if(!a)return null;null!=n&&n.length?($(a,n,i,A,j),$(a,n,i,D,C)):(k(a,A),k(a,D));var o={};null!=r&&r.length?o=$(a,r,i,_,C):k(a,_);var s=[];return Object.entries(o).forEach(t=>{var[e,{ids:r,idProperty:n}]=t;s.push(...a.queryRenderedFeatures({layers:[e]}).filter(t=>{var e;return r.has(n?null===(e=t.properties)||void 0===e?void 0:e[n]:t.id)}))}),((t,e)=>{if(!e.length)return null;var a=new t;return e.forEach(t=>{var e=t=>"number"==typeof t[0]?a.extend(t):t.forEach(e);e(t.geometry.coordinates)}),[a.getWest(),a.getSouth(),a.getEast(),a.getNorth()]})(e,s)}({LngLatBounds:r,map:this.map,selectedFeatures:t,activeFeatures:e,stylesMap:a})}highlightNextLabel(t){var e;return(null===(e=this.labelNavigator)||void 0===e?void 0:e.highlightNextLabel(t))||null}highlightLabelAtCenter(){var t;return(null===(t=this.labelNavigator)||void 0===t?void 0:t.highlightLabelAtCenter())||null}clearHighlightedLabel(){var t;return(null===(t=this.labelNavigator)||void 0===t?void 0:t.clearHighlightedLabel())||null}getCenter(){var t=this.map.getCenter();return[Number(t.lng.toFixed(i)),Number(t.lat.toFixed(i))]}getZoom(){return Number(this.map.getZoom().toFixed(i))}getBounds(){return this.map.getBounds().toArray().flat(1)}getFeaturesAtPoint(t,e){return G(this.map,t,e)}getVisibleFeatures(t){var e=t.filter(t=>this.map.getLayer(t));return e.length?this.map.queryRenderedFeatures(void 0,{layers:e}):[]}addSymbolsToMap(t,e,r){var n=this;return a(function*(){var a=n.map.getPixelRatio()||1;return J(n.map,t,e,r,a)})()}addPatternsToMap(t,e,r){var n=this;return a(function*(){var a=n.map.getPixelRatio()||1;return V(n.map,t,e,r,a)})()}getAreaDimensions(){var{LngLatBounds:t}=this.maplibreModule;return(t=>{var e,a,r,n;if(t&&"function"==typeof t.getWest)e=t.getWest(),a=t.getSouth(),r=t.getEast(),n=t.getNorth();else{if(!Array.isArray(t)||2!==t.length)return"";[[e,a],[r,n]]=t}var i=f([e,a],[r,a]),o=f([e,a],[e,n]),s=y(i),l=y(o);return"".concat(l," by ").concat(s)})(((t,e)=>{var{width:a,height:r}=e.getContainer().getBoundingClientRect(),n=e.getPadding(),i=[n.left,r-n.bottom],o=[a-n.right,n.top];return new t(e.unproject(i),e.unproject(o))})(t,this.map))}getCardinalMove(t,e){return((t,e)=>{var[a,r]=t,[n,i]=e,o=i-r,s=n-a,l=[];if(Math.abs(o)>1e-4){var h=Math.round(f([a,r],[a,i]));l.push("".concat(o>0?"north":"south"," ").concat(y(h)))}if(Math.abs(s)>1e-4){var u=Math.round(f([a,r],[n,r]));l.push("".concat(s>0?"east":"west"," ").concat(y(u)))}return l.join(", ")})(t,e)}getResolution(){return t=this.map.getCenter(),e=this.map.getZoom(),a=t.lat,r=Math.pow(2,e),40075016.686*Math.cos(a*Math.PI/180)/(512*r);var t,e,a,r}mapToScreen(t){return this.map.project(t)}screenToMap(t){var{lng:e,lat:a}=this.map.unproject([t.x,t.y]);return[e,a]}isGeometryObscured(t,e){return((t,e,a)=>{var r=a.getContainer().getBoundingClientRect(),[n,i,o,s]=m(t),l=[a.project([n,i]),a.project([n,s]),a.project([o,i]),a.project([o,s])],h=Math.min(...l.map(t=>t.x)),u=Math.max(...l.map(t=>t.x)),c=Math.min(...l.map(t=>t.y)),d=Math.max(...l.map(t=>t.y)),p=e.left-r.left,g=e.top-r.top,f=e.right-r.left,y=e.bottom-r.top;return h<f&&u>p&&c<y&&d>g})(t,e,this.map)}}export{X as default};
1
+ import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/objectWithoutProperties";import a from"@babel/runtime/helpers/asyncToGenerator";class r{_notImplemented(t){throw new Error("".concat(this.name," must implement ").concat(t,"()"))}isBaseMapReady(){this._notImplemented("isBaseMapReady")}addSymbolsToMap(){this._notImplemented("addSymbolsToMap")}addPatternsToMap(){this._notImplemented("addPatternsToMap")}getActiveSymbolImageId(){this._notImplemented("getActiveSymbolImageId")}getSelectedSymbolImageId(){this._notImplemented("getSelectedSymbolImageId")}}var n=400,i=7,o=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom","highlightLabelAtCenter","highlightNextLabel"];var s=(t,e)=>{var a=null,r=function(){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];clearTimeout(a),a=setTimeout(()=>{t(...n)},e)};return r.cancel=()=>{a&&(clearTimeout(a),a=null)},r};function l(t){var{map:e,events:a,eventBus:r,getCenter:n,getZoom:i,getBounds:o,getResolution:l}=t,h=[],c=[],u=()=>{var t=i();return{center:n(),bounds:o(),resolution:l(),zoom:t,isAtMaxZoom:e.getMaxZoom()<=t,isAtMinZoom:e.getMinZoom()>=t}},d=(t,e)=>r.emit(t,e),g=()=>d(a.MAP_LOADED);e.on("load",g),h.push(["load",g]);e.once("idle",()=>d(a.MAP_FIRST_IDLE,u()));var p=()=>d(a.MAP_MOVE_START);e.on("movestart",p),h.push(["movestart",p]);var m=s(()=>{d(a.MAP_MOVE_END,u())},500);e.on("moveend",m),h.push(["moveend",m]);var y,f,v,M=(y=()=>{d(a.MAP_MOVE,u())},f=10,v=0,function(){var t=Date.now();t-v>=f&&(v=t,y(...arguments))});e.on("zoom",M),h.push(["zoom",M]);var b=()=>d(a.MAP_RENDER);e.on("render",b),h.push(["render",b]);var w=s(()=>{d(a.MAP_DATA_CHANGE,u())},500),I=t=>{t.isSourceLoaded&&w()};e.on("styledata",w),e.on("sourcedata",I),h.push(["styledata",w],["sourcedata",I]);var x=()=>d(a.MAP_STYLE_CHANGE);e.on("style.load",x),h.push(["style.load",x]);var S=t=>d(a.MAP_CLICK,{point:t.point,coords:[t.lngLat.lng,t.lngLat.lat]});return e.on("click",S),h.push(["click",S]),c.push(m,M,w),{remove(){c.forEach(t=>t.cancel()),h.forEach(t=>{var[a,r]=t;return e.off(a,r)})}}}let h=" ";class c{static get separator(){return h}static set separator(t){h=t}static parse(t){if(!isNaN(parseFloat(t))&&isFinite(t))return Number(t);const e=String(t).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==e[e.length-1]&&e.splice(e.length-1),""==e)return NaN;let a=null;switch(e.length){case 3:a=e[0]/1+e[1]/60+e[2]/3600;break;case 2:a=e[0]/1+e[1]/60;break;case 1:a=e[0];break;default:return NaN}return/^-|[WS]$/i.test(t.trim())&&(a=-a),Number(a)}static toDms(t,e="d",a=void 0){if(isNaN(t))return null;if("string"==typeof t&&""==t.trim())return null;if("boolean"==typeof t)return null;if(t==1/0)return null;if(null==t)return null;if(void 0===a)switch(e){case"d":case"deg":a=4;break;case"dm":case"deg+min":a=2;break;case"dms":case"deg+min+sec":a=0;break;default:e="d",a=4}t=Math.abs(t);let r=null,n=null,i=null,o=null;switch(e){default:case"d":case"deg":n=t.toFixed(a),n<100&&(n="0"+n),n<10&&(n="0"+n),r=n+"°";break;case"dm":case"deg+min":n=Math.floor(t),i=(60*t%60).toFixed(a),60==i&&(i=(0).toFixed(a),n++),n=("000"+n).slice(-3),i<10&&(i="0"+i),r=n+"°"+c.separator+i+"′";break;case"dms":case"deg+min+sec":n=Math.floor(t),i=Math.floor(3600*t/60)%60,o=(3600*t%60).toFixed(a),60==o&&(o=(0).toFixed(a),i++),60==i&&(i=0,n++),n=("000"+n).slice(-3),i=("00"+i).slice(-2),o<10&&(o="0"+o),r=n+"°"+c.separator+i+"′"+c.separator+o+"″"}return r}static toLat(t,e,a){const r=c.toDms(c.wrap90(t),e,a);return null===r?"–":r.slice(1)+c.separator+(t<0?"S":"N")}static toLon(t,e,a){const r=c.toDms(c.wrap180(t),e,a);return null===r?"–":r+c.separator+(t<0?"W":"E")}static toBrng(t,e,a){const r=c.toDms(c.wrap360(t),e,a);return null===r?"–":r.replace("360","0")}static fromLocale(t){const e=123456.789.toLocaleString(),a={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(a.thousands,"⁜").replace(a.decimal,".").replace("⁜",",")}static toLocale(t){const e=123456.789.toLocaleString(),a={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(/,([0-9])/,"⁜$1").replace(".",a.decimal).replace("⁜",a.thousands)}static compassPoint(t,e=3){if(![1,2,3].includes(Number(e)))throw new RangeError(`invalid precision ‘${e}’`);t=c.wrap360(t);const a=4*2**(e-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(t*a/360)%a*16/a]}static wrap90(t){if(-90<=t&&t<=90)return t;const e=t,a=360;return 1*Math.abs(((e-90)%a+a)%a-180)-90}static wrap180(t){if(-180<=t&&t<=180)return t;const e=360;return((360*t/e-180)%e+e)%e-180}static wrap360(t){if(0<=t&&t<360)return t;const e=360;return(360*t/e%e+e)%e}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const u=Math.PI;class d{constructor(t,e){if(isNaN(t))throw new TypeError(`invalid lat ‘${t}’`);if(isNaN(e))throw new TypeError(`invalid lon ‘${e}’`);this._lat=c.wrap90(Number(t)),this._lon=c.wrap180(Number(e))}get lat(){return this._lat}get latitude(){return this._lat}set lat(t){if(this._lat=isNaN(t)?c.wrap90(c.parse(t)):c.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${t}’`)}set latitude(t){if(this._lat=isNaN(t)?c.wrap90(c.parse(t)):c.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${t}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(t){if(this._lon=isNaN(t)?c.wrap180(c.parse(t)):c.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${t}’`)}set lng(t){if(this._lon=isNaN(t)?c.wrap180(c.parse(t)):c.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${t}’`)}set longitude(t){if(this._lon=isNaN(t)?c.wrap180(c.parse(t)):c.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${t}’`)}static get metresToKm(){return.001}static get metresToMiles(){return 1/1609.344}static get metresToNauticalMiles(){return 1/1852}static parse(...t){if(0==t.length)throw new TypeError("invalid (empty) point");if(null===t[0]||null===t[1])throw new TypeError("invalid (null) point");let e,a;if(2==t.length&&([e,a]=t,e=c.wrap90(c.parse(e)),a=c.wrap180(c.parse(a)),isNaN(e)||isNaN(a)))throw new TypeError(`invalid point ‘${t.toString()}’`);if(1==t.length&&"string"==typeof t[0]&&([e,a]=t[0].split(","),e=c.wrap90(c.parse(e)),a=c.wrap180(c.parse(a)),isNaN(e)||isNaN(a)))throw new TypeError(`invalid point ‘${t[0]}’`);if(1==t.length&&"object"==typeof t[0]){const r=t[0];if("Point"==r.type&&Array.isArray(r.coordinates)?[a,e]=r.coordinates:(null!=r.latitude&&(e=r.latitude),null!=r.lat&&(e=r.lat),null!=r.longitude&&(a=r.longitude),null!=r.lng&&(a=r.lng),null!=r.lon&&(a=r.lon),e=c.wrap90(c.parse(e)),a=c.wrap180(c.parse(a))),isNaN(e)||isNaN(a))throw new TypeError(`invalid point ‘${JSON.stringify(t[0])}’`)}if(isNaN(e)||isNaN(a))throw new TypeError(`invalid point ‘${t.toString()}’`);return new d(e,a)}distanceTo(t,e=6371e3){if(t instanceof d||(t=d.parse(t)),isNaN(e))throw new TypeError(`invalid radius ‘${e}’`);const a=e,r=this.lat.toRadians(),n=this.lon.toRadians(),i=t.lat.toRadians(),o=i-r,s=t.lon.toRadians()-n,l=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r)*Math.cos(i)*Math.sin(s/2)*Math.sin(s/2);return a*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))}initialBearingTo(t){if(t instanceof d||(t=d.parse(t)),this.equals(t))return NaN;const e=this.lat.toRadians(),a=t.lat.toRadians(),r=(t.lon-this.lon).toRadians(),n=Math.cos(e)*Math.sin(a)-Math.sin(e)*Math.cos(a)*Math.cos(r),i=Math.sin(r)*Math.cos(a),o=Math.atan2(i,n).toDegrees();return c.wrap360(o)}finalBearingTo(t){t instanceof d||(t=d.parse(t));const e=t.initialBearingTo(this)+180;return c.wrap360(e)}midpointTo(t){t instanceof d||(t=d.parse(t));const e=this.lat.toRadians(),a=this.lon.toRadians(),r=t.lat.toRadians(),n=(t.lon-this.lon).toRadians(),i=Math.cos(e),o=0,s=Math.sin(e),l={x:i+Math.cos(r)*Math.cos(n),y:o+Math.cos(r)*Math.sin(n),z:s+Math.sin(r)},h=Math.atan2(l.z,Math.sqrt(l.x*l.x+l.y*l.y)),c=a+Math.atan2(l.y,l.x),u=h.toDegrees(),g=c.toDegrees();return new d(u,g)}intermediatePointTo(t,e){if(t instanceof d||(t=d.parse(t)),this.equals(t))return new d(this.lat,this.lon);const a=this.lat.toRadians(),r=this.lon.toRadians(),n=t.lat.toRadians(),i=t.lon.toRadians(),o=n-a,s=i-r,l=Math.sin(o/2)*Math.sin(o/2)+Math.cos(a)*Math.cos(n)*Math.sin(s/2)*Math.sin(s/2),h=2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),c=Math.sin((1-e)*h)/Math.sin(h),u=Math.sin(e*h)/Math.sin(h),g=c*Math.cos(a)*Math.cos(r)+u*Math.cos(n)*Math.cos(i),p=c*Math.cos(a)*Math.sin(r)+u*Math.cos(n)*Math.sin(i),m=c*Math.sin(a)+u*Math.sin(n),y=Math.atan2(m,Math.sqrt(g*g+p*p)),f=Math.atan2(p,g),v=y.toDegrees(),M=f.toDegrees();return new d(v,M)}destinationPoint(t,e,a=6371e3){const r=t/a,n=Number(e).toRadians(),i=this.lat.toRadians(),o=this.lon.toRadians(),s=Math.sin(i)*Math.cos(r)+Math.cos(i)*Math.sin(r)*Math.cos(n),l=Math.asin(s),h=Math.sin(n)*Math.sin(r)*Math.cos(i),c=Math.cos(r)-Math.sin(i)*s,u=o+Math.atan2(h,c),g=l.toDegrees(),p=u.toDegrees();return new d(g,p)}static intersection(t,e,a,r){if(t instanceof d||(t=d.parse(t)),a instanceof d||(a=d.parse(a)),isNaN(e))throw new TypeError(`invalid brng1 ‘${e}’`);if(isNaN(r))throw new TypeError(`invalid brng2 ‘${r}’`);const n=t.lat.toRadians(),i=t.lon.toRadians(),o=a.lat.toRadians(),s=a.lon.toRadians(),l=Number(e).toRadians(),h=Number(r).toRadians(),c=o-n,g=s-i,p=2*Math.asin(Math.sqrt(Math.sin(c/2)*Math.sin(c/2)+Math.cos(n)*Math.cos(o)*Math.sin(g/2)*Math.sin(g/2)));if(Math.abs(p)<Number.EPSILON)return new d(t.lat,t.lon);const m=(Math.sin(o)-Math.sin(n)*Math.cos(p))/(Math.sin(p)*Math.cos(n)),y=(Math.sin(n)-Math.sin(o)*Math.cos(p))/(Math.sin(p)*Math.cos(o)),f=Math.acos(Math.min(Math.max(m,-1),1)),v=Math.acos(Math.min(Math.max(y,-1),1)),M=l-(Math.sin(s-i)>0?f:2*u-f),b=(Math.sin(s-i)>0?2*u-v:v)-h;if(0==Math.sin(M)&&0==Math.sin(b))return null;if(Math.sin(M)*Math.sin(b)<0)return null;const w=-Math.cos(M)*Math.cos(b)+Math.sin(M)*Math.sin(b)*Math.cos(p),I=Math.atan2(Math.sin(p)*Math.sin(M)*Math.sin(b),Math.cos(b)+Math.cos(M)*w),x=Math.asin(Math.min(Math.max(Math.sin(n)*Math.cos(I)+Math.cos(n)*Math.sin(I)*Math.cos(l),-1),1)),S=i+Math.atan2(Math.sin(l)*Math.sin(I)*Math.cos(n),Math.cos(I)-Math.sin(n)*Math.sin(x)),P=x.toDegrees(),N=S.toDegrees();return new d(P,N)}crossTrackDistanceTo(t,e,a=6371e3){t instanceof d||(t=d.parse(t)),e instanceof d||(e=d.parse(e));const r=a;if(this.equals(t))return 0;const n=t.distanceTo(this,r)/r,i=t.initialBearingTo(this).toRadians(),o=t.initialBearingTo(e).toRadians();return Math.asin(Math.sin(n)*Math.sin(i-o))*r}alongTrackDistanceTo(t,e,a=6371e3){t instanceof d||(t=d.parse(t)),e instanceof d||(e=d.parse(e));const r=a;if(this.equals(t))return 0;const n=t.distanceTo(this,r)/r,i=t.initialBearingTo(this).toRadians(),o=t.initialBearingTo(e).toRadians(),s=Math.asin(Math.sin(n)*Math.sin(i-o));return Math.acos(Math.cos(n)/Math.abs(Math.cos(s)))*Math.sign(Math.cos(o-i))*r}maxLatitude(t){const e=Number(t).toRadians(),a=this.lat.toRadians();return Math.acos(Math.abs(Math.sin(e)*Math.cos(a))).toDegrees()}static crossingParallels(t,e,a){if(t.equals(e))return null;const r=Number(a).toRadians(),n=t.lat.toRadians(),i=t.lon.toRadians(),o=e.lat.toRadians(),s=e.lon.toRadians()-i,l=Math.sin(n)*Math.cos(o)*Math.cos(r)*Math.sin(s),h=Math.sin(n)*Math.cos(o)*Math.cos(r)*Math.cos(s)-Math.cos(n)*Math.sin(o)*Math.cos(r),u=Math.cos(n)*Math.cos(o)*Math.sin(r)*Math.sin(s);if(u*u>l*l+h*h)return null;const d=Math.atan2(-h,l),g=Math.acos(u/Math.sqrt(l*l+h*h)),p=i+d+g,m=(i+d-g).toDegrees(),y=p.toDegrees();return{lon1:c.wrap180(m),lon2:c.wrap180(y)}}rhumbDistanceTo(t,e=6371e3){t instanceof d||(t=d.parse(t));const a=e,r=this.lat.toRadians(),n=t.lat.toRadians(),i=n-r;let o=Math.abs(t.lon-this.lon).toRadians();Math.abs(o)>u&&(o=o>0?-(2*u-o):2*u+o);const s=Math.log(Math.tan(n/2+u/4)/Math.tan(r/2+u/4)),l=Math.abs(s)>1e-11?i/s:Math.cos(r);return Math.sqrt(i*i+l*l*o*o)*a}rhumbBearingTo(t){if(t instanceof d||(t=d.parse(t)),this.equals(t))return NaN;const e=this.lat.toRadians(),a=t.lat.toRadians();let r=(t.lon-this.lon).toRadians();Math.abs(r)>u&&(r=r>0?-(2*u-r):2*u+r);const n=Math.log(Math.tan(a/2+u/4)/Math.tan(e/2+u/4)),i=Math.atan2(r,n).toDegrees();return c.wrap360(i)}rhumbDestinationPoint(t,e,a=6371e3){const r=this.lat.toRadians(),n=this.lon.toRadians(),i=Number(e).toRadians(),o=t/a,s=o*Math.cos(i);let l=r+s;Math.abs(l)>u/2&&(l=l>0?u-l:-u-l);const h=Math.log(Math.tan(l/2+u/4)/Math.tan(r/2+u/4)),c=Math.abs(h)>1e-11?s/h:Math.cos(r),g=n+o*Math.sin(i)/c,p=l.toDegrees(),m=g.toDegrees();return new d(p,m)}rhumbMidpointTo(t){t instanceof d||(t=d.parse(t));const e=this.lat.toRadians();let a=this.lon.toRadians();const r=t.lat.toRadians(),n=t.lon.toRadians();Math.abs(n-a)>u&&(a+=2*u);const i=(e+r)/2,o=Math.tan(u/4+e/2),s=Math.tan(u/4+r/2),l=Math.tan(u/4+i/2);let h=((n-a)*Math.log(l)+a*Math.log(s)-n*Math.log(o))/Math.log(s/o);isFinite(h)||(h=(a+n)/2);const c=i.toDegrees(),g=h.toDegrees();return new d(c,g)}static areaOf(t,e=6371e3){const a=e,r=t[0].equals(t[t.length-1]);r||t.push(t[0]);const n=t.length-1;let i=0;for(let e=0;e<n;e++){const a=t[e].lat.toRadians(),r=t[e+1].lat.toRadians(),n=(t[e+1].lon-t[e].lon).toRadians();i+=2*Math.atan2(Math.tan(n/2)*(Math.tan(a/2)+Math.tan(r/2)),1+Math.tan(a/2)*Math.tan(r/2))}(function(t){let e=0,a=t[0].initialBearingTo(t[1]);for(let r=0;r<t.length-1;r++){const n=t[r].initialBearingTo(t[r+1]),i=t[r].finalBearingTo(t[r+1]);e+=(n-a+540)%360-180,e+=(i-n+540)%360-180,a=i}const r=t[0].initialBearingTo(t[1]);e+=(r-a+540)%360-180;return Math.abs(e)<90})(t)&&(i=Math.abs(i)-2*u);const o=Math.abs(i*a*a);return r||t.pop(),o}equals(t){return t instanceof d||(t=d.parse(t)),!(Math.abs(this.lat-t.lat)>Number.EPSILON)&&!(Math.abs(this.lon-t.lon)>Number.EPSILON)}toGeoJSON(){return{type:"Point",coordinates:[this.lon,this.lat]}}toString(t="d",e=void 0){if(!["d","dm","dms","n"].includes(t))throw new RangeError(`invalid format ‘${t}’`);if("n"==t)return null==e&&(e=4),`${this.lat.toFixed(e)},${this.lon.toFixed(e)}`;return`${c.toLat(this.lat,t,e)}, ${c.toLon(this.lon,t,e)}`}}function g(t,e,a){if(null!==t)for(var r,n,i,o,s,l,h,c,u=0,d=0,p=t.type,m="FeatureCollection"===p,y="Feature"===p,f=m?t.features.length:1,v=0;v<f;v++){s=(c=!!(h=m?t.features[v].geometry:y?t.geometry:t)&&"GeometryCollection"===h.type)?h.geometries.length:1;for(var M=0;M<s;M++){var b=0,w=0;if(null!==(o=c?h.geometries[M]:h)){l=o.coordinates;var I=o.type;switch(u=0,I){case null:break;case"Point":if(!1===e(l,d,v,b,w))return!1;d++,b++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(!1===e(l[r],d,v,b,w))return!1;d++,"MultiPoint"===I&&b++}"LineString"===I&&b++;break;case"Polygon":case"MultiLineString":for(r=0;r<l.length;r++){for(n=0;n<l[r].length-u;n++){if(!1===e(l[r][n],d,v,b,w))return!1;d++}"MultiLineString"===I&&b++,"Polygon"===I&&w++}"Polygon"===I&&b++;break;case"MultiPolygon":for(r=0;r<l.length;r++){for(w=0,n=0;n<l[r].length;n++){for(i=0;i<l[r][n].length-u;i++){if(!1===e(l[r][n][i],d,v,b,w))return!1;d++}w++}b++}break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(!1===g(o.geometries[r],e))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}var p=function(t,e={}){if(null!=t.bbox&&!0!==e.recompute)return t.bbox;const a=[1/0,1/0,-1/0,-1/0];return g(t,t=>{a[0]>t[0]&&(a[0]=t[0]),a[1]>t[1]&&(a[1]=t[1]),a[2]<t[0]&&(a[2]=t[0]),a[3]<t[1]&&(a[3]=t[1])}),a},m=(t,e)=>{var[a,r]=t,[n,i]=e,o=new d(r,a),s=new d(i,n);return o.distanceTo(s)},y=t=>{var e=t/1609.344;if(e<.5){var a=Math.round(t),r=1===a?"metre":"metres";return"".concat(a," ").concat(r)}if(e<10){var n=Number.parseFloat(e.toFixed(1)),i=1===n?"mile":"miles";return"".concat(n," ").concat(i)}var o=Math.round(e);return"".concat(o," miles")},f=t=>p(t);function v(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,r)}return a}function M(e){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?v(Object(r),!0).forEach(function(a){t(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var b="highlighted-label";function w(t,e){if("number"==typeof t)return t;if(!Array.isArray(t)||"interpolate"!==t[0])return function(t,e){var{stops:a}=t;if(a.length<2)return a.length>0?a[0][1]:0;for(var r=a[0],n=a[a.length-1],i=1;i<a.length;i++){var o=a[i];if(o[0]>e){n=o,r=a[i-1];break}r=a[i-1],n=o}var[s,l]=r,[h,c]=n;return e<=s?l:e>=h?c:l+(e-s)/(h-s)*(c-l)}(t,e);var[,,a,...r]=t;if("zoom"!==a[0])throw new Error("Only zoom-based expressions supported");for(var n=0;n<r.length-2;n+=2){var i=r[n],o=r[n+1],s=r[n+2],l=r[n+3];if(e<=i)return o;if(e<=s)return o+(e-i)/(s-i)*(l-o)}return r[r.length-1]}function I(t,e,a){return e.flatMap(e=>{var r,n=function(t){var e,a;return"string"==typeof t?null===(e=/^{(.+)}$/.exec(t))||void 0===e?void 0:e[1]:Array.isArray(t)?null===(a=t.find(t=>Array.isArray(t)&&"get"===t[0]))||void 0===a?void 0:a[1]:null}(null===(r=e.layout)||void 0===r?void 0:r["text-field"]);return n?a.filter(t=>{var a;return t.layer.id===e.id&&(null===(a=t.properties)||void 0===a?void 0:a[n])}).map(a=>function(t,e,a,r){var n=function(t){var{type:e,coordinates:a}=t;if("Point"===e)return a;if("MultiPoint"===e)return a[0];if(e.includes("LineString")){var r="LineString"===e?a:a[0];return[(r[0][0]+r[r.length-1][0])/2,(r[0][1]+r[r.length-1][1])/2]}if(e.includes("Polygon")){var n="Polygon"===e?a[0]:a[0][0],i=n.reduce((t,e)=>[t[0]+e[0],t[1]+e[1]],[0,0]);return[i[0]/n.length,i[1]/n.length]}return null}(t.geometry);if(!n)return null;var i=r.project({lng:n[0],lat:n[1]});return{text:t.properties[a],x:i.x,y:i.y,feature:t,layer:e}}(a,e,n,t)).filter(Boolean):[]})}function x(t,e){if(e.highlightLayerId&&t.getLayer(e.highlightLayerId)){try{t.removeLayer(e.highlightLayerId)}catch(t){}e.highlightLayerId=null,e.highlightedExpr=null}}function S(t,e,a){var r;if(null!=e&&null!==(r=e.feature)&&void 0!==r&&r.layer){x(t,a);var{feature:n,layer:i}=e;a.highlightLayerId="highlight-".concat(i.id);var{id:o,type:s,properties:l,geometry:h}=n;t.getSource(b).setData({id:o,type:s,properties:l,geometry:h}),a.highlightedExpr=i.layout["text-size"];var c=t.getZoom(),u=function(t,e,a){return{id:"highlight-".concat(t.id),type:t.type,source:b,layout:M(M({},t.layout),{},{"text-size":e,"text-allow-overlap":!0,"text-ignore-placement":!0,"text-max-angle":90}),paint:M(M({},t.paint),{},{"text-color":a.text,"text-halo-color":a.halo,"text-halo-width":3,"text-halo-blur":1,"text-opacity":1})}}(i,1.5*w(a.highlightedExpr,c),a.isDarkStyle?{text:"#ffffff",halo:"#000000"}:{text:"#000000",halo:"#ffffff"});t.addLayer(u),t.moveLayer(a.highlightLayerId)}}function P(t,e){if(!e.currentPixel)return null;var a=e.labels.map((t,e)=>({pixel:[t.x,t.y],index:e})).filter(t=>t.pixel[0]!==e.currentPixel.x||t.pixel[1]!==e.currentPixel.y);if(!a.length)return null;var r=a.map(t=>t.pixel),n=((t,e,a)=>{var r=(t,e)=>t[0]===e[0]&&t[1]===e[1],n=e.filter(e=>{var n=Math.abs(e[0]-t[0]),i=Math.abs(e[1]-t[1]);return("ArrowUp"===a?e[1]<=t[1]&&i>=n:"ArrowDown"===a?e[1]>t[1]&&i>=n:"ArrowLeft"===a?e[0]<=t[0]&&i<n:"ArrowRight"!==a||e[0]>t[0]&&i<n)&&!r(e,t)});n.length||n.push(t);var i=e=>Math.hypot(t[0]-e[0],t[1]-e[1]),o=n.reduce((t,e)=>i(e)<i(t)?e:t,n[0]);return e.findIndex(t=>r(t,o))})([e.currentPixel.x,e.currentPixel.y],r,t);return(null==n||n<0||n>=a.length)&&(n=0),e.labels[a[n].index]}function N(t){t.getSource(b)||t.addSource(b,{type:"geojson",data:{type:"FeatureCollection",features:[]}})}function E(t){t.getStyle().layers.filter(t=>{var e;return"line"===(null===(e=t.layout)||void 0===e?void 0:e["symbol-placement"])}).forEach(e=>t.setLayoutProperty(e.id,"symbol-placement","line-center"))}var L=t=>t.endsWith(".cold")?"".concat(t.slice(0,-5),".hot"):t.endsWith(".hot")?"".concat(t.slice(0,-4),".cold"):null;function R(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,r)}return a}function O(e){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?R(Object(r),!0).forEach(function(a){t(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):R(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var T="icon-image",A="active-highlight",D="active-highlight-inner",j="selected-highlight",_=(t,e)=>"active"===e?{property:"user_symbolActiveImageId",getImageId:e=>{var a;return null!==(a=null==t?void 0:t.getActiveImageId(e))&&void 0!==a?a:null}}:{property:"user_symbolSelectedImageId",getImageId:e=>{var a;return null!==(a=null==t?void 0:t.getSelectedImageId(e))&&void 0!==a?a:null}},C=(t,e,a,r)=>{var{featureId:n,idProperty:i,geometry:o}=r,s=t.getLayer(a);s&&(e[a]||(e[a]={ids:new Set,fillIds:new Set,idProperty:i,sourceId:s.source,hasFillGeometry:!1}),!o||"Polygon"!==o.type&&"MultiPolygon"!==o.type||(e[a].hasFillGeometry=!0,e[a].fillIds.add(n)),e[a].ids.add(n))},B=(t,e,a,r)=>{e.forEach(e=>{if(!a.has(e)){var n="".concat(r,"-").concat(e);["".concat(n,"-fill"),"".concat(n,"-line"),"".concat(n,"-symbol")].forEach(e=>{t.getLayer(e)&&t.setFilter(e,["==","id",""])})}})},F=(t,e)=>{var a="_".concat(e.replaceAll("-",""),"Sources");B(t,t[a]||new Set,new Set,e),t[a]=new Set},k=(t,e,a,r,n,i,o)=>{!!t.getLayer(e)||t.addLayer(O(O({id:e,type:a,source:r},n&&{"source-layer":n}),{},{paint:i})),Object.entries(i).forEach(a=>{var[r,n]=a;t.setPaintProperty(e,r,n)}),t.setFilter(e,o),t.moveLayer(e)},z=(t,e,a,r,n,i,o)=>{var s,l=t.getLayoutProperty(n,"icon-offset");t.getLayer(e)||t.addLayer(O(O({id:e,type:"symbol",source:a},r&&{"source-layer":r}),{},{layout:O(O({[T]:i,"icon-anchor":null!==(s=t.getLayoutProperty(n,"icon-anchor"))&&void 0!==s?s:"center"},void 0!==l&&{"icon-offset":l}),{},{"icon-allow-overlap":!0})}));t.setLayoutProperty(e,T,i),void 0!==l&&t.setLayoutProperty(e,"icon-offset",l),t.setFilter(e,o),t.moveLayer(e)},W=(t,e,a,r,n,i)=>{var o,{ids:s,fillIds:l,idProperty:h,sourceId:c,hasFillGeometry:u}=a[e],d=t.getLayer(e),g=null!==(o=r[e])&&void 0!==o?o:r[L(e)];if(d&&g){var p=d.sourceLayer,m=u?"fill":d.type,y="".concat(n,"-").concat(e),{fill:f}=g,v=n===j,M=(t=>t===j||t===D)(n),{lineColor:b,lineWidth:w}=((t,e)=>({lineColor:e?t.selectionStroke:t.stroke,lineWidth:e?t.strokeWidth:t.activeStrokeWidth}))(g,M),I=h?["get",h]:["id"],x=["in",I,["literal",Array.from(s)]];if("fill-extrusion"!==d.type)switch(m){case"fill":((t,e,a,r,n)=>{var{isSelected:i,idExpression:o,fillIds:s,fill:l,lineColor:h,lineWidth:c,filter:u}=n;if(i){var d=[];s.forEach(t=>d.push(t));var g=["in",o,["literal",d]];k(t,"".concat(e,"-fill"),"fill",a,r,{"fill-color":l},g)}k(t,"".concat(e,"-line"),"line",a,r,{"line-color":h,"line-width":c},u)})(t,y,c,p,{isSelected:v,idExpression:I,fillIds:l,fill:f,lineColor:b,lineWidth:w,filter:x});break;case"line":((t,e,a,r,n,i,o)=>{t.getLayer("".concat(e,"-fill"))&&t.setFilter("".concat(e,"-fill"),["==","id",""]),k(t,"".concat(e,"-line"),"line",a,r,{"line-color":n,"line-width":i},o)})(t,y,c,p,b,w,x);break;case"symbol":((t,e,a,r,n,i,o)=>{var s=t.getLayoutProperty(n,T);if(Array.isArray(s))z(t,"".concat(e,"-symbol"),a,r,n,["get",o.property],i);else{var l=o.getImageId(s);l&&z(t,"".concat(e,"-symbol"),a,r,n,l,i)}})(t,y,c,p,e,x,i)}else((t,e,a,r)=>{var{ids:n,lineColor:i,lineWidth:o,idExpression:s}=r,l=[];n.forEach(t=>l.push(t));var h=["in",s,["literal",l]],{source:c,sourceLayer:u}=t.getLayer(a);k(t,"".concat(e,"-line"),"line",c,u,{"line-color":i,"line-width":o},h)})(t,y,e,{ids:s,lineColor:b,lineWidth:w,idExpression:I})}},q=(t,e,a,r,n)=>{var i=((t,e)=>{var a={};return null==e||e.forEach(e=>{C(t,a,e.layerId,e);var r=L(e.layerId);r&&C(t,a,r,e)}),a})(t,e),o=new Set(Object.keys(i)),s="_".concat(r.replaceAll("-",""),"Sources"),l=t[s]||new Set;return B(t,l,o,r),t[s]=o,o.forEach(e=>W(t,e,i,a,r,n)),i};var $=(t,e,a)=>{var r=(e.x-a.x)**2+(e.y-a.y)**2;if(0===r)return(t.x-e.x)**2+(t.y-e.y)**2;var n=((t.x-e.x)*(a.x-e.x)+(t.y-e.y)*(a.y-e.y))/r;return n=Math.max(0,Math.min(1,n)),(t.x-(e.x+n*(a.x-e.x)))**2+(t.y-(e.y+n*(a.y-e.y)))**2},Z=function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{radius:r=10}=a,n=[[e.x-r,e.y-r],[e.x+r,e.y+r]],i=t.queryRenderedFeatures(n);if(0===i.length)return[];var o=new Set(t.queryRenderedFeatures([e.x,e.y]).map(t=>{var e,a=void 0===t.id?JSON.stringify(t.properties):t.id;return"".concat(null===(e=t.layer)||void 0===e?void 0:e.source,":").concat(a)})),s=[];i.forEach(t=>{!1===s.includes(t.layer.id)&&s.push(t.layer.id)});for(var l=new Set,h=[],c=i.length-1;c>=0;c--){var u,d=i[c],g=void 0===d.id?JSON.stringify(d.properties):d.id,p="".concat(null===(u=d.layer)||void 0===u?void 0:u.source,":").concat(g);!1===l.has(p)&&(l.add(p),h.push(d))}var m=t.unproject(e),y=[m.lng,m.lat],f=h.filter(t=>{var e=t.geometry.type;if(e.includes("Polygon"))return("Polygon"===e?[t.geometry.coordinates]:t.geometry.coordinates).some(t=>((t,e)=>{for(var[a,r]=t,n=!1,i=0,o=e.length-1;i<e.length;o=i,i++){var[s,l]=e[i],[h,c]=e[o];l>r!=c>r&&a<(h-s)*(r-l)/(c-l)+s&&(n=!n)}return n})(y,t[0]));if("Point"===e||"MultiPoint"===e){var a,r=void 0===t.id?JSON.stringify(t.properties):t.id;return o.has("".concat(null===(a=t.layer)||void 0===a?void 0:a.source,":").concat(r))}return!0});return f.map(a=>{var r=0,n=a.geometry.type,i=((t,e,a)=>{var{coordinates:r,type:n}=a,i=1/0,o=e=>t.project(e),s=t=>{for(var a=0;a<t.length-1;a++){var r=$(e,o(t[a]),o(t[a+1]));r<i&&(i=r)}};if("Point"===n){var l=o(r);i=(e.x-l.x)**2+(e.y-l.y)**2}else"LineString"===n||"MultiPoint"===n?"LineString"===n?s(r):r.forEach(t=>{var a=o(t),r=(e.x-a.x)**2+(e.y-a.y)**2;r<i&&(i=r)}):"Polygon"===n||"MultiLineString"===n?r.forEach(s):"MultiPolygon"===n&&r.forEach(t=>t.forEach(s));return i})(t,e,a.geometry);return r+=1e6*s.indexOf(a.layer.id),n.includes("Polygon")&&(r-=5e5),{f:a,score:r+=i}}).sort((t,e)=>t.score-e.score).map(t=>{var{f:e}=t;return e})},G=(t,e,a)=>{var r=t.getCanvas();if(a&&t.off("mousemove",a),null==e||!e.length)return r.style.cursor="",null;var n=a=>{var n=(t=>{var e=new Set(t);return t.forEach(t=>{var a=L(t);a&&e.add(a)}),[...e]})(e).filter(e=>t.getLayer(e));if(0!==n.length){var{lineLayers:i,otherLayers:o}=((t,e)=>{var a=[],r=[];for(var n of e)if("line"===t.getLayer(n).type){var i=n.endsWith("-stroke")?n.slice(0,-7):null;null!==i&&e.includes(i)||a.push(n)}else r.push(n);return{lineLayers:a,otherLayers:r}})(t,n),{x:s,y:l}=a.point,h=[[s-10,l-10],[s+10,l+10]],c=i.length>0&&t.queryRenderedFeatures(h,{layers:i}).length>0,u=o.length>0&&t.queryRenderedFeatures(a.point,{layers:o}).length>0;r.style.cursor=c||u?"pointer":""}else r.style.cursor=""};return t.on("mousemove",n),n};class H{constructor(){t(this,"sets",new Map)}add(t,e){var a,r=null!==(a=this.sets.get(t))&&void 0!==a?a:new Set;this.sets.delete(t),this.sets.set(t,r),e.forEach(t=>r.add(t));for(var n=new Set;this.sets.size>2;){var[i,o]=this.sets.entries().next().value;this.sets.delete(i),o.forEach(t=>n.add(t))}return this.sets.forEach(t=>t.forEach(t=>n.delete(t))),Array.from(n)}}var J=.25,V=.75,Y=t=>{var[e,a]=t,r=(t=>t<=J?"left":t>=V?"right":"")(e),n=(t=>t<=J?"top":t>=V?"bottom":"")(a);return n+(r&&n?"-":"")+r||"center"},K=t=>t<=J?0:t>=V?1:.5,U=t=>Math.round(100*t)/100,X=(t,e)=>{var[a,r]=t,[,,n,i]=e.split(" ").map(Number);return[U((K(a)-a)*n),U((K(r)-r)*i)]};class Q{constructor(e){t(this,"activeImageIds",new Map),t(this,"selectedImageIds",new Map),t(this,"recentImageSets",new H),this.map=e}getActiveImageId(t){var e;return null!==(e=this.activeImageIds.get(t))&&void 0!==e?e:null}getSelectedImageId(t){var e;return null!==(e=this.selectedImageIds.get(t))&&void 0!==e?e:null}removeImage(t){this.map.hasImage(t)&&this.map.removeImage(t),this.activeImageIds.delete(t),this.selectedImageIds.delete(t)}registerSymbols(t,e,r,n){var i=this;return a(function*(){var{map:o}=i,s=yield Promise.all(t.map(function(){var t=a(function*(t){var s=r.getSymbolImageIds(t,e,n);return s?(i.activeImageIds.set(s.normal,s.active),i.selectedImageIds.set(s.normal,s.selected),yield Promise.all(Object.entries(s).map(function(){var i=a(function*(a){var[i,s]=a;if(!o.hasImage(s)){var l=yield r.rasteriseSymbolImage(t,e,i,n);l&&!o.hasImage(l.imageId)&&o.addImage(l.imageId,l.imageData,{pixelRatio:n})}});return function(t){return i.apply(this,arguments)}}())),Object.values(s)):[]});return function(e){return t.apply(this,arguments)}}()));i.recentImageSets.add("".concat(null==e?void 0:e.id,"|").concat(n),s.flat()).forEach(t=>i.removeImage(t))})()}}class tt{constructor(e){t(this,"recentImageSets",new H),this.map=e}registerPatterns(t,e,r,n){var i=this;return a(function*(){var{map:o}=i,s=new Map;t.forEach(t=>{var a=r.getPatternImageId(t,e,n);a&&!s.has(a)&&s.set(a,t)});var l=(t=>Math.max(2,2*t))(n);yield Promise.all(Array.from(s,function(){var t=a(function*(t){var[a,i]=t;if(!o.hasImage(a)){var s=yield r.rasterisePatternImage(i,e,n);s&&!o.hasImage(s.imageId)&&o.addImage(s.imageId,s.imageData,{pixelRatio:l})}});return function(e){return t.apply(this,arguments)}}())),i.recentImageSets.add("".concat(e,"|").concat(n),Array.from(s.keys())).forEach(t=>{o.hasImage(t)&&o.removeImage(t)})})()}}var et=["container","padding","mapStyle","mapSize","center","zoom","bounds","pixelRatio"];function at(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),a.push.apply(a,r)}return a}function rt(e){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?at(Object(r),!0).forEach(function(a){t(e,a,r[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):at(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}class nt extends r{constructor(t){var{mapFramework:e,mapProviderConfig:a={},events:r,eventBus:n}=t;super(),this.maplibreModule=e,this.events=r,this.eventBus=n,this.capabilities={supportedShortcuts:o,supportsMapSizes:!0},Object.assign(this,a)}get name(){return"MapLibreProvider"}initMap(t){var r=this;return a(function*(){var{container:a,padding:n,mapStyle:i,mapSize:o,center:s,zoom:h,bounds:c,pixelRatio:u}=t,d=e(t,et);r.mapStyleId=null==i?void 0:i.id,r.mapSize=o;var{Map:g}=r.maplibreModule,{events:p,eventBus:m}=r,y=new g(rt(rt({},d),{},{container:a,style:null==i?void 0:i.url,pixelRatio:u,padding:n,center:s,zoom:h,fadeDuration:0,attributionControl:!1,dragRotate:!1,doubleClickZoom:!1}));y.touchZoomRotate.disableRotation(),r.map=y,r.symbolImages=new Q(y),r.patternImages=new tt(y),r.map.setPadding(n),c&&y.fitBounds(c,{duration:0}),function(t){var e=Event.prototype.preventDefault;Event.prototype.preventDefault=function(){if(("touchmove"===this.type||"touchstart"===this.type)&&!this.cancelable){var a=t.getCanvas();if(a&&(this.target===a||a.contains(this.target)))return}e.call(this)}}(y),function(t){var e=t.getCanvas();e.removeAttribute("role"),e.setAttribute("tabindex",-1),e.removeAttribute("aria-label"),e.style.display="block",e.addEventListener("focus",t=>{e.blur(),t.relatedTarget&&t.relatedTarget.focus({preventScroll:!0})})}(y),l({map:y,events:p,eventBus:m,getCenter:r.getCenter.bind(r),getZoom:r.getZoom.bind(r),getBounds:r.getBounds.bind(r),getResolution:r.getResolution.bind(r)}),function(t){var{mapProvider:e,map:a,events:r,eventBus:n}=t,i=t=>{a.once("style.load",()=>{n.emit(r.MAP_STYLE_CHANGE,{mapStyleId:t.id})}),a.setStyle(t.url,{diff:!1})},o=t=>{a.setPixelRatio(t)},s=t=>{var{mapSize:a}=t;e.mapSize=a};n.on(r.MAP_SET_STYLE,i),n.on(r.MAP_SET_PIXEL_RATIO,o),n.on(r.MAP_SIZE_CHANGE,s)}({mapProvider:r,map:y,events:p,eventBus:m}),y.on("load",()=>{r.labelNavigator=function(t,e,a,r){var n={isDarkStyle:"dark"===e,labels:[],currentPixel:null,highlightLayerId:null,highlightedExpr:null};function i(){var e=t.getStyle().layers.filter(t=>"symbol"===t.type),a=t.queryRenderedFeatures({layers:e.map(t=>t.id)});n.labels=I(t,e,a)}function o(){if(i(),!n.labels.length)return null;var e=t.project(t.getCenter()),a=function(t,e){var a;return null===(a=t.reduce((t,a)=>{var r=(a.x-e.x)**2+(a.y-e.y)**2;return!t||r<t.dist?{label:a,dist:r}:t},null))||void 0===a?void 0:a.label}(n.labels,e);return n.currentPixel={x:a.x,y:a.y},S(t,a,n),a.text}return E(t),N(t),null==r||r.on(a.MAP_SET_STYLE,e=>{t.once("styledata",()=>t.once("idle",()=>{E(t),N(t),n.isDarkStyle="dark"===(null==e?void 0:e.mapColorScheme)}))}),t.on("zoom",()=>{if(n.highlightLayerId&&n.highlightedExpr){var e=w(n.highlightedExpr,t.getZoom());t.setLayoutProperty(n.highlightLayerId,"text-size",1.5*e)}}),function(t){t.getStyle().layers.filter(t=>"symbol"===t.type).forEach(e=>{t.setPaintProperty(e.id,"text-opacity",["case",["boolean",["feature-state","highlighted"],!1],0,1])})}(t),{refreshLabels:i,highlightNextLabel:function(e){if(i(),!n.labels.length)return null;if(!n.currentPixel)return o();var a=P(e,n);return a?(n.currentPixel={x:a.x,y:a.y},S(t,a,n),a.text):null},highlightLabelAtCenter:o,clearHighlightedLabel:()=>x(t,n)}}(y,null==i?void 0:i.mapColorScheme,p,m)}),r.eventBus.emit(p.MAP_READY,{map:r.map,mapStyleId:r.mapStyleId,mapSize:r.mapSize,crs:r.crs})})()}isBaseMapReady(){var t;return Boolean(null===(t=this.map)||void 0===t?void 0:t.getStyle())}destroyMap(){var t,e;this.setHoverCursor([]),null===(t=this.mapEvents)||void 0===t||t.remove(),null===(e=this.appEvents)||void 0===e||e.remove(),this.mapEvents=null,this.appEvents=null,this.map.remove()}setHoverCursor(t){this.map&&(this._onHoverMove=G(this.map,t,this._onHoverMove))}setView(t){var{center:e,zoom:a}=t;this.map.flyTo({center:e||this.getCenter(),zoom:a||this.getZoom(),duration:this.map.isStyleLoaded()?n:0})}zoomIn(t){this.map.easeTo({zoom:this.getZoom()+t,duration:n})}zoomOut(t){this.map.easeTo({zoom:this.getZoom()-t,duration:n})}panBy(t){this.map.panBy(t,{duration:n})}fitToBounds(t){var e=Array.isArray(t)?t:f(t),a=this.map.isStyleLoaded()?n:0;this.map.fitBounds(e,{duration:a})}setPadding(t){this.map.setPadding(t)}updateHighlightedFeatures(t,e,a){var{LngLatBounds:r}=this.maplibreModule;return function(t){var{LngLatBounds:e,map:a,selectedFeatures:r,activeFeatures:n,stylesMap:i,symbolImages:o}=t;if(!a)return null;var s=_(o,"active"),l=_(o,"selected");null!=n&&n.length?(q(a,n,i,A,s),q(a,n,i,D,l)):(F(a,A),F(a,D));var h={};null!=r&&r.length?h=q(a,r,i,j,l):F(a,j);var c=[];return Object.entries(h).forEach(t=>{var[e,{ids:r,idProperty:n}]=t;c.push(...a.queryRenderedFeatures({layers:[e]}).filter(t=>{var e;return r.has(n?null===(e=t.properties)||void 0===e?void 0:e[n]:t.id)}))}),((t,e)=>{if(!e.length)return null;var a=new t;return e.forEach(t=>{var e=t=>"number"==typeof t[0]?a.extend(t):t.forEach(e);e(t.geometry.coordinates)}),[a.getWest(),a.getSouth(),a.getEast(),a.getNorth()]})(e,c)}({LngLatBounds:r,map:this.map,selectedFeatures:t,activeFeatures:e,stylesMap:a,symbolImages:this.symbolImages})}highlightNextLabel(t){var e;return(null===(e=this.labelNavigator)||void 0===e?void 0:e.highlightNextLabel(t))||null}highlightLabelAtCenter(){var t;return(null===(t=this.labelNavigator)||void 0===t?void 0:t.highlightLabelAtCenter())||null}clearHighlightedLabel(){var t;return(null===(t=this.labelNavigator)||void 0===t?void 0:t.clearHighlightedLabel())||null}getCenter(){var t=this.map.getCenter();return[Number(t.lng.toFixed(i)),Number(t.lat.toFixed(i))]}getZoom(){return Number(this.map.getZoom().toFixed(i))}getBounds(){return this.map.getBounds().toArray().flat(1)}getFeaturesAtPoint(t,e){return Z(this.map,t,e)}getVisibleFeatures(t){var e=t.filter(t=>this.map.getLayer(t));return e.length?this.map.queryRenderedFeatures(void 0,{layers:e}):[]}addSymbolsToMap(t,e,r){var n=arguments,i=this;return a(function*(){var a=n.length>3&&void 0!==n[3]?n[3]:i.map.getPixelRatio()||1;return i.symbolImages.registerSymbols(t,e,r,a)})()}getSymbolIconLayout(t){return(t=>{var{anchor:e,viewBox:a}=t;return{"icon-anchor":Y(e),"icon-offset":X(e,a)}})(t)}getActiveSymbolImageId(t){var e,a;return null!==(e=null===(a=this.symbolImages)||void 0===a?void 0:a.getActiveImageId(t))&&void 0!==e?e:null}getSelectedSymbolImageId(t){var e,a;return null!==(e=null===(a=this.symbolImages)||void 0===a?void 0:a.getSelectedImageId(t))&&void 0!==e?e:null}addPatternsToMap(t,e,r){var n=arguments,i=this;return a(function*(){var a=n.length>3&&void 0!==n[3]?n[3]:i.map.getPixelRatio()||1;return i.patternImages.registerPatterns(t,e,r,a)})()}getAreaDimensions(){var{LngLatBounds:t}=this.maplibreModule;return(t=>{var e,a,r,n;if(t&&"function"==typeof t.getWest)e=t.getWest(),a=t.getSouth(),r=t.getEast(),n=t.getNorth();else{if(!Array.isArray(t)||2!==t.length)return"";[[e,a],[r,n]]=t}var i=m([e,a],[r,a]),o=m([e,a],[e,n]),s=y(i),l=y(o);return"".concat(l," by ").concat(s)})(((t,e)=>{var{width:a,height:r}=e.getContainer().getBoundingClientRect(),n=e.getPadding(),i=[n.left,r-n.bottom],o=[a-n.right,n.top];return new t(e.unproject(i),e.unproject(o))})(t,this.map))}getCardinalMove(t,e){return((t,e)=>{var[a,r]=t,[n,i]=e,o=i-r,s=n-a,l=[];if(Math.abs(o)>1e-4){var h=Math.round(m([a,r],[a,i]));l.push("".concat(o>0?"north":"south"," ").concat(y(h)))}if(Math.abs(s)>1e-4){var c=Math.round(m([a,r],[n,r]));l.push("".concat(s>0?"east":"west"," ").concat(y(c)))}return l.join(", ")})(t,e)}getResolution(){return t=this.map.getCenter(),e=this.map.getZoom(),a=t.lat,r=Math.pow(2,e),40075016.686*Math.cos(a*Math.PI/180)/(512*r);var t,e,a,r}mapToScreen(t){return this.map.project(t)}screenToMap(t){var{lng:e,lat:a}=this.map.unproject([t.x,t.y]);return[e,a]}isGeometryObscured(t,e){return((t,e,a)=>{var r=a.getContainer().getBoundingClientRect(),[n,i,o,s]=f(t),l=[a.project([n,i]),a.project([n,s]),a.project([o,i]),a.project([o,s])],h=Math.min(...l.map(t=>t.x)),c=Math.max(...l.map(t=>t.x)),u=Math.min(...l.map(t=>t.y)),d=Math.max(...l.map(t=>t.y)),g=e.left-r.left,p=e.top-r.top,m=e.right-r.left,y=e.bottom-r.top;return h<m&&c>g&&u<y&&d>p})(t,e,this.map)}}export{nt as default};