@yappkit/front-module-map 0.1.3 → 0.1.5

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,40 +1,62 @@
1
- import { defineComponent as y, ref as d, toRefs as f, shallowRef as u, provide as c, computed as k, h as L, onMounted as g, onUnmounted as v, watch as M } from "vue";
1
+ import { defineComponent as y, ref as d, toRefs as g, shallowRef as w, provide as l, computed as k, h as v, onMounted as L, onUnmounted as M, watch as h } from "vue";
2
2
  class D {
3
3
  constructor() {
4
- this.deckgl = null, this.map = null, this.watching = { layers: !1 };
4
+ this.deckgl = null, this.map = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = [];
5
5
  }
6
- watchLayers(e, t = {}) {
6
+ watchOptions(e, a = {}) {
7
+ if (!this.map)
8
+ throw new Error("map should be set");
9
+ if (this.watching.options) {
10
+ console.warn("No need to call DeckGLMap.watchOptions(). options are already being watched");
11
+ return;
12
+ }
13
+ this.watching.options = !0;
14
+ const t = h(e, () => {
15
+ this.map.setProps({ ...e.value });
16
+ }, {
17
+ immediate: !0,
18
+ deep: !0,
19
+ ...a
20
+ });
21
+ this.unwatchFn.push(t);
22
+ }
23
+ watchLayers(e, a = {}) {
7
24
  if (!this.map)
8
25
  throw new Error("map should be set");
9
26
  if (this.watching.layers) {
10
27
  console.warn("No need to call DeckGLMap.watchLayers(). layers are already being watched");
11
28
  return;
12
29
  }
13
- this.watching.layers = !0, M(e, () => {
30
+ this.watching.layers = !0;
31
+ const t = h(e, () => {
14
32
  this.map.setProps({ layers: e.value });
15
- }, t);
33
+ }, {
34
+ immediate: !0,
35
+ ...a
36
+ });
37
+ this.unwatchFn.push(t);
16
38
  }
17
39
  }
18
- class P {
40
+ class G {
19
41
  constructor(e) {
20
42
  this.deckgl = null;
21
43
  }
22
44
  get Map() {
23
45
  return y(
24
- (e, { emit: t, attrs: a, slots: s }) => {
25
- const l = d(null), { options: n, layers: m } = f(e), o = u(null);
26
- c("deckGLMap", o);
27
- const i = u([]);
28
- c("deckGLPrependLayers", i);
29
- const w = k(() => [
30
- ...i.value,
31
- ...m.value
46
+ (e, { emit: a, attrs: t, slots: c }) => {
47
+ const n = d(null), { options: o, layers: i } = g(e), r = w(null);
48
+ l("deckGLMap", r);
49
+ const u = w([]);
50
+ l("deckGLPrependLayers", u);
51
+ const f = k(() => [
52
+ ...u.value,
53
+ ...i.value
32
54
  ]);
33
- this.createMap(l, n.value).then((r) => {
34
- o.value = r, r.watchLayers(w, n.value.watchLayersOptions || { immediate: !0 }), t("loaded", r);
55
+ this.createMap(n, o.value).then((s) => {
56
+ r.value = s, s.watchOptions(o, o.value.watchOptionsOptions), s.watchLayers(f, o.value.watchLayersOptions), a("loaded", s);
35
57
  });
36
58
  const p = d([]);
37
- return c("deckGLAppendVNodeFn", p), () => [L("div", { ...a, ref: l }, o.value ? s : []), p.value.map((r) => r())];
59
+ return l("deckGLAppendVNodeFn", p), () => [v("div", { ...t, ref: n }, r.value ? c : []), p.value.map((s) => s())];
38
60
  },
39
61
  {
40
62
  props: {
@@ -46,34 +68,44 @@ class P {
46
68
  type: Array,
47
69
  default: () => []
48
70
  }
49
- }
71
+ },
72
+ emits: ["loaded"]
50
73
  }
51
74
  );
52
75
  }
53
76
  async loadDeckGL() {
54
- const { Deck: e } = await import("deck.gl");
55
- this.deckgl = { Deck: e };
77
+ if (!this.deckgl) {
78
+ const { Deck: e } = await import("deck.gl");
79
+ this.deckgl = { Deck: e };
80
+ }
56
81
  }
57
- async createMap(e, t = {}) {
58
- const a = new D();
59
- return new Promise((s, l) => {
60
- g(async () => {
61
- await (this.deckgl ? Promise.resolve() : this.loadDeckGL());
62
- const n = () => {
82
+ async createMap(e, a = {}) {
83
+ const t = new D(), c = () => {
84
+ for (const n of t.unwatchFn)
85
+ n();
86
+ t.unwatchFn = [], t.map && (t.map.finalize(), t.map = null);
87
+ };
88
+ return new Promise((n, o) => {
89
+ L(async () => {
90
+ await this.loadDeckGL();
91
+ const i = () => {
63
92
  if (!e.value)
64
93
  throw new Error("Missing HTML element");
65
- a.deckgl = this.deckgl, a.map = new this.deckgl.Deck({
94
+ const r = h(e, () => {
95
+ e.value || (c(), r());
96
+ });
97
+ t.deckgl = this.deckgl, t.map = new this.deckgl.Deck({
66
98
  parent: e.value,
67
- ...t
68
- }), s(a);
99
+ ...a
100
+ }), n(t);
69
101
  };
70
- t.onMounted ? t.onMounted(n) : n();
71
- }), v(() => {
72
- a.map && (a.map.finalize(), a.map = null);
102
+ a.onMounted ? a.onMounted(i) : i();
103
+ }), M(() => {
104
+ c();
73
105
  });
74
106
  });
75
107
  }
76
108
  }
77
109
  export {
78
- P as default
110
+ G as default
79
111
  };
@@ -1,44 +1,142 @@
1
- import { defineComponent as l, ref as d, toRefs as n, shallowRef as u, provide as y, h as w, inject as p, onMounted as v, onUnmounted as L, watch as g } from "vue";
2
- class m {
3
- constructor() {
4
- this.overlay = null, this.watching = { layers: !1 };
1
+ import { defineComponent as p, ref as y, toRefs as u, shallowRef as g, provide as m, watch as c, h as v, inject as f, onMounted as L, onUnmounted as M, nextTick as O, toRaw as k } from "vue";
2
+ class b {
3
+ constructor({ unwatchFn: e }) {
4
+ this.overlay = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = e;
5
+ }
6
+ watchOptions(e, s = {}) {
7
+ if (!this.overlay)
8
+ throw new Error("overlay should be set");
9
+ if (this.watching.options) {
10
+ console.warn("No need to call GoogleMapsDeckGLOverlay.watchOptions(). options are already being watched");
11
+ return;
12
+ }
13
+ this.watching.options = !0;
14
+ const t = c(e, () => {
15
+ this.overlay.setProps({ ...e.value });
16
+ }, {
17
+ immediate: !0,
18
+ deep: !0,
19
+ ...s
20
+ });
21
+ this.unwatchFn.push(t);
5
22
  }
6
- watchLayers(e, a = {}) {
23
+ watchLayers(e, s = {}) {
7
24
  if (!this.overlay)
8
25
  throw new Error("overlay should be set");
9
26
  if (this.watching.layers) {
10
27
  console.warn("No need to call GoogleMapsDeckGLOverlay.watchLayers(). layers are already being watched");
11
28
  return;
12
29
  }
13
- this.watching.layers = !0, g(e, () => {
30
+ this.watching.layers = !0;
31
+ const t = c(e, () => {
14
32
  this.overlay.setProps({ layers: e.value });
15
- }, a);
33
+ }, {
34
+ immediate: !0,
35
+ ...s
36
+ });
37
+ this.unwatchFn.push(t);
16
38
  }
17
39
  }
18
- class k {
40
+ class G {
19
41
  constructor() {
20
- this.map = null;
42
+ this.map = null, this.unwatchFn = [];
21
43
  }
22
44
  async setDeckGLOverlay(e = {}) {
23
45
  if (!this.map)
24
46
  throw new Error("map should be set");
25
- const { GoogleMapsOverlay: a } = await import("@deck.gl/google-maps"), t = new m();
26
- return t.overlay = new a(e), t.overlay.setMap(this.map), t;
47
+ const { GoogleMapsOverlay: s } = await import("@deck.gl/google-maps"), t = new b({ unwatchFn: this.unwatchFn });
48
+ return t.overlay = new s(e), t.overlay.setMap(this.map), t;
27
49
  }
28
50
  }
29
- class G {
51
+ class D {
52
+ constructor() {
53
+ this.map = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = [];
54
+ }
55
+ _getSetters(e) {
56
+ const s = [], t = { ...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(e)) };
57
+ for (const [r, a] of Object.entries(t))
58
+ a.enumerable && s.push(r);
59
+ return s;
60
+ }
61
+ _getOptions(e) {
62
+ const s = {}, t = this._getSetters(e);
63
+ for (const r of t) {
64
+ let a = e[r];
65
+ e[r] instanceof Object && (a = this._getOptions(e[r])), s[r] = a;
66
+ }
67
+ return s;
68
+ }
69
+ setProps(e = {}) {
70
+ for (const [s, t] of Object.entries(e))
71
+ this.map[s] = t;
72
+ }
73
+ getProps() {
74
+ return this._getOptions(this.map);
75
+ }
76
+ getLayer(e) {
77
+ if (!this.map)
78
+ throw new Error("map should be set");
79
+ return this.map.children.namedItem(e);
80
+ }
81
+ watchOptions(e, s = {}) {
82
+ if (!this.map)
83
+ throw new Error("map should be set");
84
+ if (this.watching.options) {
85
+ console.warn("No need to call GoogleMapsMap3D.watchOptions(). options are already being watched");
86
+ return;
87
+ }
88
+ this.watching.options = !0;
89
+ let t = {};
90
+ const r = c(e, async () => {
91
+ await O();
92
+ const a = k(e.value);
93
+ for (const [o, n] of Object.entries(a))
94
+ JSON.stringify(n) !== JSON.stringify(t[o]) && (this.map[o] = n);
95
+ t = structuredClone(a);
96
+ }, {
97
+ immediate: !0,
98
+ deep: !0,
99
+ ...s
100
+ });
101
+ this.unwatchFn.push(r);
102
+ }
103
+ watchLayers(e, s = {}) {
104
+ if (!this.map)
105
+ throw new Error("map should be set");
106
+ if (this.watching.layers) {
107
+ console.warn("No need to call GoogleMapsMap3D.watchLayers(). layers are already being watched");
108
+ return;
109
+ }
110
+ this.watching.layers = !0;
111
+ const t = c(e, async (r, a) => {
112
+ const o = a || [], n = r || [], i = n.filter((l, w) => l !== o[w]), h = o.filter((l, w) => l !== n[w]);
113
+ await O();
114
+ for (const l of h)
115
+ this.map.children.namedItem(l.id).remove();
116
+ for (const l of i)
117
+ l.element.setAttribute("name", l.id), this.map.appendChild(l.element);
118
+ }, {
119
+ immediate: !0,
120
+ ...s
121
+ });
122
+ this.unwatchFn.push(t);
123
+ }
124
+ }
125
+ class F {
30
126
  constructor(e) {
31
127
  if (this.apiKey = e.apiKey, !this.apiKey)
32
128
  throw new Error("apiKey is required");
33
- this.libraries = e.libraries || ["maps"], this.version = e.version || "weekly", this.loader = null, this.sdk = {}, this.deckgl = null;
129
+ this.libraries = [...e.libraries || []], this.version = e.version || "weekly", this.loader = null, this.sdk = {}, this.deckgl = null, this.getSDK();
34
130
  }
35
131
  get Map() {
36
- return l(
37
- (e, { emit: a, slots: t }) => {
38
- const r = d(null), { options: o } = n(e), s = u(null);
39
- return y("googleMapsMap", s), this.createMap(r, o.value).then((i) => {
40
- s.value = i, a("loaded", i);
41
- }), () => w("div", { ref: r }, s.value ? t : []);
132
+ return p(
133
+ (e, { emit: s, slots: t }) => {
134
+ const r = y(null), { options: a } = u(e), o = g(null);
135
+ return m("googleMapsMap", o), this.createMap(r, a.value).then((n) => {
136
+ o.value = n, c(a, () => {
137
+ console.error("Cannot update options (missing function similar to deckglMap.setProps()). Use SDK dedicated functions instead");
138
+ }, { once: !0 }), s("loaded", n);
139
+ }), () => v("div", { ref: r }, o.value ? t : []);
42
140
  },
43
141
  {
44
142
  props: {
@@ -46,18 +144,42 @@ class G {
46
144
  type: Object,
47
145
  default: () => ({})
48
146
  }
49
- }
147
+ },
148
+ emits: ["loaded"]
149
+ }
150
+ );
151
+ }
152
+ get Map3D() {
153
+ return p(
154
+ (e, { emit: s, attrs: t, slots: r }) => {
155
+ const a = y(null), { options: o, layers: n } = u(e), i = g(null);
156
+ return m("googleMapsMap3D", i), this.createMap3D(a, o.value).then((h) => {
157
+ i.value = h, h.watchOptions(o, o.value.watchOptionsOptions), h.watchLayers(n, o.value.watchLayersOptions), s("loaded", h);
158
+ }), () => v("div", { ref: a }, i.value ? r : []);
159
+ },
160
+ {
161
+ props: {
162
+ options: {
163
+ type: Object,
164
+ default: () => ({})
165
+ },
166
+ layers: {
167
+ type: Array,
168
+ default: () => []
169
+ }
170
+ },
171
+ emits: ["loaded"]
50
172
  }
51
173
  );
52
174
  }
53
175
  get DeckGLOverlay() {
54
- return l(
55
- (e, { emit: a, slots: t }) => {
56
- const { options: r, layers: o } = n(e), s = p("googleMapsMap");
57
- if (!s || !s.value)
176
+ return p(
177
+ (e, { emit: s, slots: t }) => {
178
+ const { options: r, layers: a } = u(e), o = f("googleMapsMap");
179
+ if (!o || !o.value)
58
180
  throw new Error("map should exist");
59
- return s.value.setDeckGLOverlay(r.value).then((i) => {
60
- i.watchLayers(o, r.value.watchLayersOptions || { immediate: !0 }), a("loaded", i);
181
+ return o.value.setDeckGLOverlay(r.value).then((n) => {
182
+ n.watchOptions(r, r.value.watchOptionsOptions), n.watchLayers(a, r.value.watchLayersOptions), s("loaded", n);
61
183
  }), () => {
62
184
  };
63
185
  },
@@ -71,27 +193,30 @@ class G {
71
193
  type: Array,
72
194
  default: () => []
73
195
  }
74
- }
196
+ },
197
+ emits: ["loaded"]
75
198
  }
76
199
  );
77
200
  }
78
201
  get DeckGL3DTileLayer() {
79
- return l(
80
- (e, { emit: a, slots: t }) => {
81
- const { options: r } = n(e), o = p("deckGLPrependLayers");
82
- if (!o || !o.value)
202
+ return p(
203
+ (e, { emit: s, slots: t }) => {
204
+ const { options: r } = u(e), a = f("deckGLPrependLayers");
205
+ if (!a || !a.value)
83
206
  throw new Error("deckGLPrependLayers should exist");
84
- const s = d("");
85
- this.createDeckGL3DTileLayer(s, r).then((h) => {
86
- o.value = [
87
- ...o.value,
88
- h
207
+ const o = y("");
208
+ this.createDeckGL3DTileLayer(o, r.value).then((i) => {
209
+ c(r, () => {
210
+ console.error("Cannot update options on DeckGL layer. Replace layer instead");
211
+ }, { once: !0 }), a.value = [
212
+ ...a.value,
213
+ i
89
214
  ];
90
215
  });
91
- const i = p("deckGLAppendVNodeFn");
92
- if (!i)
216
+ const n = f("deckGLAppendVNodeFn");
217
+ if (!n)
93
218
  throw new Error("deckGLAppendVNodeFn should exist");
94
- return t.appendMap && i.value.push(() => t.appendMap({ credits: s.value })), () => {
219
+ return t.appendMap && n.value.push(() => t.appendMap({ credits: o.value })), () => {
95
220
  };
96
221
  },
97
222
  {
@@ -104,35 +229,73 @@ class G {
104
229
  }
105
230
  );
106
231
  }
107
- async loadGoogleMaps() {
108
- const { Loader: e } = await import("@googlemaps/js-api-loader");
109
- this.loader = new e({
232
+ async loadGoogleMapsSDK({ libraries: e = [] } = {}) {
233
+ const { Loader: s } = await import("@googlemaps/js-api-loader"), t = [.../* @__PURE__ */ new Set([...this.libraries, ...e])];
234
+ this.libraries.length === t.length && this.libraries.every((a) => t.includes(a)) || 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 s({
110
235
  apiKey: this.apiKey,
111
236
  version: this.version,
112
237
  libraries: this.libraries
113
238
  });
114
- const a = await Promise.all(this.libraries.map((t) => this.loader.importLibrary(t)));
115
- for (const [t, r] of this.libraries.entries())
116
- this.sdk[r] = a[t];
117
- }
118
- async getSDK() {
119
- return await (Object.keys(this.sdk).length ? Promise.resolve() : this.loadGoogleMaps()), this.sdk;
120
- }
121
- async createMap(e, a = {}) {
122
- const t = new k();
123
- return new Promise((r, o) => {
124
- v(async () => {
125
- await (this.sdk.maps ? Promise.resolve() : this.loadGoogleMaps());
126
- const s = () => {
239
+ const r = await Promise.all(this.libraries.map((a) => this.sdk[a] || this.loader.importLibrary(a)));
240
+ for (const [a, o] of this.libraries.entries())
241
+ this.sdk[o] = r[a];
242
+ }
243
+ async getSDK(e) {
244
+ let s = {};
245
+ if (typeof e == "string" ? s.libraries = [e] : s = { ...e }, await this.loadGoogleMapsSDK(s), typeof e == "string") {
246
+ if (!this.sdk[e] || !Object.keys(this.sdk[e]).length)
247
+ throw new Error(`${e} library is not loaded${e === "maps3d" ? ". Missing version: 'alpha' or apiKey not authorized?" : ""}`);
248
+ return this.sdk[e];
249
+ }
250
+ return this.sdk;
251
+ }
252
+ async createMap(e, s = {}) {
253
+ const t = new G(), r = () => {
254
+ for (const a of t.unwatchFn)
255
+ a();
256
+ t.unwatchFn = [], t.map && (t.map = null);
257
+ };
258
+ return new Promise((a, o) => {
259
+ L(async () => {
260
+ await this.getSDK("maps");
261
+ const n = () => {
127
262
  if (!e.value)
128
263
  throw new Error("Missing HTML element");
264
+ const i = c(e, () => {
265
+ e.value || (r(), i());
266
+ });
129
267
  t.map = new this.sdk.maps.Map(e.value, {
130
- ...a
131
- }), r(t);
268
+ ...s
269
+ }), a(t);
270
+ };
271
+ s.onMounted ? s.onMounted(n) : n();
272
+ }), M(() => {
273
+ r();
274
+ });
275
+ });
276
+ }
277
+ async createMap3D(e, s = {}) {
278
+ const t = new D(), r = () => {
279
+ for (const a of t.unwatchFn)
280
+ a();
281
+ t.unwatchFn = [], t.map && (t.map = null);
282
+ };
283
+ return new Promise((a, o) => {
284
+ L(async () => {
285
+ await this.getSDK("maps3d");
286
+ const n = () => {
287
+ if (!e.value)
288
+ throw new Error("Missing HTML element");
289
+ const i = c(e, () => {
290
+ e.value || (r(), i());
291
+ });
292
+ t.map = new this.sdk.maps3d.Map3DElement({
293
+ ...s
294
+ }), e.value.appendChild(t.map), a(t);
132
295
  };
133
- a.onMounted ? a.onMounted(s) : s();
134
- }), L(() => {
135
- t.map && (t.map = null);
296
+ s.onMounted ? s.onMounted(n) : n();
297
+ }), M(() => {
298
+ r();
136
299
  });
137
300
  });
138
301
  }
@@ -140,7 +303,7 @@ class G {
140
303
  const { Tile3DLayer: e } = await import("deck.gl");
141
304
  this.deckgl = { Tile3DLayer: e };
142
305
  }
143
- async createDeckGL3DTileLayer(e, a = {}) {
306
+ async createDeckGL3DTileLayer(e, s = {}) {
144
307
  return await (this.deckgl ? Promise.resolve() : this.loadDeckGL()), new this.deckgl.Tile3DLayer({
145
308
  id: "google-3d-tiles",
146
309
  data: "https://tile.googleapis.com/v1/3dtiles/root.json",
@@ -153,18 +316,18 @@ class G {
153
316
  },
154
317
  onTilesetLoad: (t) => {
155
318
  e && (t.options.onTraversalComplete = (r) => {
156
- const o = /* @__PURE__ */ new Set();
157
- return r.forEach((s) => {
158
- const { copyright: i } = s.content.gltf.asset;
159
- i.split(";").forEach(o.add, o), e.value = [...o].join("; ");
319
+ const a = /* @__PURE__ */ new Set();
320
+ return r.forEach((o) => {
321
+ const { copyright: n } = o.content.gltf.asset;
322
+ n.split(";").forEach(a.add, a), e.value = [...a].join("; ");
160
323
  }), r;
161
324
  });
162
325
  },
163
326
  operation: "terrain+draw",
164
- ...a
327
+ ...s
165
328
  });
166
329
  }
167
330
  }
168
331
  export {
169
- G as default
332
+ F as default
170
333
  };