@yappkit/front-module-map 0.1.3 → 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.
- package/lib/providers/deckgl.js +65 -33
- package/lib/providers/google-maps.js +230 -67
- package/lib/providers/mapbox.js +130 -71
- package/lib/providers/maplibre.js +134 -75
- package/lib/yappkit-map.js +400 -146
- package/package.json +1 -1
package/lib/providers/mapbox.js
CHANGED
|
@@ -1,80 +1,120 @@
|
|
|
1
|
-
import { defineComponent as m, ref as
|
|
2
|
-
class
|
|
3
|
-
constructor() {
|
|
4
|
-
this.overlay = null, this.watching = { layers: !1 };
|
|
1
|
+
import { defineComponent as m, ref as v, toRefs as y, shallowRef as g, provide as b, watch as d, h as M, inject as x, onMounted as S, onUnmounted as L, nextTick as f } from "vue";
|
|
2
|
+
class O {
|
|
3
|
+
constructor({ unwatchFn: e }) {
|
|
4
|
+
this.overlay = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = e;
|
|
5
|
+
}
|
|
6
|
+
watchOptions(e, a = {}) {
|
|
7
|
+
if (!this.overlay)
|
|
8
|
+
throw new Error("overlay should be set");
|
|
9
|
+
if (this.watching.options) {
|
|
10
|
+
console.warn("No need to call MapboxDeckGLOverlay.watchOptions(). options are already being watched");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
this.watching.options = !0;
|
|
14
|
+
const t = d(e, () => {
|
|
15
|
+
this.overlay.setProps({ ...e.value });
|
|
16
|
+
}, {
|
|
17
|
+
immediate: !0,
|
|
18
|
+
deep: !0,
|
|
19
|
+
...a
|
|
20
|
+
});
|
|
21
|
+
this.unwatchFn.push(t);
|
|
5
22
|
}
|
|
6
|
-
watchLayers(
|
|
23
|
+
watchLayers(e, a = {}) {
|
|
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 MapboxDeckGLOverlay.watchLayers(). layers are already being watched");
|
|
11
28
|
return;
|
|
12
29
|
}
|
|
13
|
-
this.watching.layers = !0
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
this.watching.layers = !0;
|
|
31
|
+
const t = d(e, () => {
|
|
32
|
+
this.overlay.setProps({ layers: e.value });
|
|
33
|
+
}, {
|
|
34
|
+
immediate: !0,
|
|
35
|
+
...a
|
|
36
|
+
});
|
|
37
|
+
this.unwatchFn.push(t);
|
|
16
38
|
}
|
|
17
39
|
}
|
|
18
40
|
class k {
|
|
19
41
|
constructor() {
|
|
20
|
-
this.map = null, this.watching = { sources: !1, layers: !1 };
|
|
42
|
+
this.map = null, this.watching = { sources: !1, layers: !1 }, this.unwatchFn = [];
|
|
21
43
|
}
|
|
22
|
-
watchSources(
|
|
44
|
+
watchSources(e, a = {}) {
|
|
23
45
|
if (!this.map)
|
|
24
46
|
throw new Error("map should be set");
|
|
25
47
|
if (this.watching.sources) {
|
|
26
48
|
console.warn("No need to call MapboxMap.watchSources(). sources are already being watched");
|
|
27
49
|
return;
|
|
28
50
|
}
|
|
29
|
-
this.watching.sources = !0
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
this.watching.sources = !0;
|
|
52
|
+
const t = d(() => (e.value || []).map((o) => {
|
|
53
|
+
const { data: n, ...s } = o;
|
|
54
|
+
return o.propsId = JSON.stringify(s), o;
|
|
55
|
+
}), async (o, n) => {
|
|
56
|
+
const s = n || [], i = o || [], c = i.filter((r, h) => {
|
|
57
|
+
var u;
|
|
58
|
+
return r !== s[h] && r.propsId === ((u = s[h]) == null ? void 0 : u.propsId);
|
|
59
|
+
}), p = i.filter((r, h) => r !== s[h] && !c.find((u) => u.id === r.id)), l = s.filter((r, h) => r !== i[h] && !c.find((u) => u.id === r.id));
|
|
60
|
+
for (const r of c)
|
|
61
|
+
this.map.getSource(r.id).setData(r.data);
|
|
62
|
+
await f();
|
|
63
|
+
for (const r of l)
|
|
64
|
+
this.map.removeSource(r.id);
|
|
65
|
+
for (const r of p) {
|
|
66
|
+
const h = { ...r };
|
|
67
|
+
delete h.id, delete h.propsId, this.map.addSource(r.id, h);
|
|
38
68
|
}
|
|
39
|
-
},
|
|
69
|
+
}, {
|
|
70
|
+
immediate: !0,
|
|
71
|
+
...a
|
|
72
|
+
});
|
|
73
|
+
this.unwatchFn.push(t);
|
|
40
74
|
}
|
|
41
|
-
watchLayers(
|
|
75
|
+
watchLayers(e, a = {}) {
|
|
42
76
|
if (!this.map)
|
|
43
77
|
throw new Error("map should be set");
|
|
44
78
|
if (this.watching.layers) {
|
|
45
79
|
console.warn("No need to call MapboxMap.watchLayers(). layers are already being watched");
|
|
46
80
|
return;
|
|
47
81
|
}
|
|
48
|
-
this.watching.layers = !0
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
82
|
+
this.watching.layers = !0;
|
|
83
|
+
const t = d(e, async (o, n) => {
|
|
84
|
+
const s = n || [], i = o || [], c = i.filter((l, r) => l !== s[r]), p = s.filter((l, r) => l !== i[r]);
|
|
85
|
+
for (const l of p)
|
|
86
|
+
this.map.removeLayer(l.id), this.map.getSource(l.id) && this.map.removeSource(l.id);
|
|
87
|
+
await f();
|
|
88
|
+
for (const l of c)
|
|
89
|
+
this.map.addLayer(l);
|
|
90
|
+
}, {
|
|
91
|
+
immediate: !0,
|
|
92
|
+
...a
|
|
93
|
+
});
|
|
94
|
+
this.unwatchFn.push(t);
|
|
57
95
|
}
|
|
58
|
-
async setDeckGLOverlay(
|
|
96
|
+
async setDeckGLOverlay(e = {}) {
|
|
59
97
|
if (!this.map)
|
|
60
98
|
throw new Error("map should be set");
|
|
61
|
-
const { MapboxOverlay:
|
|
62
|
-
return
|
|
99
|
+
const { MapboxOverlay: a } = await import("@deck.gl/mapbox"), t = new O({ unwatchFn: this.unwatchFn });
|
|
100
|
+
return t.overlay = new a(e), this.map.addControl(t.overlay), t;
|
|
63
101
|
}
|
|
64
102
|
}
|
|
65
|
-
class
|
|
66
|
-
constructor(
|
|
67
|
-
if (this.apiKey =
|
|
103
|
+
class K {
|
|
104
|
+
constructor(e) {
|
|
105
|
+
if (this.apiKey = e.apiKey, !this.apiKey)
|
|
68
106
|
throw new Error("apiKey is required");
|
|
69
|
-
this.services =
|
|
107
|
+
this.services = [...e.services || []], this.sdk = {}, this.mapboxgl = null, this.getSDK();
|
|
70
108
|
}
|
|
71
109
|
get Map() {
|
|
72
110
|
return m(
|
|
73
|
-
(
|
|
74
|
-
const
|
|
75
|
-
return b("mapboxMap",
|
|
76
|
-
|
|
77
|
-
|
|
111
|
+
(e, { emit: a, slots: t }) => {
|
|
112
|
+
const o = v(null), { options: n, layers: s, sources: i } = y(e), c = g(null);
|
|
113
|
+
return b("mapboxMap", c), this.createMap(o, n.value).then((p) => {
|
|
114
|
+
c.value = p, d(n, () => {
|
|
115
|
+
console.error("Cannot update options (missing function similar to deckglMap.setProps()). Use SDK dedicated functions instead");
|
|
116
|
+
}, { once: !0 }), p.watchSources(i, n.value.watchSourcesOptions), p.watchLayers(s, n.value.watchLayersOptions), a("loaded", p);
|
|
117
|
+
}), () => M("div", { ref: o }, c.value ? t : []);
|
|
78
118
|
},
|
|
79
119
|
{
|
|
80
120
|
props: {
|
|
@@ -90,18 +130,19 @@ class D {
|
|
|
90
130
|
type: Array,
|
|
91
131
|
default: () => []
|
|
92
132
|
}
|
|
93
|
-
}
|
|
133
|
+
},
|
|
134
|
+
emits: ["loaded"]
|
|
94
135
|
}
|
|
95
136
|
);
|
|
96
137
|
}
|
|
97
138
|
get DeckGLOverlay() {
|
|
98
139
|
return m(
|
|
99
|
-
(
|
|
100
|
-
const { options:
|
|
101
|
-
if (!
|
|
140
|
+
(e, { emit: a, slots: t }) => {
|
|
141
|
+
const { options: o, layers: n } = y(e), s = x("mapboxMap");
|
|
142
|
+
if (!s || !s.value)
|
|
102
143
|
throw new Error("map should exist");
|
|
103
|
-
return
|
|
104
|
-
|
|
144
|
+
return s.value.setDeckGLOverlay(o.value).then((i) => {
|
|
145
|
+
i.watchOptions(o, o.value.watchOptionsOptions), i.watchLayers(n, o.value.watchLayersOptions), a("loaded", i);
|
|
105
146
|
}), () => {
|
|
106
147
|
};
|
|
107
148
|
},
|
|
@@ -115,13 +156,16 @@ class D {
|
|
|
115
156
|
type: Array,
|
|
116
157
|
default: () => []
|
|
117
158
|
}
|
|
118
|
-
}
|
|
159
|
+
},
|
|
160
|
+
emits: ["loaded"]
|
|
119
161
|
}
|
|
120
162
|
);
|
|
121
163
|
}
|
|
122
164
|
async loadMapbox() {
|
|
123
|
-
|
|
124
|
-
|
|
165
|
+
if (!this.mapboxgl) {
|
|
166
|
+
const e = await import("../mapbox-gl.js").then((a) => a.mapboxGl);
|
|
167
|
+
this.mapboxgl = e;
|
|
168
|
+
}
|
|
125
169
|
}
|
|
126
170
|
get servicesLoader() {
|
|
127
171
|
return {
|
|
@@ -141,37 +185,52 @@ class D {
|
|
|
141
185
|
isochrone: () => import("@mapbox/mapbox-sdk/services/isochrone.js")
|
|
142
186
|
};
|
|
143
187
|
}
|
|
144
|
-
async loadMapboxSDK() {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
188
|
+
async loadMapboxSDK({ services: e = [] } = {}) {
|
|
189
|
+
const t = (await import("@mapbox/mapbox-sdk")).default({ accessToken: this.apiKey }), o = [.../* @__PURE__ */ new Set([...this.services, ...e])];
|
|
190
|
+
this.services = o;
|
|
191
|
+
const n = await Promise.all(this.services.map((s) => this.sdk[s] || this.servicesLoader[s]().then((i) => i.default(t))));
|
|
192
|
+
for (const [s, i] of this.services.entries())
|
|
193
|
+
this.sdk[i] = n[s];
|
|
148
194
|
}
|
|
149
|
-
async getSDK() {
|
|
150
|
-
|
|
195
|
+
async getSDK(e) {
|
|
196
|
+
let a = {};
|
|
197
|
+
if (typeof e == "string" ? a.services = [e] : a = { ...e }, await this.loadMapboxSDK(a), typeof e == "string") {
|
|
198
|
+
if (!this.sdk[e])
|
|
199
|
+
throw new Error(e + " service is not loaded");
|
|
200
|
+
return this.sdk[e];
|
|
201
|
+
}
|
|
202
|
+
return this.sdk;
|
|
151
203
|
}
|
|
152
|
-
async createMap(
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
204
|
+
async createMap(e, a = {}) {
|
|
205
|
+
const t = new k(), o = () => {
|
|
206
|
+
for (const n of t.unwatchFn)
|
|
207
|
+
n();
|
|
208
|
+
t.unwatchFn = [], t.map && (t.map.remove(), t.map = null);
|
|
209
|
+
};
|
|
210
|
+
return new Promise((n, s) => {
|
|
211
|
+
S(async () => {
|
|
212
|
+
await this.loadMapbox();
|
|
157
213
|
const i = () => {
|
|
158
|
-
if (!
|
|
214
|
+
if (!e.value)
|
|
159
215
|
throw new Error("Missing HTML element");
|
|
160
|
-
|
|
161
|
-
|
|
216
|
+
const c = d(e, () => {
|
|
217
|
+
e.value || (o(), c());
|
|
218
|
+
});
|
|
219
|
+
t.map = new this.mapboxgl.Map({
|
|
220
|
+
container: e.value,
|
|
162
221
|
accessToken: this.apiKey,
|
|
163
|
-
...
|
|
164
|
-
}),
|
|
165
|
-
|
|
222
|
+
...a
|
|
223
|
+
}), t.map.on("load", () => {
|
|
224
|
+
n(t);
|
|
166
225
|
});
|
|
167
226
|
};
|
|
168
|
-
|
|
227
|
+
a.onMounted ? a.onMounted(i) : i();
|
|
169
228
|
}), L(() => {
|
|
170
|
-
|
|
229
|
+
o();
|
|
171
230
|
});
|
|
172
231
|
});
|
|
173
232
|
}
|
|
174
233
|
}
|
|
175
234
|
export {
|
|
176
|
-
|
|
235
|
+
K as default
|
|
177
236
|
};
|
|
@@ -1,80 +1,120 @@
|
|
|
1
|
-
import { defineComponent as m, ref as
|
|
2
|
-
class
|
|
3
|
-
constructor() {
|
|
4
|
-
this.overlay = null, this.watching = { layers: !1 };
|
|
1
|
+
import { defineComponent as m, ref as v, toRefs as y, shallowRef as b, provide as g, watch as d, h as x, inject as M, onMounted as S, onUnmounted as L, nextTick as f } from "vue";
|
|
2
|
+
class O {
|
|
3
|
+
constructor({ unwatchFn: e }) {
|
|
4
|
+
this.overlay = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = e;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
watchOptions(e, a = {}) {
|
|
7
|
+
if (!this.overlay)
|
|
8
|
+
throw new Error("overlay should be set");
|
|
9
|
+
if (this.watching.options) {
|
|
10
|
+
console.warn("No need to call MapboxDeckGLOverlay.watchOptions(). options are already being watched");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
this.watching.options = !0;
|
|
14
|
+
const t = d(e, () => {
|
|
15
|
+
this.overlay.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.overlay)
|
|
8
25
|
throw new Error("overlay should be set");
|
|
9
26
|
if (this.watching.layers) {
|
|
10
27
|
console.warn("No need to call MapboxDeckGLOverlay.watchLayers(). layers are already being watched");
|
|
11
28
|
return;
|
|
12
29
|
}
|
|
13
|
-
this.watching.layers = !0
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
this.watching.layers = !0;
|
|
31
|
+
const t = d(e, () => {
|
|
32
|
+
this.overlay.setProps({ layers: e.value });
|
|
33
|
+
}, {
|
|
34
|
+
immediate: !0,
|
|
35
|
+
...a
|
|
36
|
+
});
|
|
37
|
+
this.unwatchFn.push(t);
|
|
16
38
|
}
|
|
17
39
|
}
|
|
18
40
|
class k {
|
|
19
41
|
constructor() {
|
|
20
|
-
this.map = null, this.watching = { sources: !1, layers: !1 };
|
|
42
|
+
this.map = null, this.watching = { sources: !1, layers: !1 }, this.unwatchFn = [];
|
|
21
43
|
}
|
|
22
|
-
watchSources(
|
|
44
|
+
watchSources(e, a = {}) {
|
|
23
45
|
if (!this.map)
|
|
24
46
|
throw new Error("map should be set");
|
|
25
47
|
if (this.watching.sources) {
|
|
26
48
|
console.warn("No need to call MapboxMap.watchSources(). sources are already being watched");
|
|
27
49
|
return;
|
|
28
50
|
}
|
|
29
|
-
this.watching.sources = !0
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
this.watching.sources = !0;
|
|
52
|
+
const t = d(() => (e.value || []).map((o) => {
|
|
53
|
+
const { data: n, ...s } = o;
|
|
54
|
+
return o.propsId = JSON.stringify(s), o;
|
|
55
|
+
}), async (o, n) => {
|
|
56
|
+
const s = n || [], i = o || [], c = i.filter((r, h) => {
|
|
57
|
+
var u;
|
|
58
|
+
return r !== s[h] && r.propsId === ((u = s[h]) == null ? void 0 : u.propsId);
|
|
59
|
+
}), p = i.filter((r, h) => r !== s[h] && !c.find((u) => u.id === r.id)), l = s.filter((r, h) => r !== i[h] && !c.find((u) => u.id === r.id));
|
|
60
|
+
for (const r of c)
|
|
61
|
+
this.map.getSource(r.id).setData(r.data);
|
|
62
|
+
await f();
|
|
63
|
+
for (const r of l)
|
|
64
|
+
this.map.removeSource(r.id);
|
|
65
|
+
for (const r of p) {
|
|
66
|
+
const h = { ...r };
|
|
67
|
+
delete h.id, delete h.propsId, this.map.addSource(r.id, h);
|
|
38
68
|
}
|
|
39
|
-
},
|
|
69
|
+
}, {
|
|
70
|
+
immediate: !0,
|
|
71
|
+
...a
|
|
72
|
+
});
|
|
73
|
+
this.unwatchFn.push(t);
|
|
40
74
|
}
|
|
41
|
-
watchLayers(
|
|
75
|
+
watchLayers(e, a = {}) {
|
|
42
76
|
if (!this.map)
|
|
43
77
|
throw new Error("map should be set");
|
|
44
78
|
if (this.watching.layers) {
|
|
45
79
|
console.warn("No need to call MapboxMap.watchLayers(). layers are already being watched");
|
|
46
80
|
return;
|
|
47
81
|
}
|
|
48
|
-
this.watching.layers = !0
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
this.watching.layers = !0;
|
|
83
|
+
const t = d(e, async (o, n) => {
|
|
84
|
+
const s = n || [], i = o || [], c = i.filter((l, r) => l !== s[r]), p = s.filter((l, r) => l !== i[r]);
|
|
85
|
+
for (const l of p)
|
|
86
|
+
this.map.removeLayer(l.id), this.map.getSource(l.id) && this.map.removeSource(l.id);
|
|
87
|
+
await f();
|
|
88
|
+
for (const l of c)
|
|
89
|
+
this.map.addLayer(l);
|
|
90
|
+
}, {
|
|
91
|
+
immediate: !0,
|
|
92
|
+
...a
|
|
93
|
+
});
|
|
94
|
+
this.unwatchFn.push(t);
|
|
95
|
+
}
|
|
96
|
+
async setDeckGLOverlay(e = {}) {
|
|
59
97
|
if (!this.map)
|
|
60
98
|
throw new Error("map should be set");
|
|
61
|
-
const { MapboxOverlay:
|
|
62
|
-
return
|
|
99
|
+
const { MapboxOverlay: a } = await import("@deck.gl/mapbox"), t = new O({ unwatchFn: this.unwatchFn });
|
|
100
|
+
return t.overlay = new a(e), this.map.addControl(t.overlay), t;
|
|
63
101
|
}
|
|
64
102
|
}
|
|
65
|
-
class
|
|
66
|
-
constructor(
|
|
67
|
-
if (this.apiKey =
|
|
103
|
+
class D {
|
|
104
|
+
constructor(e) {
|
|
105
|
+
if (this.apiKey = e.apiKey, !this.apiKey)
|
|
68
106
|
throw new Error("apiKey is required");
|
|
69
|
-
this.services =
|
|
107
|
+
this.services = [...e.services || []], this.sdk = {}, this.mapboxgl = null, this.getSDK();
|
|
70
108
|
}
|
|
71
109
|
get Map() {
|
|
72
110
|
return m(
|
|
73
|
-
(
|
|
74
|
-
const
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
111
|
+
(e, { emit: a, slots: t }) => {
|
|
112
|
+
const o = v(null), { options: n, layers: s, sources: i } = y(e), c = b(null);
|
|
113
|
+
return g("mapboxMap", c), this.createMap(o, n.value).then((p) => {
|
|
114
|
+
c.value = p, d(n, () => {
|
|
115
|
+
console.error("Cannot update options (missing function similar to deckglMap.setProps()). Use SDK dedicated functions instead");
|
|
116
|
+
}, { once: !0 }), p.watchSources(i, n.value.watchSourcesOptions), p.watchLayers(s, n.value.watchLayersOptions), a("loaded", p);
|
|
117
|
+
}), () => x("div", { ref: o }, c.value ? t : []);
|
|
78
118
|
},
|
|
79
119
|
{
|
|
80
120
|
props: {
|
|
@@ -90,18 +130,19 @@ class O {
|
|
|
90
130
|
type: Array,
|
|
91
131
|
default: () => []
|
|
92
132
|
}
|
|
93
|
-
}
|
|
133
|
+
},
|
|
134
|
+
emits: ["loaded"]
|
|
94
135
|
}
|
|
95
136
|
);
|
|
96
137
|
}
|
|
97
138
|
get DeckGLOverlay() {
|
|
98
139
|
return m(
|
|
99
|
-
(
|
|
100
|
-
const { options:
|
|
101
|
-
if (!
|
|
140
|
+
(e, { emit: a, slots: t }) => {
|
|
141
|
+
const { options: o, layers: n } = y(e), s = M("mapboxMap");
|
|
142
|
+
if (!s || !s.value)
|
|
102
143
|
throw new Error("map should exist");
|
|
103
|
-
return
|
|
104
|
-
|
|
144
|
+
return s.value.setDeckGLOverlay(o.value).then((i) => {
|
|
145
|
+
i.watchOptions(o, o.value.watchOptionsOptions), i.watchLayers(n, o.value.watchLayersOptions), a("loaded", i);
|
|
105
146
|
}), () => {
|
|
106
147
|
};
|
|
107
148
|
},
|
|
@@ -115,13 +156,16 @@ class O {
|
|
|
115
156
|
type: Array,
|
|
116
157
|
default: () => []
|
|
117
158
|
}
|
|
118
|
-
}
|
|
159
|
+
},
|
|
160
|
+
emits: ["loaded"]
|
|
119
161
|
}
|
|
120
162
|
);
|
|
121
163
|
}
|
|
122
164
|
async loadMapbox() {
|
|
123
|
-
|
|
124
|
-
|
|
165
|
+
if (!this.mapboxgl) {
|
|
166
|
+
const e = await import("../mapbox-gl.js").then((a) => a.mapboxGl);
|
|
167
|
+
this.mapboxgl = e;
|
|
168
|
+
}
|
|
125
169
|
}
|
|
126
170
|
get servicesLoader() {
|
|
127
171
|
return {
|
|
@@ -141,43 +185,58 @@ class O {
|
|
|
141
185
|
isochrone: () => import("@mapbox/mapbox-sdk/services/isochrone.js")
|
|
142
186
|
};
|
|
143
187
|
}
|
|
144
|
-
async loadMapboxSDK() {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
188
|
+
async loadMapboxSDK({ services: e = [] } = {}) {
|
|
189
|
+
const t = (await import("@mapbox/mapbox-sdk")).default({ accessToken: this.apiKey }), o = [.../* @__PURE__ */ new Set([...this.services, ...e])];
|
|
190
|
+
this.services = o;
|
|
191
|
+
const n = await Promise.all(this.services.map((s) => this.sdk[s] || this.servicesLoader[s]().then((i) => i.default(t))));
|
|
192
|
+
for (const [s, i] of this.services.entries())
|
|
193
|
+
this.sdk[i] = n[s];
|
|
148
194
|
}
|
|
149
|
-
async getSDK() {
|
|
150
|
-
|
|
195
|
+
async getSDK(e) {
|
|
196
|
+
let a = {};
|
|
197
|
+
if (typeof e == "string" ? a.services = [e] : a = { ...e }, await this.loadMapboxSDK(a), typeof e == "string") {
|
|
198
|
+
if (!this.sdk[e])
|
|
199
|
+
throw new Error(e + " service is not loaded");
|
|
200
|
+
return this.sdk[e];
|
|
201
|
+
}
|
|
202
|
+
return this.sdk;
|
|
151
203
|
}
|
|
152
|
-
async createMap(
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
204
|
+
async createMap(e, a = {}) {
|
|
205
|
+
const t = new k(), o = () => {
|
|
206
|
+
for (const n of t.unwatchFn)
|
|
207
|
+
n();
|
|
208
|
+
t.unwatchFn = [], t.map && (t.map.remove(), t.map = null);
|
|
209
|
+
};
|
|
210
|
+
return new Promise((n, s) => {
|
|
211
|
+
S(async () => {
|
|
212
|
+
await this.loadMapbox();
|
|
157
213
|
const i = () => {
|
|
158
|
-
if (!
|
|
214
|
+
if (!e.value)
|
|
159
215
|
throw new Error("Missing HTML element");
|
|
160
|
-
|
|
161
|
-
|
|
216
|
+
const c = d(e, () => {
|
|
217
|
+
e.value || (o(), c());
|
|
218
|
+
});
|
|
219
|
+
t.map = new this.mapboxgl.Map({
|
|
220
|
+
container: e.value,
|
|
162
221
|
accessToken: this.apiKey,
|
|
163
|
-
...
|
|
164
|
-
}),
|
|
165
|
-
|
|
222
|
+
...a
|
|
223
|
+
}), t.map.on("load", () => {
|
|
224
|
+
n(t);
|
|
166
225
|
});
|
|
167
226
|
};
|
|
168
|
-
|
|
227
|
+
a.onMounted ? a.onMounted(i) : i();
|
|
169
228
|
}), L(() => {
|
|
170
|
-
|
|
229
|
+
o();
|
|
171
230
|
});
|
|
172
231
|
});
|
|
173
232
|
}
|
|
174
233
|
}
|
|
175
|
-
class
|
|
234
|
+
class F extends D {
|
|
176
235
|
async loadMapbox() {
|
|
177
|
-
const
|
|
178
|
-
this.mapboxgl =
|
|
236
|
+
const e = await import("maplibre-gl");
|
|
237
|
+
this.mapboxgl = e;
|
|
179
238
|
}
|
|
180
239
|
}
|
|
181
240
|
export {
|
|
182
|
-
|
|
241
|
+
F as default
|
|
183
242
|
};
|