@yappkit/front-module-map 0.1.8 → 0.2.1

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.
@@ -1,729 +1,60 @@
1
- import { defineComponent as w, ref as f, toRefs as y, shallowRef as v, provide as g, watch as d, h as M, inject as L, onMounted as b, onUnmounted as k, nextTick as O, toRaw as x, computed as E } from "vue";
2
- import { lineString as K, length as P, along as j, point as G } from "@turf/turf";
3
- class T {
4
- constructor({ unwatchFn: e }) {
5
- this.overlay = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = e;
6
- }
7
- watchOptions(e, a = {}) {
8
- if (!this.overlay)
9
- throw new Error("overlay should be set");
10
- if (this.watching.options) {
11
- console.warn("No need to call MapboxDeckGLOverlay.watchOptions(). options are already being watched");
12
- return;
13
- }
14
- this.watching.options = !0;
15
- const t = d(e, () => {
16
- this.overlay.setProps({ ...e.value });
17
- }, {
18
- immediate: !0,
19
- deep: !0,
20
- ...a
21
- });
22
- this.unwatchFn.push(t);
23
- }
24
- watchLayers(e, a = {}) {
25
- if (!this.overlay)
26
- throw new Error("overlay should be set");
27
- if (this.watching.layers) {
28
- console.warn("No need to call MapboxDeckGLOverlay.watchLayers(). layers are already being watched");
29
- return;
30
- }
31
- this.watching.layers = !0;
32
- const t = d(e, () => {
33
- this.overlay.setProps({ layers: e.value });
34
- }, {
35
- immediate: !0,
36
- ...a
37
- });
38
- this.unwatchFn.push(t);
39
- }
40
- }
41
- class N {
42
- constructor() {
43
- this.map = null, this.watching = { sources: !1, layers: !1 }, this.unwatchFn = [];
44
- }
45
- watchSources(e, a = {}) {
46
- if (!this.map)
47
- throw new Error("map should be set");
48
- if (this.watching.sources) {
49
- console.warn("No need to call MapboxMap.watchSources(). sources are already being watched");
50
- return;
51
- }
52
- this.watching.sources = !0;
53
- const t = d(() => (e.value || []).map((r) => {
54
- if (!r.propsId) {
55
- const { data: s, ...o } = r;
56
- r.propsId = JSON.stringify(o);
57
- }
58
- return r;
59
- }), async (r, s) => {
60
- const o = s || [], n = r || [], i = n.filter((c, u) => {
61
- var m;
62
- return c !== o[u] && c.propsId === ((m = o[u]) == null ? void 0 : m.propsId);
63
- }), p = n.filter((c, u) => c !== o[u] && !i.find((m) => m.id === c.id)), l = o.filter((c, u) => c !== n[u] && !i.find((m) => m.id === c.id));
64
- for (const c of i)
65
- this.map.getSource(c.id).setData(c.data);
66
- await O();
67
- for (const c of l)
68
- this.map.removeSource(c.id);
69
- for (const c of p) {
70
- const u = { ...c };
71
- delete u.id, delete u.propsId, this.map.addSource(c.id, u);
72
- }
73
- }, {
74
- immediate: !0,
75
- ...a
76
- });
77
- this.unwatchFn.push(t);
78
- }
79
- watchLayers(e, a = {}) {
80
- if (!this.map)
81
- throw new Error("map should be set");
82
- if (this.watching.layers) {
83
- console.warn("No need to call MapboxMap.watchLayers(). layers are already being watched");
84
- return;
85
- }
86
- this.watching.layers = !0;
87
- const t = d(e, async (r, s) => {
88
- const o = s || [], n = r || [], i = n.filter((l, c) => l !== o[c]), p = o.filter((l, c) => l !== n[c]);
89
- for (const l of p)
90
- this.map.removeLayer(l.id), this.map.getSource(l.id) && this.map.removeSource(l.id);
91
- await O();
92
- for (const l of i)
93
- this.map.addLayer(l);
94
- }, {
95
- immediate: !0,
96
- ...a
97
- });
98
- this.unwatchFn.push(t);
99
- }
100
- async setDeckGLOverlay(e = {}) {
101
- if (!this.map)
102
- throw new Error("map should be set");
103
- const { MapboxOverlay: a } = await import("@deck.gl/mapbox"), t = new T({ unwatchFn: this.unwatchFn });
104
- return t.overlay = new a(e), this.map.addControl(t.overlay), t;
105
- }
106
- }
107
- class A {
108
- constructor(e) {
109
- if (this.apiKey = e.apiKey, !this.apiKey)
110
- throw new Error("apiKey is required");
111
- this.services = [...e.services || []], this.sdk = {}, this.mapboxgl = null, this.getSDK();
112
- }
113
- get Map() {
114
- return w(
115
- (e, { emit: a, slots: t }) => {
116
- const r = f(null), { options: s, layers: o, sources: n } = y(e), i = v(null);
117
- return g("mapboxMap", i), this.createMap(r, s.value).then((p) => {
118
- i.value = p, d(s, () => {
119
- console.error("Cannot update options (missing function similar to deckglMap.setProps()). Use SDK dedicated functions instead");
120
- }, { once: !0 }), p.watchSources(n, s.value.watchSourcesOptions), p.watchLayers(o, s.value.watchLayersOptions), a("loaded", p);
121
- }), () => M("div", { ref: r }, i.value ? t : []);
122
- },
123
- {
124
- props: {
125
- options: {
126
- type: Object,
127
- default: () => ({})
128
- },
129
- layers: {
130
- type: Array,
131
- default: () => []
132
- },
133
- sources: {
134
- type: Array,
135
- default: () => []
136
- }
137
- },
138
- emits: ["loaded"]
139
- }
140
- );
141
- }
142
- get DeckGLOverlay() {
143
- return w(
144
- (e, { emit: a, slots: t }) => {
145
- const { options: r, layers: s } = y(e), o = L("mapboxMap");
146
- if (!o || !o.value)
147
- throw new Error("map should exist");
148
- return o.value.setDeckGLOverlay(r.value).then((n) => {
149
- n.watchOptions(r, r.value.watchOptionsOptions), n.watchLayers(s, r.value.watchLayersOptions), a("loaded", n);
150
- }), () => {
151
- };
152
- },
153
- {
154
- props: {
155
- options: {
156
- type: Object,
157
- default: () => ({})
158
- },
159
- layers: {
160
- type: Array,
161
- default: () => []
162
- }
163
- },
164
- emits: ["loaded"]
165
- }
166
- );
167
- }
168
- async loadMapbox() {
169
- if (!this.mapboxgl) {
170
- const e = await import("./mapbox-gl.js").then((a) => a.mapboxGl);
171
- this.mapboxgl = e;
172
- }
173
- }
174
- get servicesLoader() {
175
- return {
176
- datasets: () => import("@mapbox/mapbox-sdk/services/datasets.js"),
177
- directions: () => import("@mapbox/mapbox-sdk/services/directions.js"),
178
- geocoding: () => import("@mapbox/mapbox-sdk/services/geocoding.js"),
179
- geocodingV6: () => import("@mapbox/mapbox-sdk/services/geocoding-v6.js"),
180
- mapMatching: () => import("@mapbox/mapbox-sdk/services/map-matching.js"),
181
- matrix: () => import("@mapbox/mapbox-sdk/services/matrix.js"),
182
- optimization: () => import("@mapbox/mapbox-sdk/services/optimization.js"),
183
- static: () => import("@mapbox/mapbox-sdk/services/static.js"),
184
- styles: () => import("@mapbox/mapbox-sdk/services/styles.js"),
185
- tilequery: () => import("@mapbox/mapbox-sdk/services/tilequery.js"),
186
- tilesets: () => import("@mapbox/mapbox-sdk/services/tilesets.js"),
187
- tokens: () => import("@mapbox/mapbox-sdk/services/tokens.js"),
188
- uploads: () => import("@mapbox/mapbox-sdk/services/uploads.js"),
189
- isochrone: () => import("@mapbox/mapbox-sdk/services/isochrone.js")
190
- };
191
- }
192
- async loadMapboxSDK({ services: e = [] } = {}) {
193
- const t = (await import("@mapbox/mapbox-sdk")).default({ accessToken: this.apiKey }), r = [.../* @__PURE__ */ new Set([...this.services, ...e])];
194
- this.services = r;
195
- const s = await Promise.all(this.services.map((o) => this.sdk[o] || this.servicesLoader[o]().then((n) => n.default(t))));
196
- for (const [o, n] of this.services.entries())
197
- this.sdk[n] = s[o];
198
- }
199
- async getSDK(e) {
200
- let a = {};
201
- if (typeof e == "string" ? a.services = [e] : a = { ...e }, await this.loadMapboxSDK(a), typeof e == "string") {
202
- if (!this.sdk[e])
203
- throw new Error(e + " service is not loaded");
204
- return this.sdk[e];
205
- }
206
- return this.sdk;
207
- }
208
- async createMap(e, a = {}) {
209
- const t = new N(), r = () => {
210
- for (const s of t.unwatchFn)
211
- s();
212
- t.unwatchFn = [], t.map && (t.map.remove(), t.map = null);
213
- };
214
- return new Promise((s, o) => {
215
- b(async () => {
216
- await this.loadMapbox();
217
- const n = () => {
218
- if (!e.value)
219
- throw new Error("Missing HTML element");
220
- const i = d(e, () => {
221
- e.value || (r(), i());
222
- });
223
- t.map = new this.mapboxgl.Map({
224
- container: e.value,
225
- accessToken: this.apiKey,
226
- ...a
227
- }), t.map.on("load", () => {
228
- s(t);
229
- });
230
- };
231
- a.onMounted ? a.onMounted(n) : n();
232
- }), k(() => {
233
- r();
234
- });
235
- });
236
- }
237
- }
238
- class C {
239
- constructor({ unwatchFn: e }) {
240
- this.overlay = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = e;
241
- }
242
- watchOptions(e, a = {}) {
243
- if (!this.overlay)
244
- throw new Error("overlay should be set");
245
- if (this.watching.options) {
246
- console.warn("No need to call GoogleMapsDeckGLOverlay.watchOptions(). options are already being watched");
247
- return;
248
- }
249
- this.watching.options = !0;
250
- const t = d(e, () => {
251
- this.overlay.setProps({ ...e.value });
252
- }, {
253
- immediate: !0,
254
- deep: !0,
255
- ...a
256
- });
257
- this.unwatchFn.push(t);
258
- }
259
- watchLayers(e, a = {}) {
260
- if (!this.overlay)
261
- throw new Error("overlay should be set");
262
- if (this.watching.layers) {
263
- console.warn("No need to call GoogleMapsDeckGLOverlay.watchLayers(). layers are already being watched");
264
- return;
265
- }
266
- this.watching.layers = !0;
267
- const t = d(e, () => {
268
- this.overlay.setProps({ layers: e.value });
269
- }, {
270
- immediate: !0,
271
- ...a
272
- });
273
- this.unwatchFn.push(t);
274
- }
275
- }
276
- class V {
277
- constructor() {
278
- this.map = null, this.unwatchFn = [];
279
- }
280
- async setDeckGLOverlay(e = {}) {
281
- if (!this.map)
282
- throw new Error("map should be set");
283
- const { GoogleMapsOverlay: a } = await import("@deck.gl/google-maps"), t = new C({ unwatchFn: this.unwatchFn });
284
- return t.overlay = new a(e), t.overlay.setMap(this.map), t;
285
- }
286
- }
287
- class I {
288
- constructor() {
289
- this.map = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = [];
290
- }
291
- _getSetters(e) {
292
- const a = [], t = { ...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(e)) };
293
- for (const [r, s] of Object.entries(t))
294
- s.enumerable && a.push(r);
295
- return a;
296
- }
297
- _getOptions(e) {
298
- const a = {}, t = this._getSetters(e);
299
- for (const r of t) {
300
- let s = e[r];
301
- e[r] instanceof Object && (s = this._getOptions(e[r])), a[r] = s;
302
- }
303
- return a;
304
- }
305
- setProps(e = {}) {
306
- for (const [a, t] of Object.entries(e))
307
- this.map[a] = t;
308
- }
309
- getProps() {
310
- return this._getOptions(this.map);
311
- }
312
- getLayer(e) {
313
- if (!this.map)
314
- throw new Error("map should be set");
315
- return this.map.children.namedItem(e);
316
- }
317
- watchOptions(e, a = {}) {
318
- if (!this.map)
319
- throw new Error("map should be set");
320
- if (this.watching.options) {
321
- console.warn("No need to call GoogleMapsMap3D.watchOptions(). options are already being watched");
322
- return;
323
- }
324
- this.watching.options = !0;
325
- let t = {};
326
- const r = d(e, async () => {
327
- await O();
328
- const s = x(e.value);
329
- for (const [o, n] of Object.entries(s))
330
- JSON.stringify(n) !== JSON.stringify(t[o]) && (this.map[o] = n);
331
- t = structuredClone(s);
332
- }, {
333
- immediate: !0,
334
- deep: !0,
335
- ...a
336
- });
337
- this.unwatchFn.push(r);
338
- }
339
- watchLayers(e, a = {}) {
340
- if (!this.map)
341
- throw new Error("map should be set");
342
- if (this.watching.layers) {
343
- console.warn("No need to call GoogleMapsMap3D.watchLayers(). layers are already being watched");
344
- return;
345
- }
346
- this.watching.layers = !0;
347
- const t = d(e, async (r, s) => {
348
- const o = s || [], n = r || [], i = n.filter((l, c) => l !== o[c]), p = o.filter((l, c) => l !== n[c]);
349
- await O();
350
- for (const l of p)
351
- this.map.children.namedItem(l.id).remove();
352
- for (const l of i)
353
- l.element.setAttribute("name", l.id), this.map.appendChild(l.element);
354
- }, {
355
- immediate: !0,
356
- ...a
357
- });
358
- this.unwatchFn.push(t);
359
- }
360
- }
361
- class S {
362
- constructor(e) {
363
- if (this.apiKey = e.apiKey, !this.apiKey)
364
- throw new Error("apiKey is required");
365
- this.libraries = [...e.libraries || []], this.version = e.version || "weekly", this.loader = null, this.sdk = {}, this.deckgl = null, this.getSDK();
366
- }
367
- get Map() {
368
- return w(
369
- (e, { emit: a, slots: t }) => {
370
- const r = f(null), { options: s } = y(e), o = v(null);
371
- return g("googleMapsMap", o), this.createMap(r, s.value).then((n) => {
372
- o.value = n, d(s, () => {
373
- console.error("Cannot update options (missing function similar to deckglMap.setProps()). Use SDK dedicated functions instead");
374
- }, { once: !0 }), a("loaded", n);
375
- }), () => M("div", { ref: r }, o.value ? t : []);
376
- },
377
- {
378
- props: {
379
- options: {
380
- type: Object,
381
- default: () => ({})
382
- }
383
- },
384
- emits: ["loaded"]
385
- }
386
- );
387
- }
388
- get Map3D() {
389
- return w(
390
- (e, { emit: a, attrs: t, slots: r }) => {
391
- const s = f(null), { options: o, layers: n } = y(e), i = v(null);
392
- return g("googleMapsMap3D", i), this.createMap3D(s, o.value).then((p) => {
393
- i.value = p, p.watchOptions(o, o.value.watchOptionsOptions), p.watchLayers(n, o.value.watchLayersOptions), a("loaded", p);
394
- }), () => M("div", { ref: s }, i.value ? r : []);
395
- },
396
- {
397
- props: {
398
- options: {
399
- type: Object,
400
- default: () => ({})
401
- },
402
- layers: {
403
- type: Array,
404
- default: () => []
405
- }
406
- },
407
- emits: ["loaded"]
408
- }
409
- );
410
- }
411
- get DeckGLOverlay() {
412
- return w(
413
- (e, { emit: a, slots: t }) => {
414
- const { options: r, layers: s } = y(e), o = L("googleMapsMap");
415
- if (!o || !o.value)
416
- throw new Error("map should exist");
417
- return o.value.setDeckGLOverlay(r.value).then((n) => {
418
- n.watchOptions(r, r.value.watchOptionsOptions), n.watchLayers(s, r.value.watchLayersOptions), a("loaded", n);
419
- }), () => {
420
- };
421
- },
422
- {
423
- props: {
424
- options: {
425
- type: Object,
426
- default: () => ({})
427
- },
428
- layers: {
429
- type: Array,
430
- default: () => []
431
- }
432
- },
433
- emits: ["loaded"]
434
- }
435
- );
436
- }
437
- get DeckGL3DTileLayer() {
438
- return w(
439
- (e, { emit: a, slots: t }) => {
440
- const { options: r } = y(e), s = L("deckGLPrependLayers");
441
- if (!s || !s.value)
442
- throw new Error("deckGLPrependLayers should exist");
443
- const o = f("");
444
- this.createDeckGL3DTileLayer(o, r.value).then((i) => {
445
- d(r, () => {
446
- console.error("Cannot update options on DeckGL layer. Replace layer instead");
447
- }, { once: !0 }), s.value = [
448
- ...s.value,
449
- i
450
- ];
451
- });
452
- const n = L("deckGLAppendVNodeFn");
453
- if (!n)
454
- throw new Error("deckGLAppendVNodeFn should exist");
455
- return t.appendMap && n.value.push(() => t.appendMap({ credits: o.value })), () => {
456
- };
457
- },
458
- {
459
- props: {
460
- options: {
461
- type: Object,
462
- default: () => ({})
463
- }
464
- }
465
- }
466
- );
467
- }
468
- async loadGoogleMapsSDK({ libraries: e = [] } = {}) {
469
- const { Loader: a } = await import("@googlemaps/js-api-loader"), t = [.../* @__PURE__ */ new Set([...this.libraries, ...e])];
470
- this.libraries.length === t.length && this.libraries.every((s) => t.includes(s)) || console.error("GoogleMaps Loader does not allow loading one library after the other. Set libraries option on a single googleMaps config"), this.libraries = t, this.loader = new a({
471
- apiKey: this.apiKey,
472
- version: this.version,
473
- libraries: this.libraries
474
- });
475
- const r = await Promise.all(this.libraries.map((s) => this.sdk[s] || this.loader.importLibrary(s)));
476
- for (const [s, o] of this.libraries.entries())
477
- this.sdk[o] = r[s];
478
- }
479
- async getSDK(e) {
480
- let a = {};
481
- if (typeof e == "string" ? a.libraries = [e] : a = { ...e }, await this.loadGoogleMapsSDK(a), typeof e == "string") {
482
- if (!this.sdk[e] || !Object.keys(this.sdk[e]).length)
483
- throw new Error(`${e} library is not loaded${e === "maps3d" ? ". Missing version: 'alpha' or apiKey not authorized?" : ""}`);
484
- return this.sdk[e];
485
- }
486
- return this.sdk;
487
- }
488
- async createMap(e, a = {}) {
489
- const t = new V(), r = () => {
490
- for (const s of t.unwatchFn)
491
- s();
492
- t.unwatchFn = [], t.map && (t.map = null);
493
- };
494
- return new Promise((s, o) => {
495
- b(async () => {
496
- await this.getSDK("maps");
497
- const n = () => {
498
- if (!e.value)
499
- throw new Error("Missing HTML element");
500
- const i = d(e, () => {
501
- e.value || (r(), i());
502
- });
503
- t.map = new this.sdk.maps.Map(e.value, {
504
- ...a
505
- }), s(t);
506
- };
507
- a.onMounted ? a.onMounted(n) : n();
508
- }), k(() => {
509
- r();
510
- });
511
- });
512
- }
513
- async createMap3D(e, a = {}) {
514
- const t = new I(), r = () => {
515
- for (const s of t.unwatchFn)
516
- s();
517
- t.unwatchFn = [], t.map && (t.map = null);
518
- };
519
- return new Promise((s, o) => {
520
- b(async () => {
521
- await this.getSDK("maps3d");
522
- const n = () => {
523
- if (!e.value)
524
- throw new Error("Missing HTML element");
525
- const i = d(e, () => {
526
- e.value || (r(), i());
527
- });
528
- t.map = new this.sdk.maps3d.Map3DElement({
529
- ...a
530
- }), e.value.appendChild(t.map), s(t);
531
- };
532
- a.onMounted ? a.onMounted(n) : n();
533
- }), k(() => {
534
- r();
535
- });
536
- });
537
- }
538
- async loadDeckGL() {
539
- const { Tile3DLayer: e } = await import("deck.gl");
540
- this.deckgl = { Tile3DLayer: e };
541
- }
542
- async createDeckGL3DTileLayer(e, a = {}) {
543
- return await (this.deckgl ? Promise.resolve() : this.loadDeckGL()), new this.deckgl.Tile3DLayer({
544
- id: "google-3d-tiles",
545
- data: "https://tile.googleapis.com/v1/3dtiles/root.json",
546
- loadOptions: {
547
- fetch: {
548
- headers: {
549
- "X-GOOG-API-KEY": this.apiKey
550
- }
551
- }
552
- },
553
- onTilesetLoad: (t) => {
554
- e && (t.options.onTraversalComplete = (r) => {
555
- const s = /* @__PURE__ */ new Set();
556
- return r.forEach((o) => {
557
- const { copyright: n } = o.content.gltf.asset;
558
- n.split(";").forEach(s.add, s), e.value = [...s].join("; ");
559
- }), r;
560
- });
561
- },
562
- operation: "terrain+draw",
563
- ...a
564
- });
565
- }
566
- }
567
- class _ {
568
- constructor() {
569
- this.deckgl = null, this.map = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = [];
570
- }
571
- watchOptions(e, a = {}) {
572
- if (!this.map)
573
- throw new Error("map should be set");
574
- if (this.watching.options) {
575
- console.warn("No need to call DeckGLMap.watchOptions(). options are already being watched");
576
- return;
577
- }
578
- this.watching.options = !0;
579
- const t = d(e, () => {
580
- this.map.setProps({ ...e.value });
581
- }, {
582
- immediate: !0,
583
- deep: !0,
584
- ...a
585
- });
586
- this.unwatchFn.push(t);
587
- }
588
- watchLayers(e, a = {}) {
589
- if (!this.map)
590
- throw new Error("map should be set");
591
- if (this.watching.layers) {
592
- console.warn("No need to call DeckGLMap.watchLayers(). layers are already being watched");
593
- return;
594
- }
595
- this.watching.layers = !0;
596
- const t = d(e, () => {
597
- this.map.setProps({ layers: e.value });
598
- }, {
599
- immediate: !0,
600
- ...a
601
- });
602
- this.unwatchFn.push(t);
603
- }
604
- }
605
- class F {
606
- constructor(e) {
607
- this.deckgl = null;
608
- }
609
- get Map() {
610
- return w(
611
- (e, { emit: a, attrs: t, slots: r }) => {
612
- const s = f(null), { options: o, layers: n } = y(e), i = v(null);
613
- g("deckGLMap", i);
614
- const p = v([]);
615
- g("deckGLPrependLayers", p);
616
- const l = E(() => [
617
- ...p.value,
618
- ...n.value
619
- ]);
620
- this.createMap(s, o.value).then((u) => {
621
- i.value = u, u.watchOptions(o, o.value.watchOptionsOptions), u.watchLayers(l, o.value.watchLayersOptions), a("loaded", u);
622
- });
623
- const c = f([]);
624
- return g("deckGLAppendVNodeFn", c), () => [M("div", { ...t, ref: s }, i.value ? r : []), c.value.map((u) => u())];
625
- },
626
- {
627
- props: {
628
- options: {
629
- type: Object,
630
- default: () => ({})
631
- },
632
- layers: {
633
- type: Array,
634
- default: () => []
635
- }
636
- },
637
- emits: ["loaded"]
638
- }
639
- );
640
- }
641
- async loadDeckGL() {
642
- if (!this.deckgl) {
643
- const { Deck: e } = await import("deck.gl");
644
- this.deckgl = { Deck: e };
645
- }
646
- }
647
- async createMap(e, a = {}) {
648
- const t = new _(), r = () => {
649
- for (const s of t.unwatchFn)
650
- s();
651
- t.unwatchFn = [], t.map && (t.map.finalize(), t.map = null);
652
- };
653
- return new Promise((s, o) => {
654
- b(async () => {
655
- await this.loadDeckGL();
656
- const n = () => {
657
- if (!e.value)
658
- throw new Error("Missing HTML element");
659
- const i = d(e, () => {
660
- e.value || (r(), i());
661
- });
662
- t.deckgl = this.deckgl, t.map = new this.deckgl.Deck({
663
- parent: e.value,
664
- ...a
665
- }), s(t);
666
- };
667
- a.onMounted ? a.onMounted(n) : n();
668
- }), k(() => {
669
- r();
670
- });
671
- });
672
- }
673
- }
674
- function D(h) {
675
- let e = 0;
676
- return h.map((a) => {
677
- let t = a[0];
678
- return t - e > 180 ? t += -360 : e - t > 180 ? t += 360 : t += 0, e = t, [t, a[1]];
679
- });
680
- }
681
- function z({ origin: h, destination: e, step: a = 100 }) {
682
- const t = K([h, e]), r = P(t), s = [];
683
- for (let o = 0; o < r; o += r / a) {
684
- const n = j(t, o);
685
- s.push(n.geometry.coordinates);
686
- }
687
- return s.push(e), t.geometry.coordinates = D(s), t;
688
- }
689
- async function H({ origin: h, destination: e, includeBoundaries: a = !1 }) {
690
- const t = (await import("./searoute.js")).default, r = t(G(h), G(e));
691
- return a && (r.geometry.coordinates.unshift(h), r.geometry.coordinates.push(e)), r.geometry.coordinates = D(r.geometry.coordinates), r;
692
- }
693
- const R = {
694
- getAirRoute: z,
695
- getWaterRoute: H,
696
- normalizeRoute: D
697
- }, U = {
698
- mapbox: A,
699
- google: S,
700
- "google-maps": S,
701
- deckgl: F,
702
- "deck-gl": F
703
- };
704
- class q {
705
- constructor(e = {}) {
706
- this.options = { ...e };
707
- }
708
- install(e, a) {
709
- const t = {};
710
- for (const [r, s] of Object.entries(e.config.maps || {})) {
711
- if (!s.type)
712
- throw new Error("Map type should be defined");
713
- const o = U[s.type];
714
- o ? t[r] = new o(s) : console.warn(`Map provider: ${s.type} is not supported`);
715
- }
716
- return e.maps = t, e.map = t, this.yAppKit = e, {
717
- // onBeforeSetup,
718
- // onAfterSetup,
719
- // options
720
- };
721
- }
722
- }
723
- const W = (h) => new q(h);
724
- export {
725
- q as default,
726
- W as loadMapModule,
727
- U as mapProviders,
728
- R as utils
729
- };
1
+ import e from "./providers/mapbox.js";
2
+ import t from "./providers/maplibre.js";
3
+ import n from "./providers/google-maps.js";
4
+ import r from "./providers/deckgl.js";
5
+ import { isPlainObject as i } from "lodash-es";
6
+ import { along as a, length as o, lineString as s, point as c } from "@turf/turf";
7
+ function l(e) {
8
+ let t = 0, n = e.map((e) => {
9
+ let n = e[0];
10
+ return n - t > 180 ? n += -360 : t - n > 180 && (n += 360), t = n, [n, e[1]];
11
+ }), r = n.filter((e, t) => t === 0 || e[0] !== n[t - 1][0] || e[1] !== n[t - 1][1]);
12
+ return r.length < 2 && n.length >= 2 ? [n[0], n[0]] : r;
13
+ }
14
+ function u({ origin: e, destination: t, step: n = 100, units: r = "nm" }) {
15
+ (!Number.isInteger(n) || n <= 0) && (n = 100);
16
+ let i = s([e, t]), c = o(i);
17
+ if (c === 0) return i.properties.units = r, i.properties.length = 0, i;
18
+ let u = [];
19
+ for (let e = 0; e < n; e++) {
20
+ let t = a(i, e * c / n);
21
+ u.push(t.geometry.coordinates);
22
+ }
23
+ return u.push(t), i.geometry.coordinates = l(u), i.properties.units = r, i.properties.length = o(i, { units: r === "nm" ? "nauticalmiles" : r }), i;
24
+ }
25
+ async function d({ origin: e, destination: t, includeBoundaries: n = !1, units: r = "nm" }) {
26
+ let i = (await import("./searoute.js")).default, a = i(c(e), c(t), r);
27
+ return a == null ? null : (n && (a.geometry.coordinates.unshift(e), a.geometry.coordinates.push(t)), a.geometry.coordinates = l(a.geometry.coordinates), n && (a.properties.length = o(a, { units: a.properties.units === "nm" ? "nauticalmiles" : a.properties.units })), a);
28
+ }
29
+ var f = {
30
+ getAirRoute: u,
31
+ getWaterRoute: d,
32
+ normalizeRoute: l
33
+ }, p = {
34
+ mapbox: e,
35
+ maplibre: t,
36
+ "maplibre-gl": t,
37
+ google: n,
38
+ "google-maps": n,
39
+ deckgl: r,
40
+ "deck-gl": r
41
+ }, m = class {
42
+ install(e) {
43
+ return { onAfterSetup: () => {
44
+ let t = {};
45
+ for (let [n, r] of Object.entries(e.config.maps || {})) if (!i(r)) console.warn(`Map "${n}": config should be an object`);
46
+ else if (!r.type) console.warn(`Map "${n}": type should be defined`);
47
+ else {
48
+ let e = p[r.type];
49
+ if (!e) console.warn(`Map "${n}": provider "${r.type}" is not supported (available: ${Object.keys(p).join(", ")})`);
50
+ else try {
51
+ t[n] = new e(r);
52
+ } catch (e) {
53
+ console.warn(`Map "${n}": ${e.message}`);
54
+ }
55
+ }
56
+ e.maps = t;
57
+ } };
58
+ }
59
+ }, h = () => new m();
60
+ export { m as default, h as loadMapModule, p as mapProviders, f as utils };