@defra/interactive-map 0.0.59-alpha → 0.0.61-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/templates/add-polygons.njk +2 -2
- package/assets/templates/add-symbols.njk +2 -2
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/button-definition.md +11 -0
- package/docs/api/context.md +2 -0
- package/docs/api/panel-definition.md +30 -0
- package/docs/api/symbol-config.md +12 -0
- package/docs/api.md +21 -2
- package/docs/assets/images/slot-map.svg +3 -3
- package/docs/plugins/datasets.md +11 -1
- package/docs/plugins/draw.md +26 -0
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/datasets/src/index.js +0 -1
- package/plugins/datasets/src/index.test.js +2 -8
- package/plugins/datasets/src/registry/dataset.test.js +9 -0
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +3 -0
- package/plugins/draw/src/DrawInit.test.jsx +16 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
- package/plugins/draw/src/defaults.js +4 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
- package/plugins/draw/src/manifest.js +4 -1
- package/plugins/draw/src/manifest.test.js +15 -2
- package/plugins/draw/src/utils/snapMinZoom.js +8 -0
- package/plugins/draw/src/utils/snapMinZoom.test.js +22 -0
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/src/manifest.js +1 -1
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/src/components/Form/Form.module.scss +1 -0
- package/providers/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/esri/src/esriProvider.js +10 -21
- package/providers/esri/src/utils/coords.js +37 -7
- package/providers/esri/src/utils/coords.test.js +22 -1
- package/providers/esri/src/utils/spatial.js +1 -47
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +5 -14
- package/providers/maplibre/src/maplibreProvider.test.js +143 -146
- package/providers/maplibre/src/utils/spatial.js +0 -40
- package/providers/maplibre/src/utils/spatial.test.js +0 -35
- package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/openlayers/src/openlayersProvider.js +5 -14
- package/providers/openlayers/src/openlayersProvider.test.js +12 -10
- package/providers/openlayers/src/utils/spatial.js +0 -39
- package/providers/openlayers/src/utils/spatial.test.js +1 -26
- package/src/App/components/Hints/Hints.jsx +9 -21
- package/src/App/components/Hints/Hints.test.jsx +20 -33
- package/src/App/components/MapButton/MapButton.jsx +20 -2
- package/src/App/components/MapButton/MapButton.module.scss +15 -1
- package/src/App/components/MapButton/MapButton.test.jsx +21 -3
- package/src/App/components/Panel/Panel.jsx +16 -1
- package/src/App/components/Panel/Panel.test.jsx +44 -0
- package/src/App/components/Tooltip/Tooltip.jsx +29 -11
- package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
- package/src/App/components/Viewport/MapController.jsx +2 -0
- package/src/App/components/Viewport/MapController.test.jsx +3 -0
- package/src/App/hooks/useCrossHairAPI.js +27 -28
- package/src/App/hooks/useCrossHairAPI.test.js +64 -7
- package/src/App/hooks/useLayoutMeasurements.js +175 -131
- package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
- package/src/App/hooks/useMapProviderOverrides.js +114 -35
- package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
- package/src/App/hooks/useModalPanelBehaviour.js +18 -32
- package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
- package/src/App/hooks/useUserMoveTracking.js +65 -0
- package/src/App/hooks/useUserMoveTracking.test.js +99 -0
- package/src/App/hooks/useVisibleGeometry.js +35 -45
- package/src/App/hooks/useVisibleGeometry.test.js +149 -121
- package/src/App/layout/Layout.jsx +4 -4
- package/src/App/layout/layout.module.scss +124 -61
- package/src/App/renderer/mapButtons.js +1 -0
- package/src/App/renderer/mapButtons.test.js +8 -0
- package/src/App/store/AppProvider.jsx +3 -0
- package/src/App/store/appDispatchMiddleware.js +18 -10
- package/src/App/store/appDispatchMiddleware.test.js +42 -4
- package/src/App/store/mapActionsMap.js +2 -1
- package/src/App/store/mapActionsMap.test.js +6 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +1 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -2
- package/src/InteractiveMap/InteractiveMap.test.js +2 -2
- package/src/config/events.js +1 -1
- package/src/config/mapPanelSlots.js +8 -0
- package/src/config/symbolConfig.js +1 -1
- package/src/scss/settings/_colors.scss +4 -0
- package/src/services/symbolRegistry.js +1 -1
- package/src/services/symbolRegistry.test.js +19 -0
- package/src/types.js +33 -8
- package/src/utils/getFitMove.js +73 -0
- package/src/utils/getFitMove.test.js +114 -0
- package/src/utils/getSafeZoneInset.js +122 -77
- package/src/utils/getSafeZoneInset.test.js +241 -54
- package/src/utils/getValueForStyle.js +10 -5
- package/src/utils/getValueForStyle.test.js +13 -2
- package/src/utils/renderedBoxes.js +25 -0
- package/src/utils/renderedBoxes.test.js +61 -0
- package/src/utils/screenBox.js +70 -0
- package/src/utils/screenBox.test.js +69 -0
- package/src/utils/symbolUtils.js +9 -9
- package/src/utils/symbolUtils.test.js +21 -0
- package/providers/esri/src/utils/spatial.test.js +0 -58
|
@@ -10,9 +10,9 @@ import Point from '@arcgis/core/geometry/Point.js'
|
|
|
10
10
|
import { defaults, supportedShortcuts } from './defaults.js'
|
|
11
11
|
import { attachAppEvents } from './appEvents.js'
|
|
12
12
|
import { attachMapEvents } from './mapEvents.js'
|
|
13
|
-
import { getAreaDimensions, getCardinalMove, getPaddedExtent
|
|
13
|
+
import { getAreaDimensions, getCardinalMove, getPaddedExtent } from './utils/spatial.js'
|
|
14
14
|
import { queryVectorTileFeatures } from './utils/query.js'
|
|
15
|
-
import { getExtentFromFlatCoords, getPointFromFlatCoords, getBboxFromGeoJSON } from './utils/coords.js'
|
|
15
|
+
import { getExtentFromFlatCoords, getPointFromFlatCoords, getBboxFromGeoJSON, padExtent } from './utils/coords.js'
|
|
16
16
|
import { cleanDOM } from './utils/esriFixes.js'
|
|
17
17
|
|
|
18
18
|
export default class EsriProvider extends MapProvider {
|
|
@@ -74,7 +74,7 @@ export default class EsriProvider extends MapProvider {
|
|
|
74
74
|
|
|
75
75
|
// Uses bounds internally
|
|
76
76
|
if (config.bounds) {
|
|
77
|
-
view.when(() => view.goTo(getExtentFromFlatCoords(config.bounds), { duration: 0 }))
|
|
77
|
+
view.when(() => view.goTo(getExtentFromFlatCoords(config.bounds), { duration: 0 })) // NOSONAR: goTo rejects when a newer move interrupts it
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// Attach map events and store handles
|
|
@@ -140,29 +140,29 @@ export default class EsriProvider extends MapProvider {
|
|
|
140
140
|
this.view.animation?.destroy()
|
|
141
141
|
const point = center ? new Point({ x: center[0], y: center[1], spatialReference: { wkid: 27700 } }) : this.view.center
|
|
142
142
|
const target = { center: point, zoom: zoom ?? this.view.zoom }
|
|
143
|
-
this.view.goTo({ ...target, duration: defaults.animationDuration })
|
|
143
|
+
this.view.goTo({ ...target, duration: defaults.animationDuration }) // NOSONAR: goTo rejects when a newer move interrupts it
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
zoomIn (zoomDelta) {
|
|
147
147
|
this.view.animation?.destroy()
|
|
148
|
-
this.view.goTo({ zoom: this.view.zoom + zoomDelta, duration: defaults.animationDuration })
|
|
148
|
+
this.view.goTo({ zoom: this.view.zoom + zoomDelta, duration: defaults.animationDuration }) // NOSONAR: goTo rejects when a newer move interrupts it
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
zoomOut (zoomDelta) {
|
|
152
152
|
this.view.animation?.destroy()
|
|
153
|
-
this.view.goTo({ zoom: this.view.zoom - zoomDelta, duration: defaults.animationDuration })
|
|
153
|
+
this.view.goTo({ zoom: this.view.zoom - zoomDelta, duration: defaults.animationDuration }) // NOSONAR: goTo rejects when a newer move interrupts it
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
panBy (offset) {
|
|
157
157
|
const { x, y } = this.view.toScreen(this.view.center)
|
|
158
158
|
const newPixel = { x: x + offset[0], y: y + offset[1] }
|
|
159
159
|
const newCentre = this.view.toMap(newPixel)
|
|
160
|
-
this.view.goTo({ center: newCentre, duration: defaults.animationDuration })
|
|
160
|
+
this.view.goTo({ center: newCentre, duration: defaults.animationDuration }) // NOSONAR: goTo rejects when a newer move interrupts it
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
fitToBounds (bounds) {
|
|
163
|
+
fitToBounds (bounds, { padding } = {}) {
|
|
164
164
|
const extent = Array.isArray(bounds) ? getExtentFromFlatCoords(bounds) : getBboxFromGeoJSON(bounds)
|
|
165
|
-
this.view.goTo(extent, { duration: defaults.DELAY })
|
|
165
|
+
this.view.goTo(padding ? padExtent(extent, padding, this.view) : extent, { duration: defaults.DELAY }) // NOSONAR: goTo rejects when a newer move interrupts it
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
setPadding (padding) {
|
|
@@ -193,7 +193,7 @@ export default class EsriProvider extends MapProvider {
|
|
|
193
193
|
return [xmin, ymin, xmax, ymax].map(n => Math.round(n * 100) / 100)
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
getFeaturesAtPoint (point
|
|
196
|
+
getFeaturesAtPoint (point) {
|
|
197
197
|
return queryVectorTileFeatures(this.view, point)
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -227,15 +227,4 @@ export default class EsriProvider extends MapProvider {
|
|
|
227
227
|
const mapPoint = this.view.toMap(point)
|
|
228
228
|
return [mapPoint.x, mapPoint.y]
|
|
229
229
|
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Returns true if the geometry's screen bounding box overlaps the given panel rectangle.
|
|
233
|
-
*
|
|
234
|
-
* @param {object} geojson - GeoJSON Feature, FeatureCollection, or geometry.
|
|
235
|
-
* @param {DOMRect} panelRect - Bounding rect of the panel element (viewport coordinates).
|
|
236
|
-
* @returns {boolean}
|
|
237
|
-
*/
|
|
238
|
-
isGeometryObscured (geojson, panelRect) {
|
|
239
|
-
return isGeometryObscured(geojson, panelRect, this.view)
|
|
240
|
-
}
|
|
241
230
|
}
|
|
@@ -7,7 +7,7 @@ const getExtentFromFlatCoords = (coords) => {
|
|
|
7
7
|
xmin: coords[0],
|
|
8
8
|
ymin: coords[1],
|
|
9
9
|
xmax: coords[2],
|
|
10
|
-
ymax: coords[3],
|
|
10
|
+
ymax: coords[3], // NOSONAR, this is an extent reference
|
|
11
11
|
spatialReference: { wkid: 27700 }
|
|
12
12
|
})
|
|
13
13
|
: undefined
|
|
@@ -24,18 +24,21 @@ const getPointFromFlatCoords = (coords) => {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const collectCoords = (obj, acc) => {
|
|
27
|
-
if (!obj) return
|
|
27
|
+
if (!obj) { return }
|
|
28
28
|
if (obj.type === 'FeatureCollection') {
|
|
29
|
-
obj.features.forEach(
|
|
29
|
+
obj.features.forEach(feature => collectCoords(feature, acc))
|
|
30
30
|
} else if (obj.type === 'Feature') {
|
|
31
31
|
collectCoords(obj.geometry, acc)
|
|
32
32
|
} else if (obj.type === 'GeometryCollection') {
|
|
33
|
-
obj.geometries.forEach(
|
|
33
|
+
obj.geometries.forEach(geometry => collectCoords(geometry, acc))
|
|
34
34
|
} else {
|
|
35
35
|
const flatten = (coords) => {
|
|
36
36
|
if (!Array.isArray(coords)) { return }
|
|
37
|
-
if (typeof coords[0] === 'number')
|
|
38
|
-
|
|
37
|
+
if (typeof coords[0] === 'number') {
|
|
38
|
+
acc.push(coords)
|
|
39
|
+
} else {
|
|
40
|
+
coords.forEach(flatten)
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
flatten(obj.coordinates)
|
|
41
44
|
}
|
|
@@ -55,8 +58,35 @@ const getBboxFromGeoJSON = (geojson) => {
|
|
|
55
58
|
return getExtentFromFlatCoords([Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)])
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Grow an extent so that fitting it to the view keeps `padding` pixels clear around the
|
|
63
|
+
* original extent, inside the view's own padding. MapView.goTo has no padding option.
|
|
64
|
+
*
|
|
65
|
+
* @param {import('@arcgis/core/geometry/Extent.js').default} extent
|
|
66
|
+
* @param {{ top: number, right: number, bottom: number, left: number }} padding - Pixels.
|
|
67
|
+
* @param {{ width: number, height: number, padding?: object }} view - The MapView.
|
|
68
|
+
* @returns {import('@arcgis/core/geometry/Extent.js').default}
|
|
69
|
+
*/
|
|
70
|
+
const padExtent = (extent, padding, { width, height, padding: viewPadding }) => {
|
|
71
|
+
const availableWidth = width - (viewPadding?.left ?? 0) - (viewPadding?.right ?? 0) - padding.left - padding.right
|
|
72
|
+
const availableHeight = height - (viewPadding?.top ?? 0) - (viewPadding?.bottom ?? 0) - padding.top - padding.bottom
|
|
73
|
+
if (availableWidth <= 0 || availableHeight <= 0) {
|
|
74
|
+
return extent
|
|
75
|
+
}
|
|
76
|
+
// The map units per pixel the fit will use: whichever side of the extent is tighter
|
|
77
|
+
const resolution = Math.max((extent.xmax - extent.xmin) / availableWidth, (extent.ymax - extent.ymin) / availableHeight)
|
|
78
|
+
return new Extent({
|
|
79
|
+
xmin: extent.xmin - padding.left * resolution,
|
|
80
|
+
ymin: extent.ymin - padding.bottom * resolution,
|
|
81
|
+
xmax: extent.xmax + padding.right * resolution,
|
|
82
|
+
ymax: extent.ymax + padding.top * resolution,
|
|
83
|
+
spatialReference: extent.spatialReference
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
58
87
|
export {
|
|
59
88
|
getExtentFromFlatCoords,
|
|
60
89
|
getPointFromFlatCoords,
|
|
61
|
-
getBboxFromGeoJSON
|
|
90
|
+
getBboxFromGeoJSON,
|
|
91
|
+
padExtent
|
|
62
92
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getExtentFromFlatCoords, getPointFromFlatCoords, getBboxFromGeoJSON } from './coords.js'
|
|
1
|
+
import { getExtentFromFlatCoords, getPointFromFlatCoords, getBboxFromGeoJSON, padExtent } from './coords.js'
|
|
2
2
|
|
|
3
3
|
jest.mock('@arcgis/core/geometry/Extent.js', () =>
|
|
4
4
|
jest.fn().mockImplementation((opts) => ({ ...opts, type: 'extent' }))
|
|
@@ -123,4 +123,25 @@ describe('coords utils', () => {
|
|
|
123
123
|
expect(result.spatialReference).toEqual({ wkid: 27700 })
|
|
124
124
|
})
|
|
125
125
|
})
|
|
126
|
+
|
|
127
|
+
describe('padExtent', () => {
|
|
128
|
+
// A 400 × 200 extent in a 1000 × 600 view. With 100px of view padding and 500px of extra
|
|
129
|
+
// padding off the width, 400px are left, so the fit uses 1 unit per pixel
|
|
130
|
+
const extent = { xmin: 0, ymin: 0, xmax: 400, ymax: 200, spatialReference: { wkid: 27700 } }
|
|
131
|
+
const view = { width: 1000, height: 600, padding: { left: 100, right: 0, top: 0, bottom: 0 } }
|
|
132
|
+
|
|
133
|
+
test('grows the extent by the padding at the resolution the fit will use', () => {
|
|
134
|
+
const result = padExtent(extent, { top: 10, right: 300, bottom: 20, left: 200 }, view)
|
|
135
|
+
expect(result).toEqual(expect.objectContaining({ xmin: -200, ymin: -20, xmax: 700, ymax: 210, spatialReference: { wkid: 27700 } }))
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('handles a view with no padding', () => {
|
|
139
|
+
const result = padExtent(extent, { top: 0, right: 100, bottom: 0, left: 100 }, { width: 600, height: 600, padding: null })
|
|
140
|
+
expect(result).toEqual(expect.objectContaining({ xmin: -100, xmax: 500 }))
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('returns the extent unchanged when the padding leaves no room', () => {
|
|
144
|
+
expect(padExtent(extent, { top: 0, right: 500, bottom: 0, left: 500 }, view)).toBe(extent)
|
|
145
|
+
})
|
|
146
|
+
})
|
|
126
147
|
})
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import Extent from '@arcgis/core/geometry/Extent.js'
|
|
2
|
-
import Point from '@arcgis/core/geometry/Point.js'
|
|
3
|
-
import { getBboxFromGeoJSON } from './coords.js'
|
|
4
2
|
|
|
5
3
|
// -----------------------------------------------------------------------------
|
|
6
4
|
// Internal (not exported)
|
|
@@ -127,52 +125,8 @@ const getPaddedExtent = (view, padding = DEFAULT_PADDING) => {
|
|
|
127
125
|
})
|
|
128
126
|
}
|
|
129
127
|
|
|
130
|
-
/**
|
|
131
|
-
* Returns true if the geometry's screen bounding box overlaps the given panel rectangle.
|
|
132
|
-
* Used to decide whether to pan/zoom when a panel opens over a visibleGeometry target.
|
|
133
|
-
*
|
|
134
|
-
* @param {object} geojson - GeoJSON Feature, FeatureCollection, or geometry
|
|
135
|
-
* @param {DOMRect} panelRect - Bounding rect of the panel element (viewport coordinates)
|
|
136
|
-
* @param {import('@arcgis/core/views/MapView.js').default} view - ESRI MapView instance
|
|
137
|
-
* @returns {boolean}
|
|
138
|
-
*/
|
|
139
|
-
const isGeometryObscured = (geojson, panelRect, view) => {
|
|
140
|
-
if (!view?.container) {
|
|
141
|
-
return false
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const containerRect = view.container.getBoundingClientRect()
|
|
145
|
-
const extent = getBboxFromGeoJSON(geojson)
|
|
146
|
-
|
|
147
|
-
const corners = [
|
|
148
|
-
view.toScreen(new Point({ x: extent.xmin, y: extent.ymin, spatialReference: extent.spatialReference })),
|
|
149
|
-
view.toScreen(new Point({ x: extent.xmin, y: extent.ymax, spatialReference: extent.spatialReference })),
|
|
150
|
-
view.toScreen(new Point({ x: extent.xmax, y: extent.ymin, spatialReference: extent.spatialReference })),
|
|
151
|
-
view.toScreen(new Point({ x: extent.xmax, y: extent.ymax, spatialReference: extent.spatialReference }))
|
|
152
|
-
]
|
|
153
|
-
|
|
154
|
-
const screenMinX = Math.min(...corners.map(c => c.x))
|
|
155
|
-
const screenMaxX = Math.max(...corners.map(c => c.x))
|
|
156
|
-
const screenMinY = Math.min(...corners.map(c => c.y))
|
|
157
|
-
const screenMaxY = Math.max(...corners.map(c => c.y))
|
|
158
|
-
|
|
159
|
-
// Convert panelRect from viewport coords to view-container-relative coords
|
|
160
|
-
const panelLeft = panelRect.left - containerRect.left
|
|
161
|
-
const panelTop = panelRect.top - containerRect.top
|
|
162
|
-
const panelRight = panelRect.right - containerRect.left
|
|
163
|
-
const panelBottom = panelRect.bottom - containerRect.top
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
screenMinX < panelRight &&
|
|
167
|
-
screenMaxX > panelLeft &&
|
|
168
|
-
screenMinY < panelBottom &&
|
|
169
|
-
screenMaxY > panelTop
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
128
|
export {
|
|
174
129
|
getAreaDimensions,
|
|
175
130
|
getCardinalMove,
|
|
176
|
-
getPaddedExtent
|
|
177
|
-
isGeometryObscured
|
|
131
|
+
getPaddedExtent
|
|
178
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{_notImplemented(e){throw new Error(`${this.name} must implement ${e}()`)}isBaseMapReady(){this._notImplemented("isBaseMapReady")}addSymbolsToMap(){this._notImplemented("addSymbolsToMap")}addPatternsToMap(){this._notImplemented("addPatternsToMap")}getActiveSymbolImageId(){this._notImplemented("getActiveSymbolImageId")}getSelectedSymbolImageId(){this._notImplemented("getSelectedSymbolImageId")}}const t=400,r=7,o=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom","highlightLabelAtCenter","highlightNextLabel"];const n=(e,t)=>{let r=null;const o=(...o)=>{clearTimeout(r),r=setTimeout(()=>{e(...o)},t)};return o.cancel=()=>{r&&(clearTimeout(r),r=null)},o};function i({map:e,events:t,eventBus:r,getCenter:o,getZoom:i,getBounds:s,getResolution:a}){const l=[],c=[],u=()=>{const t=i();return{center:o(),bounds:s(),resolution:a(),zoom:t,isAtMaxZoom:e.getMaxZoom()<=t,isAtMinZoom:e.getMinZoom()>=t}},h=(e,t)=>r.emit(e,t),g=()=>h(t.MAP_LOADED);e.on("load",g),l.push(["load",g]);e.once("idle",()=>h(t.MAP_FIRST_IDLE,u()));const d=()=>h(t.MAP_MOVE_START);e.on("movestart",d),l.push(["movestart",d]);const m=n(()=>{h(t.MAP_MOVE_END,u())},500);e.on("moveend",m),l.push(["moveend",m]);const y=((e,t)=>{let r=0;return(...o)=>{const n=Date.now();n-r>=t&&(r=n,e(...o))}})(()=>{h(t.MAP_MOVE,u())},10);e.on("zoom",y),l.push(["zoom",y]);const p=()=>h(t.MAP_RENDER);e.on("render",p),l.push(["render",p]);const f=n(()=>{h(t.MAP_DATA_CHANGE,u())},500),I=e=>{e.isSourceLoaded&&f()};e.on("styledata",f),e.on("sourcedata",I),l.push(["styledata",f],["sourcedata",I]);const b=()=>h(t.MAP_STYLE_CHANGE);e.on("style.load",b),l.push(["style.load",b]);const x=e=>h(t.MAP_CLICK,{point:e.point,coords:[e.lngLat.lng,e.lngLat.lat]});return e.on("click",x),l.push(["click",x]),c.push(m,y,f),{remove(){c.forEach(e=>e.cancel()),l.forEach(([t,r])=>e.off(t,r))}}}function s(e,t,r){if(null!==e)for(var o,n,i,a,l,c,u,h,g=0,d=0,m=e.type,y="FeatureCollection"===m,p="Feature"===m,f=y?e.features.length:1,I=0;I<f;I++){l=(h=!!(u=y?e.features[I].geometry:p?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var b=0;b<l;b++){var x=0,v=0;if(null!==(a=h?u.geometries[b]:u)){c=a.coordinates;var S=a.type;switch(g=0,S){case null:break;case"Point":if(!1===t(c,d,I,x,v))return!1;d++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<c.length;o++){if(!1===t(c[o],d,I,x,v))return!1;d++,"MultiPoint"===S&&x++}"LineString"===S&&x++;break;case"Polygon":case"MultiLineString":for(o=0;o<c.length;o++){for(n=0;n<c[o].length-g;n++){if(!1===t(c[o][n],d,I,x,v))return!1;d++}"MultiLineString"===S&&x++,"Polygon"===S&&v++}"Polygon"===S&&x++;break;case"MultiPolygon":for(o=0;o<c.length;o++){for(v=0,n=0;n<c[o].length;n++){for(i=0;i<c[o][n].length-g;i++){if(!1===t(c[o][n][i],d,I,x,v))return!1;d++}v++}x++}break;case"GeometryCollection":for(o=0;o<a.geometries.length;o++)if(!1===s(a.geometries[o],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}var a=function(e,t={}){if(null!=e.bbox&&!0!==t.recompute)return e.bbox;const r=[1/0,1/0,-1/0,-1/0];return s(e,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r};const l=Math.PI/180,c=1e-4,u=e=>e*l,h=(e,t)=>{const[r,o]=e,[n,i]=t,s=u(o),a=u(i),l=a-s,c=u(n-r),h=Math.sin(l/2)**2+Math.cos(s)*Math.cos(a)*Math.sin(c/2)**2;return 6371e3*(2*Math.atan2(Math.sqrt(h),Math.sqrt(1-h)))},g=e=>{const t=e/1609.344;if(t<.5){const t=Math.round(e);return`${t} ${1===t?"metre":"metres"}`}if(t<10){const e=Number.parseFloat(t.toFixed(1));return`${e} ${1===e?"mile":"miles"}`}return`${Math.round(t)} miles`},d=e=>a(e);const m="highlighted-label";function y(e,t){if("number"==typeof e)return e;if(!Array.isArray(e)||"interpolate"!==e[0])return function(e,t){const{stops:r}=e;if(r.length<2)return r.length>0?r[0][1]:0;let o=r[0],n=r[r.length-1];for(let e=1;e<r.length;e++){const i=r[e];if(i[0]>t){n=i,o=r[e-1];break}o=r[e-1],n=i}const[i,s]=o,[a,l]=n;return t<=i?s:t>=a?l:s+(t-i)/(a-i)*(l-s)}(e,t);const[,,r,...o]=e;if("zoom"!==r[0])throw new Error("Only zoom-based expressions supported");for(let e=0;e<o.length-2;e+=2){const r=o[e],n=o[e+1],i=o[e+2],s=o[e+3];if(t<=r)return n;if(t<=i)return n+(t-r)/(i-r)*(s-n)}return o[o.length-1]}function p(e,t,r){return t.flatMap(t=>{const o=t.layout?.["text-field"],n=function(e){return"string"==typeof e?/^{(.+)}$/.exec(e)?.[1]:Array.isArray(e)?e.find(e=>Array.isArray(e)&&"get"===e[0])?.[1]:null}(o);return n?r.filter(e=>e.layer.id===t.id&&e.properties?.[n]).map(r=>function(e,t,r,o){const n=function(e){const{type:t,coordinates:r}=e;if("Point"===t)return r;if("MultiPoint"===t)return r[0];if(t.includes("LineString")){const e="LineString"===t?r:r[0];return[(e[0][0]+e[e.length-1][0])/2,(e[0][1]+e[e.length-1][1])/2]}if(t.includes("Polygon")){const e="Polygon"===t?r[0]:r[0][0],o=e.reduce((e,t)=>[e[0]+t[0],e[1]+t[1]],[0,0]);return[o[0]/e.length,o[1]/e.length]}return null}(e.geometry);if(!n)return null;const i=o.project({lng:n[0],lat:n[1]});return{text:e.properties[r],x:i.x,y:i.y,feature:e,layer:t}}(r,t,n,e)).filter(Boolean):[]})}function f(e,t){if(t.highlightLayerId&&e.getLayer(t.highlightLayerId)){try{e.removeLayer(t.highlightLayerId)}catch{}t.highlightLayerId=null,t.highlightedExpr=null}}function I(e,t,r){if(!t?.feature?.layer)return;f(e,r);const{feature:o,layer:n}=t;r.highlightLayerId=`highlight-${n.id}`;const{id:i,type:s,properties:a,geometry:l}=o;e.getSource(m).setData({id:i,type:s,properties:a,geometry:l}),r.highlightedExpr=n.layout["text-size"];const c=e.getZoom();const u=function(e,t,r){return{id:`highlight-${e.id}`,type:e.type,source:m,layout:{...e.layout,"text-size":t,"text-allow-overlap":!0,"text-ignore-placement":!0,"text-max-angle":90},paint:{...e.paint,"text-color":r.text,"text-halo-color":r.halo,"text-halo-width":3,"text-halo-blur":1,"text-opacity":1}}}(n,1.5*y(r.highlightedExpr,c),r.isDarkStyle?{text:"#ffffff",halo:"#000000"}:{text:"#000000",halo:"#ffffff"});e.addLayer(u),e.moveLayer(r.highlightLayerId)}function b(e,t){if(!t.currentPixel)return null;const r=t.labels.map((e,t)=>({pixel:[e.x,e.y],index:t})).filter(e=>e.pixel[0]!==t.currentPixel.x||e.pixel[1]!==t.currentPixel.y);if(!r.length)return null;const o=r.map(e=>e.pixel);let n=((e,t,r)=>{const o=(e,t)=>e[0]===t[0]&&e[1]===t[1],n=t.filter(t=>{const n=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);let s=!1;return s="ArrowUp"===r?t[1]<=e[1]&&i>=n:"ArrowDown"===r?t[1]>e[1]&&i>=n:"ArrowLeft"===r?t[0]<=e[0]&&i<n:"ArrowRight"!==r||t[0]>e[0]&&i<n,s&&!o(t,e)});n.length||n.push(e);const i=t=>Math.hypot(e[0]-t[0],e[1]-t[1]),s=n.reduce((e,t)=>i(t)<i(e)?t:e,n[0]);return t.findIndex(e=>o(e,s))})([t.currentPixel.x,t.currentPixel.y],o,e);return(null==n||n<0||n>=r.length)&&(n=0),t.labels[r[n].index]}function x(e){e.getSource(m)||e.addSource(m,{type:"geojson",data:{type:"FeatureCollection",features:[]}})}function v(e){e.getStyle().layers.filter(e=>"line"===e.layout?.["symbol-placement"]).forEach(t=>e.setLayoutProperty(t.id,"symbol-placement","line-center"))}const S=e=>e.endsWith(".cold")?`${e.slice(0,-5)}.hot`:e.endsWith(".hot")?`${e.slice(0,-4)}.cold`:null,M="icon-image",L="active-highlight",P="active-highlight-inner",E="selected-highlight",A=(e,t)=>"active"===t?{property:"user_symbolActiveImageId",getImageId:t=>e?.getActiveImageId(t)??null}:{property:"user_symbolSelectedImageId",getImageId:t=>e?.getSelectedImageId(t)??null},w=(e,t,r,{featureId:o,idProperty:n,geometry:i})=>{const s=e.getLayer(r);s&&(t[r]||(t[r]={ids:new Set,fillIds:new Set,idProperty:n,sourceId:s.source,hasFillGeometry:!1}),!i||"Polygon"!==i.type&&"MultiPolygon"!==i.type||(t[r].hasFillGeometry=!0,t[r].fillIds.add(o)),t[r].ids.add(o))},$=(e,t,r,o)=>{t.forEach(t=>{if(!r.has(t)){const r=`${o}-${t}`;[`${r}-fill`,`${r}-line`,`${r}-symbol`].forEach(t=>{e.getLayer(t)&&e.setFilter(t,["==","id",""])})}})},C=(e,t)=>{const r=`_${t.replaceAll("-","")}Sources`;$(e,e[r]||new Set,new Set,t),e[r]=new Set},_=(e,t,r,o,n,i,s)=>{!!e.getLayer(t)||e.addLayer({id:t,type:r,source:o,...n&&{"source-layer":n},paint:i}),Object.entries(i).forEach(([r,o])=>{e.setPaintProperty(t,r,o)}),e.setFilter(t,s),e.moveLayer(t)},R=(e,t,r,o,n,i,s)=>{const a=e.getLayoutProperty(n,"icon-offset");e.getLayer(t)||e.addLayer({id:t,type:"symbol",source:r,...o&&{"source-layer":o},layout:{[M]:i,"icon-anchor":e.getLayoutProperty(n,"icon-anchor")??"center",...void 0!==a&&{"icon-offset":a},"icon-allow-overlap":!0}}),e.setLayoutProperty(t,M,i),void 0!==a&&e.setLayoutProperty(t,"icon-offset",a),e.setFilter(t,s),e.moveLayer(t)},F=(e,t,r,o,n,i)=>{const{ids:s,fillIds:a,idProperty:l,sourceId:c,hasFillGeometry:u}=r[t],h=e.getLayer(t),g=o[t]??o[S(t)];if(!h||!g)return;const d=h.sourceLayer,m=u?"fill":h.type,y=`${n}-${t}`,{fill:p}=g,f=n===E,I=(e=>e===E||e===P)(n),{lineColor:b,lineWidth:x}=((e,t)=>({lineColor:t?e.selectionStroke:e.stroke,lineWidth:t?e.strokeWidth:e.activeStrokeWidth}))(g,I),v=l?["get",l]:["id"],L=["in",v,["literal",Array.from(s)]];if("fill-extrusion"!==h.type)switch(m){case"fill":((e,t,r,o,{isSelected:n,idExpression:i,fillIds:s,fill:a,lineColor:l,lineWidth:c,filter:u})=>{if(n){const n=[];s.forEach(e=>n.push(e)),_(e,`${t}-fill`,"fill",r,o,{"fill-color":a},["in",i,["literal",n]])}_(e,`${t}-line`,"line",r,o,{"line-color":l,"line-width":c},u)})(e,y,c,d,{isSelected:f,idExpression:v,fillIds:a,fill:p,lineColor:b,lineWidth:x,filter:L});break;case"line":((e,t,r,o,n,i,s)=>{e.getLayer(`${t}-fill`)&&e.setFilter(`${t}-fill`,["==","id",""]),_(e,`${t}-line`,"line",r,o,{"line-color":n,"line-width":i},s)})(e,y,c,d,b,x,L);break;case"symbol":((e,t,r,o,n,i,s)=>{const a=e.getLayoutProperty(n,M);if(Array.isArray(a))return void R(e,`${t}-symbol`,r,o,n,["get",s.property],i);const l=s.getImageId(a);l&&R(e,`${t}-symbol`,r,o,n,l,i)})(e,y,c,d,t,L,i)}else((e,t,r,{ids:o,lineColor:n,lineWidth:i,idExpression:s})=>{const a=[];o.forEach(e=>a.push(e));const l=["in",s,["literal",a]],{source:c,sourceLayer:u}=e.getLayer(r);_(e,`${t}-line`,"line",c,u,{"line-color":n,"line-width":i},l)})(e,y,t,{ids:s,lineColor:b,lineWidth:x,idExpression:v})},B=(e,t,r,o,n)=>{const i=((e,t)=>{const r={};return t?.forEach(t=>{w(e,r,t.layerId,t);const o=S(t.layerId);o&&w(e,r,o,t)}),r})(e,t),s=new Set(Object.keys(i)),a=`_${o.replaceAll("-","")}Sources`,l=e[a]||new Set;return $(e,l,s,o),e[a]=s,s.forEach(t=>F(e,t,i,r,o,n)),i};const T=(e,t,r)=>{const o=(t.x-r.x)**2+(t.y-r.y)**2;if(0===o)return(e.x-t.x)**2+(e.y-t.y)**2;let n=((e.x-t.x)*(r.x-t.x)+(e.y-t.y)*(r.y-t.y))/o;return n=Math.max(0,Math.min(1,n)),(e.x-(t.x+n*(r.x-t.x)))**2+(e.y-(t.y+n*(r.y-t.y)))**2},k=(e,t,r={})=>{const{radius:o=10}=r,n=[[t.x-o,t.y-o],[t.x+o,t.y+o]],i=e.queryRenderedFeatures(n);if(0===i.length)return[];const s=new Set(e.queryRenderedFeatures([t.x,t.y]).map(e=>{const t=void 0===e.id?JSON.stringify(e.properties):e.id;return`${e.layer?.source}:${t}`})),a=[];i.forEach(e=>{!1===a.includes(e.layer.id)&&a.push(e.layer.id)});const l=new Set,c=[];for(let e=i.length-1;e>=0;e--){const t=i[e],r=void 0===t.id?JSON.stringify(t.properties):t.id,o=`${t.layer?.source}:${r}`;!1===l.has(o)&&(l.add(o),c.push(t))}const u=e.unproject(t),h=[u.lng,u.lat],g=c.filter(e=>{const t=e.geometry.type;if(t.includes("Polygon")){return("Polygon"===t?[e.geometry.coordinates]:e.geometry.coordinates).some(e=>((e,t)=>{const[r,o]=e;let n=!1;for(let e=0,i=t.length-1;e<t.length;i=e,e++){const[s,a]=t[e],[l,c]=t[i];a>o!=c>o&&(r<(l-s)*(o-a)/(c-a)+s&&(n=!n))}return n})(h,e[0]))}if("Point"===t||"MultiPoint"===t){const t=void 0===e.id?JSON.stringify(e.properties):e.id;return s.has(`${e.layer?.source}:${t}`)}return!0});return g.map(r=>{let o=0;const n=r.geometry.type,i=((e,t,r)=>{const{coordinates:o,type:n}=r;let i=1/0;const s=t=>e.project(t),a=e=>{for(let r=0;r<e.length-1;r++){const o=T(t,s(e[r]),s(e[r+1]));o<i&&(i=o)}};if("Point"===n){const e=s(o);i=(t.x-e.x)**2+(t.y-e.y)**2}else"LineString"===n||"MultiPoint"===n?"LineString"===n?a(o):o.forEach(e=>{const r=s(e),o=(t.x-r.x)**2+(t.y-r.y)**2;o<i&&(i=o)}):"Polygon"===n||"MultiLineString"===n?o.forEach(a):"MultiPolygon"===n&&o.forEach(e=>e.forEach(a));return i})(e,t,r.geometry);return o+=1e6*a.indexOf(r.layer.id),n.includes("Polygon")&&(o-=5e5),o+=i,{f:r,score:o}}).sort((e,t)=>e.score-t.score).map(({f:e})=>e)},z=(e,t,r)=>{const o=e.getCanvas();if(r&&e.off("mousemove",r),!t?.length)return o.style.cursor="",null;const n=r=>{const n=(e=>{const t=new Set(e);return e.forEach(e=>{const r=S(e);r&&t.add(r)}),[...t]})(t).filter(t=>e.getLayer(t));if(0===n.length)return void(o.style.cursor="");const{lineLayers:i,otherLayers:s}=((e,t)=>{const r=[],o=[];for(const n of t)if("line"===e.getLayer(n).type){const e=n.endsWith("-stroke")?n.slice(0,-7):null;null!==e&&t.includes(e)||r.push(n)}else o.push(n);return{lineLayers:r,otherLayers:o}})(e,n),{x:a,y:l}=r.point,c=[[a-10,l-10],[a+10,l+10]],u=i.length>0&&e.queryRenderedFeatures(c,{layers:i}).length>0,h=s.length>0&&e.queryRenderedFeatures(r.point,{layers:s}).length>0;o.style.cursor=u||h?"pointer":""};return e.on("mousemove",n),n};class N{sets=(()=>new Map)();add(e,t){const r=this.sets.get(e)??new Set;this.sets.delete(e),this.sets.set(e,r),t.forEach(e=>r.add(e));const o=new Set;for(;this.sets.size>2;){const[e,t]=this.sets.entries().next().value;this.sets.delete(e),t.forEach(e=>o.add(e))}return this.sets.forEach(e=>e.forEach(e=>o.delete(e))),Array.from(o)}}const j=.25,D=.75,Z=([e,t])=>{const r=(e=>e<=j?"left":e>=D?"right":"")(e),o=(e=>e<=j?"top":e>=D?"bottom":"")(t);return o+(r&&o?"-":"")+r||"center"},O=e=>e<=j?0:e>=D?1:.5,W=e=>Math.round(100*e)/100,H=([e,t],r)=>{const[,,o,n]=r.split(" ").map(Number);return[W((O(e)-e)*o),W((O(t)-t)*n)]};class G{activeImageIds=(()=>new Map)();selectedImageIds=(()=>new Map)();recentImageSets=(()=>new N)();constructor(e){this.map=e}getActiveImageId(e){return this.activeImageIds.get(e)??null}getSelectedImageId(e){return this.selectedImageIds.get(e)??null}removeImage(e){this.map.hasImage(e)&&this.map.removeImage(e),this.activeImageIds.delete(e),this.selectedImageIds.delete(e)}async registerSymbols(e,t,r,o){const{map:n}=this,i=await Promise.all(e.map(async e=>{const i=r.getSymbolImageIds(e,t,o);return i?(this.activeImageIds.set(i.normal,i.active),this.selectedImageIds.set(i.normal,i.selected),await Promise.all(Object.entries(i).map(async([i,s])=>{if(n.hasImage(s))return;const a=await r.rasteriseSymbolImage(e,t,i,o);a&&!n.hasImage(a.imageId)&&n.addImage(a.imageId,a.imageData,{pixelRatio:o})})),Object.values(i)):[]}));this.recentImageSets.add(`${t?.id}|${o}`,i.flat()).forEach(e=>this.removeImage(e))}}class q{recentImageSets=(()=>new N)();constructor(e){this.map=e}async registerPatterns(e,t,r,o){const{map:n}=this,i=new Map;e.forEach(e=>{const n=r.getPatternImageId(e,t,o);n&&!i.has(n)&&i.set(n,e)});const s=(e=>Math.max(2,2*e))(o);await Promise.all(Array.from(i,async([e,i])=>{if(n.hasImage(e))return;const a=await r.rasterisePatternImage(i,t,o);a&&!n.hasImage(a.imageId)&&n.addImage(a.imageId,a.imageData,{pixelRatio:s})})),this.recentImageSets.add(`${t}|${o}`,Array.from(i.keys())).forEach(e=>{n.hasImage(e)&&n.removeImage(e)})}}class V extends e{constructor({mapFramework:e,mapProviderConfig:t={},events:r,eventBus:n}){super(),this.maplibreModule=e,this.events=r,this.eventBus=n,this.capabilities={supportedShortcuts:o,supportsMapSizes:!0},Object.assign(this,t)}get name(){return"MapLibreProvider"}async initMap(e){const{container:t,padding:r,mapStyle:o,mapSize:n,center:s,zoom:a,bounds:l,pixelRatio:c,...u}=e;this.mapStyleId=o?.id,this.mapSize=n;const{Map:h}=this.maplibreModule,{events:g,eventBus:d}=this,m=new h({...u,container:t,style:o?.url,pixelRatio:c,padding:r,center:s,zoom:a,fadeDuration:0,attributionControl:!1,dragRotate:!1,doubleClickZoom:!1});m.touchZoomRotate.disableRotation(),this.map=m,this.symbolImages=new G(m),this.patternImages=new q(m),this.map.setPadding(r),l&&m.fitBounds(l,{duration:0}),function(e){const t=Event.prototype.preventDefault;Event.prototype.preventDefault=function(){if(("touchmove"===this.type||"touchstart"===this.type)&&!this.cancelable){const t=e.getCanvas();if(t&&(this.target===t||t.contains(this.target)))return}t.call(this)}}(m),function(e){const t=e.getCanvas();t.removeAttribute("role"),t.setAttribute("tabindex",-1),t.removeAttribute("aria-label"),t.style.display="block",t.addEventListener("focus",e=>{t.blur(),e.relatedTarget&&e.relatedTarget.focus({preventScroll:!0})})}(m),i({map:m,events:g,eventBus:d,getCenter:this.getCenter.bind(this),getZoom:this.getZoom.bind(this),getBounds:this.getBounds.bind(this),getResolution:this.getResolution.bind(this)}),function({mapProvider:e,map:t,events:r,eventBus:o}){const n=e=>{t.once("style.load",()=>{o.emit(r.MAP_STYLE_CHANGE,{mapStyleId:e.id})}),t.setStyle(e.url,{diff:!1})},i=e=>{t.setPixelRatio(e)},s=({mapSize:t})=>{e.mapSize=t};o.on(r.MAP_SET_STYLE,n),o.on(r.MAP_SET_PIXEL_RATIO,i),o.on(r.MAP_SIZE_CHANGE,s)}({mapProvider:this,map:m,events:g,eventBus:d}),m.on("load",()=>{this.labelNavigator=function(e,t,r,o){const n={isDarkStyle:"dark"===t,labels:[],currentPixel:null,highlightLayerId:null,highlightedExpr:null};function i(){const t=e.getStyle().layers.filter(e=>"symbol"===e.type),r=e.queryRenderedFeatures({layers:t.map(e=>e.id)});n.labels=p(e,t,r)}function s(){if(i(),!n.labels.length)return null;const t=e.project(e.getCenter()),r=function(e,t){return e.reduce((e,r)=>{const o=(r.x-t.x)**2+(r.y-t.y)**2;return!e||o<e.dist?{label:r,dist:o}:e},null)?.label}(n.labels,t);return n.currentPixel={x:r.x,y:r.y},I(e,r,n),r.text}return v(e),x(e),o?.on(r.MAP_SET_STYLE,t=>{e.once("styledata",()=>e.once("idle",()=>{v(e),x(e),n.isDarkStyle="dark"===t?.mapColorScheme}))}),e.on("zoom",()=>{if(n.highlightLayerId&&n.highlightedExpr){const t=y(n.highlightedExpr,e.getZoom());e.setLayoutProperty(n.highlightLayerId,"text-size",1.5*t)}}),function(e){e.getStyle().layers.filter(e=>"symbol"===e.type).forEach(t=>{e.setPaintProperty(t.id,"text-opacity",["case",["boolean",["feature-state","highlighted"],!1],0,1])})}(e),{refreshLabels:i,highlightNextLabel:function(t){if(i(),!n.labels.length)return null;if(!n.currentPixel)return s();const r=b(t,n);return r?(n.currentPixel={x:r.x,y:r.y},I(e,r,n),r.text):null},highlightLabelAtCenter:s,clearHighlightedLabel:()=>f(e,n)}}(m,o?.mapColorScheme,g,d)}),this.eventBus.emit(g.MAP_READY,{map:this.map,mapStyleId:this.mapStyleId,mapSize:this.mapSize,crs:this.crs})}isBaseMapReady(){return Boolean(this.map?.getStyle())}destroyMap(){this.setHoverCursor([]),this.mapEvents?.remove(),this.appEvents?.remove(),this.mapEvents=null,this.appEvents=null,this.map.remove()}setHoverCursor(e){this.map&&(this._onHoverMove=z(this.map,e,this._onHoverMove))}setView({center:e,zoom:r}){this.map.flyTo({center:e||this.getCenter(),zoom:r||this.getZoom(),duration:this.map.isStyleLoaded()?t:0})}zoomIn(e){this.map.easeTo({zoom:this.getZoom()+e,duration:t})}zoomOut(e){this.map.easeTo({zoom:this.getZoom()-e,duration:t})}panBy(e){this.map.panBy(e,{duration:t})}fitToBounds(e){const r=Array.isArray(e)?e:d(e),o=this.map.isStyleLoaded()?t:0;this.map.fitBounds(r,{duration:o})}setPadding(e){this.map.setPadding(e)}updateHighlightedFeatures(e,t,r){const{LngLatBounds:o}=this.maplibreModule;return function({LngLatBounds:e,map:t,selectedFeatures:r,activeFeatures:o,stylesMap:n,symbolImages:i}){if(!t)return null;const s=A(i,"active"),a=A(i,"selected");o?.length?(B(t,o,n,L,s),B(t,o,n,P,a)):(C(t,L),C(t,P));let l={};r?.length?l=B(t,r,n,E,a):C(t,E);const c=[];return Object.entries(l).forEach(([e,{ids:r,idProperty:o}])=>{c.push(...t.queryRenderedFeatures({layers:[e]}).filter(e=>r.has(o?e.properties?.[o]:e.id)))}),((e,t)=>{if(!t.length)return null;const r=new e;return t.forEach(e=>{const t=e=>"number"==typeof e[0]?r.extend(e):e.forEach(t);t(e.geometry.coordinates)}),[r.getWest(),r.getSouth(),r.getEast(),r.getNorth()]})(e,c)}({LngLatBounds:o,map:this.map,selectedFeatures:e,activeFeatures:t,stylesMap:r,symbolImages:this.symbolImages})}highlightNextLabel(e){return this.labelNavigator?.highlightNextLabel(e)||null}highlightLabelAtCenter(){return this.labelNavigator?.highlightLabelAtCenter()||null}clearHighlightedLabel(){return this.labelNavigator?.clearHighlightedLabel()||null}getCenter(){const e=this.map.getCenter();return[Number(e.lng.toFixed(r)),Number(e.lat.toFixed(r))]}getZoom(){return Number(this.map.getZoom().toFixed(r))}getBounds(){return this.map.getBounds().toArray().flat(1)}getFeaturesAtPoint(e,t){return k(this.map,e,t)}getVisibleFeatures(e){const t=e.filter(e=>this.map.getLayer(e));return t.length?this.map.queryRenderedFeatures(void 0,{layers:t}):[]}async addSymbolsToMap(e,t,r,o=this.map.getPixelRatio()||1){return this.symbolImages.registerSymbols(e,t,r,o)}getSymbolIconLayout(e){return(({anchor:e,viewBox:t})=>({"icon-anchor":Z(e),"icon-offset":H(e,t)}))(e)}getActiveSymbolImageId(e){return this.symbolImages?.getActiveImageId(e)??null}getSelectedSymbolImageId(e){return this.symbolImages?.getSelectedImageId(e)??null}async addPatternsToMap(e,t,r,o=this.map.getPixelRatio()||1){return this.patternImages.registerPatterns(e,t,r,o)}getAreaDimensions(){const{LngLatBounds:e}=this.maplibreModule;return(e=>{let t,r,o,n;if(e&&"function"==typeof e.getWest)t=e.getWest(),r=e.getSouth(),o=e.getEast(),n=e.getNorth();else{if(!Array.isArray(e)||2!==e.length)return"";[[t,r],[o,n]]=e}const i=h([t,r],[o,r]),s=h([t,r],[t,n]),a=g(i);return`${g(s)} by ${a}`})(((e,t)=>{const{width:r,height:o}=t.getContainer().getBoundingClientRect(),n=t.getPadding(),i=[n.left,o-n.bottom],s=[r-n.right,n.top];return new e(t.unproject(i),t.unproject(s))})(e,this.map))}getCardinalMove(e,t){return((e,t)=>{const[r,o]=e,[n,i]=t,s=i-o,a=n-r,l=[];if(Math.abs(s)>c){const e=Math.round(h([r,o],[r,i]));l.push(`${s>0?"north":"south"} ${g(e)}`)}if(Math.abs(a)>c){const e=Math.round(h([r,o],[n,o]));l.push(`${a>0?"east":"west"} ${g(e)}`)}return l.join(", ")})(e,t)}getResolution(){return((e,t)=>{const r=e.lat,o=Math.pow(2,t);return 40075016.686*Math.cos(u(r))/(512*o)})(this.map.getCenter(),this.map.getZoom())}mapToScreen(e){return this.map.project(e)}screenToMap(e){const{lng:t,lat:r}=this.map.unproject([e.x,e.y]);return[t,r]}isGeometryObscured(e,t){return((e,t,r)=>{const o=r.getContainer().getBoundingClientRect(),[n,i,s,a]=d(e),l=[r.project([n,i]),r.project([n,a]),r.project([s,i]),r.project([s,a])],c=Math.min(...l.map(e=>e.x)),u=Math.max(...l.map(e=>e.x)),h=Math.min(...l.map(e=>e.y)),g=Math.max(...l.map(e=>e.y)),m=t.left-o.left,y=t.top-o.top,p=t.right-o.left,f=t.bottom-o.top;return c<p&&u>m&&h<f&&g>y})(e,t,this.map)}}export{V as default};
|
|
1
|
+
class e{_notImplemented(e){throw new Error(`${this.name} must implement ${e}()`)}isBaseMapReady(){this._notImplemented("isBaseMapReady")}addSymbolsToMap(){this._notImplemented("addSymbolsToMap")}addPatternsToMap(){this._notImplemented("addPatternsToMap")}getActiveSymbolImageId(){this._notImplemented("getActiveSymbolImageId")}getSelectedSymbolImageId(){this._notImplemented("getSelectedSymbolImageId")}}const t=400,r=7,o=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom","highlightLabelAtCenter","highlightNextLabel"];const n=(e,t)=>{let r=null;const o=(...o)=>{clearTimeout(r),r=setTimeout(()=>{e(...o)},t)};return o.cancel=()=>{r&&(clearTimeout(r),r=null)},o};function i({map:e,events:t,eventBus:r,getCenter:o,getZoom:i,getBounds:s,getResolution:a}){const l=[],c=[],u=()=>{const t=i();return{center:o(),bounds:s(),resolution:a(),zoom:t,isAtMaxZoom:e.getMaxZoom()<=t,isAtMinZoom:e.getMinZoom()>=t}},h=(e,t)=>r.emit(e,t),d=()=>h(t.MAP_LOADED);e.on("load",d),l.push(["load",d]);e.once("idle",()=>h(t.MAP_FIRST_IDLE,u()));const g=()=>h(t.MAP_MOVE_START);e.on("movestart",g),l.push(["movestart",g]);const m=n(()=>{h(t.MAP_MOVE_END,u())},500);e.on("moveend",m),l.push(["moveend",m]);const y=((e,t)=>{let r=0;return(...o)=>{const n=Date.now();n-r>=t&&(r=n,e(...o))}})(()=>{h(t.MAP_MOVE,u())},10);e.on("zoom",y),l.push(["zoom",y]);const p=()=>h(t.MAP_RENDER);e.on("render",p),l.push(["render",p]);const f=n(()=>{h(t.MAP_DATA_CHANGE,u())},500),I=e=>{e.isSourceLoaded&&f()};e.on("styledata",f),e.on("sourcedata",I),l.push(["styledata",f],["sourcedata",I]);const b=()=>h(t.MAP_STYLE_CHANGE);e.on("style.load",b),l.push(["style.load",b]);const x=e=>h(t.MAP_CLICK,{point:e.point,coords:[e.lngLat.lng,e.lngLat.lat]});return e.on("click",x),l.push(["click",x]),c.push(m,y,f),{remove(){c.forEach(e=>e.cancel()),l.forEach(([t,r])=>e.off(t,r))}}}function s(e,t,r){if(null!==e)for(var o,n,i,a,l,c,u,h,d=0,g=0,m=e.type,y="FeatureCollection"===m,p="Feature"===m,f=y?e.features.length:1,I=0;I<f;I++){l=(h=!!(u=y?e.features[I].geometry:p?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var b=0;b<l;b++){var x=0,v=0;if(null!==(a=h?u.geometries[b]:u)){c=a.coordinates;var S=a.type;switch(d=0,S){case null:break;case"Point":if(!1===t(c,g,I,x,v))return!1;g++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<c.length;o++){if(!1===t(c[o],g,I,x,v))return!1;g++,"MultiPoint"===S&&x++}"LineString"===S&&x++;break;case"Polygon":case"MultiLineString":for(o=0;o<c.length;o++){for(n=0;n<c[o].length-d;n++){if(!1===t(c[o][n],g,I,x,v))return!1;g++}"MultiLineString"===S&&x++,"Polygon"===S&&v++}"Polygon"===S&&x++;break;case"MultiPolygon":for(o=0;o<c.length;o++){for(v=0,n=0;n<c[o].length;n++){for(i=0;i<c[o][n].length-d;i++){if(!1===t(c[o][n][i],g,I,x,v))return!1;g++}v++}x++}break;case"GeometryCollection":for(o=0;o<a.geometries.length;o++)if(!1===s(a.geometries[o],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}var a=function(e,t={}){if(null!=e.bbox&&!0!==t.recompute)return e.bbox;const r=[1/0,1/0,-1/0,-1/0];return s(e,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r};const l=Math.PI/180,c=1e-4,u=e=>e*l,h=(e,t)=>{const[r,o]=e,[n,i]=t,s=u(o),a=u(i),l=a-s,c=u(n-r),h=Math.sin(l/2)**2+Math.cos(s)*Math.cos(a)*Math.sin(c/2)**2;return 6371e3*(2*Math.atan2(Math.sqrt(h),Math.sqrt(1-h)))},d=e=>{const t=e/1609.344;if(t<.5){const t=Math.round(e);return`${t} ${1===t?"metre":"metres"}`}if(t<10){const e=Number.parseFloat(t.toFixed(1));return`${e} ${1===e?"mile":"miles"}`}return`${Math.round(t)} miles`};const g="highlighted-label";function m(e,t){if("number"==typeof e)return e;if(!Array.isArray(e)||"interpolate"!==e[0])return function(e,t){const{stops:r}=e;if(r.length<2)return r.length>0?r[0][1]:0;let o=r[0],n=r[r.length-1];for(let e=1;e<r.length;e++){const i=r[e];if(i[0]>t){n=i,o=r[e-1];break}o=r[e-1],n=i}const[i,s]=o,[a,l]=n;return t<=i?s:t>=a?l:s+(t-i)/(a-i)*(l-s)}(e,t);const[,,r,...o]=e;if("zoom"!==r[0])throw new Error("Only zoom-based expressions supported");for(let e=0;e<o.length-2;e+=2){const r=o[e],n=o[e+1],i=o[e+2],s=o[e+3];if(t<=r)return n;if(t<=i)return n+(t-r)/(i-r)*(s-n)}return o[o.length-1]}function y(e,t,r){return t.flatMap(t=>{const o=t.layout?.["text-field"],n=function(e){return"string"==typeof e?/^{(.+)}$/.exec(e)?.[1]:Array.isArray(e)?e.find(e=>Array.isArray(e)&&"get"===e[0])?.[1]:null}(o);return n?r.filter(e=>e.layer.id===t.id&&e.properties?.[n]).map(r=>function(e,t,r,o){const n=function(e){const{type:t,coordinates:r}=e;if("Point"===t)return r;if("MultiPoint"===t)return r[0];if(t.includes("LineString")){const e="LineString"===t?r:r[0];return[(e[0][0]+e[e.length-1][0])/2,(e[0][1]+e[e.length-1][1])/2]}if(t.includes("Polygon")){const e="Polygon"===t?r[0]:r[0][0],o=e.reduce((e,t)=>[e[0]+t[0],e[1]+t[1]],[0,0]);return[o[0]/e.length,o[1]/e.length]}return null}(e.geometry);if(!n)return null;const i=o.project({lng:n[0],lat:n[1]});return{text:e.properties[r],x:i.x,y:i.y,feature:e,layer:t}}(r,t,n,e)).filter(Boolean):[]})}function p(e,t){if(t.highlightLayerId&&e.getLayer(t.highlightLayerId)){try{e.removeLayer(t.highlightLayerId)}catch{}t.highlightLayerId=null,t.highlightedExpr=null}}function f(e,t,r){if(!t?.feature?.layer)return;p(e,r);const{feature:o,layer:n}=t;r.highlightLayerId=`highlight-${n.id}`;const{id:i,type:s,properties:a,geometry:l}=o;e.getSource(g).setData({id:i,type:s,properties:a,geometry:l}),r.highlightedExpr=n.layout["text-size"];const c=e.getZoom();const u=function(e,t,r){return{id:`highlight-${e.id}`,type:e.type,source:g,layout:{...e.layout,"text-size":t,"text-allow-overlap":!0,"text-ignore-placement":!0,"text-max-angle":90},paint:{...e.paint,"text-color":r.text,"text-halo-color":r.halo,"text-halo-width":3,"text-halo-blur":1,"text-opacity":1}}}(n,1.5*m(r.highlightedExpr,c),r.isDarkStyle?{text:"#ffffff",halo:"#000000"}:{text:"#000000",halo:"#ffffff"});e.addLayer(u),e.moveLayer(r.highlightLayerId)}function I(e,t){if(!t.currentPixel)return null;const r=t.labels.map((e,t)=>({pixel:[e.x,e.y],index:t})).filter(e=>e.pixel[0]!==t.currentPixel.x||e.pixel[1]!==t.currentPixel.y);if(!r.length)return null;const o=r.map(e=>e.pixel);let n=((e,t,r)=>{const o=(e,t)=>e[0]===t[0]&&e[1]===t[1],n=t.filter(t=>{const n=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);let s=!1;return s="ArrowUp"===r?t[1]<=e[1]&&i>=n:"ArrowDown"===r?t[1]>e[1]&&i>=n:"ArrowLeft"===r?t[0]<=e[0]&&i<n:"ArrowRight"!==r||t[0]>e[0]&&i<n,s&&!o(t,e)});n.length||n.push(e);const i=t=>Math.hypot(e[0]-t[0],e[1]-t[1]),s=n.reduce((e,t)=>i(t)<i(e)?t:e,n[0]);return t.findIndex(e=>o(e,s))})([t.currentPixel.x,t.currentPixel.y],o,e);return(null==n||n<0||n>=r.length)&&(n=0),t.labels[r[n].index]}function b(e){e.getSource(g)||e.addSource(g,{type:"geojson",data:{type:"FeatureCollection",features:[]}})}function x(e){e.getStyle().layers.filter(e=>"line"===e.layout?.["symbol-placement"]).forEach(t=>e.setLayoutProperty(t.id,"symbol-placement","line-center"))}const v=e=>e.endsWith(".cold")?`${e.slice(0,-5)}.hot`:e.endsWith(".hot")?`${e.slice(0,-4)}.cold`:null,S="icon-image",L="active-highlight",M="active-highlight-inner",P="selected-highlight",E=(e,t)=>"active"===t?{property:"user_symbolActiveImageId",getImageId:t=>e?.getActiveImageId(t)??null}:{property:"user_symbolSelectedImageId",getImageId:t=>e?.getSelectedImageId(t)??null},A=(e,t,r,{featureId:o,idProperty:n,geometry:i})=>{const s=e.getLayer(r);s&&(t[r]||(t[r]={ids:new Set,fillIds:new Set,idProperty:n,sourceId:s.source,hasFillGeometry:!1}),!i||"Polygon"!==i.type&&"MultiPolygon"!==i.type||(t[r].hasFillGeometry=!0,t[r].fillIds.add(o)),t[r].ids.add(o))},w=(e,t,r,o)=>{t.forEach(t=>{if(!r.has(t)){const r=`${o}-${t}`;[`${r}-fill`,`${r}-line`,`${r}-symbol`].forEach(t=>{e.getLayer(t)&&e.setFilter(t,["==","id",""])})}})},$=(e,t)=>{const r=`_${t.replaceAll("-","")}Sources`;w(e,e[r]||new Set,new Set,t),e[r]=new Set},C=(e,t,r,o,n,i,s)=>{!!e.getLayer(t)||e.addLayer({id:t,type:r,source:o,...n&&{"source-layer":n},paint:i}),Object.entries(i).forEach(([r,o])=>{e.setPaintProperty(t,r,o)}),e.setFilter(t,s),e.moveLayer(t)},_=(e,t,r,o,n,i,s)=>{const a=e.getLayoutProperty(n,"icon-offset");e.getLayer(t)||e.addLayer({id:t,type:"symbol",source:r,...o&&{"source-layer":o},layout:{[S]:i,"icon-anchor":e.getLayoutProperty(n,"icon-anchor")??"center",...void 0!==a&&{"icon-offset":a},"icon-allow-overlap":!0}}),e.setLayoutProperty(t,S,i),void 0!==a&&e.setLayoutProperty(t,"icon-offset",a),e.setFilter(t,s),e.moveLayer(t)},R=(e,t,r,o,n,i)=>{const{ids:s,fillIds:a,idProperty:l,sourceId:c,hasFillGeometry:u}=r[t],h=e.getLayer(t),d=o[t]??o[v(t)];if(!h||!d)return;const g=h.sourceLayer,m=u?"fill":h.type,y=`${n}-${t}`,{fill:p}=d,f=n===P,I=(e=>e===P||e===M)(n),{lineColor:b,lineWidth:x}=((e,t)=>({lineColor:t?e.selectionStroke:e.stroke,lineWidth:t?e.strokeWidth:e.activeStrokeWidth}))(d,I),L=l?["get",l]:["id"],E=["in",L,["literal",Array.from(s)]];if("fill-extrusion"!==h.type)switch(m){case"fill":((e,t,r,o,{isSelected:n,idExpression:i,fillIds:s,fill:a,lineColor:l,lineWidth:c,filter:u})=>{if(n){const n=[];s.forEach(e=>n.push(e)),C(e,`${t}-fill`,"fill",r,o,{"fill-color":a},["in",i,["literal",n]])}C(e,`${t}-line`,"line",r,o,{"line-color":l,"line-width":c},u)})(e,y,c,g,{isSelected:f,idExpression:L,fillIds:a,fill:p,lineColor:b,lineWidth:x,filter:E});break;case"line":((e,t,r,o,n,i,s)=>{e.getLayer(`${t}-fill`)&&e.setFilter(`${t}-fill`,["==","id",""]),C(e,`${t}-line`,"line",r,o,{"line-color":n,"line-width":i},s)})(e,y,c,g,b,x,E);break;case"symbol":((e,t,r,o,n,i,s)=>{const a=e.getLayoutProperty(n,S);if(Array.isArray(a))return void _(e,`${t}-symbol`,r,o,n,["get",s.property],i);const l=s.getImageId(a);l&&_(e,`${t}-symbol`,r,o,n,l,i)})(e,y,c,g,t,E,i)}else((e,t,r,{ids:o,lineColor:n,lineWidth:i,idExpression:s})=>{const a=[];o.forEach(e=>a.push(e));const l=["in",s,["literal",a]],{source:c,sourceLayer:u}=e.getLayer(r);C(e,`${t}-line`,"line",c,u,{"line-color":n,"line-width":i},l)})(e,y,t,{ids:s,lineColor:b,lineWidth:x,idExpression:L})},F=(e,t,r,o,n)=>{const i=((e,t)=>{const r={};return t?.forEach(t=>{A(e,r,t.layerId,t);const o=v(t.layerId);o&&A(e,r,o,t)}),r})(e,t),s=new Set(Object.keys(i)),a=`_${o.replaceAll("-","")}Sources`,l=e[a]||new Set;return w(e,l,s,o),e[a]=s,s.forEach(t=>R(e,t,i,r,o,n)),i};const T=(e,t,r)=>{const o=(t.x-r.x)**2+(t.y-r.y)**2;if(0===o)return(e.x-t.x)**2+(e.y-t.y)**2;let n=((e.x-t.x)*(r.x-t.x)+(e.y-t.y)*(r.y-t.y))/o;return n=Math.max(0,Math.min(1,n)),(e.x-(t.x+n*(r.x-t.x)))**2+(e.y-(t.y+n*(r.y-t.y)))**2},B=(e,t,r={})=>{const{radius:o=10}=r,n=[[t.x-o,t.y-o],[t.x+o,t.y+o]],i=e.queryRenderedFeatures(n);if(0===i.length)return[];const s=new Set(e.queryRenderedFeatures([t.x,t.y]).map(e=>{const t=void 0===e.id?JSON.stringify(e.properties):e.id;return`${e.layer?.source}:${t}`})),a=[];i.forEach(e=>{!1===a.includes(e.layer.id)&&a.push(e.layer.id)});const l=new Set,c=[];for(let e=i.length-1;e>=0;e--){const t=i[e],r=void 0===t.id?JSON.stringify(t.properties):t.id,o=`${t.layer?.source}:${r}`;!1===l.has(o)&&(l.add(o),c.push(t))}const u=e.unproject(t),h=[u.lng,u.lat],d=c.filter(e=>{const t=e.geometry.type;if(t.includes("Polygon")){return("Polygon"===t?[e.geometry.coordinates]:e.geometry.coordinates).some(e=>((e,t)=>{const[r,o]=e;let n=!1;for(let e=0,i=t.length-1;e<t.length;i=e,e++){const[s,a]=t[e],[l,c]=t[i];a>o!=c>o&&(r<(l-s)*(o-a)/(c-a)+s&&(n=!n))}return n})(h,e[0]))}if("Point"===t||"MultiPoint"===t){const t=void 0===e.id?JSON.stringify(e.properties):e.id;return s.has(`${e.layer?.source}:${t}`)}return!0});return d.map(r=>{let o=0;const n=r.geometry.type,i=((e,t,r)=>{const{coordinates:o,type:n}=r;let i=1/0;const s=t=>e.project(t),a=e=>{for(let r=0;r<e.length-1;r++){const o=T(t,s(e[r]),s(e[r+1]));o<i&&(i=o)}};if("Point"===n){const e=s(o);i=(t.x-e.x)**2+(t.y-e.y)**2}else"LineString"===n||"MultiPoint"===n?"LineString"===n?a(o):o.forEach(e=>{const r=s(e),o=(t.x-r.x)**2+(t.y-r.y)**2;o<i&&(i=o)}):"Polygon"===n||"MultiLineString"===n?o.forEach(a):"MultiPolygon"===n&&o.forEach(e=>e.forEach(a));return i})(e,t,r.geometry);return o+=1e6*a.indexOf(r.layer.id),n.includes("Polygon")&&(o-=5e5),o+=i,{f:r,score:o}}).sort((e,t)=>e.score-t.score).map(({f:e})=>e)},k=(e,t,r)=>{const o=e.getCanvas();if(r&&e.off("mousemove",r),!t?.length)return o.style.cursor="",null;const n=r=>{const n=(e=>{const t=new Set(e);return e.forEach(e=>{const r=v(e);r&&t.add(r)}),[...t]})(t).filter(t=>e.getLayer(t));if(0===n.length)return void(o.style.cursor="");const{lineLayers:i,otherLayers:s}=((e,t)=>{const r=[],o=[];for(const n of t)if("line"===e.getLayer(n).type){const e=n.endsWith("-stroke")?n.slice(0,-7):null;null!==e&&t.includes(e)||r.push(n)}else o.push(n);return{lineLayers:r,otherLayers:o}})(e,n),{x:a,y:l}=r.point,c=[[a-10,l-10],[a+10,l+10]],u=i.length>0&&e.queryRenderedFeatures(c,{layers:i}).length>0,h=s.length>0&&e.queryRenderedFeatures(r.point,{layers:s}).length>0;o.style.cursor=u||h?"pointer":""};return e.on("mousemove",n),n};class z{sets=(()=>new Map)();add(e,t){const r=this.sets.get(e)??new Set;this.sets.delete(e),this.sets.set(e,r),t.forEach(e=>r.add(e));const o=new Set;for(;this.sets.size>2;){const[e,t]=this.sets.entries().next().value;this.sets.delete(e),t.forEach(e=>o.add(e))}return this.sets.forEach(e=>e.forEach(e=>o.delete(e))),Array.from(o)}}const N=.25,D=.75,Z=([e,t])=>{const r=(e=>e<=N?"left":e>=D?"right":"")(e),o=(e=>e<=N?"top":e>=D?"bottom":"")(t);return o+(r&&o?"-":"")+r||"center"},O=e=>e<=N?0:e>=D?1:.5,j=e=>Math.round(100*e)/100,W=([e,t],r)=>{const[,,o,n]=r.split(" ").map(Number);return[j((O(e)-e)*o),j((O(t)-t)*n)]};class H{activeImageIds=(()=>new Map)();selectedImageIds=(()=>new Map)();recentImageSets=(()=>new z)();constructor(e){this.map=e}getActiveImageId(e){return this.activeImageIds.get(e)??null}getSelectedImageId(e){return this.selectedImageIds.get(e)??null}removeImage(e){this.map.hasImage(e)&&this.map.removeImage(e),this.activeImageIds.delete(e),this.selectedImageIds.delete(e)}async registerSymbols(e,t,r,o){const{map:n}=this,i=await Promise.all(e.map(async e=>{const i=r.getSymbolImageIds(e,t,o);return i?(this.activeImageIds.set(i.normal,i.active),this.selectedImageIds.set(i.normal,i.selected),await Promise.all(Object.entries(i).map(async([i,s])=>{if(n.hasImage(s))return;const a=await r.rasteriseSymbolImage(e,t,i,o);a&&!n.hasImage(a.imageId)&&n.addImage(a.imageId,a.imageData,{pixelRatio:o})})),Object.values(i)):[]}));this.recentImageSets.add(`${t?.id}|${o}`,i.flat()).forEach(e=>this.removeImage(e))}}class G{recentImageSets=(()=>new z)();constructor(e){this.map=e}async registerPatterns(e,t,r,o){const{map:n}=this,i=new Map;e.forEach(e=>{const n=r.getPatternImageId(e,t,o);n&&!i.has(n)&&i.set(n,e)});const s=(e=>Math.max(2,2*e))(o);await Promise.all(Array.from(i,async([e,i])=>{if(n.hasImage(e))return;const a=await r.rasterisePatternImage(i,t,o);a&&!n.hasImage(a.imageId)&&n.addImage(a.imageId,a.imageData,{pixelRatio:s})})),this.recentImageSets.add(`${t}|${o}`,Array.from(i.keys())).forEach(e=>{n.hasImage(e)&&n.removeImage(e)})}}class q extends e{constructor({mapFramework:e,mapProviderConfig:t={},events:r,eventBus:n}){super(),this.maplibreModule=e,this.events=r,this.eventBus=n,this.capabilities={supportedShortcuts:o,supportsMapSizes:!0},Object.assign(this,t)}get name(){return"MapLibreProvider"}async initMap(e){const{container:t,padding:r,mapStyle:o,mapSize:n,center:s,zoom:a,bounds:l,pixelRatio:c,...u}=e;this.mapStyleId=o?.id,this.mapSize=n;const{Map:h}=this.maplibreModule,{events:d,eventBus:g}=this,v=new h({...u,container:t,style:o?.url,pixelRatio:c,padding:r,center:s,zoom:a,fadeDuration:0,attributionControl:!1,dragRotate:!1,doubleClickZoom:!1});v.touchZoomRotate.disableRotation(),this.map=v,this.symbolImages=new H(v),this.patternImages=new G(v),this.map.setPadding(r),l&&v.fitBounds(l,{duration:0}),function(e){const t=Event.prototype.preventDefault;Event.prototype.preventDefault=function(){if(("touchmove"===this.type||"touchstart"===this.type)&&!this.cancelable){const t=e.getCanvas();if(t&&(this.target===t||t.contains(this.target)))return}t.call(this)}}(v),function(e){const t=e.getCanvas();t.removeAttribute("role"),t.setAttribute("tabindex",-1),t.removeAttribute("aria-label"),t.style.display="block",t.addEventListener("focus",e=>{t.blur(),e.relatedTarget&&e.relatedTarget.focus({preventScroll:!0})})}(v),i({map:v,events:d,eventBus:g,getCenter:this.getCenter.bind(this),getZoom:this.getZoom.bind(this),getBounds:this.getBounds.bind(this),getResolution:this.getResolution.bind(this)}),function({mapProvider:e,map:t,events:r,eventBus:o}){const n=e=>{t.once("style.load",()=>{o.emit(r.MAP_STYLE_CHANGE,{mapStyleId:e.id})}),t.setStyle(e.url,{diff:!1})},i=e=>{t.setPixelRatio(e)},s=({mapSize:t})=>{e.mapSize=t};o.on(r.MAP_SET_STYLE,n),o.on(r.MAP_SET_PIXEL_RATIO,i),o.on(r.MAP_SIZE_CHANGE,s)}({mapProvider:this,map:v,events:d,eventBus:g}),v.on("load",()=>{this.labelNavigator=function(e,t,r,o){const n={isDarkStyle:"dark"===t,labels:[],currentPixel:null,highlightLayerId:null,highlightedExpr:null};function i(){const t=e.getStyle().layers.filter(e=>"symbol"===e.type),r=e.queryRenderedFeatures({layers:t.map(e=>e.id)});n.labels=y(e,t,r)}function s(){if(i(),!n.labels.length)return null;const t=e.project(e.getCenter()),r=function(e,t){return e.reduce((e,r)=>{const o=(r.x-t.x)**2+(r.y-t.y)**2;return!e||o<e.dist?{label:r,dist:o}:e},null)?.label}(n.labels,t);return n.currentPixel={x:r.x,y:r.y},f(e,r,n),r.text}return x(e),b(e),o?.on(r.MAP_SET_STYLE,t=>{e.once("styledata",()=>e.once("idle",()=>{x(e),b(e),n.isDarkStyle="dark"===t?.mapColorScheme}))}),e.on("zoom",()=>{if(n.highlightLayerId&&n.highlightedExpr){const t=m(n.highlightedExpr,e.getZoom());e.setLayoutProperty(n.highlightLayerId,"text-size",1.5*t)}}),function(e){e.getStyle().layers.filter(e=>"symbol"===e.type).forEach(t=>{e.setPaintProperty(t.id,"text-opacity",["case",["boolean",["feature-state","highlighted"],!1],0,1])})}(e),{refreshLabels:i,highlightNextLabel:function(t){if(i(),!n.labels.length)return null;if(!n.currentPixel)return s();const r=I(t,n);return r?(n.currentPixel={x:r.x,y:r.y},f(e,r,n),r.text):null},highlightLabelAtCenter:s,clearHighlightedLabel:()=>p(e,n)}}(v,o?.mapColorScheme,d,g)}),this.eventBus.emit(d.MAP_READY,{map:this.map,mapStyleId:this.mapStyleId,mapSize:this.mapSize,crs:this.crs})}isBaseMapReady(){return Boolean(this.map?.getStyle())}destroyMap(){this.setHoverCursor([]),this.mapEvents?.remove(),this.appEvents?.remove(),this.mapEvents=null,this.appEvents=null,this.map.remove()}setHoverCursor(e){this.map&&(this._onHoverMove=k(this.map,e,this._onHoverMove))}setView({center:e,zoom:r}){this.map.flyTo({center:e||this.getCenter(),zoom:r||this.getZoom(),duration:this.map.isStyleLoaded()?t:0})}zoomIn(e){this.map.easeTo({zoom:this.getZoom()+e,duration:t})}zoomOut(e){this.map.easeTo({zoom:this.getZoom()-e,duration:t})}panBy(e){this.map.panBy(e,{duration:t})}fitToBounds(e,{padding:r}={}){const o=Array.isArray(e)?e:a(e);const n=this.map.isStyleLoaded()?t:0;this.map.fitBounds(o,{duration:n,...r&&{padding:r}})}setPadding(e){this.map.setPadding(e)}updateHighlightedFeatures(e,t,r){const{LngLatBounds:o}=this.maplibreModule;return function({LngLatBounds:e,map:t,selectedFeatures:r,activeFeatures:o,stylesMap:n,symbolImages:i}){if(!t)return null;const s=E(i,"active"),a=E(i,"selected");o?.length?(F(t,o,n,L,s),F(t,o,n,M,a)):($(t,L),$(t,M));let l={};r?.length?l=F(t,r,n,P,a):$(t,P);const c=[];return Object.entries(l).forEach(([e,{ids:r,idProperty:o}])=>{c.push(...t.queryRenderedFeatures({layers:[e]}).filter(e=>r.has(o?e.properties?.[o]:e.id)))}),((e,t)=>{if(!t.length)return null;const r=new e;return t.forEach(e=>{const t=e=>"number"==typeof e[0]?r.extend(e):e.forEach(t);t(e.geometry.coordinates)}),[r.getWest(),r.getSouth(),r.getEast(),r.getNorth()]})(e,c)}({LngLatBounds:o,map:this.map,selectedFeatures:e,activeFeatures:t,stylesMap:r,symbolImages:this.symbolImages})}highlightNextLabel(e){return this.labelNavigator?.highlightNextLabel(e)||null}highlightLabelAtCenter(){return this.labelNavigator?.highlightLabelAtCenter()||null}clearHighlightedLabel(){return this.labelNavigator?.clearHighlightedLabel()||null}getCenter(){const e=this.map.getCenter();return[Number(e.lng.toFixed(r)),Number(e.lat.toFixed(r))]}getZoom(){return Number(this.map.getZoom().toFixed(r))}getBounds(){return this.map.getBounds().toArray().flat(1)}getFeaturesAtPoint(e,t){return B(this.map,e,t)}getVisibleFeatures(e){const t=e.filter(e=>this.map.getLayer(e));return t.length?this.map.queryRenderedFeatures(void 0,{layers:t}):[]}async addSymbolsToMap(e,t,r,o=this.map.getPixelRatio()||1){return this.symbolImages.registerSymbols(e,t,r,o)}getSymbolIconLayout(e){return(({anchor:e,viewBox:t})=>({"icon-anchor":Z(e),"icon-offset":W(e,t)}))(e)}getActiveSymbolImageId(e){return this.symbolImages?.getActiveImageId(e)??null}getSelectedSymbolImageId(e){return this.symbolImages?.getSelectedImageId(e)??null}async addPatternsToMap(e,t,r,o=this.map.getPixelRatio()||1){return this.patternImages.registerPatterns(e,t,r,o)}getAreaDimensions(){const{LngLatBounds:e}=this.maplibreModule;return(e=>{let t,r,o,n;if(e&&"function"==typeof e.getWest)t=e.getWest(),r=e.getSouth(),o=e.getEast(),n=e.getNorth();else{if(!Array.isArray(e)||2!==e.length)return"";[[t,r],[o,n]]=e}const i=h([t,r],[o,r]),s=h([t,r],[t,n]),a=d(i);return`${d(s)} by ${a}`})(((e,t)=>{const{width:r,height:o}=t.getContainer().getBoundingClientRect(),n=t.getPadding(),i=[n.left,o-n.bottom],s=[r-n.right,n.top];return new e(t.unproject(i),t.unproject(s))})(e,this.map))}getCardinalMove(e,t){return((e,t)=>{const[r,o]=e,[n,i]=t,s=i-o,a=n-r,l=[];if(Math.abs(s)>c){const e=Math.round(h([r,o],[r,i]));l.push(`${s>0?"north":"south"} ${d(e)}`)}if(Math.abs(a)>c){const e=Math.round(h([r,o],[n,o]));l.push(`${a>0?"east":"west"} ${d(e)}`)}return l.join(", ")})(e,t)}getResolution(){return((e,t)=>{const r=e.lat,o=Math.pow(2,t);return 40075016.686*Math.cos(u(r))/(512*o)})(this.map.getCenter(),this.map.getZoom())}mapToScreen(e){return this.map.project(e)}screenToMap(e){const{lng:t,lat:r}=this.map.unproject([e.x,e.y]);return[t,r]}}export{q as default};
|