@yappkit/front-module-map 0.1.2 → 0.1.4

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