@edugis-org/webmapx 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/{decorate-CWgUV1hU.js → decorate-DnZTfaod.js} +6 -6
- package/dist-lib/dist-BIbq3o-p.js +213 -0
- package/dist-lib/{dist-Dm6b7XCs.js → dist-CKAaoSoW.js} +2743 -2491
- package/dist-lib/{dist-kKlmcBXq.js → dist-CWCNMXMK.js} +1 -1
- package/dist-lib/{dist-Ha9LQCut.js → dist-D-5Gmgwo.js} +1 -1
- package/dist-lib/{layer-discovery-afWzu5hY.js → layer-discovery-DFP-WHAh.js} +1 -1
- package/dist-lib/{leaflet-adapter-D9djjrKv.js → leaflet-adapter-A0rte-c7.js} +1 -1
- package/dist-lib/{maplibre-adapter-TFc3e0G9.js → maplibre-adapter-Cy6yX6o7.js} +1 -1
- package/dist-lib/ol-tilegrid-Ct4my3IN.js +24 -0
- package/dist-lib/openlayers-adapter-B8WtV1tn.js +1462 -0
- package/dist-lib/{toast-Cm28o9U6.js → toast-BsoXOdeA.js} +1 -1
- package/dist-lib/{webmapx-3d-tool-D4CTD2gB.js → webmapx-3d-tool-CLppA7mK.js} +13 -13
- package/dist-lib/{webmapx-base-tool-Dm9NAWLD.js → webmapx-base-tool-DfRa7TlD.js} +1 -1
- package/dist-lib/{webmapx-config-edit-tool-BgcSkmmg.js → webmapx-config-edit-tool-BztWspia.js} +21 -21
- package/dist-lib/{webmapx-coordinates-tool-B3cuq_hG.js → webmapx-coordinates-tool-EOqZodjr.js} +20 -20
- package/dist-lib/{webmapx-core-bundle-BDImi1RE.js → webmapx-core-bundle-CH-5vYXU.js} +607 -1519
- package/dist-lib/webmapx-draw-tool-DxQgUF1Q.js +2117 -0
- package/dist-lib/{webmapx-geolocation-tool-Rw3-Iad1.js → webmapx-geolocation-tool-DIMh2kIr.js} +26 -25
- package/dist-lib/{webmapx-import-layer-tool-DRYviHd5.js → webmapx-import-layer-tool-DMiC1TpU.js} +16 -16
- package/dist-lib/{webmapx-info-tool-BJA157cy.js → webmapx-info-tool-D-XbAU9J.js} +56 -56
- package/dist-lib/{webmapx-language-osmvector-M5y_lwOg.js → webmapx-language-osmvector-BAw9TR-M.js} +12 -11
- package/dist-lib/{webmapx-measure-tool-BXhMJFC6.js → webmapx-measure-tool-CXlg11s8.js} +34 -34
- package/dist-lib/{webmapx-modal-tool-eF6Naluv.js → webmapx-modal-tool-Cs7LRrgW.js} +3 -3
- package/dist-lib/{webmapx-plugin-tool-D2Hghf9n.js → webmapx-plugin-tool-qe2yTrWB.js} +7 -7
- package/dist-lib/{webmapx-print-tool-ob1bOsR5.js → webmapx-print-tool-DrK9sLC7.js} +27 -26
- package/dist-lib/{webmapx-search-tool-Cv8BrYvY.js → webmapx-search-tool-H7NisgWH.js} +11 -11
- package/dist-lib/webmapx-settings-EHSm-AGU.js +167 -0
- package/dist-lib/{webmapx-truearea-tool-CMB4Orm-.js → webmapx-truearea-tool-CSU9mE1D.js} +26 -26
- package/dist-lib/{webmapx-view-mode-tool-CUpLNjOj.js → webmapx-view-mode-tool-D1QyQfq8.js} +9 -9
- package/dist-lib/webmapx.css +1 -1
- package/dist-lib/webmapx.js +22 -21
- package/package.json +1 -1
- package/dist-lib/WMTS-DCN4zX0-.js +0 -1169
- package/dist-lib/alert-GeHlqlN8.js +0 -310
- package/dist-lib/button-DFdGkRPQ.js +0 -741
- package/dist-lib/checkbox-QoR4S8tV.js +0 -284
- package/dist-lib/chunk.36O46B5H-B6ZL7Sm1.js +0 -77
- package/dist-lib/chunk.3RPBFEDE-BFO1fHVm.js +0 -138
- package/dist-lib/chunk.5JY5FUCG-DTXsslmx.js +0 -1090
- package/dist-lib/chunk.6CTB5ZDJ-DjZrBd6Y.js +0 -99
- package/dist-lib/chunk.AJ3ENQ5C-Ci7Gm2b6.js +0 -175
- package/dist-lib/chunk.LD4M4QGE-CiCfhE8r.js +0 -8
- package/dist-lib/chunk.NYIIDP5N-BikXIStD.js +0 -99
- package/dist-lib/chunk.RWUUFNUL-DFztA4uV.js +0 -43
- package/dist-lib/chunk.SI4ACBFK-CLb9VfMG.js +0 -61
- package/dist-lib/chunk.YHLNUJ7P-D-kanrCf.js +0 -503
- package/dist-lib/decorators-B35AgiCU.js +0 -351
- package/dist-lib/dist-c1PlDAd1.js +0 -2359
- package/dist-lib/divider-CPm675yY.js +0 -41
- package/dist-lib/icon-CEOgWlro.js +0 -9
- package/dist-lib/icon-button-Da_nBTy3.js +0 -408
- package/dist-lib/input-CeGntPlT.js +0 -590
- package/dist-lib/ol-tilegrid-9VtyxaLG.js +0 -64
- package/dist-lib/openlayers-adapter-DVW1KCRv.js +0 -13307
- package/dist-lib/option-CBxl1mZP.js +0 -1106
- package/dist-lib/rbush-C8k41T4z.js +0 -254
- package/dist-lib/spinner-DysxdNG9.js +0 -6
- package/dist-lib/tooltip-Cucn1SiD.js +0 -197
- package/dist-lib/webmapx-draw-tool-DooAV8cF.js +0 -4336
- package/dist-lib/webmapx-settings-DDEJ8aoV.js +0 -479
|
@@ -0,0 +1,1462 @@
|
|
|
1
|
+
import { t as e } from "./wms-feature-info-C0RVMEQC.js";
|
|
2
|
+
import { a as t, i as n, n as r, o as i, r as a, t as o } from "./deferred-query-service-BJDcngw6.js";
|
|
3
|
+
import { n as s } from "./marker-utils-DztWXeop.js";
|
|
4
|
+
import { fromLonLat as c, toLonLat as l } from "ol/proj";
|
|
5
|
+
import { VERSION as u } from "ol/util.js";
|
|
6
|
+
import d from "ol/Map";
|
|
7
|
+
import f from "ol/View";
|
|
8
|
+
import { apply as p, stylefunction as m } from "ol-mapbox-style";
|
|
9
|
+
import "ol/ol.css";
|
|
10
|
+
import h from "ol/layer/Vector";
|
|
11
|
+
import g from "ol/source/Vector";
|
|
12
|
+
import _ from "ol/format/GeoJSON";
|
|
13
|
+
import v from "ol/layer/Tile";
|
|
14
|
+
import y from "ol/source/OSM";
|
|
15
|
+
import b from "ol/source/XYZ";
|
|
16
|
+
import { Fill as x, Stroke as S, Style as C } from "ol/style";
|
|
17
|
+
import w from "ol/layer/VectorTile";
|
|
18
|
+
import T from "ol/source/VectorTile";
|
|
19
|
+
import E from "ol/format/MVT";
|
|
20
|
+
import D from "ol/source/ImageWMS";
|
|
21
|
+
import O from "ol/layer/Image";
|
|
22
|
+
import k from "ol/source/TileWMS";
|
|
23
|
+
import { createXYZ as A } from "ol/tilegrid";
|
|
24
|
+
import { createFromTemplate as j } from "ol/tileurlfunction";
|
|
25
|
+
import M from "ol/Overlay";
|
|
26
|
+
//#region src/map/openlayers-services/MapCoreService.ts
|
|
27
|
+
var N = class e {
|
|
28
|
+
static {
|
|
29
|
+
this.ZOOM_OFFSET = 1;
|
|
30
|
+
}
|
|
31
|
+
constructor(e, t) {
|
|
32
|
+
this.store = e, this.eventBus = t, this.mapInstance = null, this.panDisabled = !1, this.mapReadyCallbacks = [], this.silentSourceIds = /* @__PURE__ */ new Set(), this.initialConfig = {
|
|
33
|
+
center: [10.45, 51.17],
|
|
34
|
+
zoom: 4
|
|
35
|
+
}, this.layerOrderRegistry = null, this.sources = /* @__PURE__ */ new Map(), this.pendingTileLoads = 0;
|
|
36
|
+
}
|
|
37
|
+
toLogicalBearing(e) {
|
|
38
|
+
return -(e.getRotation() || 0) * 180 / Math.PI;
|
|
39
|
+
}
|
|
40
|
+
toOLZoom(t) {
|
|
41
|
+
return t + e.ZOOM_OFFSET;
|
|
42
|
+
}
|
|
43
|
+
fromOLZoom(t) {
|
|
44
|
+
return t - e.ZOOM_OFFSET;
|
|
45
|
+
}
|
|
46
|
+
getViewportState() {
|
|
47
|
+
if (this.mapInstance) {
|
|
48
|
+
let e = this.mapInstance.getView();
|
|
49
|
+
return {
|
|
50
|
+
center: l(e.getCenter() || [0, 0]),
|
|
51
|
+
zoom: this.fromOLZoom(e.getZoom() || 1),
|
|
52
|
+
bearing: this.toLogicalBearing(e),
|
|
53
|
+
pitch: 0
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
center: [0, 0],
|
|
58
|
+
zoom: 1,
|
|
59
|
+
bearing: 0,
|
|
60
|
+
pitch: 0
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
setViewport(e, t) {
|
|
64
|
+
if (this.mapInstance) {
|
|
65
|
+
let n = this.clampZoom(t);
|
|
66
|
+
this.mapInstance.getView().animate({
|
|
67
|
+
center: c(e),
|
|
68
|
+
zoom: this.toOLZoom(n),
|
|
69
|
+
duration: 500
|
|
70
|
+
}), n !== t && this.scheduleViewportSync();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
initialize(e, t) {
|
|
74
|
+
let n = t?.center ?? this.initialConfig.center, r = t?.zoom ?? this.initialConfig.zoom, i = this.toOLZoom(r);
|
|
75
|
+
this.minZoom = t?.minZoom, this.maxZoom = t?.maxZoom;
|
|
76
|
+
let a = t?.minZoom, o = t?.maxZoom, s = this.resolveContainer(e), u = {
|
|
77
|
+
center: c(n),
|
|
78
|
+
zoom: i
|
|
79
|
+
};
|
|
80
|
+
a !== void 0 && (u.minZoom = this.toOLZoom(a)), o !== void 0 && (u.maxZoom = this.toOLZoom(o)), this.mapInstance = new d({
|
|
81
|
+
target: s,
|
|
82
|
+
layers: [],
|
|
83
|
+
view: new f({ ...u }),
|
|
84
|
+
controls: [],
|
|
85
|
+
keyboardEventTarget: document
|
|
86
|
+
});
|
|
87
|
+
let m = this.mapInstance.getViewport();
|
|
88
|
+
if (m && (m.tabIndex = -1), t?.styleUrl) p(this.mapInstance, t.styleUrl).catch((e) => {
|
|
89
|
+
console.error("[OL CORE] Failed to apply style from URL:", e);
|
|
90
|
+
});
|
|
91
|
+
else if (t?.style) {
|
|
92
|
+
let e = {
|
|
93
|
+
version: 8,
|
|
94
|
+
...t.style
|
|
95
|
+
};
|
|
96
|
+
Array.isArray(e.layers) && e.layers.length > 0 && p(this.mapInstance, e).catch((e) => {
|
|
97
|
+
console.error("[OL CORE] Failed to apply inline style:", e);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
this.mapInstance.once("rendercomplete", () => {
|
|
101
|
+
let e = this.buildViewportFeature();
|
|
102
|
+
this.store.dispatch({
|
|
103
|
+
mapLoaded: !0,
|
|
104
|
+
zoomLevel: r,
|
|
105
|
+
mapCenter: n,
|
|
106
|
+
mapViewportBounds: e
|
|
107
|
+
}, "MAP"), this.flushMapReadyCallbacks();
|
|
108
|
+
}), this.attachLoadingEvents(this.mapInstance);
|
|
109
|
+
let h = this.mapInstance.getView();
|
|
110
|
+
h.on("change:resolution", () => {
|
|
111
|
+
let e = this.fromOLZoom(h.getZoom() || 0), t = this.buildViewportFeature();
|
|
112
|
+
this.store.dispatch({
|
|
113
|
+
zoomLevel: e,
|
|
114
|
+
mapViewportBounds: t
|
|
115
|
+
}, "MAP"), this.eventBus?.emit({
|
|
116
|
+
type: "zoom-end",
|
|
117
|
+
zoom: e
|
|
118
|
+
});
|
|
119
|
+
}), h.on("change:center", () => {
|
|
120
|
+
let e = l(h.getCenter() || [0, 0]), t = this.fromOLZoom(h.getZoom() || 0), n = this.buildViewportFeature();
|
|
121
|
+
this.store.dispatch({
|
|
122
|
+
mapCenter: e,
|
|
123
|
+
zoomLevel: t,
|
|
124
|
+
mapViewportBounds: n
|
|
125
|
+
}, "MAP");
|
|
126
|
+
}), h.on("change:rotation", () => {
|
|
127
|
+
let e = l(h.getCenter() || [0, 0]), t = this.fromOLZoom(h.getZoom() || 0), n = this.buildViewportFeature();
|
|
128
|
+
this.store.dispatch({
|
|
129
|
+
mapCenter: e,
|
|
130
|
+
zoomLevel: t,
|
|
131
|
+
mapViewportBounds: n
|
|
132
|
+
}, "MAP"), this.emitViewChange();
|
|
133
|
+
}), this.mapInstance.on("moveend", () => {
|
|
134
|
+
this.emitViewChangeEnd();
|
|
135
|
+
}), this.mapInstance.on("pointerdrag", () => {
|
|
136
|
+
this.dispatchViewportBoundsSnapshot(), this.emitViewChange();
|
|
137
|
+
}), this.attachPointerEvents(this.mapInstance);
|
|
138
|
+
}
|
|
139
|
+
attachPointerEvents(e) {
|
|
140
|
+
e.on("pointermove", (e) => {
|
|
141
|
+
if (e.dragging && !this.panDisabled) return;
|
|
142
|
+
let t = l(e.coordinate), n = [e.pixel[0], e.pixel[1]], r = this.computePointerResolution();
|
|
143
|
+
this.eventBus?.emit({
|
|
144
|
+
type: "pointer-move",
|
|
145
|
+
coords: t,
|
|
146
|
+
pixel: n,
|
|
147
|
+
resolution: r,
|
|
148
|
+
originalEvent: e.originalEvent
|
|
149
|
+
}), this.store.dispatch({
|
|
150
|
+
pointerCoordinates: t,
|
|
151
|
+
pointerResolution: r
|
|
152
|
+
}, "MAP");
|
|
153
|
+
}), e.getViewport().addEventListener("mouseout", (e) => {
|
|
154
|
+
this.eventBus?.emit({
|
|
155
|
+
type: "pointer-leave",
|
|
156
|
+
originalEvent: e
|
|
157
|
+
}), this.store.dispatch({
|
|
158
|
+
pointerCoordinates: null,
|
|
159
|
+
pointerResolution: null
|
|
160
|
+
}, "MAP");
|
|
161
|
+
}), e.on("click", (e) => {
|
|
162
|
+
let t = l(e.coordinate), n = [e.pixel[0], e.pixel[1]], r = this.computePointerResolution();
|
|
163
|
+
this.eventBus?.emit({
|
|
164
|
+
type: "click",
|
|
165
|
+
coords: t,
|
|
166
|
+
pixel: n,
|
|
167
|
+
resolution: r,
|
|
168
|
+
originalEvent: e.originalEvent
|
|
169
|
+
}), this.store.dispatch({
|
|
170
|
+
lastClickedCoordinates: t,
|
|
171
|
+
lastClickedResolution: r,
|
|
172
|
+
pointerCoordinates: t,
|
|
173
|
+
pointerResolution: r
|
|
174
|
+
}, "MAP");
|
|
175
|
+
}), e.on("dblclick", (e) => {
|
|
176
|
+
let t = l(e.coordinate), n = [e.pixel[0], e.pixel[1]];
|
|
177
|
+
this.eventBus?.emit({
|
|
178
|
+
type: "dblclick",
|
|
179
|
+
coords: t,
|
|
180
|
+
pixel: n,
|
|
181
|
+
originalEvent: e.originalEvent
|
|
182
|
+
});
|
|
183
|
+
}), e.getViewport().addEventListener("pointerdown", (t) => {
|
|
184
|
+
let n = e.getEventPixel(t), r = e.getCoordinateFromPixel(n);
|
|
185
|
+
if (!r) return;
|
|
186
|
+
let i = l(r);
|
|
187
|
+
this.eventBus?.emit({
|
|
188
|
+
type: "pointer-down",
|
|
189
|
+
coords: i,
|
|
190
|
+
pixel: n,
|
|
191
|
+
button: t.button,
|
|
192
|
+
originalEvent: t
|
|
193
|
+
});
|
|
194
|
+
}), e.getViewport().addEventListener("pointerup", (t) => {
|
|
195
|
+
let n = e.getEventPixel(t), r = e.getCoordinateFromPixel(n);
|
|
196
|
+
if (!r) return;
|
|
197
|
+
let i = l(r);
|
|
198
|
+
this.eventBus?.emit({
|
|
199
|
+
type: "pointer-up",
|
|
200
|
+
coords: i,
|
|
201
|
+
pixel: n,
|
|
202
|
+
button: t.button,
|
|
203
|
+
originalEvent: t
|
|
204
|
+
});
|
|
205
|
+
}), e.getViewport().addEventListener("pointercancel", () => {
|
|
206
|
+
this.eventBus?.emit({ type: "pointer-cancel" });
|
|
207
|
+
}), e.getViewport().addEventListener("contextmenu", (t) => {
|
|
208
|
+
t.preventDefault();
|
|
209
|
+
let n = e.getEventPixel(t), r = e.getCoordinateFromPixel(n);
|
|
210
|
+
if (r) {
|
|
211
|
+
let e = l(r);
|
|
212
|
+
this.eventBus?.emit({
|
|
213
|
+
type: "contextmenu",
|
|
214
|
+
coords: e,
|
|
215
|
+
pixel: [n[0], n[1]],
|
|
216
|
+
originalEvent: t
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
computePointerResolution() {
|
|
222
|
+
if (!this.mapInstance) return null;
|
|
223
|
+
let e = this.mapInstance.getView().getResolution();
|
|
224
|
+
if (!e) return null;
|
|
225
|
+
let t = e / 111320;
|
|
226
|
+
return {
|
|
227
|
+
lng: t,
|
|
228
|
+
lat: t
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
emitViewChange() {
|
|
232
|
+
if (!this.eventBus || !this.mapInstance) return;
|
|
233
|
+
let e = this.mapInstance.getView(), t = l(e.getCenter() || [0, 0]), n = e.calculateExtent(this.mapInstance.getSize()), r = l([n[0], n[1]]), i = l([n[2], n[3]]);
|
|
234
|
+
this.eventBus.emit({
|
|
235
|
+
type: "view-change",
|
|
236
|
+
center: t,
|
|
237
|
+
zoom: this.fromOLZoom(e.getZoom() || 0),
|
|
238
|
+
bearing: this.toLogicalBearing(e),
|
|
239
|
+
pitch: 0,
|
|
240
|
+
bounds: {
|
|
241
|
+
sw: r,
|
|
242
|
+
ne: i
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
emitViewChangeEnd() {
|
|
247
|
+
if (!this.eventBus || !this.mapInstance) return;
|
|
248
|
+
let e = this.mapInstance.getView(), t = l(e.getCenter() || [0, 0]), n = e.calculateExtent(this.mapInstance.getSize()), r = l([n[0], n[1]]), i = l([n[2], n[3]]);
|
|
249
|
+
this.eventBus.emit({
|
|
250
|
+
type: "view-change-end",
|
|
251
|
+
center: t,
|
|
252
|
+
zoom: this.fromOLZoom(e.getZoom() || 0),
|
|
253
|
+
bearing: this.toLogicalBearing(e),
|
|
254
|
+
pitch: 0,
|
|
255
|
+
bounds: {
|
|
256
|
+
sw: r,
|
|
257
|
+
ne: i
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
setZoom(e) {
|
|
262
|
+
if (this.mapInstance) {
|
|
263
|
+
let t = this.clampZoom(e), n = this.mapInstance.getView();
|
|
264
|
+
if (this.fromOLZoom(n.getZoom() || 0) === t && t !== e) {
|
|
265
|
+
this.scheduleViewportSync();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
n.setZoom(this.toOLZoom(t));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
getZoom() {
|
|
272
|
+
return this.fromOLZoom(this.mapInstance?.getView().getZoom() || this.toOLZoom(this.initialConfig.zoom));
|
|
273
|
+
}
|
|
274
|
+
getNavigationCapabilities() {
|
|
275
|
+
return {
|
|
276
|
+
bearing: !0,
|
|
277
|
+
pitch: !1
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
getBearing() {
|
|
281
|
+
let e = this.mapInstance?.getView();
|
|
282
|
+
return e ? this.toLogicalBearing(e) : 0;
|
|
283
|
+
}
|
|
284
|
+
setBearing(e) {
|
|
285
|
+
let t = this.mapInstance?.getView();
|
|
286
|
+
t && t.setRotation(-e * Math.PI / 180);
|
|
287
|
+
}
|
|
288
|
+
getPitch() {
|
|
289
|
+
return 0;
|
|
290
|
+
}
|
|
291
|
+
setPitch(e) {}
|
|
292
|
+
setTerrainEnabled(e) {
|
|
293
|
+
return !1;
|
|
294
|
+
}
|
|
295
|
+
isTerrainEnabled() {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
resetNorth() {
|
|
299
|
+
this.setBearing(0);
|
|
300
|
+
}
|
|
301
|
+
resetNorthPitch() {
|
|
302
|
+
this.resetNorth();
|
|
303
|
+
}
|
|
304
|
+
setProjection(e) {
|
|
305
|
+
return !1;
|
|
306
|
+
}
|
|
307
|
+
getProjection() {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
scheduleViewportSync() {
|
|
311
|
+
this.mapInstance && requestAnimationFrame(() => {
|
|
312
|
+
if (!this.mapInstance) return;
|
|
313
|
+
let e = this.mapInstance.getView(), t = l(e.getCenter() || [0, 0]), n = this.fromOLZoom(e.getZoom() || 0), r = this.buildViewportFeature();
|
|
314
|
+
this.store.dispatch({
|
|
315
|
+
zoomLevel: n,
|
|
316
|
+
mapCenter: t,
|
|
317
|
+
mapViewportBounds: r
|
|
318
|
+
}, "MAP"), this.emitViewChangeEnd();
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
clampZoom(e) {
|
|
322
|
+
let t = e;
|
|
323
|
+
return this.minZoom !== void 0 && (t = Math.max(t, this.minZoom)), this.maxZoom !== void 0 && (t = Math.min(t, this.maxZoom)), t;
|
|
324
|
+
}
|
|
325
|
+
setLayerOrderRegistry(e) {
|
|
326
|
+
this.layerOrderRegistry = e;
|
|
327
|
+
}
|
|
328
|
+
addLayer(e, t) {
|
|
329
|
+
if (!this.mapInstance) return !1;
|
|
330
|
+
let n = e.source, r = this.sources.get(n);
|
|
331
|
+
if (!r) return console.error(`[OL CORE] Source "${n}" not found for layer "${e.id}".`), !1;
|
|
332
|
+
let i = e?.metadata && typeof e.metadata == "object" ? e.metadata : {};
|
|
333
|
+
r.olLayer.__mapLayerId = typeof i.mapLayerId == "string" ? i.mapLayerId : e.id, this.layerOrderRegistry?.registerInlineLayer(r.olLayer.__mapLayerId ?? e.id, r.olLayer, t);
|
|
334
|
+
let a = t?.beforeLayerId, o = t?.afterLayerId;
|
|
335
|
+
if (typeof a == "string") {
|
|
336
|
+
let t = r.layers.findIndex((e) => e?.id === a);
|
|
337
|
+
t >= 0 ? r.layers.splice(t, 0, e) : r.layers.push(e);
|
|
338
|
+
} else if (typeof o == "string") {
|
|
339
|
+
let t = r.layers.findIndex((e) => e?.id === o);
|
|
340
|
+
t >= 0 ? r.layers.splice(t + 1, 0, e) : r.layers.push(e);
|
|
341
|
+
} else r.layers.push(e);
|
|
342
|
+
return this.updateStyle(n), !0;
|
|
343
|
+
}
|
|
344
|
+
removeLayer(e) {
|
|
345
|
+
for (let [t, n] of this.sources.entries()) {
|
|
346
|
+
let r = n.layers.findIndex((t) => t.id === e);
|
|
347
|
+
if (r > -1) {
|
|
348
|
+
n.layers.splice(r, 1), n.layers.length === 0 ? (this.mapInstance?.removeLayer(n.olLayer), this.sources.delete(t), this.layerOrderRegistry?.unregisterInlineLayer(e)) : this.updateStyle(t);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
addSource(e, t) {
|
|
354
|
+
if (this.sources.has(e)) return;
|
|
355
|
+
let n = new g({ features: new _().readFeatures(t.data, {
|
|
356
|
+
dataProjection: "EPSG:4326",
|
|
357
|
+
featureProjection: "EPSG:3857"
|
|
358
|
+
}) });
|
|
359
|
+
n.set("_webmapx_source_id", e);
|
|
360
|
+
let r = new h({ source: n });
|
|
361
|
+
this.sources.set(e, {
|
|
362
|
+
source: n,
|
|
363
|
+
layers: [],
|
|
364
|
+
olLayer: r
|
|
365
|
+
}), this.mapInstance?.addLayer(r);
|
|
366
|
+
}
|
|
367
|
+
removeSource(e) {
|
|
368
|
+
let t = this.sources.get(e);
|
|
369
|
+
t && (this.mapInstance?.removeLayer(t.olLayer), this.sources.delete(e));
|
|
370
|
+
}
|
|
371
|
+
getSource(e) {
|
|
372
|
+
let t = this.sources.get(e);
|
|
373
|
+
if (t) return {
|
|
374
|
+
id: e,
|
|
375
|
+
setData: (e) => {
|
|
376
|
+
t.source.clear(), t.source.addFeatures(new _().readFeatures(e, {
|
|
377
|
+
dataProjection: "EPSG:4326",
|
|
378
|
+
featureProjection: "EPSG:3857"
|
|
379
|
+
}));
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
project(e) {
|
|
384
|
+
if (!this.mapInstance) return console.warn("[CORE SERVICE - OpenLayers] project called before map instance is ready."), [0, 0];
|
|
385
|
+
let t = c(e), n = this.mapInstance.getPixelFromCoordinate(t);
|
|
386
|
+
return n ? [n[0], n[1]] : [0, 0];
|
|
387
|
+
}
|
|
388
|
+
unproject(e) {
|
|
389
|
+
if (!this.mapInstance) return null;
|
|
390
|
+
let t = this.mapInstance.getCoordinateFromPixel([e[0], e[1]]);
|
|
391
|
+
return t ? l(t) : null;
|
|
392
|
+
}
|
|
393
|
+
fitBounds(e) {
|
|
394
|
+
if (!this.mapInstance) return;
|
|
395
|
+
let t = c([e[0], e[1]]), n = c([e[2], e[3]]), r = [
|
|
396
|
+
t[0],
|
|
397
|
+
t[1],
|
|
398
|
+
n[0],
|
|
399
|
+
n[1]
|
|
400
|
+
];
|
|
401
|
+
this.mapInstance.getView().fit(r, {
|
|
402
|
+
size: this.mapInstance.getSize(),
|
|
403
|
+
padding: [
|
|
404
|
+
40,
|
|
405
|
+
40,
|
|
406
|
+
40,
|
|
407
|
+
40
|
|
408
|
+
],
|
|
409
|
+
duration: 300
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
setCursor(e) {
|
|
413
|
+
if (!this.mapInstance) return;
|
|
414
|
+
let t = this.mapInstance.getViewport();
|
|
415
|
+
t.style.cursor = e;
|
|
416
|
+
}
|
|
417
|
+
setPanEnabled(e) {
|
|
418
|
+
this.mapInstance && (this.panDisabled = !e, this.mapInstance.getInteractions().forEach((t) => {
|
|
419
|
+
t.constructor?.name === "DragPan" && t.setActive(e);
|
|
420
|
+
}));
|
|
421
|
+
}
|
|
422
|
+
setTouchCaptureEnabled(e) {
|
|
423
|
+
if (!this.mapInstance) return;
|
|
424
|
+
let t = this.mapInstance.getViewport();
|
|
425
|
+
t.style.touchAction = e ? "" : "none";
|
|
426
|
+
}
|
|
427
|
+
setDoubleClickZoomEnabled(e) {}
|
|
428
|
+
setLayerVisibility(e, t) {
|
|
429
|
+
let n = this.sources.get(e);
|
|
430
|
+
n?.olLayer && n.olLayer.setVisible(t);
|
|
431
|
+
}
|
|
432
|
+
getSourceData(e) {
|
|
433
|
+
let t = this.sources.get(e);
|
|
434
|
+
if (!t) return null;
|
|
435
|
+
let n = new _();
|
|
436
|
+
return {
|
|
437
|
+
type: "FeatureCollection",
|
|
438
|
+
features: t.source.getFeatures().map((e) => JSON.parse(n.writeFeature(e, {
|
|
439
|
+
dataProjection: "EPSG:4326",
|
|
440
|
+
featureProjection: "EPSG:3857"
|
|
441
|
+
})))
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
updateStyle(e) {
|
|
445
|
+
let t = this.sources.get(e);
|
|
446
|
+
if (!t) return;
|
|
447
|
+
let n = {
|
|
448
|
+
version: 8,
|
|
449
|
+
sources: { [e]: { type: "geojson" } },
|
|
450
|
+
layers: t.layers
|
|
451
|
+
};
|
|
452
|
+
m(t.olLayer, n, e);
|
|
453
|
+
}
|
|
454
|
+
suppressBusySignalForSource(e) {
|
|
455
|
+
this.silentSourceIds.add(e);
|
|
456
|
+
}
|
|
457
|
+
unsuppressBusySignalForSource(e) {
|
|
458
|
+
this.silentSourceIds.delete(e);
|
|
459
|
+
}
|
|
460
|
+
onMapReady(e) {
|
|
461
|
+
if (this.mapInstance) {
|
|
462
|
+
e(this.mapInstance);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
this.mapReadyCallbacks.push(e);
|
|
466
|
+
}
|
|
467
|
+
flushMapReadyCallbacks() {
|
|
468
|
+
this.mapInstance && this.mapReadyCallbacks.splice(0).forEach((e) => {
|
|
469
|
+
try {
|
|
470
|
+
e(this.mapInstance);
|
|
471
|
+
} catch (e) {
|
|
472
|
+
console.error("[OL CORE SERVICE] mapReady callback failed.", e);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
attachLoadingEvents(e) {
|
|
477
|
+
let t = (e) => {
|
|
478
|
+
let t = e.getSource?.();
|
|
479
|
+
if (!t) return;
|
|
480
|
+
let n = t.get?.("_webmapx_source_id");
|
|
481
|
+
t.on?.("tileloadstart", () => {
|
|
482
|
+
n && this.silentSourceIds.has(n) || (this.pendingTileLoads++, this.store.dispatch({ mapBusy: !0 }, "MAP"));
|
|
483
|
+
});
|
|
484
|
+
let r = () => {
|
|
485
|
+
this.pendingTileLoads = Math.max(0, this.pendingTileLoads - 1), this.pendingTileLoads === 0 && this.store.dispatch({ mapBusy: !1 }, "MAP");
|
|
486
|
+
};
|
|
487
|
+
t.on?.("tileloadend", r), t.on?.("tileloaderror", r);
|
|
488
|
+
};
|
|
489
|
+
e.getLayers().forEach(t), e.getLayers().on("add", (e) => {
|
|
490
|
+
t(e.element);
|
|
491
|
+
}), e.on("rendercomplete", () => {
|
|
492
|
+
this.pendingTileLoads === 0 && this.store.dispatch({ mapBusy: !1 }, "MAP");
|
|
493
|
+
}), e.on("loadstart", () => {
|
|
494
|
+
this.store.dispatch({ mapBusy: !0 }, "MAP");
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
dispatchViewportBoundsSnapshot() {
|
|
498
|
+
let e = this.buildViewportFeature();
|
|
499
|
+
this.store.dispatch({ mapViewportBounds: e }, "MAP");
|
|
500
|
+
}
|
|
501
|
+
buildViewportFeature() {
|
|
502
|
+
if (!this.mapInstance) return null;
|
|
503
|
+
let e = this.mapInstance.getView(), t = this.mapInstance.getSize();
|
|
504
|
+
if (!t) return null;
|
|
505
|
+
let n = [], r = e.getCenter(), i = e.getResolution();
|
|
506
|
+
if (r && typeof i == "number") {
|
|
507
|
+
let a = e.getRotation(), o = t[0] * i / 2, s = t[1] * i / 2, c = Math.cos(a), u = Math.sin(a), d = (e, t) => l([r[0] + e * c - t * u, r[1] + e * u + t * c]);
|
|
508
|
+
n.push(d(-o, -s), d(o, -s), d(o, s), d(-o, s));
|
|
509
|
+
}
|
|
510
|
+
if (n.length === 0) {
|
|
511
|
+
let r = e.calculateExtent(t), i = l([r[0], r[1]]), a = l([r[2], r[3]]);
|
|
512
|
+
n.push([i[0], i[1]], [i[0], a[1]], [a[0], a[1]], [a[0], i[1]]);
|
|
513
|
+
}
|
|
514
|
+
return n.length > 0 && n.push(n[0]), {
|
|
515
|
+
type: "Feature",
|
|
516
|
+
properties: { role: "mapViewport" },
|
|
517
|
+
geometry: {
|
|
518
|
+
type: "Polygon",
|
|
519
|
+
coordinates: [n]
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
resolveContainer(e) {
|
|
524
|
+
let t = document.getElementById(e);
|
|
525
|
+
if (!t) throw Error(`Container #${e} not found.`);
|
|
526
|
+
if (t.tagName.toLowerCase() === "webmapx-map") {
|
|
527
|
+
let e = t.querySelector("[slot=\"map-view\"]");
|
|
528
|
+
if (e) return e;
|
|
529
|
+
}
|
|
530
|
+
return t;
|
|
531
|
+
}
|
|
532
|
+
}, P = class {
|
|
533
|
+
constructor() {}
|
|
534
|
+
setBufferRadius(e) {
|
|
535
|
+
console.log(`[OL SERVICE] Set buffer radius to ${e}km.`);
|
|
536
|
+
}
|
|
537
|
+
toggleTool() {
|
|
538
|
+
console.log("[OL SERVICE] Toggled tool activation.");
|
|
539
|
+
}
|
|
540
|
+
}, F = class {
|
|
541
|
+
constructor(e, t) {
|
|
542
|
+
this.id = e, this.source = t;
|
|
543
|
+
}
|
|
544
|
+
setData(e) {
|
|
545
|
+
this.source.clear();
|
|
546
|
+
let t = new _().readFeatures(e, { featureProjection: "EPSG:3857" });
|
|
547
|
+
this.source.addFeatures(t);
|
|
548
|
+
}
|
|
549
|
+
}, I = class {
|
|
550
|
+
constructor(e, t, n, r) {
|
|
551
|
+
this.id = e, this.layer = t, this.sourceId = n, this.map = r;
|
|
552
|
+
}
|
|
553
|
+
getSource() {
|
|
554
|
+
return new F(this.sourceId, this.layer.getSource());
|
|
555
|
+
}
|
|
556
|
+
remove() {
|
|
557
|
+
this.map.removeLayer(this.layer);
|
|
558
|
+
}
|
|
559
|
+
}, L = 1, R = class {
|
|
560
|
+
constructor(e) {
|
|
561
|
+
this.map = e, this.sources = new globalThis.Map(), this.layers = new globalThis.Map();
|
|
562
|
+
}
|
|
563
|
+
setViewport(e, t, n, r) {
|
|
564
|
+
this.map.getView().animate({
|
|
565
|
+
center: c(e),
|
|
566
|
+
zoom: t + L,
|
|
567
|
+
rotation: n ? n * Math.PI / 180 : 0,
|
|
568
|
+
duration: 0
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
createSource(e, t) {
|
|
572
|
+
if (!this.sources.has(e)) {
|
|
573
|
+
let n = new g({ features: new _().readFeatures(t, { featureProjection: "EPSG:3857" }) });
|
|
574
|
+
this.sources.set(e, n);
|
|
575
|
+
}
|
|
576
|
+
return new F(e, this.sources.get(e));
|
|
577
|
+
}
|
|
578
|
+
getSource(e) {
|
|
579
|
+
let t = this.sources.get(e);
|
|
580
|
+
return t ? new F(e, t) : null;
|
|
581
|
+
}
|
|
582
|
+
createLayer(e) {
|
|
583
|
+
if (!this.layers.has(e.id)) {
|
|
584
|
+
let t = this.sources.get(e.sourceId);
|
|
585
|
+
if (!t) throw Error(`Source "${e.sourceId}" not found. Create source before layer.`);
|
|
586
|
+
let n = new h({
|
|
587
|
+
source: t,
|
|
588
|
+
style: this.createStyle(e)
|
|
589
|
+
});
|
|
590
|
+
n.__layerId = e.id, this.map.addLayer(n), this.layers.set(e.id, n);
|
|
591
|
+
}
|
|
592
|
+
return new I(e.id, this.layers.get(e.id), e.sourceId, this.map);
|
|
593
|
+
}
|
|
594
|
+
getLayer(e) {
|
|
595
|
+
let t = this.layers.get(e);
|
|
596
|
+
return t ? new I(e, t, Array.from(this.sources.entries()).find(([e, n]) => n === t.getSource())?.[0] ?? "", this.map) : null;
|
|
597
|
+
}
|
|
598
|
+
onReady(e) {
|
|
599
|
+
this.map.once("rendercomplete", e), setTimeout(() => {
|
|
600
|
+
this.map.getView() && e();
|
|
601
|
+
}, 0);
|
|
602
|
+
}
|
|
603
|
+
destroy() {
|
|
604
|
+
this.map.setTarget(void 0), this.sources.clear(), this.layers.clear();
|
|
605
|
+
}
|
|
606
|
+
createStyle(e) {
|
|
607
|
+
let t = e.paint || {};
|
|
608
|
+
switch (e.type) {
|
|
609
|
+
case "fill": return new C({
|
|
610
|
+
fill: new x({ color: this.toRgba(t["fill-color"] || "#000000", t["fill-opacity"] ?? 1) }),
|
|
611
|
+
stroke: new S({
|
|
612
|
+
color: this.toRgba(t["fill-color"] || "#000000", t["fill-opacity"] ?? 1),
|
|
613
|
+
width: 1
|
|
614
|
+
})
|
|
615
|
+
});
|
|
616
|
+
case "line": return new C({ stroke: new S({
|
|
617
|
+
color: this.toRgba(t["line-color"] || "#000000", t["line-opacity"] ?? 1),
|
|
618
|
+
width: t["line-width"] || 1
|
|
619
|
+
}) });
|
|
620
|
+
case "circle": return new C({
|
|
621
|
+
fill: new x({ color: "#3399CC" }),
|
|
622
|
+
stroke: new S({
|
|
623
|
+
color: "#fff",
|
|
624
|
+
width: 1
|
|
625
|
+
})
|
|
626
|
+
});
|
|
627
|
+
default: return new C();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
toRgba(e, t) {
|
|
631
|
+
if (e.startsWith("#")) {
|
|
632
|
+
let n = e.slice(1);
|
|
633
|
+
return `rgba(${parseInt(n.slice(0, 2), 16)}, ${parseInt(n.slice(2, 4), 16)}, ${parseInt(n.slice(4, 6), 16)}, ${t})`;
|
|
634
|
+
}
|
|
635
|
+
return e;
|
|
636
|
+
}
|
|
637
|
+
}, z = class {
|
|
638
|
+
createMap(e, t) {
|
|
639
|
+
let n = t?.center ?? [0, 0], r = (t?.zoom ?? 2) + L, i = new d({
|
|
640
|
+
target: e,
|
|
641
|
+
layers: [new v({ source: t?.tileUrl || Array.isArray(t?.tileUrls) && t.tileUrls.length > 0 ? new b({
|
|
642
|
+
...Array.isArray(t?.tileUrls) && t.tileUrls.length > 0 ? { urls: t.tileUrls } : { url: t?.tileUrl },
|
|
643
|
+
tileSize: t.tileSize ?? 256,
|
|
644
|
+
attributions: t.tileAttribution
|
|
645
|
+
}) : new y({ attributions: t?.tileAttribution }) })],
|
|
646
|
+
view: new f({
|
|
647
|
+
center: c(n),
|
|
648
|
+
zoom: r
|
|
649
|
+
}),
|
|
650
|
+
controls: []
|
|
651
|
+
});
|
|
652
|
+
return t?.interactive === !1 && i.getInteractions().forEach((e) => {
|
|
653
|
+
e.setActive(!1);
|
|
654
|
+
}), new R(i);
|
|
655
|
+
}
|
|
656
|
+
}, B = "warpedmap://", V = class e {
|
|
657
|
+
static {
|
|
658
|
+
this.LAYOUT_KEYS = new Set([
|
|
659
|
+
"text-size",
|
|
660
|
+
"icon-size",
|
|
661
|
+
"text-field",
|
|
662
|
+
"visibility"
|
|
663
|
+
]);
|
|
664
|
+
}
|
|
665
|
+
constructor(e, t) {
|
|
666
|
+
this.logicalToNative = /* @__PURE__ */ new Map(), this.logicalSourceToNative = /* @__PURE__ */ new Map(), this.nativeLayerToSource = /* @__PURE__ */ new Map(), this.nativeLayerInstances = /* @__PURE__ */ new Map(), this.spriteResourceCache = /* @__PURE__ */ new Map(), this.warpedMapLayers = /* @__PURE__ */ new Map(), this.compositeSubLayerCache = /* @__PURE__ */ new Map(), this.styleBackedLayerCache = /* @__PURE__ */ new Map(), this.sourceIdCounter = 0, this.map = e, this.store = t;
|
|
667
|
+
}
|
|
668
|
+
findLayerIndexByInstance(e) {
|
|
669
|
+
return this.map.getLayers().getArray().findIndex((t) => t === e);
|
|
670
|
+
}
|
|
671
|
+
resolveInsertIndexFromOptions(e) {
|
|
672
|
+
if (e?.beforeLayerId) {
|
|
673
|
+
let t = this.logicalToNative.get(e.beforeLayerId) ?? [];
|
|
674
|
+
for (let e of t) {
|
|
675
|
+
let t = this.nativeLayerInstances.get(e);
|
|
676
|
+
if (!t) continue;
|
|
677
|
+
let n = this.findLayerIndexByInstance(t);
|
|
678
|
+
if (n >= 0) return n;
|
|
679
|
+
}
|
|
680
|
+
let n = this.map.getLayers().getArray().findIndex((t) => t.__mapLayerId === e.beforeLayerId);
|
|
681
|
+
if (n >= 0) return n;
|
|
682
|
+
}
|
|
683
|
+
if (e?.afterLayerId) {
|
|
684
|
+
let t = this.logicalToNative.get(e.afterLayerId) ?? [];
|
|
685
|
+
for (let e = t.length - 1; e >= 0; --e) {
|
|
686
|
+
let n = this.nativeLayerInstances.get(t[e]);
|
|
687
|
+
if (!n) continue;
|
|
688
|
+
let r = this.findLayerIndexByInstance(n);
|
|
689
|
+
if (r >= 0) return r + 1;
|
|
690
|
+
}
|
|
691
|
+
let n = this.map.getLayers().getArray().findIndex((t) => t.__mapLayerId === e.afterLayerId);
|
|
692
|
+
if (n >= 0) return n + 1;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
resolveInsertIndex(e) {
|
|
696
|
+
let t = this.resolveInsertIndexFromOptions(e);
|
|
697
|
+
if (t !== void 0) return t;
|
|
698
|
+
let n = e?.beforeLayerId ?? e?.afterLayerId;
|
|
699
|
+
if (!n) return;
|
|
700
|
+
let r = e?.beforeLayerId !== void 0, i = 0;
|
|
701
|
+
for (let [e, t] of this.logicalToNative.entries()) {
|
|
702
|
+
if (e === n) return r ? i : i + t.length;
|
|
703
|
+
for (let e of t) this.nativeLayerInstances.has(e) && i++;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
addMapLayerAtIndex(e, t) {
|
|
707
|
+
if (typeof t != "number" || !Number.isFinite(t)) {
|
|
708
|
+
this.map.addLayer(e);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
let n = this.map.getLayers(), r = Math.max(0, Math.min(t, n.getLength()));
|
|
712
|
+
return n.insertAt(r, e), r + 1;
|
|
713
|
+
}
|
|
714
|
+
getOrCreateNativeSourceId(e) {
|
|
715
|
+
if (this.logicalSourceToNative.has(e.id)) return this.logicalSourceToNative.get(e.id);
|
|
716
|
+
let t = `src-${e.id}-${this.sourceIdCounter++}`;
|
|
717
|
+
return this.logicalSourceToNative.set(e.id, t), t;
|
|
718
|
+
}
|
|
719
|
+
isWarpedMapSource(e) {
|
|
720
|
+
return e.type === "raster" && "url" in e ? (Array.isArray(e.url) ? e.url[0] : e.url).startsWith(B) : !1;
|
|
721
|
+
}
|
|
722
|
+
parseWarpedMapUrl(e) {
|
|
723
|
+
return e.startsWith(B) ? "https://" + e.slice(12) : e;
|
|
724
|
+
}
|
|
725
|
+
async addWarpedMapLayer(e, t, n) {
|
|
726
|
+
let { WarpedMapLayer: r } = await import("./dist-BIbq3o-p.js"), i = `warpedmap-${e}`, a = new r(), o = a;
|
|
727
|
+
return typeof o.getDeclutter != "function" && (o.getDeclutter = () => !1), typeof o.renderDeferred != "function" && (o.renderDeferred = () => {}), this.addMapLayerAtIndex(a, n), await a.addGeoreferenceAnnotationByUrl(t), this.warpedMapLayers.set(e, a), this.nativeLayerInstances.set(i, a), this.logicalToNative.set(e, [i]), !0;
|
|
728
|
+
}
|
|
729
|
+
async addLayer(e, r) {
|
|
730
|
+
let i = e.id, a = this.resolveInsertIndex(r);
|
|
731
|
+
if (e.type === "allmaps") return this.addWarpedMapLayer(i, e.annotation, a);
|
|
732
|
+
if (e.type === "style") {
|
|
733
|
+
let t = n(e);
|
|
734
|
+
return t ? this.addCompositeLayer(t, r) : !1;
|
|
735
|
+
}
|
|
736
|
+
let o = e;
|
|
737
|
+
if (!o.source) return !1;
|
|
738
|
+
let s = e.sources?.[o.source], c = s ? t(o.source, s) : null;
|
|
739
|
+
if (!c) return !1;
|
|
740
|
+
if (this.isWarpedMapSource(c)) {
|
|
741
|
+
let e = Array.isArray(c.url) ? c.url[0] : c.url, t = this.parseWarpedMapUrl(e);
|
|
742
|
+
return this.addWarpedMapLayer(i, t, a);
|
|
743
|
+
}
|
|
744
|
+
let l = this.getOrCreateNativeSourceId(c), u = [], d = `${i}-${c.id}-${o.type}`;
|
|
745
|
+
if (!this.nativeLayerInstances.has(d)) {
|
|
746
|
+
let e = await this.createLayer(d, o, c);
|
|
747
|
+
e && (e.__mapLayerId = i, a = this.addMapLayerAtIndex(e, a), this.nativeLayerInstances.set(d, e));
|
|
748
|
+
}
|
|
749
|
+
return u.push(d), this.nativeLayerToSource.set(d, l), this.logicalToNative.set(i, this.mergeNativeLayerIds(i, u)), u.length > 0;
|
|
750
|
+
}
|
|
751
|
+
async addCompositeLayer(e, t) {
|
|
752
|
+
let n = e.styleId, r = this.resolveInsertIndex(t), i = e.rawConfig, o = [], s = e.sources.filter((e) => e.config.type === "vector");
|
|
753
|
+
if (s.length > 0 && typeof e.metadata?.styleUrl == "string") for (let e of s) {
|
|
754
|
+
if (!this.isStyleBackedVectorSource(i, e.config)) continue;
|
|
755
|
+
let t = this.getOrCreateNativeSourceId(e.config), a = `${n}-${e.config.id}-vector-style`;
|
|
756
|
+
if (!this.nativeLayerInstances.has(a)) {
|
|
757
|
+
let t = await this.createStyleBackedVectorTileLayer(a, i, e.config);
|
|
758
|
+
if (!t) return !1;
|
|
759
|
+
let { layer: o, mapboxLayerIds: s, spriteResources: c } = t;
|
|
760
|
+
o.__mapLayerId = n, r = this.addMapLayerAtIndex(o, r), this.nativeLayerInstances.set(a, o), this.styleBackedLayerCache.set(a, {
|
|
761
|
+
layer: o,
|
|
762
|
+
layerConfig: i,
|
|
763
|
+
sourceConfig: e.config,
|
|
764
|
+
mapboxLayerIds: s,
|
|
765
|
+
spriteResources: c
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
o.push(a), this.nativeLayerToSource.set(a, t);
|
|
769
|
+
}
|
|
770
|
+
else for (let t of e.subLayers) {
|
|
771
|
+
let i = a(e, t.source);
|
|
772
|
+
if (!i) continue;
|
|
773
|
+
let s = this.getOrCreateNativeSourceId(i.config), c = `${n}-${t.id}`;
|
|
774
|
+
if (!this.nativeLayerInstances.has(c)) {
|
|
775
|
+
let e = await this.createLayer(c, t, i.config);
|
|
776
|
+
e && (e.__mapLayerId = n, r = this.addMapLayerAtIndex(e, r), this.nativeLayerInstances.set(c, e), this.compositeSubLayerCache.set(c, {
|
|
777
|
+
spec: t,
|
|
778
|
+
sourceConfig: i.config
|
|
779
|
+
}));
|
|
780
|
+
}
|
|
781
|
+
o.push(c), this.nativeLayerToSource.set(c, s);
|
|
782
|
+
}
|
|
783
|
+
return this.logicalToNative.set(n, this.mergeNativeLayerIds(n, o)), o.length > 0;
|
|
784
|
+
}
|
|
785
|
+
updateLayerStyle(e, t, n) {
|
|
786
|
+
let r = `${e}-${t}`, i = this.compositeSubLayerCache.get(r), a = this.nativeLayerInstances.get(r);
|
|
787
|
+
if (!i || !a) return this.updateStyleBackedSubLayer(e, t, n);
|
|
788
|
+
let o = {
|
|
789
|
+
...i.spec,
|
|
790
|
+
paint: {
|
|
791
|
+
...i.spec.paint ?? {},
|
|
792
|
+
...n
|
|
793
|
+
}
|
|
794
|
+
}, s = this.findLayerIndexByInstance(a);
|
|
795
|
+
return this.createLayer(r, o, i.sourceConfig).then((e) => {
|
|
796
|
+
if (!e) return;
|
|
797
|
+
e.__mapLayerId = a.__mapLayerId;
|
|
798
|
+
let t = this.map.getLayers(), n = this.findLayerIndexByInstance(a);
|
|
799
|
+
n >= 0 ? (t.removeAt(n), t.insertAt(n, e)) : s >= 0 ? t.insertAt(Math.min(s, t.getLength()), e) : this.map.addLayer(e), this.nativeLayerInstances.set(r, e), this.compositeSubLayerCache.set(r, {
|
|
800
|
+
spec: o,
|
|
801
|
+
sourceConfig: i.sourceConfig
|
|
802
|
+
});
|
|
803
|
+
}), !0;
|
|
804
|
+
}
|
|
805
|
+
updateStyleBackedSubLayer(t, n, r) {
|
|
806
|
+
for (let [i, a] of this.styleBackedLayerCache) {
|
|
807
|
+
if (!i.startsWith(`${t}-`)) continue;
|
|
808
|
+
let o = (a.layerConfig.layers ?? []).find((e) => e.id === n);
|
|
809
|
+
if (!o) continue;
|
|
810
|
+
for (let [t, n] of Object.entries(r)) e.LAYOUT_KEYS.has(t) ? o.layout = {
|
|
811
|
+
...o.layout ?? {},
|
|
812
|
+
[t]: n
|
|
813
|
+
} : o.paint = {
|
|
814
|
+
...o.paint ?? {},
|
|
815
|
+
[t]: n
|
|
816
|
+
};
|
|
817
|
+
let s = this.buildStyleBackedGlStyle(a.layerConfig, a.sourceConfig);
|
|
818
|
+
return m(a.layer, s, a.mapboxLayerIds, void 0, a.spriteResources?.spriteData, a.spriteResources?.spriteImageUrl), a.layer.changed(), !0;
|
|
819
|
+
}
|
|
820
|
+
return !1;
|
|
821
|
+
}
|
|
822
|
+
mergeNativeLayerIds(e, t) {
|
|
823
|
+
let n = this.logicalToNative.get(e) ?? [];
|
|
824
|
+
return Array.from(new Set([...n, ...t]));
|
|
825
|
+
}
|
|
826
|
+
isStyleBackedVectorSource(e, t) {
|
|
827
|
+
let n = e?.metadata;
|
|
828
|
+
return t.type === "vector" && typeof n?.styleUrl == "string" && e.type === "style" && Array.isArray(e.layers) && e.layers.length > 0;
|
|
829
|
+
}
|
|
830
|
+
async createStyleBackedVectorTileLayer(e, t, n) {
|
|
831
|
+
let r = await this.resolveVectorTileSourceInfo(n);
|
|
832
|
+
if (!r) return null;
|
|
833
|
+
let { urlTemplate: i, minZoom: a, maxZoom: o } = r, s = new w({
|
|
834
|
+
source: new T({
|
|
835
|
+
format: new E(),
|
|
836
|
+
attributions: n.attribution,
|
|
837
|
+
...a === void 0 ? {} : { minZoom: a },
|
|
838
|
+
...o === void 0 ? {} : { maxZoom: o },
|
|
839
|
+
...o === void 0 ? { url: i } : { tileUrlFunction: this.createClampedVectorTileUrlFunction(i, o) }
|
|
840
|
+
}),
|
|
841
|
+
declutter: !0
|
|
842
|
+
}), c = this.buildStyleBackedGlStyle(t, n), l = await this.resolveStyleSpriteResources(t?.metadata ?? {}), u = (t.type === "style" ? t.layers ?? [] : []).map((e) => typeof e.id == "string" ? e.id : null).filter((e) => typeof e == "string" && e.length > 0), d = u.length > 0 ? u : n.id;
|
|
843
|
+
return m(s, c, d, void 0, l?.spriteData, l?.spriteImageUrl), s.__layerId = e, {
|
|
844
|
+
layer: s,
|
|
845
|
+
mapboxLayerIds: d,
|
|
846
|
+
spriteResources: l ?? null
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
buildStyleBackedGlStyle(e, t) {
|
|
850
|
+
let n = e?.metadata ?? {}, r = e.type === "style" ? e.layers ?? [] : [], i = { type: "vector" };
|
|
851
|
+
typeof t.url == "string" && t.url.length > 0 && (i.url = t.url);
|
|
852
|
+
let a = Array.isArray(t.tiles) ? t.tiles.filter((e) => typeof e == "string" && e.length > 0) : [];
|
|
853
|
+
return a.length > 0 && (i.tiles = a), typeof t.minzoom == "number" && (i.minzoom = t.minzoom), typeof t.attribution == "string" && (i.attribution = t.attribution), {
|
|
854
|
+
version: 8,
|
|
855
|
+
...typeof n.styleSpriteUrl == "string" ? { sprite: n.styleSpriteUrl } : {},
|
|
856
|
+
...typeof n.styleGlyphsUrl == "string" ? { glyphs: n.styleGlyphsUrl } : {},
|
|
857
|
+
sources: { [t.id]: i },
|
|
858
|
+
layers: r.map((e) => ({
|
|
859
|
+
id: e.id,
|
|
860
|
+
type: e.type,
|
|
861
|
+
source: t.id,
|
|
862
|
+
...typeof e["source-layer"] == "string" ? { "source-layer": e["source-layer"] } : {},
|
|
863
|
+
...typeof e.minzoom == "number" ? { minzoom: e.minzoom } : {},
|
|
864
|
+
...typeof e.maxzoom == "number" ? { maxzoom: e.maxzoom } : {},
|
|
865
|
+
...e.filter ? { filter: e.filter } : {},
|
|
866
|
+
...e.layout ? { layout: e.layout } : {},
|
|
867
|
+
...e.paint ? { paint: e.paint } : {}
|
|
868
|
+
}))
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
async resolveStyleSpriteResources(e) {
|
|
872
|
+
let t = typeof e.styleSpriteUrl == "string" ? e.styleSpriteUrl : null;
|
|
873
|
+
return t ? (this.spriteResourceCache.has(t) || this.spriteResourceCache.set(t, (async () => {
|
|
874
|
+
try {
|
|
875
|
+
let e = this.buildSpriteAssetUrl(t, ".json"), n = await fetch(e);
|
|
876
|
+
if (!n.ok) return null;
|
|
877
|
+
let r = await n.json();
|
|
878
|
+
return typeof r != "object" || !r || Array.isArray(r) ? null : {
|
|
879
|
+
spriteData: r,
|
|
880
|
+
spriteImageUrl: this.buildSpriteAssetUrl(t, ".png")
|
|
881
|
+
};
|
|
882
|
+
} catch {
|
|
883
|
+
return null;
|
|
884
|
+
}
|
|
885
|
+
})()), this.spriteResourceCache.get(t) ?? null) : null;
|
|
886
|
+
}
|
|
887
|
+
buildSpriteAssetUrl(e, t) {
|
|
888
|
+
try {
|
|
889
|
+
let n = new URL(e);
|
|
890
|
+
return n.pathname.endsWith(t) || (n.pathname = `${n.pathname}${t}`), n.toString();
|
|
891
|
+
} catch {
|
|
892
|
+
return e.endsWith(t) ? e : `${e}${t}`;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
async createLayer(e, t, n) {
|
|
896
|
+
if (t.type === "raster" && n.type === "raster") {
|
|
897
|
+
if (n.service === "xyz") return this.createXYZLayer(e, n, t);
|
|
898
|
+
if (n.service === "wms") return this.createWMSLayer(e, n, t);
|
|
899
|
+
} else if ([
|
|
900
|
+
"fill",
|
|
901
|
+
"line",
|
|
902
|
+
"circle"
|
|
903
|
+
].includes(t.type) && n.type === "geojson") return this.createGeoJSONLayer(e, n, t);
|
|
904
|
+
else if ([
|
|
905
|
+
"fill",
|
|
906
|
+
"line",
|
|
907
|
+
"circle",
|
|
908
|
+
"symbol"
|
|
909
|
+
].includes(t.type) && n.type === "vector") return this.createVectorTileLayer(e, n, t);
|
|
910
|
+
return null;
|
|
911
|
+
}
|
|
912
|
+
async resolveVectorTileUrl(e) {
|
|
913
|
+
return (await this.resolveVectorTileSourceInfo(e))?.urlTemplate ?? null;
|
|
914
|
+
}
|
|
915
|
+
async resolveVectorTileSourceInfo(e) {
|
|
916
|
+
let t = typeof e.minzoom == "number" ? e.minzoom : void 0, n = typeof e.maxzoom == "number" ? e.maxzoom : void 0, r = Array.isArray(e.tiles) ? e.tiles.filter((e) => typeof e == "string") : [];
|
|
917
|
+
if (r.length > 0) return {
|
|
918
|
+
urlTemplate: r[0],
|
|
919
|
+
...t === void 0 ? {} : { minZoom: t },
|
|
920
|
+
...n === void 0 ? {} : { maxZoom: n }
|
|
921
|
+
};
|
|
922
|
+
let i = e.url;
|
|
923
|
+
if (typeof i != "string" || i.length === 0) return null;
|
|
924
|
+
if (i.includes("{z}") && i.includes("{x}") && i.includes("{y}")) return {
|
|
925
|
+
urlTemplate: i,
|
|
926
|
+
...t === void 0 ? {} : { minZoom: t },
|
|
927
|
+
...n === void 0 ? {} : { maxZoom: n }
|
|
928
|
+
};
|
|
929
|
+
try {
|
|
930
|
+
let e = await fetch(i);
|
|
931
|
+
if (!e.ok) return null;
|
|
932
|
+
let r = await e.json();
|
|
933
|
+
if (Array.isArray(r?.tiles)) {
|
|
934
|
+
let e = r.tiles.find((e) => typeof e == "string");
|
|
935
|
+
if (typeof e == "string") return {
|
|
936
|
+
urlTemplate: e,
|
|
937
|
+
...t === void 0 ? typeof r?.minzoom == "number" ? { minZoom: r.minzoom } : {} : { minZoom: t },
|
|
938
|
+
...n === void 0 ? typeof r?.maxzoom == "number" ? { maxZoom: r.maxzoom } : {} : { maxZoom: n }
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
} catch {
|
|
942
|
+
return null;
|
|
943
|
+
}
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
createClampedVectorTileUrlFunction(e, t) {
|
|
947
|
+
let n = j(e, null);
|
|
948
|
+
return (e, r, i) => {
|
|
949
|
+
if (!e || e.length < 3) return;
|
|
950
|
+
let [a, o, s] = e;
|
|
951
|
+
if (!Number.isInteger(a) || !Number.isInteger(o) || !Number.isInteger(s) || a <= t) return n(e, r, i);
|
|
952
|
+
let c = 2 ** (a - t);
|
|
953
|
+
return n([
|
|
954
|
+
t,
|
|
955
|
+
Math.floor(o / c),
|
|
956
|
+
Math.floor(s / c)
|
|
957
|
+
], r, i);
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
createBboxTileUrlFunction(e) {
|
|
961
|
+
let t = A();
|
|
962
|
+
return (n) => {
|
|
963
|
+
if (!n || n.length < 3) return;
|
|
964
|
+
let [, r, i] = n, a = t.getTileCoordExtent(n).join(",");
|
|
965
|
+
return e[Math.abs(r + i) % e.length].replace("{bbox-epsg-3857}", a);
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
getLiteralNumberValue(e, t) {
|
|
969
|
+
return typeof e == "number" && Number.isFinite(e) ? e : t;
|
|
970
|
+
}
|
|
971
|
+
createVectorTileLayer(e, t, n) {
|
|
972
|
+
return this.resolveVectorTileSourceInfo(t).then((r) => {
|
|
973
|
+
if (!r) return null;
|
|
974
|
+
let { urlTemplate: i, minZoom: a, maxZoom: o } = r, s = new w({
|
|
975
|
+
source: new T({
|
|
976
|
+
format: new E(),
|
|
977
|
+
attributions: t.attribution,
|
|
978
|
+
...a === void 0 ? {} : { minZoom: a },
|
|
979
|
+
...o === void 0 ? {} : { maxZoom: o },
|
|
980
|
+
...o === void 0 ? { url: i } : { tileUrlFunction: this.createClampedVectorTileUrlFunction(i, o) }
|
|
981
|
+
}),
|
|
982
|
+
minZoom: n.minzoom,
|
|
983
|
+
maxZoom: n.maxzoom
|
|
984
|
+
}), c = e, l = n.id ?? e;
|
|
985
|
+
return m(s, {
|
|
986
|
+
version: 8,
|
|
987
|
+
sources: { [c]: {
|
|
988
|
+
type: "vector",
|
|
989
|
+
tiles: [i]
|
|
990
|
+
} },
|
|
991
|
+
layers: [{
|
|
992
|
+
...n,
|
|
993
|
+
id: l,
|
|
994
|
+
source: c
|
|
995
|
+
}]
|
|
996
|
+
}, [l]), s.__layerId = e, s;
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
createXYZLayer(e, t, n) {
|
|
1000
|
+
let r = Array.isArray(t.url) ? t.url : [t.url], i = new v({
|
|
1001
|
+
source: r.some((e) => e.includes("{bbox-epsg-3857}")) ? new b({
|
|
1002
|
+
tileUrlFunction: this.createBboxTileUrlFunction(r),
|
|
1003
|
+
tileSize: t.tileSize,
|
|
1004
|
+
attributions: t.attribution,
|
|
1005
|
+
minZoom: t.minzoom,
|
|
1006
|
+
maxZoom: t.maxzoom
|
|
1007
|
+
}) : new b({
|
|
1008
|
+
urls: r,
|
|
1009
|
+
tileSize: t.tileSize,
|
|
1010
|
+
attributions: t.attribution,
|
|
1011
|
+
minZoom: t.minzoom,
|
|
1012
|
+
maxZoom: t.maxzoom
|
|
1013
|
+
}),
|
|
1014
|
+
minZoom: n.minzoom,
|
|
1015
|
+
maxZoom: n.maxzoom,
|
|
1016
|
+
opacity: this.getLiteralNumberValue(n.paint?.["raster-opacity"], 1)
|
|
1017
|
+
});
|
|
1018
|
+
return i.__layerId = e, i;
|
|
1019
|
+
}
|
|
1020
|
+
createWMSLayer(e, t, n) {
|
|
1021
|
+
let r = Array.isArray(t.url) ? t.url[0] : t.url, { baseUrl: i, params: a } = this.parseUrlParams(r), o = new Set(Object.keys(a).map((e) => e.toLowerCase()));
|
|
1022
|
+
o.has("format") || (a.FORMAT = t.format || "image/png"), o.has("transparent") || (a.TRANSPARENT = t.transparent === !1 ? "false" : "true"), t.layers && !o.has("layers") && (a.LAYERS = t.layers), t.styles && !o.has("styles") && (a.STYLES = t.styles), t.version && !o.has("version") && (a.VERSION = t.version);
|
|
1023
|
+
let s;
|
|
1024
|
+
if (t.tileSize) {
|
|
1025
|
+
let e = A({
|
|
1026
|
+
tileSize: t.tileSize,
|
|
1027
|
+
minZoom: t.minzoom,
|
|
1028
|
+
maxZoom: t.maxzoom
|
|
1029
|
+
});
|
|
1030
|
+
s = new v({
|
|
1031
|
+
source: new k({
|
|
1032
|
+
url: i,
|
|
1033
|
+
params: a,
|
|
1034
|
+
attributions: t.attribution,
|
|
1035
|
+
tileGrid: e
|
|
1036
|
+
}),
|
|
1037
|
+
minZoom: n.minzoom,
|
|
1038
|
+
maxZoom: n.maxzoom,
|
|
1039
|
+
opacity: this.getLiteralNumberValue(n.paint?.["raster-opacity"], 1)
|
|
1040
|
+
});
|
|
1041
|
+
} else s = new O({
|
|
1042
|
+
source: new D({
|
|
1043
|
+
url: i,
|
|
1044
|
+
params: a,
|
|
1045
|
+
attributions: t.attribution,
|
|
1046
|
+
ratio: 1
|
|
1047
|
+
}),
|
|
1048
|
+
minZoom: n.minzoom,
|
|
1049
|
+
maxZoom: n.maxzoom,
|
|
1050
|
+
opacity: this.getLiteralNumberValue(n.paint?.["raster-opacity"], 1)
|
|
1051
|
+
});
|
|
1052
|
+
return s.__layerId = e, s;
|
|
1053
|
+
}
|
|
1054
|
+
parseUrlParams(e) {
|
|
1055
|
+
let t = e.indexOf("?");
|
|
1056
|
+
if (t === -1) return {
|
|
1057
|
+
baseUrl: e,
|
|
1058
|
+
params: {}
|
|
1059
|
+
};
|
|
1060
|
+
let n = e.substring(0, t), r = e.substring(t + 1), i = {};
|
|
1061
|
+
for (let e of r.split("&")) {
|
|
1062
|
+
let t = e.indexOf("=");
|
|
1063
|
+
if (t !== -1) {
|
|
1064
|
+
let n = e.substring(0, t);
|
|
1065
|
+
i[n] = decodeURIComponent(e.substring(t + 1));
|
|
1066
|
+
} else e && (i[e] = "");
|
|
1067
|
+
}
|
|
1068
|
+
return {
|
|
1069
|
+
baseUrl: n,
|
|
1070
|
+
params: i
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
createGeoJSONLayer(e, t, n) {
|
|
1074
|
+
let r = new h({
|
|
1075
|
+
source: new g({
|
|
1076
|
+
features: typeof t.data == "string" ? void 0 : new _().readFeatures(t.data, { featureProjection: "EPSG:3857" }),
|
|
1077
|
+
url: typeof t.data == "string" ? t.data : void 0,
|
|
1078
|
+
format: typeof t.data == "string" ? new _() : void 0,
|
|
1079
|
+
attributions: t.attribution
|
|
1080
|
+
}),
|
|
1081
|
+
minZoom: n.minzoom,
|
|
1082
|
+
maxZoom: n.maxzoom
|
|
1083
|
+
}), i = e, a = n.id ?? e;
|
|
1084
|
+
return m(r, {
|
|
1085
|
+
version: 8,
|
|
1086
|
+
sources: { [i]: {
|
|
1087
|
+
type: "geojson",
|
|
1088
|
+
data: t.data ?? {
|
|
1089
|
+
type: "FeatureCollection",
|
|
1090
|
+
features: []
|
|
1091
|
+
}
|
|
1092
|
+
} },
|
|
1093
|
+
layers: [{
|
|
1094
|
+
...n,
|
|
1095
|
+
id: a,
|
|
1096
|
+
source: i
|
|
1097
|
+
}]
|
|
1098
|
+
}, [a]), r.__layerId = e, r;
|
|
1099
|
+
}
|
|
1100
|
+
moveLayer(e, t) {
|
|
1101
|
+
let n = (this.logicalToNative.get(e) ?? []).map((e) => this.nativeLayerInstances.get(e)).filter((e) => !!e);
|
|
1102
|
+
if (n.length === 0) return;
|
|
1103
|
+
let r = this.map.getLayers(), i = t ? this.resolveInsertIndex({ beforeLayerId: t }) : void 0;
|
|
1104
|
+
i === void 0 && (i = r.getLength());
|
|
1105
|
+
for (let e of n) {
|
|
1106
|
+
let t = this.findLayerIndexByInstance(e);
|
|
1107
|
+
t !== -1 && (r.removeAt(t), t < i && i--);
|
|
1108
|
+
}
|
|
1109
|
+
i = Math.max(0, Math.min(i, r.getLength())), n.forEach((e, t) => r.insertAt(i + t, e));
|
|
1110
|
+
}
|
|
1111
|
+
removeLayer(e) {
|
|
1112
|
+
if (this.warpedMapLayers.has(e)) {
|
|
1113
|
+
let t = this.warpedMapLayers.get(e);
|
|
1114
|
+
this.map.removeLayer(t);
|
|
1115
|
+
let n = this.logicalToNative.get(e) || [];
|
|
1116
|
+
for (let e of n) this.nativeLayerInstances.delete(e);
|
|
1117
|
+
this.warpedMapLayers.delete(e), this.logicalToNative.delete(e);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
let t = this.logicalToNative.get(e) || [], n = /* @__PURE__ */ new Set();
|
|
1121
|
+
for (let e of t) {
|
|
1122
|
+
let t = this.nativeLayerToSource.get(e);
|
|
1123
|
+
t && n.add(t);
|
|
1124
|
+
let r = this.nativeLayerInstances.get(e);
|
|
1125
|
+
r && (this.map.removeLayer(r), this.nativeLayerInstances.delete(e)), this.nativeLayerToSource.delete(e), this.compositeSubLayerCache.delete(e);
|
|
1126
|
+
}
|
|
1127
|
+
this.logicalToNative.delete(e);
|
|
1128
|
+
for (let e of n) {
|
|
1129
|
+
let t = !1;
|
|
1130
|
+
for (let n of this.nativeLayerToSource.values()) if (n === e) {
|
|
1131
|
+
t = !0;
|
|
1132
|
+
break;
|
|
1133
|
+
}
|
|
1134
|
+
if (!t) {
|
|
1135
|
+
for (let [t, n] of this.logicalSourceToNative.entries()) if (n === e) {
|
|
1136
|
+
this.logicalSourceToNative.delete(t);
|
|
1137
|
+
break;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
getVisibleLayers() {
|
|
1143
|
+
return Array.from(this.logicalToNative.keys());
|
|
1144
|
+
}
|
|
1145
|
+
isLayerVisible(e) {
|
|
1146
|
+
return this.logicalToNative.has(e);
|
|
1147
|
+
}
|
|
1148
|
+
setLayerVisibility(e, t) {
|
|
1149
|
+
let n = this.logicalToNative.get(e) ?? [];
|
|
1150
|
+
for (let e of n) this.nativeLayerInstances.get(e)?.setVisible(t);
|
|
1151
|
+
}
|
|
1152
|
+
setLayerOpacity(e, t) {
|
|
1153
|
+
let n = this.logicalToNative.get(e) ?? [];
|
|
1154
|
+
for (let e of n) this.nativeLayerInstances.get(e)?.setOpacity(t);
|
|
1155
|
+
}
|
|
1156
|
+
getSourceData(e) {
|
|
1157
|
+
let t = this.logicalSourceToNative.get(e);
|
|
1158
|
+
if (!t) return null;
|
|
1159
|
+
let n = new _();
|
|
1160
|
+
for (let [e, r] of this.nativeLayerToSource.entries()) {
|
|
1161
|
+
if (r !== t) continue;
|
|
1162
|
+
let i = this.nativeLayerInstances.get(e)?.getSource?.();
|
|
1163
|
+
if (!i || typeof i.getFeatures != "function") continue;
|
|
1164
|
+
let a = i.getFeatures().map((e) => JSON.parse(n.writeFeature(e, {
|
|
1165
|
+
dataProjection: "EPSG:4326",
|
|
1166
|
+
featureProjection: "EPSG:3857"
|
|
1167
|
+
})));
|
|
1168
|
+
if (a.length === 0 && typeof i.getUrl == "function") {
|
|
1169
|
+
let e = i.getUrl();
|
|
1170
|
+
if (typeof e == "string") return e;
|
|
1171
|
+
}
|
|
1172
|
+
return {
|
|
1173
|
+
type: "FeatureCollection",
|
|
1174
|
+
features: a
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
return null;
|
|
1178
|
+
}
|
|
1179
|
+
setSourceData(e, t) {
|
|
1180
|
+
let n = this.logicalSourceToNative.get(e);
|
|
1181
|
+
if (!n) return !1;
|
|
1182
|
+
let r = !1;
|
|
1183
|
+
for (let [e, i] of this.nativeLayerToSource.entries()) {
|
|
1184
|
+
if (i !== n) continue;
|
|
1185
|
+
let a = this.nativeLayerInstances.get(e)?.getSource?.();
|
|
1186
|
+
!a || typeof a.clear != "function" || (a.clear(), a.addFeatures(new _().readFeatures(t, {
|
|
1187
|
+
dataProjection: "EPSG:4326",
|
|
1188
|
+
featureProjection: "EPSG:3857"
|
|
1189
|
+
})), r = !0);
|
|
1190
|
+
}
|
|
1191
|
+
return r;
|
|
1192
|
+
}
|
|
1193
|
+
registerInlineLayer(e, t, n) {
|
|
1194
|
+
let r = `${e}-inline`;
|
|
1195
|
+
this.nativeLayerInstances.set(r, t), this.logicalToNative.set(e, [r]);
|
|
1196
|
+
}
|
|
1197
|
+
unregisterInlineLayer(e) {
|
|
1198
|
+
let t = this.logicalToNative.get(e) ?? [];
|
|
1199
|
+
for (let e of t) this.nativeLayerInstances.delete(e);
|
|
1200
|
+
this.logicalToNative.delete(e);
|
|
1201
|
+
}
|
|
1202
|
+
getVisibleWMSLayers() {
|
|
1203
|
+
return [];
|
|
1204
|
+
}
|
|
1205
|
+
}, H = class {
|
|
1206
|
+
constructor(e, t, n) {
|
|
1207
|
+
this.map = e, this.layerService = t, this.store = n;
|
|
1208
|
+
}
|
|
1209
|
+
async queryFeatures(t, n = {}) {
|
|
1210
|
+
let { pixel: r } = t, i = n.tolerancePx ?? 5, a = [], o = n.layerIds?.length ? new Set(n.layerIds) : null, s = this.store.getState().mapLayers ?? {};
|
|
1211
|
+
this.map.forEachFeatureAtPixel(r, (e, t) => {
|
|
1212
|
+
let n = t?.__layerId, r = this.resolveRegisteredLayerId(t, n, s);
|
|
1213
|
+
if (!r || o && !o.has(r)) return;
|
|
1214
|
+
let i = this.resolveLayerTitle(r, s), c = e.getProperties();
|
|
1215
|
+
delete c.geometry;
|
|
1216
|
+
let l, u, d = -1, f = e.get?.("layer");
|
|
1217
|
+
if (f) {
|
|
1218
|
+
let t = s[r], n = Array.isArray(t?.sublayers) ? t.sublayers : [], i = this.store.getState().zoomLevel ?? 0, a = e.getGeometry?.()?.getType?.(), o = a?.includes("Polygon") ? new Set(["fill", "fill-extrusion"]) : a?.includes("LineString") ? new Set(["line"]) : a?.includes("Point") ? new Set(["circle", "symbol"]) : null, p = o ? [!0, !1] : [!1];
|
|
1219
|
+
outer: for (let e of p) for (let t = n.length - 1; t >= 0; t--) {
|
|
1220
|
+
let r = n[t];
|
|
1221
|
+
if (r?.["source-layer"] !== f && r?.sourceLayer !== f || e && o && !o.has(r?.type) || r?.layout?.visibility === "none") continue;
|
|
1222
|
+
let a = typeof r?.minzoom == "number" ? r.minzoom : 0, s = typeof r?.maxzoom == "number" ? r.maxzoom + 1 : 24;
|
|
1223
|
+
if (!(i < a || i >= s) && !(r?.filter && !this.matchesFilter(r.filter, c))) {
|
|
1224
|
+
l = String(r.id ?? "").replace(/^style:/, ""), u = r.type, d = t;
|
|
1225
|
+
break outer;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
a.push({
|
|
1230
|
+
layerId: r,
|
|
1231
|
+
...i ? { layerTitle: i } : {},
|
|
1232
|
+
properties: c,
|
|
1233
|
+
source: "vector",
|
|
1234
|
+
...l ? {
|
|
1235
|
+
subLayerId: l,
|
|
1236
|
+
subLayerType: u
|
|
1237
|
+
} : {},
|
|
1238
|
+
_subLayerIndex: d
|
|
1239
|
+
});
|
|
1240
|
+
}, { hitTolerance: i }), a.sort((e, t) => (t._subLayerIndex ?? -1) - (e._subLayerIndex ?? -1));
|
|
1241
|
+
let c = /* @__PURE__ */ new Set(), u = [];
|
|
1242
|
+
for (let e of a) {
|
|
1243
|
+
let t = `${e.layerId}|${e.subLayerId ?? ""}`;
|
|
1244
|
+
c.has(t) || (c.add(t), u.push(e));
|
|
1245
|
+
}
|
|
1246
|
+
if (a.length = 0, a.push(...u.map((e) => {
|
|
1247
|
+
let t = { ...e };
|
|
1248
|
+
return delete t._subLayerIndex, t;
|
|
1249
|
+
})), n.includeWMS) {
|
|
1250
|
+
let t = this.map.getView(), n = this.map.getSize() ?? [0, 0], i = t.calculateExtent(n), s = l([i[0], i[1]]), c = l([i[2], i[3]]), u = {
|
|
1251
|
+
west: s[0],
|
|
1252
|
+
south: s[1],
|
|
1253
|
+
east: c[0],
|
|
1254
|
+
north: c[1]
|
|
1255
|
+
}, d = this.layerService.getVisibleWMSLayers(), f = await Promise.all(d.filter((e) => !o || o.has(e.layerId)).map((t) => e({
|
|
1256
|
+
sourceConfig: t.sourceConfig,
|
|
1257
|
+
layerId: t.layerId,
|
|
1258
|
+
layerTitle: t.layerTitle,
|
|
1259
|
+
bounds: u,
|
|
1260
|
+
containerWidth: n[0],
|
|
1261
|
+
containerHeight: n[1],
|
|
1262
|
+
pixelX: r[0],
|
|
1263
|
+
pixelY: r[1]
|
|
1264
|
+
})));
|
|
1265
|
+
for (let e of f) a.push(...e);
|
|
1266
|
+
}
|
|
1267
|
+
return a;
|
|
1268
|
+
}
|
|
1269
|
+
matchesFilter(e, t) {
|
|
1270
|
+
if (!Array.isArray(e) || e.length === 0) return !0;
|
|
1271
|
+
let n = e[0];
|
|
1272
|
+
if (n === "all") return e.slice(1).every((e) => this.matchesFilter(e, t));
|
|
1273
|
+
if (n === "any") return e.slice(1).some((e) => this.matchesFilter(e, t));
|
|
1274
|
+
if (n === "none") return !e.slice(1).some((e) => this.matchesFilter(e, t));
|
|
1275
|
+
let r = (e) => {
|
|
1276
|
+
if (Array.isArray(e) && e[0] === "get") return t[e[1]];
|
|
1277
|
+
if (!(Array.isArray(e) && e[0] === "geometry-type") && !(Array.isArray(e) && e[0] === "zoom")) return e;
|
|
1278
|
+
}, i = r(e[1]), a = r(e[2]);
|
|
1279
|
+
if (n === "==" || n === "===") return i === a;
|
|
1280
|
+
if (n === "!=" || n === "!==") return i !== a;
|
|
1281
|
+
if (n === "<") return Number(i) < Number(a);
|
|
1282
|
+
if (n === "<=") return Number(i) <= Number(a);
|
|
1283
|
+
if (n === ">") return Number(i) > Number(a);
|
|
1284
|
+
if (n === ">=") return Number(i) >= Number(a);
|
|
1285
|
+
if (n === "match") {
|
|
1286
|
+
let t = r(e[1]);
|
|
1287
|
+
for (let n = 2; n + 1 < e.length; n += 2) {
|
|
1288
|
+
let r = e[n];
|
|
1289
|
+
if (Array.isArray(r) ? r.includes(t) : r === t) return !!e[n + 1];
|
|
1290
|
+
}
|
|
1291
|
+
return !!e[e.length - 1];
|
|
1292
|
+
}
|
|
1293
|
+
if (n === "in") {
|
|
1294
|
+
let t = r(e[1]);
|
|
1295
|
+
return e.slice(2).includes(t);
|
|
1296
|
+
}
|
|
1297
|
+
return n === "has" ? t[e[1]] !== void 0 : n === "!has" ? t[e[1]] === void 0 : !0;
|
|
1298
|
+
}
|
|
1299
|
+
resolveRegisteredLayerId(e, t, n) {
|
|
1300
|
+
let r = typeof e.__mapLayerId == "string" ? e.__mapLayerId : t ?? null;
|
|
1301
|
+
return r && n[r] ? r : null;
|
|
1302
|
+
}
|
|
1303
|
+
resolveLayerTitle(e, t) {
|
|
1304
|
+
let n = t[e];
|
|
1305
|
+
return typeof n?.label == "string" && n.label.length > 0 ? n.label : null;
|
|
1306
|
+
}
|
|
1307
|
+
}, U = class {
|
|
1308
|
+
constructor(e) {
|
|
1309
|
+
this.map = e, this.markers = /* @__PURE__ */ new Map();
|
|
1310
|
+
}
|
|
1311
|
+
add(e, t, n = {}) {
|
|
1312
|
+
this.remove(e);
|
|
1313
|
+
let r = n.color ?? "#e63946", i = n.draggable ?? !1, a = document.createElement("div");
|
|
1314
|
+
a.style.cssText = "cursor:pointer;user-select:none;", a.innerHTML = s(r);
|
|
1315
|
+
let o = new M({
|
|
1316
|
+
element: a,
|
|
1317
|
+
positioning: "bottom-center",
|
|
1318
|
+
stopEvent: !1,
|
|
1319
|
+
position: c([t[0], t[1]])
|
|
1320
|
+
});
|
|
1321
|
+
this.map.addOverlay(o);
|
|
1322
|
+
let l = {
|
|
1323
|
+
overlay: o,
|
|
1324
|
+
element: a,
|
|
1325
|
+
draggable: i
|
|
1326
|
+
};
|
|
1327
|
+
i && (l.dragCleanup = this.attachDrag(e, a, o)), this.markers.set(e, l);
|
|
1328
|
+
}
|
|
1329
|
+
move(e, t) {
|
|
1330
|
+
let n = this.markers.get(e);
|
|
1331
|
+
n && n.overlay.setPosition(c([t[0], t[1]]));
|
|
1332
|
+
}
|
|
1333
|
+
remove(e) {
|
|
1334
|
+
let t = this.markers.get(e);
|
|
1335
|
+
t && (t.dragCleanup?.(), this.map.removeOverlay(t.overlay), this.markers.delete(e));
|
|
1336
|
+
}
|
|
1337
|
+
attachDrag(e, t, n) {
|
|
1338
|
+
let r = !1, i = (e) => {
|
|
1339
|
+
e.preventDefault(), r = !0, t.setPointerCapture(e.pointerId);
|
|
1340
|
+
}, a = (e) => {
|
|
1341
|
+
if (!r) return;
|
|
1342
|
+
let t = this.map.getTargetElement().getBoundingClientRect(), i = [e.clientX - t.left, e.clientY - t.top], a = this.map.getCoordinateFromPixel(i);
|
|
1343
|
+
a && n.setPosition(a);
|
|
1344
|
+
}, o = () => {
|
|
1345
|
+
r = !1;
|
|
1346
|
+
};
|
|
1347
|
+
return t.addEventListener("pointerdown", i), t.addEventListener("pointermove", a), t.addEventListener("pointerup", o), () => {
|
|
1348
|
+
t.removeEventListener("pointerdown", i), t.removeEventListener("pointermove", a), t.removeEventListener("pointerup", o);
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
}, W = class extends i {
|
|
1352
|
+
constructor() {
|
|
1353
|
+
super(), this.engineId = "openlayers", this.engineVersion = u, this.markerService = null, this.core = new N(this.store, this.events), this.toolService = new P(), this.logicalLayerExecutor = new r(), this.queryExecutor = new o(), this.queryService = this.queryExecutor, this.mapFactory = new z(), this.core.onMapReady?.((e) => {
|
|
1354
|
+
let t = new V(e, this.store);
|
|
1355
|
+
this.core.setLayerOrderRegistry(t), this.logicalLayerExecutor.bind(t), this.queryExecutor.bind(new H(e, t, this.store)), this.markerService = new U(e);
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
initialize(e, t) {
|
|
1359
|
+
this.core.initialize(e, t);
|
|
1360
|
+
}
|
|
1361
|
+
getViewportState() {
|
|
1362
|
+
return this.core.getViewportState();
|
|
1363
|
+
}
|
|
1364
|
+
setViewport(e, t) {
|
|
1365
|
+
this.core.setViewport(e, t);
|
|
1366
|
+
}
|
|
1367
|
+
getZoom() {
|
|
1368
|
+
return this.core.getZoom();
|
|
1369
|
+
}
|
|
1370
|
+
setZoom(e) {
|
|
1371
|
+
this.core.setZoom(e);
|
|
1372
|
+
}
|
|
1373
|
+
getBearing() {
|
|
1374
|
+
return this.core.getBearing();
|
|
1375
|
+
}
|
|
1376
|
+
setBearing(e) {
|
|
1377
|
+
this.core.setBearing(e);
|
|
1378
|
+
}
|
|
1379
|
+
getPitch() {
|
|
1380
|
+
return this.core.getPitch();
|
|
1381
|
+
}
|
|
1382
|
+
setPitch(e) {
|
|
1383
|
+
this.core.setPitch(e);
|
|
1384
|
+
}
|
|
1385
|
+
setTerrainEnabled(e) {
|
|
1386
|
+
return !1;
|
|
1387
|
+
}
|
|
1388
|
+
isTerrainEnabled() {
|
|
1389
|
+
return null;
|
|
1390
|
+
}
|
|
1391
|
+
resetNorth() {
|
|
1392
|
+
this.core.resetNorth();
|
|
1393
|
+
}
|
|
1394
|
+
resetNorthPitch() {
|
|
1395
|
+
this.core.resetNorthPitch();
|
|
1396
|
+
}
|
|
1397
|
+
fitBounds(e) {
|
|
1398
|
+
this.core.fitBounds(e);
|
|
1399
|
+
}
|
|
1400
|
+
setProjection(e) {
|
|
1401
|
+
return !1;
|
|
1402
|
+
}
|
|
1403
|
+
getProjection() {
|
|
1404
|
+
return null;
|
|
1405
|
+
}
|
|
1406
|
+
setCursor(e) {
|
|
1407
|
+
this.core.setCursor(e);
|
|
1408
|
+
}
|
|
1409
|
+
setPanEnabled(e) {
|
|
1410
|
+
this.core.setPanEnabled(e);
|
|
1411
|
+
}
|
|
1412
|
+
setTouchCaptureEnabled(e) {
|
|
1413
|
+
this.core.setTouchCaptureEnabled(e);
|
|
1414
|
+
}
|
|
1415
|
+
setDoubleClickZoomEnabled(e) {
|
|
1416
|
+
this.core.setDoubleClickZoomEnabled(e);
|
|
1417
|
+
}
|
|
1418
|
+
setLayerVisibility(e, t) {
|
|
1419
|
+
this.logicalLayerExecutor.setLayerVisibility(e, t);
|
|
1420
|
+
}
|
|
1421
|
+
setLayerOpacity(e, t) {
|
|
1422
|
+
this.logicalLayerExecutor.setLayerOpacity(e, t);
|
|
1423
|
+
}
|
|
1424
|
+
getSourceData(e) {
|
|
1425
|
+
return this.core.getSourceData(e) ?? this.logicalLayerExecutor.getSourceData(e);
|
|
1426
|
+
}
|
|
1427
|
+
project(e) {
|
|
1428
|
+
return this.core.project(e);
|
|
1429
|
+
}
|
|
1430
|
+
unproject(e) {
|
|
1431
|
+
return this.core.unproject(e);
|
|
1432
|
+
}
|
|
1433
|
+
getNavigationCapabilities() {
|
|
1434
|
+
return this.core.getNavigationCapabilities();
|
|
1435
|
+
}
|
|
1436
|
+
async engineAddLayer(e, t) {
|
|
1437
|
+
return await this.logicalLayerExecutor.addLayer(e, t) ? !0 : this.core.addLayer(e, t);
|
|
1438
|
+
}
|
|
1439
|
+
removeLogicalLayer(e) {
|
|
1440
|
+
this.removeLayer(e);
|
|
1441
|
+
}
|
|
1442
|
+
engineAddSource(e, t) {
|
|
1443
|
+
this.core.addSource(e, t);
|
|
1444
|
+
}
|
|
1445
|
+
engineRemoveLayer(e) {
|
|
1446
|
+
this.logicalLayerExecutor.removeLayer(e), this.core.removeLayer(e);
|
|
1447
|
+
}
|
|
1448
|
+
engineRemoveSource(e) {
|
|
1449
|
+
this.core.removeSource(e);
|
|
1450
|
+
}
|
|
1451
|
+
getCore() {
|
|
1452
|
+
return this.core;
|
|
1453
|
+
}
|
|
1454
|
+
getLogicalLayerExecutor() {
|
|
1455
|
+
return this.logicalLayerExecutor;
|
|
1456
|
+
}
|
|
1457
|
+
getMarkerService() {
|
|
1458
|
+
return this.markerService;
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
//#endregion
|
|
1462
|
+
export { W as OpenLayersAdapter };
|