@edugis-org/webmapx 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +149 -0
  2. package/dist-lib/WMTS-DCN4zX0-.js +1169 -0
  3. package/dist-lib/alert-GeHlqlN8.js +310 -0
  4. package/dist-lib/assets/epsg-lookup.worker-J7TVnHDq.js +1 -0
  5. package/dist-lib/assets/shapefile.worker-kQfZj6G2.js +4 -0
  6. package/dist-lib/attribution-format-B4f05_u0.js +62 -0
  7. package/dist-lib/button-DFdGkRPQ.js +741 -0
  8. package/dist-lib/cesium-adapter-BHXNytkU.js +1488 -0
  9. package/dist-lib/checkbox-QoR4S8tV.js +284 -0
  10. package/dist-lib/chunk-HEgqtunE.js +20 -0
  11. package/dist-lib/chunk.36O46B5H-B6ZL7Sm1.js +77 -0
  12. package/dist-lib/chunk.3RPBFEDE-BFO1fHVm.js +138 -0
  13. package/dist-lib/chunk.5JY5FUCG-DTXsslmx.js +1090 -0
  14. package/dist-lib/chunk.6CTB5ZDJ-DjZrBd6Y.js +99 -0
  15. package/dist-lib/chunk.AJ3ENQ5C-Ci7Gm2b6.js +175 -0
  16. package/dist-lib/chunk.LD4M4QGE-CiCfhE8r.js +8 -0
  17. package/dist-lib/chunk.NYIIDP5N-BikXIStD.js +99 -0
  18. package/dist-lib/chunk.RWUUFNUL-DFztA4uV.js +43 -0
  19. package/dist-lib/chunk.SI4ACBFK-CLb9VfMG.js +61 -0
  20. package/dist-lib/chunk.YHLNUJ7P-D-kanrCf.js +503 -0
  21. package/dist-lib/core-CMAlSR68.js +22 -0
  22. package/dist-lib/decorate-CWgUV1hU.js +1139 -0
  23. package/dist-lib/decorators-B35AgiCU.js +351 -0
  24. package/dist-lib/deferred-query-service-BJDcngw6.js +386 -0
  25. package/dist-lib/dist-Dm6b7XCs.js +12318 -0
  26. package/dist-lib/dist-Ha9LQCut.js +244 -0
  27. package/dist-lib/dist-c1PlDAd1.js +2359 -0
  28. package/dist-lib/dist-kKlmcBXq.js +50 -0
  29. package/dist-lib/divider-CPm675yY.js +41 -0
  30. package/dist-lib/dropped-config-C_GyVa8o.js +17 -0
  31. package/dist-lib/dropped-layer-builder-DAaYgUPk.js +396 -0
  32. package/dist-lib/epsg-definitions-BZLZWa8Q.js +668 -0
  33. package/dist-lib/esm-CTuscnN5.js +46 -0
  34. package/dist-lib/file-sniff-Dhxj3KTF.js +251 -0
  35. package/dist-lib/geo-calculations-DbFJAUoI.js +30 -0
  36. package/dist-lib/icon-CEOgWlro.js +9 -0
  37. package/dist-lib/icon-button-Da_nBTy3.js +408 -0
  38. package/dist-lib/input-CeGntPlT.js +590 -0
  39. package/dist-lib/layer-discovery-afWzu5hY.js +2825 -0
  40. package/dist-lib/leaflet-adapter-D9djjrKv.js +1227 -0
  41. package/dist-lib/lib-CdHVicAE.js +4074 -0
  42. package/dist-lib/map-layer-registry-2cmkiRDK.js +62 -0
  43. package/dist-lib/maplibre-adapter-TFc3e0G9.js +1190 -0
  44. package/dist-lib/maplibre-expression-evaluator-DCWUcpwf.js +7233 -0
  45. package/dist-lib/marker-utils-DztWXeop.js +12 -0
  46. package/dist-lib/ol-tilegrid-9VtyxaLG.js +64 -0
  47. package/dist-lib/openlayers-adapter-DVW1KCRv.js +13307 -0
  48. package/dist-lib/option-CBxl1mZP.js +1106 -0
  49. package/dist-lib/papaparse.min-B7v3c0D7.js +501 -0
  50. package/dist-lib/rbush-C8k41T4z.js +254 -0
  51. package/dist-lib/shapefile-SawVY6xg.js +207 -0
  52. package/dist-lib/spinner-DysxdNG9.js +6 -0
  53. package/dist-lib/src-CL94RDe3.js +111 -0
  54. package/dist-lib/throttle-BeneRNYK.js +16 -0
  55. package/dist-lib/toast-Cm28o9U6.js +15 -0
  56. package/dist-lib/togeojson.es-DAgiTBvg.js +579 -0
  57. package/dist-lib/tooltip-Cucn1SiD.js +197 -0
  58. package/dist-lib/webmapx-3d-tool-D4CTD2gB.js +176 -0
  59. package/dist-lib/webmapx-base-tool-Dm9NAWLD.js +75 -0
  60. package/dist-lib/webmapx-config-edit-tool-DCTyxqTk.js +389 -0
  61. package/dist-lib/webmapx-coordinates-tool-jeWohup9.js +648 -0
  62. package/dist-lib/webmapx-core-bundle-BDImi1RE.js +8203 -0
  63. package/dist-lib/webmapx-draw-tool-DooAV8cF.js +4336 -0
  64. package/dist-lib/webmapx-geolocation-tool-Rw3-Iad1.js +788 -0
  65. package/dist-lib/webmapx-import-layer-tool-DRYviHd5.js +250 -0
  66. package/dist-lib/webmapx-info-tool-BJA157cy.js +412 -0
  67. package/dist-lib/webmapx-language-osmvector-M5y_lwOg.js +489 -0
  68. package/dist-lib/webmapx-measure-tool-BXhMJFC6.js +590 -0
  69. package/dist-lib/webmapx-modal-tool-eF6Naluv.js +84 -0
  70. package/dist-lib/webmapx-plugin-tool-D2Hghf9n.js +45 -0
  71. package/dist-lib/webmapx-print-tool-ob1bOsR5.js +348 -0
  72. package/dist-lib/webmapx-search-tool-Cv8BrYvY.js +437 -0
  73. package/dist-lib/webmapx-settings-DDEJ8aoV.js +479 -0
  74. package/dist-lib/webmapx-truearea-tool-CMB4Orm-.js +615 -0
  75. package/dist-lib/webmapx-view-mode-tool-CUpLNjOj.js +106 -0
  76. package/dist-lib/webmapx.css +2 -0
  77. package/dist-lib/webmapx.js +1321 -0
  78. package/dist-lib/wms-feature-info-C0RVMEQC.js +145 -0
  79. package/dist-lib/wms-url-builder-DIJLQ1v2.js +54 -0
  80. package/dist-lib/zip.js-DVhmtjxZ.js +3615 -0
  81. package/package.json +107 -0
  82. package/public/data/country-epsg-codes.json +297 -0
  83. package/public/data/world-countries-simplified.topojson +1 -0
  84. package/src/locales/en/core.json +20 -0
@@ -0,0 +1,1139 @@
1
+ import { n as e } from "./src-CL94RDe3.js";
2
+ import { t } from "./toast-Cm28o9U6.js";
3
+ //#region src/map/adapter-registry.ts
4
+ var n = /* @__PURE__ */ new Map(), r = "maplibre";
5
+ function i(e, t) {
6
+ if (!e || typeof e != "string") {
7
+ console.error("[adapter-registry] Adapter name must be a non-empty string.");
8
+ return;
9
+ }
10
+ n.set(e.toLowerCase(), t);
11
+ }
12
+ function a() {
13
+ return Array.from(n.keys());
14
+ }
15
+ async function o(e) {
16
+ let t = (e ?? "maplibre").toLowerCase(), r = n.get(t);
17
+ if (!r) return console.error(`[adapter-registry] No adapter registered under "${t}".`), null;
18
+ try {
19
+ return await r();
20
+ } catch (e) {
21
+ return console.error(`[adapter-registry] Failed to create adapter "${t}".`, e), null;
22
+ }
23
+ }
24
+ i(r, async () => {
25
+ let { MapLibreAdapter: e } = await import("./maplibre-adapter-TFc3e0G9.js");
26
+ return new e();
27
+ }), i("openlayers", async () => {
28
+ let { OpenLayersAdapter: e } = await import("./openlayers-adapter-DVW1KCRv.js");
29
+ return new e();
30
+ }), i("ol", async () => {
31
+ let { OpenLayersAdapter: e } = await import("./openlayers-adapter-DVW1KCRv.js");
32
+ return new e();
33
+ }), i("leaflet", async () => {
34
+ let { LeafletAdapter: e } = await import("./leaflet-adapter-D9djjrKv.js");
35
+ return new e();
36
+ }), i("l", async () => {
37
+ let { LeafletAdapter: e } = await import("./leaflet-adapter-D9djjrKv.js");
38
+ return new e();
39
+ }), i("cesium", async () => {
40
+ let { createCesiumAdapter: e } = await import("./cesium-adapter-BHXNytkU.js");
41
+ return await e();
42
+ }), i("c", async () => {
43
+ let { createCesiumAdapter: e } = await import("./cesium-adapter-BHXNytkU.js");
44
+ return await e();
45
+ });
46
+ //#endregion
47
+ //#region src/config/adapter-resolution.ts
48
+ function s(e) {
49
+ if (!e) return null;
50
+ switch (e.toLowerCase()) {
51
+ case "ol": return "openlayers";
52
+ case "l": return "leaflet";
53
+ case "c": return "cesium";
54
+ default: return e.toLowerCase();
55
+ }
56
+ }
57
+ function c(e, t) {
58
+ return e ? `webmapx-${t}:${e}` : null;
59
+ }
60
+ function l({ explicitAdapter: e, savedAdapter: t, configuredAdapter: n, defaultAdapter: r = "maplibre" }) {
61
+ return s(t) ?? s(e) ?? s(n) ?? s(r) ?? "maplibre";
62
+ }
63
+ //#endregion
64
+ //#region src/map/map-state-persistence.ts
65
+ var u = "webmapx-state";
66
+ function d(e) {
67
+ return `${u}:${e}`;
68
+ }
69
+ function f(e, t) {
70
+ try {
71
+ sessionStorage.setItem(d(e), JSON.stringify(t));
72
+ } catch {}
73
+ }
74
+ function p(e) {
75
+ let t = sessionStorage.getItem(d(e));
76
+ if (!t) return null;
77
+ try {
78
+ return JSON.parse(t);
79
+ } catch {
80
+ return null;
81
+ }
82
+ }
83
+ function m(e) {
84
+ let t = p(e);
85
+ return t && sessionStorage.removeItem(d(e)), t;
86
+ }
87
+ var h = "config";
88
+ function g(e) {
89
+ return e === 0 ? "s" : `s.${e}`;
90
+ }
91
+ function _(e) {
92
+ return e === 0 ? h : `${h}.${e}`;
93
+ }
94
+ function v(e) {
95
+ let t = new URLSearchParams(window.location.search), n = t.get(`${h}.${e}`);
96
+ return n === null ? e === 0 ? t.get(h) : null : n;
97
+ }
98
+ function y(e) {
99
+ let t = Array.from(document.querySelectorAll("webmapx-map")).indexOf(e);
100
+ return t >= 0 ? t : 0;
101
+ }
102
+ function b(e) {
103
+ return btoa(JSON.stringify(e));
104
+ }
105
+ function x(e) {
106
+ try {
107
+ let t = JSON.parse(atob(e));
108
+ return !t || typeof t != "object" || !Array.isArray(t.l) || !Array.isArray(t.v) || t.v.length !== 5 ? null : t;
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+ function S(e) {
114
+ let t = new URLSearchParams(window.location.search), n = t.get(`s.${e}`) ?? (e === 0 ? t.get("s") : null);
115
+ return n ? x(n) : null;
116
+ }
117
+ function C(e, t, n, r, i, a, o) {
118
+ let s = {};
119
+ for (let [e, t] of i) t !== 0 && (s[e] = t);
120
+ let c = {
121
+ l: t,
122
+ v: [
123
+ Math.round(r.center[0] * 1e6) / 1e6,
124
+ Math.round(r.center[1] * 1e6) / 1e6,
125
+ Math.round(r.zoom * 100) / 100,
126
+ Math.round(r.bearing * 10) / 10,
127
+ Math.round(r.pitch * 10) / 10
128
+ ]
129
+ };
130
+ n.length > 0 && (c.h = n), Object.keys(s).length > 0 && (c.t = s), a && a !== "mercator" && (c.p = a);
131
+ let l = new URL(window.location.href), u = g(e);
132
+ if (l.searchParams.set(u, b(c)), e === 0 && l.searchParams.delete("s.0"), o) {
133
+ let t = _(e);
134
+ l.searchParams.set(t, o), e === 0 && l.searchParams.delete(`${h}.0`);
135
+ }
136
+ return l.toString();
137
+ }
138
+ //#endregion
139
+ //#region src/tools/tool-manager.ts
140
+ var w = class extends EventTarget {
141
+ constructor(...e) {
142
+ super(...e), this.tools = /* @__PURE__ */ new Map(), this._activeToolId = null, this.store = null;
143
+ }
144
+ setStore(e) {
145
+ this.store = e;
146
+ }
147
+ register(e) {
148
+ if (this.tools.has(e.toolId)) {
149
+ console.warn(`Tool "${e.toolId}" is already registered`);
150
+ return;
151
+ }
152
+ this.tools.set(e.toolId, e);
153
+ }
154
+ unregister(e) {
155
+ this._activeToolId === e && this.deactivate(), this.tools.delete(e);
156
+ }
157
+ activate(e) {
158
+ let t = this.tools.get(e);
159
+ if (!t) return console.warn(`Tool "${e}" not found`), !1;
160
+ if (this._activeToolId === e) return !0;
161
+ let n = this._activeToolId, r = n ? this.tools.get(n) ?? null : null;
162
+ return r && n !== e && t.isModal && (this._activeToolId = null, r.active = !1, this.updateStoreActiveTool(null), this.dispatchDeactivatedEvent(n, r)), this._activeToolId = e, t.active = !0, this.updateStoreActiveTool(e, t), this.dispatchActivatedEvent(e, t), !0;
163
+ }
164
+ deactivate(e) {
165
+ let t = e ?? this._activeToolId;
166
+ if (!t) return;
167
+ let n = this.tools.get(t);
168
+ n && this._activeToolId === t && (this._activeToolId = null, n.active = !1, this.updateStoreActiveTool(null), this.dispatchDeactivatedEvent(t, n));
169
+ }
170
+ toggle(e) {
171
+ return this._activeToolId === e ? (this.deactivate(e), !1) : this.activate(e);
172
+ }
173
+ get activeTool() {
174
+ return this._activeToolId ? this.tools.get(this._activeToolId) ?? null : null;
175
+ }
176
+ get activeToolId() {
177
+ return this._activeToolId;
178
+ }
179
+ getTool(e) {
180
+ return this.tools.get(e);
181
+ }
182
+ getToolIds() {
183
+ return Array.from(this.tools.keys());
184
+ }
185
+ updateStoreActiveTool(e, t) {
186
+ this.store && this.store.dispatch({ activeTool: e ? {
187
+ toolId: e,
188
+ ...t?.label ? { label: t.label } : {},
189
+ ...t?.icon ? { icon: t.icon } : {}
190
+ } : null }, "UI");
191
+ }
192
+ dispatchActivatedEvent(e, t) {
193
+ this.dispatchEvent(new CustomEvent("webmapx-tool-activated", { detail: {
194
+ toolId: e,
195
+ tool: t
196
+ } }));
197
+ }
198
+ dispatchDeactivatedEvent(e, t) {
199
+ this.dispatchEvent(new CustomEvent("webmapx-tool-deactivated", { detail: {
200
+ toolId: e,
201
+ tool: t
202
+ } }));
203
+ }
204
+ };
205
+ //#endregion
206
+ //#region src/components/internal/single-group-policy.ts
207
+ function T(e, t, n, r, i, a) {
208
+ let o = r?.[t];
209
+ (o?.legendRole === "background" || o?.legendRole === "overlay") && a.set(e, o.legendRole);
210
+ let s = n.indexOf(t);
211
+ if (s < 0) return;
212
+ let c = n[s + 1], l = n[s - 1];
213
+ if (typeof c == "string" && c.length > 0) {
214
+ i.set(e, { beforeLayerId: c });
215
+ return;
216
+ }
217
+ if (typeof l == "string" && l.length > 0) {
218
+ i.set(e, { afterLayerId: l });
219
+ return;
220
+ }
221
+ i.delete(e);
222
+ }
223
+ function E(e, t, n, r) {
224
+ let i = r.get(e);
225
+ if (!i) return n;
226
+ let a = new Set(t), o = typeof i.beforeLayerId == "string" && a.has(i.beforeLayerId) ? i.beforeLayerId : void 0, s = typeof i.afterLayerId == "string" && a.has(i.afterLayerId) ? i.afterLayerId : void 0;
227
+ if (!o && !s) return r.delete(e), n;
228
+ let c = {
229
+ ...o ? { beforeLayerId: o } : {},
230
+ ...s ? { afterLayerId: s } : {},
231
+ ...n?.beforeLayerId ? { beforeLayerId: n.beforeLayerId } : {},
232
+ ...n?.afterLayerId ? { afterLayerId: n.afterLayerId } : {}
233
+ };
234
+ return Object.keys(c).length > 0 ? c : void 0;
235
+ }
236
+ //#endregion
237
+ //#region src/components/internal/legend-role-policy.ts
238
+ function D(e, t, n, r, i, a) {
239
+ if (t?.legendRole === "background" || t?.legendRole === "overlay") return t.legendRole;
240
+ if (n) {
241
+ let e = r.get(n);
242
+ if (e === "background" || e === "overlay") return e;
243
+ }
244
+ if (!i) return "overlay";
245
+ if (e === i) return "background";
246
+ let o = a.get(i), s = n ?? a.get(e);
247
+ return o && s && o === s ? "background" : "overlay";
248
+ }
249
+ //#endregion
250
+ //#region src/map/geojson-loader.ts
251
+ async function O(t) {
252
+ let n = [], r = Object.values(t).filter((e) => e && e.type === "geojson" && typeof e.data == "string");
253
+ return await Promise.all(r.map(async (t) => {
254
+ if (t.service === "wfs") {
255
+ let e = await M(t);
256
+ e && n.push(e);
257
+ return;
258
+ }
259
+ if (t.service === "esri-feature") {
260
+ let e = await N(t);
261
+ e && n.push(e);
262
+ return;
263
+ }
264
+ let r = t.data, i = r.indexOf("#"), a = i >= 0 ? r.slice(0, i) : r, o = i >= 0 ? r.slice(i + 1) : null, s = await fetch(a);
265
+ if (!s.ok) throw Error(`geojson-loader: failed to fetch ${a}: ${s.status}`);
266
+ let c = await s.json();
267
+ if (c?.type === "Topology") {
268
+ let n = c.objects, r = o ?? Object.keys(n)[0];
269
+ if (!r || !n[r]) throw Error(`geojson-loader: object "${r}" not found in ${a}`);
270
+ t.data = e(c, n[r]);
271
+ } else t.data = c;
272
+ })), n;
273
+ }
274
+ var k = 6e6, A = 1e4;
275
+ function j(e) {
276
+ if (!e) return 0;
277
+ switch (e.type) {
278
+ case "GeometryCollection": return e.geometries.reduce((e, t) => e + j(t), 0);
279
+ case "Point": return 1;
280
+ case "MultiPoint":
281
+ case "LineString": return e.coordinates.length;
282
+ case "MultiLineString":
283
+ case "Polygon": return e.coordinates.reduce((e, t) => e + t.length, 0);
284
+ case "MultiPolygon": return e.coordinates.reduce((e, t) => e + t.reduce((e, t) => e + t.length, 0), 0);
285
+ default: return 0;
286
+ }
287
+ }
288
+ async function M(e) {
289
+ let t = !!e.wfsSupportsPaging, n = e.wfsVersion === "2.0.0" ? "COUNT" : "MAXFEATURES", r = e.data, i = (e) => {
290
+ let i = new URL(r);
291
+ for (let e of [...i.searchParams.keys()]) [
292
+ "maxfeatures",
293
+ "count",
294
+ "startindex"
295
+ ].includes(e.toLowerCase()) && i.searchParams.delete(e);
296
+ return i.searchParams.set(n, String(A)), t && e > 0 && i.searchParams.set("STARTINDEX", String(e)), i;
297
+ }, a = async (e) => {
298
+ let t = i(e), n = await fetch(t.toString());
299
+ if (!n.ok) throw Error(`geojson-loader: failed to fetch ${t}: ${n.status}`);
300
+ return await n.json();
301
+ }, o = await a(0), s = [...o.features ?? []], c = o.crs, l = o.numberMatched, u = 0;
302
+ for (let e of s) u += j(e.geometry);
303
+ l !== void 0 && (e.featureCount = l), e.data = {
304
+ type: "FeatureCollection",
305
+ features: s,
306
+ ...c ? { crs: c } : {}
307
+ };
308
+ let d = l !== void 0 && s.length >= l;
309
+ return !t || (o.features?.length ?? 0) === 0 || d || u >= k ? null : {
310
+ id: e.id,
311
+ run: (t) => {
312
+ (async () => {
313
+ let n = s.length;
314
+ for (;;) {
315
+ let r = await a(n), i = r.features ?? [];
316
+ s.push(...i);
317
+ for (let e of i) u += j(e.geometry);
318
+ l ??= r.numberMatched, l !== void 0 && (e.featureCount = l);
319
+ let o = {
320
+ type: "FeatureCollection",
321
+ features: s,
322
+ ...c ? { crs: c } : {}
323
+ };
324
+ if (e.data = o, !t(o) || i.length === 0 || l !== void 0 && s.length >= l || u >= k) break;
325
+ n += i.length;
326
+ }
327
+ })();
328
+ }
329
+ };
330
+ }
331
+ async function N(e) {
332
+ let t = e.data, n = async (e) => {
333
+ let n = new URL(t);
334
+ n.searchParams.set("resultRecordCount", String(A)), n.searchParams.set("resultOffset", String(e));
335
+ let r = await fetch(n.toString());
336
+ if (!r.ok) throw Error(`geojson-loader: failed to fetch ${n}: ${r.status}`);
337
+ return await r.json();
338
+ }, r = await n(0), i = [...r.features ?? []], a = 0;
339
+ for (let e of i) a += j(e.geometry);
340
+ return e.data = {
341
+ type: "FeatureCollection",
342
+ features: i
343
+ }, !r.exceededTransferLimit || i.length === 0 || a >= k ? null : {
344
+ id: e.id,
345
+ run: (t) => {
346
+ (async () => {
347
+ let r = i.length;
348
+ for (;;) {
349
+ let o = await n(r), s = o.features ?? [];
350
+ i.push(...s);
351
+ for (let e of s) a += j(e.geometry);
352
+ let c = {
353
+ type: "FeatureCollection",
354
+ features: i
355
+ };
356
+ if (e.data = c, !t(c) || !o.exceededTransferLimit || s.length === 0 || a >= k) break;
357
+ r += s.length;
358
+ }
359
+ })();
360
+ }
361
+ };
362
+ }
363
+ //#endregion
364
+ //#region src/map/layer-source-resolver.ts
365
+ function P(e, t) {
366
+ if (!t || t.length === 0) return e;
367
+ let n = new Map(t.map((e) => [e.id, e])), r = /* @__PURE__ */ new Set();
368
+ if (typeof e.source == "string" && r.add(e.source), Array.isArray(e.layers)) for (let t of e.layers) typeof t?.source == "string" && r.add(t.source);
369
+ if (r.size === 0) return e;
370
+ let i = e.sources ?? {}, a = {};
371
+ for (let e of r) {
372
+ if (i[e]) continue;
373
+ let t = n.get(e);
374
+ t && (a[e] = { ...t });
375
+ }
376
+ return Object.keys(a).length === 0 ? e : {
377
+ ...e,
378
+ sources: {
379
+ ...i,
380
+ ...a
381
+ }
382
+ };
383
+ }
384
+ //#endregion
385
+ //#region src/components/webmapx-map.ts
386
+ var F = "map-view", I = "webmapx-map__surface", L = "adapter", R = class extends HTMLElement {
387
+ constructor(...e) {
388
+ super(...e), this.initialStateLayersApplied = !1, this.activeAdapterName = null, this.runtimeStyleLayerCounter = 0, this.styleLayerCache = /* @__PURE__ */ new Map(), this.singleGroupInsertSlotByGroup = /* @__PURE__ */ new Map(), this.singleGroupLegendRoleByGroup = /* @__PURE__ */ new Map(), this.logicalLayerOrder = [], this.logicalLayerRole = /* @__PURE__ */ new Map(), this.dynamicLayerRequests = /* @__PURE__ */ new Map(), this.handleFileDragOver = (e) => {
389
+ e.dataTransfer?.types.includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = "copy");
390
+ }, this.handleFileDrop = (e) => {
391
+ let t = e.dataTransfer?.files;
392
+ !t || t.length === 0 || (e.preventDefault(), this.handleDroppedFiles(Array.from(t)));
393
+ }, this.currentSurface = null, this.adapterInstance = null, this.adapterPromise = null, this.configInstance = null, this.toolManagerInstance = null;
394
+ }
395
+ connectedCallback() {
396
+ this.upsertAndStyleSurface(), this.observeSurfaceChanges(), this.addEventListener("add-layer", this.handleLayerAddRequest), this.addEventListener("webmapx-add-layer", this.handleAddLayerEvent), this.addEventListener("webmapx-remove-layer", this.handleRemoveLayerEvent), this.addEventListener("webmapx-add-source", this.handleAddSourceEvent), this.addEventListener("webmapx-remove-source", this.handleRemoveSourceEvent), this.addEventListener("webmapx-set-source-data", this.handleSetSourceDataEvent), this.addEventListener("webmapx-suppress-busy-for-source", this.handleSuppressBusyForSource), this.addEventListener("webmapx-unsuppress-busy-for-source", this.handleUnsuppressBusyForSource), this.addEventListener("dragover", this.handleFileDragOver), this.addEventListener("drop", this.handleFileDrop);
397
+ }
398
+ disconnectedCallback() {
399
+ this.surfaceObserver?.disconnect(), this.removeEventListener("add-layer", this.handleLayerAddRequest), this.removeEventListener("webmapx-add-layer", this.handleAddLayerEvent), this.removeEventListener("webmapx-remove-layer", this.handleRemoveLayerEvent), this.removeEventListener("webmapx-add-source", this.handleAddSourceEvent), this.removeEventListener("webmapx-remove-source", this.handleRemoveSourceEvent), this.removeEventListener("webmapx-set-source-data", this.handleSetSourceDataEvent), this.removeEventListener("webmapx-suppress-busy-for-source", this.handleSuppressBusyForSource), this.removeEventListener("webmapx-unsuppress-busy-for-source", this.handleUnsuppressBusyForSource), this.removeEventListener("dragover", this.handleFileDragOver), this.removeEventListener("drop", this.handleFileDrop);
400
+ }
401
+ async handleDroppedFiles(e) {
402
+ await this.addFilesAsLayers(e);
403
+ }
404
+ async addFilesAsLayers(e) {
405
+ this.adapter?.store.dispatch({ mapBusy: !0 }, "UI");
406
+ try {
407
+ await this.processDroppedFiles(e);
408
+ } finally {
409
+ this.adapter?.store.dispatch({ mapBusy: !1 }, "UI");
410
+ }
411
+ }
412
+ async tryHandleDroppedConfig(e) {
413
+ if (e.length !== 1) return !1;
414
+ let t = e[0], { sniffFile: n } = await import("./file-sniff-Dhxj3KTF.js");
415
+ if ((await n(t)).kind !== "webmapx-config") return !1;
416
+ let { storeDroppedConfig: r } = await import("./dropped-config-C_GyVa8o.js");
417
+ return await r(await t.text()), window.location.reload(), !0;
418
+ }
419
+ async processDroppedFiles(e) {
420
+ if (await this.tryHandleDroppedConfig(e)) return;
421
+ let { sniffBlob: n } = await import("./file-sniff-Dhxj3KTF.js"), { groupDroppedFiles: r, buildLayerConfigFromGroup: i } = await import("./dropped-layer-builder-DAaYgUPk.js"), a = (e, t, n, r) => {
422
+ let i = [`${r}${e} (${(t / 1024).toFixed(1)} KB): ${n.description}`];
423
+ for (let e of n.children ?? []) i.push(...a(e.path, e.size, e.result, r + " "));
424
+ return i;
425
+ }, o = await r(e), s = [];
426
+ for (let e of o) {
427
+ let t = await i(e);
428
+ if (t) {
429
+ if (this.adapter?.hasLayer(t.id)) {
430
+ let e = t.id, n = 1;
431
+ for (; this.adapter.hasLayer(`${e}_${n}`);) n++;
432
+ let r = `${e}_${n}`, i = `${e}:`, a = `${r}:`;
433
+ t.id = r, t.sources = Object.fromEntries(Object.entries(t.sources ?? {}).map(([e, t]) => [e.startsWith(i) ? a + e.slice(i.length) : e, t])), t.layers = (t.layers ?? []).map((e) => ({
434
+ ...e,
435
+ id: e.id?.startsWith(i) ? a + e.id.slice(i.length) : e.id,
436
+ source: e.source?.startsWith(i) ? a + e.source.slice(i.length) : e.source
437
+ }));
438
+ }
439
+ console.log("addLayer()"), await this.addLayerRequest(t);
440
+ continue;
441
+ }
442
+ for (let t of e) {
443
+ let e = await n(t.blob);
444
+ s.push(...a(t.name, t.blob.size, e, ""));
445
+ }
446
+ }
447
+ s.length > 0 && t(s.join("<br>"), {
448
+ variant: "warning",
449
+ duration: 16e3
450
+ });
451
+ }
452
+ async handleAddLayerEvent(e) {
453
+ let t = e.detail ?? {}, n = {
454
+ ...typeof t.beforeLayerId == "string" ? { beforeLayerId: t.beforeLayerId } : {},
455
+ ...typeof t.afterLayerId == "string" ? { afterLayerId: t.afterLayerId } : {}
456
+ }, r = this.resolveFallbackFromRequest(t);
457
+ if (!await this.addLayerRequest(t, r, n)) {
458
+ let e = this.resolveCatalogLayerIdFromAddLayerDetail(t);
459
+ this.dispatchEvent(new CustomEvent("webmapx-addlayer-failed", {
460
+ detail: {
461
+ ...e ? { layerId: e } : {},
462
+ request: t
463
+ },
464
+ bubbles: !0,
465
+ composed: !0
466
+ }));
467
+ }
468
+ }
469
+ handleRemoveLayerEvent(e) {
470
+ this.removeInlineLayer(e.detail);
471
+ }
472
+ removeInlineLayer(e) {
473
+ this.adapter && (this.dynamicLayerRequests.delete(e), this.adapter.removeLayer(e), this.removeFromLogicalOrder(e), this.logicalLayerRole.delete(e));
474
+ }
475
+ handleAddSourceEvent(e) {
476
+ this.adapter && this.adapter.addSource(e.detail.id, e.detail.config);
477
+ }
478
+ handleRemoveSourceEvent(e) {
479
+ this.adapter && this.adapter.removeSource(e.detail);
480
+ }
481
+ handleSetSourceDataEvent(e) {
482
+ let t = this.adapter?.getSource(e.detail.id);
483
+ t && t.setData(e.detail.data);
484
+ }
485
+ handleSuppressBusyForSource(e) {
486
+ this.adapter && this.adapter.suppressBusySignalForSource(e.detail);
487
+ }
488
+ handleUnsuppressBusyForSource(e) {
489
+ this.adapter && this.adapter.unsuppressBusySignalForSource(e.detail);
490
+ }
491
+ async handleLayerAddRequest(e) {
492
+ let t = this.toRecord(e.detail), n = this.toLayerInformation(t?.layerInformation), r = t?.checked === !0, i = typeof t?.selectionGroup == "string" && t.selectionGroup.length > 0 ? t.selectionGroup : null, a = this.adapter;
493
+ if (a) if (r) {
494
+ let e = typeof n?.layer?.id == "string" ? n.layer.id : null;
495
+ if (!e) return;
496
+ await this.tryAddLayerRequest(a, { layerId: e }, void 0, /* @__PURE__ */ new Set(), i ?? void 0) ? this.dynamicLayerRequests.set(e, { request: { layerId: e } }) : this.dispatchEvent(new CustomEvent("webmapx-addlayer-failed", {
497
+ detail: { layerId: e },
498
+ bubbles: !0,
499
+ composed: !0
500
+ }));
501
+ } else n && (this.dynamicLayerRequests.delete(n.layer.id), this.rememberSingleGroupInsertSlot(a, n.layer.id, i ?? void 0), this.removeFromLogicalOrder(n.layer.id), this.logicalLayerRole.delete(n.layer.id), a.removeLogicalLayer(n.layer.id));
502
+ }
503
+ upsertAndStyleSurface() {
504
+ let e = this.ensureMapViewElement();
505
+ this.decorateMapSurface(e), this.currentSurface = e;
506
+ }
507
+ ensureMapViewElement() {
508
+ let e = this.mapElement;
509
+ if (e) return e;
510
+ let t = document.createElement("div");
511
+ return t.setAttribute("slot", F), t.classList.add("webmapx-map__auto-view"), this.prepend(t), t;
512
+ }
513
+ decorateMapSurface(e) {
514
+ e.classList.add(I), e.style.position || (e.style.position = "absolute"), e.style.top || (e.style.top = "0"), e.style.right || (e.style.right = "0"), e.style.bottom || (e.style.bottom = "0"), e.style.left || (e.style.left = "0"), e.style.width || (e.style.width = "100%"), e.style.height || (e.style.height = "100%"), e.style.background || e.style.setProperty("background", "var(--color-background-secondary, #f4f4f4)");
515
+ }
516
+ observeSurfaceChanges() {
517
+ this.surfaceObserver || (this.surfaceObserver = new MutationObserver(() => {
518
+ let e = this.mapElement;
519
+ if (!e) {
520
+ this.upsertAndStyleSurface();
521
+ return;
522
+ }
523
+ e !== this.currentSurface && (this.decorateMapSurface(e), this.currentSurface = e);
524
+ }), this.surfaceObserver.observe(this, { childList: !0 }));
525
+ }
526
+ get adapter() {
527
+ return this.ensureAdapter(), this.adapterInstance;
528
+ }
529
+ getAdapterAsync() {
530
+ return this.ensureAdapter(), this.adapterPromise ?? Promise.resolve(this.adapterInstance);
531
+ }
532
+ get mapElement() {
533
+ return this.querySelector(`[slot="${F}"]`);
534
+ }
535
+ get config() {
536
+ return this.configInstance;
537
+ }
538
+ get mapConfig() {
539
+ return this.configInstance?.map;
540
+ }
541
+ get layerDataConfig() {
542
+ return this.configInstance?.layerData ?? this.configInstance?.catalog;
543
+ }
544
+ get catalogConfig() {
545
+ return this.configInstance?.catalog;
546
+ }
547
+ get toolsConfig() {
548
+ return this.configInstance?.tools;
549
+ }
550
+ async addLayerRequest(e, t, n) {
551
+ let r = this.adapter;
552
+ if (!r) return !1;
553
+ let i = new Set(Object.keys(r.store.getState().mapLayers ?? {})), a = /* @__PURE__ */ new Set();
554
+ if (await this.tryAddLayerRequest(r, e, n, a)) {
555
+ let a = Object.keys(r.store.getState().mapLayers ?? {});
556
+ for (let r of a) i.has(r) || this.dynamicLayerRequests.set(r, {
557
+ request: e,
558
+ fallback: t,
559
+ options: n
560
+ });
561
+ return !0;
562
+ }
563
+ return t ? typeof t == "string" ? this.tryAddLayerRequest(r, { layerId: t }, n, a) : this.tryAddLayerRequest(r, t, n, a) : !1;
564
+ }
565
+ get toolManager() {
566
+ return this.toolManagerInstance || (this.toolManagerInstance = new w(), this.adapterInstance?.store && this.toolManagerInstance.setStore(this.adapterInstance.store), this.toolManagerInstance.addEventListener("webmapx-tool-activated", (e) => {
567
+ this.dispatchEvent(new CustomEvent("webmapx-tool-activated", {
568
+ detail: e.detail,
569
+ bubbles: !0,
570
+ composed: !0
571
+ }));
572
+ }), this.toolManagerInstance.addEventListener("webmapx-tool-deactivated", (e) => {
573
+ this.dispatchEvent(new CustomEvent("webmapx-tool-deactivated", {
574
+ detail: e.detail,
575
+ bubbles: !0,
576
+ composed: !0
577
+ }));
578
+ })), this.toolManagerInstance;
579
+ }
580
+ setConfig(e) {
581
+ this.configInstance = e, this.initialStateLayersApplied = !1, this.applyCatalogToAdapter(), this.dispatchEvent(new CustomEvent("webmapx-config-ready", {
582
+ detail: {
583
+ config: e,
584
+ map: this
585
+ },
586
+ bubbles: !0,
587
+ composed: !0
588
+ })), console.log(`[webmapx-map] Config set for "${this.id || "unnamed"}":`, e);
589
+ }
590
+ getScopedStorageKey(e) {
591
+ return c(this.id, e);
592
+ }
593
+ saveState(e) {
594
+ if (!this.id) return;
595
+ let t = this.adapter?.getViewportState(), n = [...this.dynamicLayerRequests.values()];
596
+ f(this.id, {
597
+ ...t ? { viewport: t } : {},
598
+ ...n.length > 0 ? { layers: n } : {},
599
+ ...e?.projection ? { projection: e.projection } : {}
600
+ });
601
+ }
602
+ setProjection(e) {
603
+ this.adapter && (this.adapter.setProjection(e) || (this.saveState({ projection: e }), window.location.reload()));
604
+ }
605
+ async restoreState() {
606
+ if (!this.id) return;
607
+ let e = m(this.id);
608
+ if (e) for (let t of e.layers ?? []) await this.addLayerRequest(t.request, t.fallback, t.options);
609
+ }
610
+ getSavedAdapterPreference() {
611
+ let e = this.getScopedStorageKey("adapter");
612
+ return e ? localStorage.getItem(e) : null;
613
+ }
614
+ resolveRequestedAdapter() {
615
+ return l({
616
+ explicitAdapter: this.getAttribute(L) ?? this.getAttribute("type"),
617
+ savedAdapter: this.getSavedAdapterPreference(),
618
+ configuredAdapter: this.mapConfig?.type ?? null,
619
+ defaultAdapter: r
620
+ });
621
+ }
622
+ ensureAdapter() {
623
+ if (this.adapterInstance || this.adapterPromise) return;
624
+ let e = this.resolveRequestedAdapter();
625
+ this.adapterPromise = (async () => {
626
+ let t = await o(e);
627
+ return t ? (this.adapterInstance = t, this.activeAdapterName = e, this.toolManagerInstance && t.store && this.toolManagerInstance.setStore(t.store), this.applyCatalogToAdapter(), this.dispatchEvent(new CustomEvent("webmapx-map-ready", {
628
+ detail: {
629
+ adapter: this.adapterInstance,
630
+ map: this
631
+ },
632
+ bubbles: !0,
633
+ composed: !0
634
+ })), t) : (console.error(`[webmapx-map] No adapter available for "${e}".`), null);
635
+ })();
636
+ }
637
+ async applyCatalogToAdapter() {
638
+ let e = this.adapterInstance, t = this.layerDataConfig;
639
+ !e || !t || this.initialStateLayersApplied || (this.initialStateLayersApplied = !0, this.applyInitialStateLayers(e, t));
640
+ }
641
+ collectInitialActiveLayerRefs() {
642
+ let e = S(y(this));
643
+ if (e?.l?.length) return e.l;
644
+ let t = this.configInstance?.state?.activeLayers;
645
+ if (!t) return (this.configInstance?.layerData?.layers ?? []).map((e) => typeof e?.id == "string" ? e.id : null).filter((e) => e !== null);
646
+ let n = [];
647
+ for (let e of t) {
648
+ if (typeof e == "string") {
649
+ n.push(e);
650
+ continue;
651
+ }
652
+ if (!e || typeof e != "object") continue;
653
+ let t = e, r = typeof t.ref == "string" ? t.ref : typeof t.layerId == "string" ? t.layerId : null, i = t.visible !== !1;
654
+ r && i && n.push(r);
655
+ }
656
+ return Array.from(new Set(n));
657
+ }
658
+ getBackgroundSeedLayerId() {
659
+ let e = this.collectInitialActiveLayerRefs();
660
+ return e.length > 0 ? e[0] : null;
661
+ }
662
+ collectSingleSelectionGroupByLayerId() {
663
+ let e = /* @__PURE__ */ new Map(), t = this.layerDataConfig?.layers;
664
+ if (!Array.isArray(t)) return e;
665
+ for (let n of t) {
666
+ let t = this.getLayerMetadata(n), r = (typeof n.singleGroup == "string" ? n.singleGroup : null) ?? (typeof t?.singleSelectionGroupKey == "string" ? t.singleSelectionGroupKey : null) ?? (typeof t?.selectionGroup == "string" ? t.selectionGroup : null) ?? (typeof t?.["webmapx:selectionGroup"] == "string" ? t["webmapx:selectionGroup"] : null);
667
+ r && r.length > 0 && e.set(n.id, r);
668
+ }
669
+ return e;
670
+ }
671
+ getSingleSelectionGroupKeyForLayer(e, t) {
672
+ return typeof t == "string" && t.length > 0 ? t : this.collectSingleSelectionGroupByLayerId().get(e) ?? null;
673
+ }
674
+ insertIntoLogicalOrder(e, t) {
675
+ if (this.logicalLayerOrder = this.logicalLayerOrder.filter((t) => t !== e), t?.beforeLayerId) {
676
+ let n = this.logicalLayerOrder.indexOf(t.beforeLayerId);
677
+ if (n >= 0) {
678
+ this.logicalLayerOrder.splice(n, 0, e);
679
+ return;
680
+ }
681
+ }
682
+ this.logicalLayerOrder.push(e);
683
+ }
684
+ removeFromLogicalOrder(e) {
685
+ this.logicalLayerOrder = this.logicalLayerOrder.filter((t) => t !== e);
686
+ }
687
+ computeInsertOptionsForLayer(e, t) {
688
+ if (t?.beforeLayerId || t?.afterLayerId) return t;
689
+ if (e === "background") {
690
+ let e = this.logicalLayerOrder.find((e) => (this.logicalLayerRole.get(e) ?? "overlay") !== "background");
691
+ return e ? { beforeLayerId: e } : void 0;
692
+ }
693
+ }
694
+ rememberSingleGroupInsertSlot(e, t, n) {
695
+ let r = this.getSingleSelectionGroupKeyForLayer(t, n);
696
+ r && T(r, t, this.logicalLayerOrder, e.store.getState().mapLayers, this.singleGroupInsertSlotByGroup, this.singleGroupLegendRoleByGroup);
697
+ }
698
+ resolveSingleGroupInsertionOptions(e, t, n) {
699
+ let r = this.getSingleSelectionGroupKeyForLayer(e, n);
700
+ return r ? E(r, this.logicalLayerOrder, t, this.singleGroupInsertSlotByGroup) : t;
701
+ }
702
+ resolveCatalogLegendRole(e, t, n) {
703
+ return D(e, this.getLayerMetadata(t), this.getSingleSelectionGroupKeyForLayer(e, n) ?? void 0, this.singleGroupLegendRoleByGroup, this.getBackgroundSeedLayerId(), this.collectSingleSelectionGroupByLayerId());
704
+ }
705
+ getConfiguredLayerInformation(e) {
706
+ let t = this.layerDataConfig;
707
+ if (!t) return null;
708
+ let n = t.layers?.find((t) => t.id === e);
709
+ return n ? { layer: n } : null;
710
+ }
711
+ resolveResourceUrl(e, t) {
712
+ try {
713
+ return new URL(e, t).toString().replace(/%7B/gi, "{").replace(/%7D/gi, "}");
714
+ } catch {
715
+ return e;
716
+ }
717
+ }
718
+ resolveStyleBackedSource(e, t, n, r) {
719
+ let i = n.type;
720
+ if (i !== "vector" && i !== "raster" && i !== "geojson") return null;
721
+ if (i === "vector") {
722
+ let e = typeof n.url == "string" ? n.url : null, i = Array.isArray(n.tiles) ? n.tiles.filter((e) => typeof e == "string") : [], a = typeof n.attribution == "string" ? n.attribution : void 0, o = typeof n.minzoom == "number" ? n.minzoom : void 0, s = typeof n.maxzoom == "number" ? n.maxzoom : void 0;
723
+ return !e && i.length === 0 ? null : {
724
+ id: t,
725
+ type: "vector",
726
+ ...e ? { url: this.resolveResourceUrl(e, r) } : {},
727
+ ...i.length > 0 ? { tiles: i.map((e) => this.resolveResourceUrl(e, r)) } : {},
728
+ ...o === void 0 ? {} : { minzoom: o },
729
+ ...s === void 0 ? {} : { maxzoom: s },
730
+ ...a ? { attribution: a } : {}
731
+ };
732
+ }
733
+ if (i === "raster") {
734
+ let e = Array.isArray(n.tiles) ? n.tiles.filter((e) => typeof e == "string") : [], i = typeof n.attribution == "string" ? n.attribution : void 0;
735
+ return e.length === 0 ? null : {
736
+ id: t,
737
+ type: "raster",
738
+ service: "xyz",
739
+ url: e.map((e) => this.resolveResourceUrl(e, r)),
740
+ tileSize: typeof n.tileSize == "number" ? n.tileSize : void 0,
741
+ minzoom: typeof n.minzoom == "number" ? n.minzoom : void 0,
742
+ maxzoom: typeof n.maxzoom == "number" ? n.maxzoom : void 0,
743
+ ...i ? { attribution: i } : {}
744
+ };
745
+ }
746
+ let a = n.data, o = typeof n.attribution == "string" ? n.attribution : void 0;
747
+ return typeof a == "string" ? {
748
+ id: t,
749
+ type: "geojson",
750
+ data: this.resolveResourceUrl(a, r),
751
+ ...o ? { attribution: o } : {}
752
+ } : null;
753
+ }
754
+ async expandStyleBackedLayer(e) {
755
+ let t = (e.type === "style" ? e : null)?.url ?? null, n = e.id, r = `style:${n}:`, i = `${n}::${t ?? ""}`;
756
+ if (!t) return null;
757
+ let a = this.styleLayerCache.get(i);
758
+ if (a) return a;
759
+ let o = (async () => {
760
+ try {
761
+ let n = await fetch(t);
762
+ if (!n.ok) return null;
763
+ let i = this.toRecord(await n.json());
764
+ return this.buildExpandedStyleLayer(e, i, t, r);
765
+ } catch {
766
+ return null;
767
+ }
768
+ })();
769
+ return this.styleLayerCache.set(i, o), o;
770
+ }
771
+ buildExpandedStyleLayer(e, t, n, r) {
772
+ let i = t && !t.sources && !t.layers && t.source && typeof t.source == "object" ? t.source : t, a = this.toRecord(i?.sources), o = Array.isArray(i?.layers) ? i.layers.map((e) => this.toRecord(e)).filter((e) => !!e) : [];
773
+ if (!a || o.length === 0) return null;
774
+ let s = r ?? `style:${e.id}:`, c = new Set([
775
+ "background",
776
+ "fill",
777
+ "line",
778
+ "circle",
779
+ "symbol",
780
+ "raster",
781
+ "fill-extrusion",
782
+ "hillshade"
783
+ ]), l = /* @__PURE__ */ new Map(), u = o.filter((e) => typeof e.type == "string" && c.has(e.type)).map((e) => {
784
+ let t = typeof e.source == "string" ? `${s}${e.source}` : void 0;
785
+ return typeof e.source == "string" && t && l.set(e.source, t), {
786
+ id: typeof e.id == "string" ? `style:${e.id}` : void 0,
787
+ type: e.type,
788
+ source: t,
789
+ "source-layer": e["source-layer"] ?? e.sourceLayer,
790
+ minzoom: e.minzoom ?? e.minZoom,
791
+ maxzoom: e.maxzoom ?? e.maxZoom,
792
+ paint: e.paint,
793
+ layout: e.layout,
794
+ filter: e.filter
795
+ };
796
+ }), d = new Set(u.map((e) => e.source).filter((e) => typeof e == "string" && e.length > 0)), f = {};
797
+ for (let [e, t] of l.entries()) {
798
+ if (!d.has(t)) continue;
799
+ let r = this.toRecord(a[e]);
800
+ if (!r) continue;
801
+ let i = n ? this.resolveStyleBackedSource(e, t, r, n) : this.resolveInlineStyleSource(t, r);
802
+ i && (f[t] = { ...i });
803
+ }
804
+ let p = new Set(Object.keys(f)), m = u.filter((e) => !e.source || p.has(e.source));
805
+ return m.length === 0 || p.size === 0 ? null : { layer: {
806
+ id: e.id,
807
+ type: "style",
808
+ title: e.title,
809
+ singleGroup: e.singleGroup,
810
+ fallbackLayerId: e.fallbackLayerId,
811
+ minzoom: e.minzoom,
812
+ maxzoom: e.maxzoom,
813
+ metadata: {
814
+ ...this.getLayerMetadata(e) ?? {},
815
+ styleUrl: n ?? void 0,
816
+ styleSpriteUrl: typeof t?.sprite == "string" && n ? this.resolveResourceUrl(t.sprite, n) : typeof t?.sprite == "string" ? t.sprite : void 0,
817
+ styleGlyphsUrl: typeof t?.glyphs == "string" && n ? this.resolveResourceUrl(t.glyphs, n) : typeof t?.glyphs == "string" ? t.glyphs : void 0
818
+ },
819
+ sources: f,
820
+ layers: m
821
+ } };
822
+ }
823
+ resolveInlineStyleSource(e, t) {
824
+ let n = t.type;
825
+ if (n !== "vector" && n !== "raster" && n !== "geojson") return null;
826
+ if (n === "vector") {
827
+ let n = typeof t.url == "string" ? t.url : null, r = Array.isArray(t.tiles) ? t.tiles.filter((e) => typeof e == "string") : [];
828
+ return !n && r.length === 0 || !n && r.length === 0 ? null : {
829
+ id: e,
830
+ type: "vector",
831
+ url: n ?? r[0] ?? "",
832
+ ...r.length > 0 ? { tiles: r } : {},
833
+ ...typeof t.minzoom == "number" ? { minzoom: t.minzoom } : {},
834
+ ...typeof t.maxzoom == "number" ? { maxzoom: t.maxzoom } : {},
835
+ ...typeof t.attribution == "string" ? { attribution: t.attribution } : {}
836
+ };
837
+ }
838
+ if (n === "raster") {
839
+ let n = Array.isArray(t.tiles) ? t.tiles.filter((e) => typeof e == "string") : [];
840
+ return n.length === 0 ? null : {
841
+ id: e,
842
+ type: "raster",
843
+ service: "xyz",
844
+ url: n,
845
+ ...typeof t.tileSize == "number" ? { tileSize: t.tileSize } : {},
846
+ ...typeof t.minzoom == "number" ? { minzoom: t.minzoom } : {},
847
+ ...typeof t.maxzoom == "number" ? { maxzoom: t.maxzoom } : {},
848
+ ...typeof t.attribution == "string" ? { attribution: t.attribution } : {}
849
+ };
850
+ }
851
+ let r = t.data;
852
+ return typeof r == "string" ? {
853
+ id: e,
854
+ type: "geojson",
855
+ data: r,
856
+ ...typeof t.attribution == "string" ? { attribution: t.attribution } : {}
857
+ } : null;
858
+ }
859
+ async getLayerInformation(e) {
860
+ let t = this.getConfiguredLayerInformation(e);
861
+ return t ? this.isStyleBackedLayer(t.layer) ? this.expandStyleBackedLayer(t.layer) : t : null;
862
+ }
863
+ resolveCatalogLayerIdFromAddLayerDetail(e) {
864
+ let t = [
865
+ e.catalogLayerId,
866
+ e.layerId,
867
+ e.ref
868
+ ];
869
+ for (let e of t) if (typeof e == "string" && this.getConfiguredLayerInformation(e)) return e;
870
+ return null;
871
+ }
872
+ isStyleRequest(e) {
873
+ return !!(this.toRecord(e.style) || typeof e.styleUrl == "string" && e.styleUrl.length > 0);
874
+ }
875
+ resolveStyleUrlFromRequest(e) {
876
+ return typeof e.styleUrl == "string" && e.styleUrl.length > 0 ? e.styleUrl : null;
877
+ }
878
+ resolveFallbackFromRequest(e) {
879
+ let t = this.toRecord(e.fallbackLayer);
880
+ if (t) return t;
881
+ let n = [
882
+ e.fallbackLayerId,
883
+ e.fallbackRef,
884
+ e.fallback
885
+ ];
886
+ for (let e of n) if (typeof e == "string" && e.length > 0) return e;
887
+ }
888
+ async tryAddLayerRequest(e, t, n, r = /* @__PURE__ */ new Set(), i) {
889
+ let a = this.resolveCatalogLayerIdFromAddLayerDetail(t);
890
+ if (a) {
891
+ if (r.has(a)) return !1;
892
+ r.add(a);
893
+ let t = this.getConfiguredLayerInformation(a);
894
+ if (!t) return !1;
895
+ let o = this.isStyleBackedLayer(t.layer), s = o ? await this.expandStyleBackedLayer(t.layer) : t;
896
+ if (s && (!o || !this.hasUnsupportedStyleComponents(s))) {
897
+ let t = this.getSingleSelectionGroupKeyForLayer(a, i), r = this.resolveCatalogLegendRole(a, s.layer, t ?? void 0), o = this.resolveSingleGroupInsertionOptions(a, n, i), c = this.computeInsertOptionsForLayer(r, o), l = {
898
+ ...s,
899
+ layer: {
900
+ ...s.layer,
901
+ metadata: {
902
+ ...this.getLayerMetadata(s.layer) ?? {},
903
+ legendRole: r,
904
+ ...t ? { singleSelectionGroupKey: t } : {}
905
+ }
906
+ }
907
+ };
908
+ if (await this.addLogicalLayerInternal(e, l, c)) {
909
+ let e = this.getSingleSelectionGroupKeyForLayer(a, i);
910
+ return e && this.singleGroupInsertSlotByGroup.delete(e), !0;
911
+ }
912
+ }
913
+ let c = this.getConfiguredFallbackLayerId(t.layer);
914
+ return c ? this.tryAddLayerRequest(e, { layerId: c }, n, r, i) : !1;
915
+ }
916
+ if (typeof t.layerId == "string" || typeof t.catalogLayerId == "string" || typeof t.ref == "string") return !1;
917
+ if (this.isStyleRequest(t)) {
918
+ let n = await this.getLayerInformationFromStyleRequest(t);
919
+ return !n || this.hasUnsupportedStyleComponents(n) ? !1 : this.addLogicalLayerInternal(e, n);
920
+ }
921
+ let { beforeLayerId: o, afterLayerId: s, fallbackLayer: c, fallbackLayerId: l, fallbackRef: u, fallback: d, ...f } = t;
922
+ return this.addInlineLayerWithTracking(e, f, n);
923
+ }
924
+ async getLayerInformationFromStyleRequest(e) {
925
+ let t = this.toRecord(e.style), n = this.resolveStyleUrlFromRequest(e);
926
+ if (!t && !n) return null;
927
+ let r = this.toRecord(e.metadata) ?? {}, i = typeof e.id == "string" && e.id.length > 0 ? e.id : `runtime-style-${++this.runtimeStyleLayerCounter}`;
928
+ return t ? this.buildExpandedStyleLayer({
929
+ id: i,
930
+ type: "style",
931
+ metadata: {
932
+ ...r,
933
+ ...n ? { styleUrl: n } : {}
934
+ }
935
+ }, t, n) : this.expandStyleBackedLayer({
936
+ id: i,
937
+ type: "style",
938
+ metadata: {
939
+ ...r,
940
+ styleUrl: n ?? void 0
941
+ }
942
+ });
943
+ }
944
+ toRecord(e) {
945
+ return typeof e == "object" && e && !Array.isArray(e) ? e : null;
946
+ }
947
+ getLayerMetadata(e) {
948
+ return this.toRecord(e?.metadata);
949
+ }
950
+ isStyleBackedLayer(e) {
951
+ if (e.type !== "style") return !1;
952
+ let t = e;
953
+ return typeof t.url == "string" && t.url.length > 0;
954
+ }
955
+ getConfiguredFallbackLayerId(e) {
956
+ if (typeof e.fallbackLayerId == "string" && e.fallbackLayerId.length > 0) return e.fallbackLayerId;
957
+ let t = this.getLayerMetadata(e)?.fallbackLayerId;
958
+ return typeof t == "string" && t.length > 0 ? t : null;
959
+ }
960
+ isSourceTypeSupportedByActiveEngine(e) {
961
+ let t = this.activeAdapterName;
962
+ return t === "leaflet" || t === "cesium" ? e === "raster" || e === "geojson" : t === "maplibre" || t === "openlayers" ? e === "raster" || e === "geojson" || e === "vector" || e === "raster-dem" : !1;
963
+ }
964
+ isSourceSupportedByActiveEngine(e) {
965
+ let t = typeof e?.type == "string" ? e.type : null;
966
+ if (!t || !this.isSourceTypeSupportedByActiveEngine(t)) return !1;
967
+ if (this.activeAdapterName === "cesium" && t === "raster") {
968
+ let t = e, n = Array.isArray(t.url) ? t.url[0] : t.url;
969
+ if (typeof n == "string" && n.startsWith("warpedmap://")) return !1;
970
+ }
971
+ return !0;
972
+ }
973
+ hasUnsupportedStyleComponents(e) {
974
+ let t = e.layer;
975
+ if (t.type === "allmaps") return this.activeAdapterName === "cesium";
976
+ if (t.type === "style") {
977
+ let e = t, n = e.sources ?? {}, r = /* @__PURE__ */ new Set();
978
+ for (let e of Object.values(n)) if (typeof e == "object" && e) {
979
+ let t = e.type;
980
+ typeof t == "string" && r.add(t);
981
+ }
982
+ let i = e.layers ?? [];
983
+ for (let e of i) {
984
+ let t = typeof e?.source == "string" ? e.source : null;
985
+ if (!t || t in n) continue;
986
+ let i = this.layerDataConfig?.sources?.find((e) => e.id === t);
987
+ i && typeof i.type == "string" && r.add(i.type);
988
+ }
989
+ return r.size === 0 ? !1 : Array.from(r).some((e) => !this.isSourceTypeSupportedByActiveEngine(e));
990
+ }
991
+ let n = t.source;
992
+ if (!n) return !1;
993
+ let r = this.layerDataConfig?.sources?.find((e) => e.id === n) ?? null;
994
+ return r ? !this.isSourceSupportedByActiveEngine(r) : !1;
995
+ }
996
+ async isCatalogLayerSupported(e) {
997
+ let t = this.getConfiguredLayerInformation(e);
998
+ if (!t) return !1;
999
+ let n = t.layer.metadata?.supportedEngines;
1000
+ if (n) return n.includes(this.activeAdapterName);
1001
+ if (!this.isStyleBackedLayer(t.layer)) return !this.hasUnsupportedStyleComponents(t);
1002
+ let r = await this.expandStyleBackedLayer(t.layer);
1003
+ return r ? !this.hasUnsupportedStyleComponents(r) : !1;
1004
+ }
1005
+ async addLogicalLayerInternal(e, t, n) {
1006
+ let r = P(t.layer, this.layerDataConfig?.sources), i = [];
1007
+ r.sources && typeof r.sources == "object" && (i = await O(r.sources));
1008
+ let a = r, o = a.metadata && typeof a.metadata == "object" ? a.metadata : void 0;
1009
+ if (!o?.bounds && typeof a.source == "string") {
1010
+ let e = this.layerDataConfig?.sources?.find((e) => e.id === a.source);
1011
+ e?.bounds && (a.metadata = {
1012
+ ...o ?? {},
1013
+ bounds: e.bounds
1014
+ });
1015
+ }
1016
+ let s;
1017
+ try {
1018
+ s = await e.addLayer(a, n);
1019
+ } catch {
1020
+ return !1;
1021
+ }
1022
+ if (s) {
1023
+ let t = (a.metadata && typeof a.metadata == "object" ? a.metadata : {}).legendRole === "background" ? "background" : "overlay";
1024
+ this.logicalLayerRole.set(a.id, t), this.insertIntoLogicalOrder(a.id, n);
1025
+ for (let t of i) t.run((n) => {
1026
+ let r = e.getSource(t.id);
1027
+ return r ? (r.setData(n), !0) : !1;
1028
+ });
1029
+ }
1030
+ return s;
1031
+ }
1032
+ async addInlineLayerWithTracking(e, t, n) {
1033
+ let r = [];
1034
+ t.sources && typeof t.sources == "object" && (r = await O(t.sources));
1035
+ let i = (t.metadata && typeof t.metadata == "object" ? t.metadata : {}).legendRole === "background" ? "background" : "overlay", a = this.computeInsertOptionsForLayer(i, n);
1036
+ await e.addLayer(t, a && Object.keys(a).length > 0 ? a : void 0);
1037
+ let o = typeof t.id == "string" ? t.id : null;
1038
+ o && (this.logicalLayerRole.set(o, i), this.insertIntoLogicalOrder(o, a));
1039
+ for (let t of r) t.run((n) => {
1040
+ let r = e.getSource(t.id);
1041
+ return r ? (r.setData(n), !0) : !1;
1042
+ });
1043
+ return !0;
1044
+ }
1045
+ async applyInitialStateLayers(e, t) {
1046
+ let n = this.collectInitialActiveLayerRefs();
1047
+ for (let t of n) await this.tryAddLayerRequest(e, { layerId: t }) || this.dispatchEvent(new CustomEvent("webmapx-addlayer-failed", {
1048
+ detail: { layerId: t },
1049
+ bubbles: !0,
1050
+ composed: !0
1051
+ }));
1052
+ await this.restoreState(), await this.applyPermalinkState(e);
1053
+ }
1054
+ async applyPermalinkState(e) {
1055
+ let t = S(y(this));
1056
+ if (!t) return;
1057
+ if (t.h && t.h.length > 0) {
1058
+ new Set(t.h);
1059
+ let n = e.store.getState().mapLayers ?? {}, r = { ...n };
1060
+ for (let i of t.h) n[i] && (e.setLayerVisibility(i, !1), r[i] = {
1061
+ ...n[i],
1062
+ visible: !1
1063
+ });
1064
+ e.store.dispatch({ mapLayers: r }, "UI");
1065
+ }
1066
+ if (t.t) {
1067
+ let n = e.store.getState().mapLayers ?? {}, r = { ...n };
1068
+ for (let [i, a] of Object.entries(t.t)) {
1069
+ let t = n[i];
1070
+ t && (e.setLayerOpacity(i, (100 - a) / 100), r[i] = {
1071
+ ...t,
1072
+ transparency: a
1073
+ });
1074
+ }
1075
+ e.store.dispatch({ mapLayers: r }, "UI");
1076
+ }
1077
+ let n = e.store.getState().mapLayers ?? {}, r = t.l.filter((e) => !n[e]);
1078
+ r.length > 0 && this.showPermalinkMissingLayersToast(r);
1079
+ }
1080
+ showPermalinkMissingLayersToast(e) {
1081
+ let n = e.length;
1082
+ t(`<strong>${n} layer${n > 1 ? "s" : ""} from the permalink could not be restored</strong><br>
1083
+ Layers may have been imported from files (not stored in permalink) or the map config may have changed:<br>
1084
+ <em>${e.join(", ")}</em>`, {
1085
+ variant: "warning",
1086
+ duration: 16e3
1087
+ });
1088
+ }
1089
+ toLayerInformation(e) {
1090
+ let t = this.toRecord(e), n = this.toRecord(t?.layer);
1091
+ if (!n) return null;
1092
+ let r = typeof n.id == "string" ? n.id : null, i = typeof n.type == "string" ? n.type : null;
1093
+ return !r || !i ? null : { layer: n };
1094
+ }
1095
+ isSubLayerSpec(e) {
1096
+ let t = this.toRecord(e);
1097
+ return !!t && typeof t.type == "string";
1098
+ }
1099
+ isSourceConfig(e) {
1100
+ let t = this.toRecord(e);
1101
+ return !!t && typeof t.id == "string" && typeof t.type == "string";
1102
+ }
1103
+ };
1104
+ customElements.get("webmapx-map") || customElements.define("webmapx-map", R);
1105
+ //#endregion
1106
+ //#region src/components/internal/map-context.ts
1107
+ function z(e, t) {
1108
+ try {
1109
+ let n = e.querySelector(t);
1110
+ return n instanceof R ? n : null;
1111
+ } catch (e) {
1112
+ return console.error(`[webmapx] Invalid selector "${t}" provided via map attribute.`, e), null;
1113
+ }
1114
+ }
1115
+ function B(e) {
1116
+ let t = e.getAttribute("map");
1117
+ if (t) {
1118
+ let n = z(e.ownerDocument ?? document, t);
1119
+ return n || console.error(`[webmapx] No <webmapx-map> found for selector "${t}" on ${e.tagName.toLowerCase()}.`), n;
1120
+ }
1121
+ let n = e.closest("webmapx-map");
1122
+ if (n instanceof R) return n;
1123
+ let r = (e.ownerDocument ?? document).querySelectorAll("webmapx-map");
1124
+ return r.length === 1 && r[0] instanceof R ? r[0] : r.length > 1 ? (console.error(`[webmapx] Multiple <webmapx-map> elements found for ${e.tagName.toLowerCase()}. Set a "map" attribute with an explicit selector.`), null) : (console.error(`[webmapx] Unable to locate a <webmapx-map> for ${e.tagName.toLowerCase()}.`), null);
1125
+ }
1126
+ function V(e) {
1127
+ let t = B(e);
1128
+ return t ? t.adapter : null;
1129
+ }
1130
+ //#endregion
1131
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
1132
+ function H(e, t, n, r) {
1133
+ var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
1134
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
1135
+ else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
1136
+ return i > 3 && a && Object.defineProperty(t, n, a), a;
1137
+ }
1138
+ //#endregion
1139
+ export { v as a, s as c, a as d, C as i, l, V as n, y as o, B as r, c as s, H as t, r as u };