@wemap/geo 11.0.0-alpha.0 → 11.0.0-alpha.12

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/dist/index.js DELETED
@@ -1,1633 +0,0 @@
1
- var ot = Object.defineProperty;
2
- var at = (i, t, e) => t in i ? ot(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
- var c = (i, t, e) => (at(i, typeof t != "symbol" ? t + "" : t, e), e);
4
- const V = 63567523142e-4, lt = 9.80665, X = 1e-8, P = 1e-3, U = (6378137 - V) / 6378137, Q = Math.sqrt(U * (2 - U)), ct = Q * Q, H = 6378137 * 6378137, ut = H * H, K = V * V, ht = K * K, gt = 6378137 * 2 * Math.PI, Pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5
- __proto__: null,
6
- R_MAJOR: 6378137,
7
- R_MINOR: V,
8
- EARTH_GRAVITY: lt,
9
- EPS_DEG_MM: X,
10
- EPS_MM: P,
11
- ELLIPSOID_FLATNESS: U,
12
- ECCENTRICITY: Q,
13
- ECCENTRICITY_2: ct,
14
- R_MAJOR_2: H,
15
- R_MAJOR_4: ut,
16
- R_MINOR_2: K,
17
- R_MINOR_4: ht,
18
- CIRCUMFERENCE: gt
19
- }, Symbol.toStringTag, { value: "Module" }));
20
- var dt = Object.defineProperty, ft = (i, t, e) => t in i ? dt(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, k = (i, t, e) => (ft(i, typeof t != "symbol" ? t + "" : t, e), e);
21
- class mt {
22
- static concat(t, e) {
23
- return t.concat(e);
24
- }
25
- }
26
- class w extends mt {
27
- static norm(t) {
28
- return Math.sqrt(t[0] * t[0] + t[1] * t[1] + t[2] * t[2]);
29
- }
30
- static normalize(t) {
31
- const e = this.norm(t), n = new Array(3);
32
- for (let r = 0; r < 3; r++)
33
- n[r] = t[r] / e;
34
- return n;
35
- }
36
- static sum(t, e) {
37
- return [t[0] + e[0], t[1] + e[1], t[2] + e[2]];
38
- }
39
- static subtract(t, e) {
40
- return [t[0] - e[0], t[1] - e[1], t[2] - e[2]];
41
- }
42
- static distance(t, e) {
43
- return w.norm(w.subtract(t, e));
44
- }
45
- static cross(t, e) {
46
- return [
47
- t[1] * e[2] - t[2] * e[1],
48
- t[2] * e[0] - t[0] * e[2],
49
- t[0] * e[1] - t[1] * e[0]
50
- ];
51
- }
52
- static dot(t, e) {
53
- return t[0] * e[0] + t[1] * e[1] + t[2] * e[2];
54
- }
55
- static multiplyScalar(t, e) {
56
- const n = new Array(3);
57
- for (let r = 0; r < 3; r++)
58
- n[r] = t[r] * e;
59
- return n;
60
- }
61
- }
62
- const F = class {
63
- static get identity() {
64
- return [1, 0, 0, 0];
65
- }
66
- static sum(i, t) {
67
- return [i[0] + t[0], i[1] + t[1], i[2] + t[2], i[3] + t[3]];
68
- }
69
- static rotateMatlab(i, t) {
70
- const [e, n, r, s] = i, [o, a, l] = t;
71
- return [
72
- e * (e * o - r * l + s * a) - r * (e * l - n * a + r * o) + n * (n * o + r * a + s * l) + s * (e * a + n * l - s * o),
73
- e * (e * a + n * l - s * o) + n * (e * l - n * a + r * o) + r * (n * o + r * a + s * l) - s * (e * o - r * l + s * a),
74
- e * (e * l - n * a + r * o) - n * (e * a + n * l - s * o) + r * (e * o - r * l + s * a) + s * (n * o + r * a + s * l)
75
- ];
76
- }
77
- static rotate(i, t) {
78
- const [e, n, r, s] = i, o = [n, r, s];
79
- let a = w.cross(o, t);
80
- a = w.sum(a, a);
81
- const l = w.sum(t, w.multiplyScalar(a, e));
82
- return w.sum(l, w.cross(o, a));
83
- }
84
- static inverse(i) {
85
- return [-i[0], i[1], i[2], i[3]];
86
- }
87
- static multiply(...i) {
88
- if (i.length === 2) {
89
- const [t, e, n, r] = i[0], [s, o, a, l] = i[1];
90
- return [
91
- t * s - e * o - n * a - r * l,
92
- t * o + s * e + n * l - r * a,
93
- t * a + s * n + r * o - e * l,
94
- t * l + s * r + e * a - n * o
95
- ];
96
- }
97
- return i.reduce((t, e) => this.multiply(t, e), F.identity);
98
- }
99
- static fromAxisAngle(i, t) {
100
- const e = Math.sin(t / 2);
101
- return [Math.cos(t / 2), i[0] * e, i[1] * e, i[2] * e];
102
- }
103
- static rotX(i) {
104
- return this.fromAxisAngle([1, 0, 0], i);
105
- }
106
- static rotY(i) {
107
- return this.fromAxisAngle([0, 1, 0], i);
108
- }
109
- static rotZ(i) {
110
- return this.fromAxisAngle([0, 0, 1], i);
111
- }
112
- static fromMatrix3(i) {
113
- const t = Math.sqrt(1 + i[0][0] + i[1][1] + i[2][2]) / 2, e = (i[2][1] - i[1][2]) / (4 * t), n = (i[0][2] - i[2][0]) / (4 * t), r = (i[1][0] - i[0][1]) / (4 * t);
114
- return [t, e, n, r];
115
- }
116
- static fromMatrix3Matlab(i) {
117
- const t = Math.sqrt(1 + i[0][0] + i[1][1] + i[2][2]) / 2, e = (i[1][2] - i[2][1]) / (4 * t), n = (i[2][0] - i[0][2]) / (4 * t), r = (i[0][1] - i[1][0]) / (4 * t);
118
- return [t, e, n, r];
119
- }
120
- static toMatrix3(i) {
121
- const [t, e, n, r] = i, s = t * e, o = t * n, a = t * r, l = e * e, h = e * n, u = e * r, g = n * n, f = n * r, M = r * r;
122
- return [
123
- [1 - 2 * (g + M), 2 * (h - a), 2 * (u + o)],
124
- [2 * (h + a), 1 - 2 * (l + M), 2 * (f - s)],
125
- [2 * (u - o), 2 * (f + s), 1 - 2 * (l + g)]
126
- ];
127
- }
128
- static wxyz2xyzw(i) {
129
- return [i[1], i[2], i[3], i[0]];
130
- }
131
- static xyzw2wxyz(i) {
132
- return [i[3], i[0], i[1], i[2]];
133
- }
134
- static distance(i, t) {
135
- return Math.acos(Math.min(2 * F.dot(i, t) ** 2 - 1, 1));
136
- }
137
- static equals(i, t) {
138
- return F.distance(i, t) < 1e-8;
139
- }
140
- static normalize(i) {
141
- const t = this.norm(i), e = new Array(4);
142
- for (let n = 0; n < 4; n++)
143
- e[n] = i[n] / t;
144
- return e;
145
- }
146
- static norm(i) {
147
- return Math.sqrt(i[0] ** 2 + i[1] ** 2 + i[2] ** 2 + i[3] ** 2);
148
- }
149
- static dot(i, t) {
150
- return i[0] * t[0] + i[1] * t[1] + i[2] * t[2] + i[3] * t[3];
151
- }
152
- static getRotationBetweenTwoVectors(i, t) {
153
- const e = w.normalize(i), n = w.normalize(t), r = w.dot(e, n);
154
- let s;
155
- if (r < -0.999999)
156
- return s = w.cross([1, 0, 0], e), w.norm(s) < 1e-6 && (s = w.cross([0, 1, 0], e)), s = w.normalize(s), F.fromAxisAngle(s, Math.PI);
157
- if (r > 0.999999)
158
- return F.identity;
159
- s = w.cross(e, n);
160
- const o = [1 + r, s[0], s[1], s[2]];
161
- return F.normalize(o);
162
- }
163
- static slerp(i, t, e) {
164
- const n = i[1], r = i[2], s = i[3], o = i[0];
165
- let a = t[1], l = t[2], h = t[3], u = t[0], g, f, M;
166
- g = n * a + r * l + s * h + o * u, g < 0 && (g = -g, u = -u, a = -a, l = -l, h = -h);
167
- const d = 1 - g < 1e-6;
168
- if (d)
169
- f = 1 - e, M = e;
170
- else {
171
- const b = Math.acos(g), A = Math.sin(b);
172
- f = Math.sin((1 - e) * b) / A, M = Math.sin(e * b) / A;
173
- }
174
- let _ = [
175
- f * o + M * u,
176
- f * n + M * a,
177
- f * r + M * l,
178
- f * s + M * h
179
- ];
180
- return d && (_ = F.normalize(_)), _;
181
- }
182
- static toString(i) {
183
- return `[${i[0].toFixed(2)}, ${i[1].toFixed(2)}, ${i[2].toFixed(2)}, ${i[3].toFixed(2)}]`;
184
- }
185
- };
186
- let E = F;
187
- k(E, "ROTX_PI2", F.rotX(Math.PI / 2)), k(E, "ROTX_PI", F.rotX(Math.PI)), k(E, "ROTX_MPI2", F.rotX(-Math.PI / 2)), k(E, "ROTY_PI2", F.rotY(Math.PI / 2)), k(E, "ROTY_PI", F.rotY(Math.PI)), k(E, "ROTY_MPI2", F.rotY(-Math.PI / 2)), k(E, "ROTZ_PI2", F.rotZ(Math.PI / 2)), k(E, "ROTZ_PI", F.rotZ(Math.PI)), k(E, "ROTZ_MPI2", F.rotZ(-Math.PI / 2));
188
- function T(i) {
189
- return i * (Math.PI / 180);
190
- }
191
- function L(i) {
192
- return i * 180 / Math.PI;
193
- }
194
- function yt(i, t) {
195
- return Math.atan2(Math.sin(i - t), Math.cos(i - t));
196
- }
197
- function wt(i, t) {
198
- let e = Math.abs(yt(i, t));
199
- return e > Math.PI / 2 && (e = Math.PI - e), e;
200
- }
201
- function rt(i, t) {
202
- return (i % t + t) % t;
203
- }
204
- function Mt(i, t, e) {
205
- const n = e - t, r = ((i - t) % n + n) % n + t;
206
- return r === t ? e : r;
207
- }
208
- class x {
209
- static eulerToQuaternionZXYDegrees(t) {
210
- const e = t.map((n) => T(n));
211
- return x.eulerToQuaternionZXY(e);
212
- }
213
- static eulerToQuaternionZXY(t) {
214
- const e = t[0], n = t[1], r = t[2], s = Math.cos(e / 2), o = Math.cos(n / 2), a = Math.cos(r / 2), l = Math.sin(e / 2), h = Math.sin(n / 2), u = Math.sin(r / 2);
215
- let g = s * o * a - l * h * u, f = s * h * a - l * o * u, M = l * h * a + s * o * u, d = l * o * a + s * h * u;
216
- return g < 0 && (g = -g, f = -f, M = -M, d = -d), [g, f, M, d];
217
- }
218
- static quaternionToEulerZXYDegrees(t) {
219
- return x.quaternionToEulerZXY(t).map((e) => L(e));
220
- }
221
- static quaternionToEulerZXY(t) {
222
- const e = t[0], n = t[1], r = t[2], s = t[3];
223
- let o, a, l;
224
- const h = r * s + n * e;
225
- return h > 0.499 ? (o = 2 * Math.atan2(r, e), a = Math.PI / 2, l = 0) : h < -0.499 ? (o = -2 * Math.atan2(r, e), a = -Math.PI / 2, l = 0) : (o = Math.atan2(
226
- 2 * s * e - 2 * r * n,
227
- 1 - 2 * Math.pow(s, 2) - 2 * Math.pow(n, 2)
228
- ), a = Math.asin(2 * h), l = Math.atan2(
229
- 2 * r * e - 2 * s * n,
230
- 1 - 2 * Math.pow(r, 2) - 2 * Math.pow(n, 2)
231
- )), o = o % (2 * Math.PI), a = a % Math.PI, l = l % (2 * Math.PI), [o, a, l];
232
- }
233
- static quaternionToEulerDegrees(t, e) {
234
- return x.quaternionToEuler(t, e).map((n) => L(n));
235
- }
236
- static quaternionToEuler(t, e) {
237
- const n = t[0], r = t[1], s = t[2], o = t[3];
238
- switch (e.toLowerCase()) {
239
- case "zyx":
240
- return x._threeaxisrot(
241
- 2 * (r * s + n * o),
242
- n ** 2 + r ** 2 - s ** 2 - o ** 2,
243
- -2 * (r * o - n * s),
244
- 2 * (s * o + n * r),
245
- n ** 2 - r ** 2 - s ** 2 + o ** 2
246
- );
247
- case "zyz":
248
- return x._twoaxisrot(
249
- 2 * (s * o - n * r),
250
- 2 * (r * o + n * s),
251
- n ** 2 - r ** 2 - s ** 2 + o ** 2,
252
- 2 * (s * o + n * r),
253
- -2 * (r * o - n * s)
254
- );
255
- case "zxy":
256
- return x._threeaxisrot(
257
- -2 * (r * s - n * o),
258
- n ** 2 - r ** 2 + s ** 2 - o ** 2,
259
- 2 * (s * o + n * r),
260
- -2 * (r * o - n * s),
261
- n ** 2 - r ** 2 - s ** 2 + o ** 2
262
- );
263
- case "zxz":
264
- return x._twoaxisrot(
265
- 2 * (r * o + n * s),
266
- -2 * (s * o - n * r),
267
- n ** 2 - r ** 2 - s ** 2 + o ** 2,
268
- 2 * (r * o - n * s),
269
- 2 * (s * o + n * r)
270
- );
271
- case "yxz":
272
- return x._threeaxisrot(
273
- 2 * (r * o + n * s),
274
- n ** 2 - r ** 2 - s ** 2 + o ** 2,
275
- -2 * (s * o - n * r),
276
- 2 * (r * s + n * o),
277
- n ** 2 - r ** 2 + s ** 2 - o ** 2
278
- );
279
- case "yxy":
280
- return x._twoaxisrot(
281
- 2 * (r * s - n * o),
282
- 2 * (s * o + n * r),
283
- n ** 2 - r ** 2 + s ** 2 - o ** 2,
284
- 2 * (r * s + n * o),
285
- -2 * (s * o - n * r)
286
- );
287
- case "yzx":
288
- return x._threeaxisrot(
289
- -2 * (r * o - n * s),
290
- n ** 2 + r ** 2 - s ** 2 - o ** 2,
291
- 2 * (r * s + n * o),
292
- -2 * (s * o - n * r),
293
- n ** 2 - r ** 2 + s ** 2 - o ** 2
294
- );
295
- case "yzy":
296
- return x._twoaxisrot(
297
- 2 * (s * o + n * r),
298
- -2 * (r * s - n * o),
299
- n ** 2 - r ** 2 + s ** 2 - o ** 2,
300
- 2 * (s * o - n * r),
301
- 2 * (r * s + n * o)
302
- );
303
- case "xyz":
304
- return x._threeaxisrot(
305
- -2 * (s * o - n * r),
306
- n ** 2 - r ** 2 - s ** 2 + o ** 2,
307
- 2 * (r * o + n * s),
308
- -2 * (r * s - n * o),
309
- n ** 2 + r ** 2 - s ** 2 - o ** 2
310
- );
311
- case "xyx":
312
- return x._twoaxisrot(
313
- 2 * (r * s + n * o),
314
- -2 * (r * o - n * s),
315
- n ** 2 + r ** 2 - s ** 2 - o ** 2,
316
- 2 * (r * s - n * o),
317
- 2 * (r * o + n * s)
318
- );
319
- case "xzy":
320
- return x._threeaxisrot(
321
- 2 * (s * o + n * r),
322
- n ** 2 - r ** 2 + s ** 2 - o ** 2,
323
- -2 * (r * s - n * o),
324
- 2 * (r * o + n * s),
325
- n ** 2 + r ** 2 - s ** 2 - o ** 2
326
- );
327
- case "xzx":
328
- return x._twoaxisrot(
329
- 2 * (r * o - n * s),
330
- 2 * (r * s + n * o),
331
- n ** 2 + r ** 2 - s ** 2 - o ** 2,
332
- 2 * (r * o + n * s),
333
- -2 * (r * s - n * o)
334
- );
335
- }
336
- throw new Error("unknown order");
337
- }
338
- static _threeaxisrot(t, e, n, r, s) {
339
- const o = Math.atan2(t, e), a = Math.asin(n), l = Math.atan2(r, s);
340
- return [o, a, l];
341
- }
342
- static _twoaxisrot(t, e, n, r, s) {
343
- const o = Math.atan2(t, e), a = Math.acos(n), l = Math.atan2(r, s);
344
- return [o, a, l];
345
- }
346
- static getHeadingFromQuaternion(t) {
347
- const [e, n, r, s] = t, o = e * n, a = r * s, l = n ** 2;
348
- return Math.asin(2 * (o + a)) < Math.PI / 4 && l + r ** 2 < 0.5 ? -Math.atan2(e * s - n * r, 0.5 - l - s ** 2) : -Math.atan2(n * s + e * r, o - a);
349
- }
350
- }
351
- const I = class {
352
- static checkType(t) {
353
- if (t !== null && !(typeof t == "number" && !isNaN(t))) {
354
- if (Array.isArray(t) && t.length === 2) {
355
- const [e, n] = t;
356
- if (typeof e == "number" && !isNaN(e) && typeof n == "number" && !isNaN(n)) {
357
- if (e > n || e === n)
358
- throw Error(`Invalid level range: [${e}, ${n}]`);
359
- return;
360
- }
361
- }
362
- throw Error(`Unknown level format: ${t}`);
363
- }
364
- }
365
- static isRange(t) {
366
- return I.VERIFY_TYPING && this.checkType(t), Array.isArray(t);
367
- }
368
- static clone(t) {
369
- return I.VERIFY_TYPING && this.checkType(t), t === null ? null : typeof t == "number" ? t : [t[0], t[1]];
370
- }
371
- static fromString(t) {
372
- if (t === null)
373
- return null;
374
- if (typeof t != "string")
375
- throw Error(`argument must be a string, got ${typeof t}`);
376
- if (!isNaN(Number(t)))
377
- return parseFloat(t);
378
- const e = t.split(";");
379
- if (e.length === 2) {
380
- const n = Number(e[0]), r = Number(e[1]);
381
- return this.checkType([n, r]), [parseFloat(e[0]), parseFloat(e[1])];
382
- }
383
- throw Error(`Cannot parse following level: ${t}`);
384
- }
385
- static contains(t, e) {
386
- return I.VERIFY_TYPING && (this.checkType(t), this.checkType(e)), t === e ? !0 : Array.isArray(t) ? Array.isArray(e) ? t[0] <= e[0] && t[1] >= e[1] : e === null ? !1 : t[0] <= e && t[1] >= e : t === null || e === null ? !1 : t <= e[0] && t >= e[1];
387
- }
388
- static intersection(t, e) {
389
- if (I.VERIFY_TYPING && (this.checkType(t), this.checkType(e)), t === null || e === null)
390
- return null;
391
- if (this.equals(t, e))
392
- return this.clone(t);
393
- if (typeof t == "number" && typeof e == "number")
394
- return t === e ? t : null;
395
- if (Array.isArray(t) && !Array.isArray(e))
396
- return this.contains(t, e) ? e : null;
397
- if (!Array.isArray(t) && Array.isArray(e))
398
- return this.contains(e, t) ? t : null;
399
- const n = Math.max(t[0], e[0]), r = Math.min(t[1], e[1]);
400
- return r === n ? r : r < n ? null : [n, r];
401
- }
402
- static intersect(t, e) {
403
- return I.VERIFY_TYPING && (this.checkType(t), this.checkType(e)), t === null && e === null ? !0 : this.intersection(t, e) !== null;
404
- }
405
- static union(t, e) {
406
- if (I.VERIFY_TYPING && (this.checkType(t), this.checkType(e)), t === e)
407
- return this.clone(t);
408
- if (e === null)
409
- return this.clone(t);
410
- if (t === null)
411
- return this.clone(e);
412
- let n, r;
413
- return !Array.isArray(t) && !Array.isArray(e) ? (n = Math.min(t, e), r = Math.max(t, e)) : Array.isArray(t) && !Array.isArray(e) ? (n = Math.min(t[0], e), r = Math.max(t[1], e)) : !Array.isArray(t) && Array.isArray(e) ? (n = Math.min(e[0], t), r = Math.max(e[1], t)) : (n = Math.min(t[0], e[0]), r = Math.max(t[1], e[1])), n === r ? n : [n, r];
414
- }
415
- static multiplyBy(t, e) {
416
- return I.VERIFY_TYPING && this.checkType(t), t === null ? null : Array.isArray(t) ? [t[0] * e, t[1] * e] : t * e;
417
- }
418
- static toString(t) {
419
- return I.VERIFY_TYPING && this.checkType(t), t === null ? null : Array.isArray(t) ? t[0] + ";" + t[1] : String(t);
420
- }
421
- static equals(t, e) {
422
- return I.VERIFY_TYPING && (this.checkType(t), this.checkType(e)), t === e ? !0 : Array.isArray(t) && Array.isArray(e) ? t[0] === e[0] && t[1] === e[1] : !1;
423
- }
424
- static diff(t, e) {
425
- return I.VERIFY_TYPING && (this.checkType(t), this.checkType(e)), t === null || e === null ? null : !Array.isArray(t) && !Array.isArray(e) ? e - t : Array.isArray(t) && !Array.isArray(e) ? t[0] === e ? e - t[1] : t[1] === e ? e - t[0] : null : Array.isArray(e) && !Array.isArray(t) ? t === e[0] ? e[1] - t : t === e[1] ? e[0] - t : null : I.equals(t, e) ? 0 : null;
426
- }
427
- };
428
- let y = I;
429
- c(y, "VERIFY_TYPING", !1);
430
- class m {
431
- constructor(t, e, n = null, r = null) {
432
- c(this, "_lat");
433
- c(this, "_lng");
434
- c(this, "_alt", null);
435
- c(this, "_level", null);
436
- c(this, "_ecef");
437
- c(this, "autoWrap", !0);
438
- this.lat = t, this.lng = e, this.alt = n, this.level = r, this._ecef = null;
439
- }
440
- get lat() {
441
- return this._lat;
442
- }
443
- set lat(t) {
444
- if (Math.abs(t) <= 90)
445
- this._lat = t;
446
- else
447
- throw new Error("lat argument is not in [-90; 90]");
448
- this._ecef = null;
449
- }
450
- get latitude() {
451
- return this._lat;
452
- }
453
- set latitude(t) {
454
- throw new Error("Please use Coordinates#lat setter instead of Coordinate#latitude");
455
- }
456
- get lng() {
457
- return this._lng;
458
- }
459
- set lng(t) {
460
- this._lng = t, this.autoWrap && this.wrap(), this._ecef = null;
461
- }
462
- get longitude() {
463
- return this._lng;
464
- }
465
- set longitude(t) {
466
- throw new Error("Please use Coordinates#lng setter instead of Coordinate#longitude");
467
- }
468
- get alt() {
469
- return this._alt;
470
- }
471
- set alt(t) {
472
- this._alt = t, this._ecef = null;
473
- }
474
- get level() {
475
- return this._level;
476
- }
477
- set level(t) {
478
- y.checkType(t), this._level = t;
479
- }
480
- clone() {
481
- const t = new m(this.lat, this.lng, this.alt);
482
- return this.level !== null && (t.level = y.clone(this.level)), t;
483
- }
484
- wrap() {
485
- (this._lng <= -180 || this._lng > 180) && (this._lng = Mt(this._lng, -180, 180));
486
- }
487
- static equals(t, e, n = X, r = P) {
488
- return t === null && t === e ? !0 : !(t instanceof m) || !(e instanceof m) ? !1 : Math.abs(e.lat - t.lat) < n && Math.abs(e.lng - t.lng) < n && (t.alt === e.alt || t.alt !== null && e.alt !== null && Math.abs(e.alt - t.alt) < r) && y.equals(t.level, e.level);
489
- }
490
- equals(t) {
491
- return m.equals(this, t);
492
- }
493
- destinationPoint(t, e, n = null) {
494
- const r = this.clone();
495
- return r.move(t, e, n), r;
496
- }
497
- move(t, e, n = null) {
498
- const r = t / 6378137, s = Math.cos(r), o = Math.sin(r), a = T(this.lat), l = T(this.lng), h = Math.asin(
499
- Math.sin(a) * s + Math.cos(a) * o * Math.cos(e)
500
- ), u = l + Math.atan2(
501
- Math.sin(e) * o * Math.cos(a),
502
- s - Math.sin(a) * Math.sin(h)
503
- );
504
- if (this.lat = L(h), this.lng = L(u), n !== null) {
505
- if (this.alt === null)
506
- throw new Error("Point altitude is not defined");
507
- this.alt += n;
508
- }
509
- return this;
510
- }
511
- distanceTo(t) {
512
- const e = this.lat, n = this.lng, r = t.lat, s = t.lng, o = T(r - e), a = T(s - n), l = Math.sin(a / 2), h = Math.sin(o / 2), u = T(e), g = Math.cos(u), f = T(r), M = Math.cos(f), d = h * h + g * M * l * l, _ = Math.sqrt(d), b = Math.sqrt(1 - d);
513
- return 6378137 * (2 * Math.atan2(_, b));
514
- }
515
- static distanceBetween(t, e) {
516
- return t.distanceTo(e);
517
- }
518
- bearingTo(t) {
519
- const e = T(this.lat), n = T(t.lat), r = T(t.lng - this.lng);
520
- return Math.atan2(
521
- Math.sin(r) * Math.cos(n),
522
- Math.cos(e) * Math.sin(n) - Math.sin(e) * Math.cos(n) * Math.cos(r)
523
- );
524
- }
525
- static bearingTo(t, e) {
526
- return t.bearingTo(e);
527
- }
528
- get enuToEcefRotation() {
529
- const t = E.fromAxisAngle([0, 0, 1], Math.PI / 2 + T(this.lng)), e = E.fromAxisAngle([1, 0, 0], Math.PI / 2 - T(this.lat));
530
- return E.multiply(t, e);
531
- }
532
- get ecefToEnuRotation() {
533
- const t = E.fromAxisAngle([1, 0, 0], T(this.lat) - Math.PI / 2), e = E.fromAxisAngle([0, 0, 1], -T(this.lng) - Math.PI / 2);
534
- return E.multiply(t, e);
535
- }
536
- get ecef() {
537
- if (!this._ecef) {
538
- const t = T(this.lat), e = T(this.lng), n = this.alt || 0, r = (6378137 + n) * Math.cos(t) * Math.cos(e), s = (6378137 + n) * Math.cos(t) * Math.sin(e), o = (6378137 + n) * Math.sin(t);
539
- this._ecef = [r, s, o];
540
- }
541
- return this._ecef;
542
- }
543
- static fromECEF(t) {
544
- const e = t[0], n = t[1], r = t[2], s = Math.sqrt(e ** 2 + n ** 2);
545
- let o = Math.atan2(n, e);
546
- const a = Math.atan2(r, s), l = s / Math.cos(a) - 6378137;
547
- o = o % (2 * Math.PI);
548
- const h = new m(L(a), L(o), l);
549
- return h._ecef = t, h;
550
- }
551
- getSegmentProjection(t, e) {
552
- const n = w.normalize(t.ecef), r = w.normalize(e.ecef), s = w.normalize(this.ecef), o = w.cross(n, r);
553
- if (w.norm(o) === 0)
554
- return null;
555
- const a = w.cross(s, o), l = w.normalize(w.cross(o, a)), h = w.multiplyScalar(l, 6378137), u = m.fromECEF(h);
556
- let g;
557
- t.alt !== null && e.alt !== null && (g = (t.alt + e.alt) / 2);
558
- const f = new m(
559
- u.lat,
560
- u.lng,
561
- g,
562
- y.intersection(t.level, e.level)
563
- );
564
- return Math.abs(t.distanceTo(e) - t.distanceTo(f) - e.distanceTo(f)) > P ? null : f;
565
- }
566
- toString() {
567
- let t = "[" + this._lat.toFixed(7) + ", " + this._lng.toFixed(7);
568
- return this._alt !== null && (t += ", " + this._alt.toFixed(2)), this._level !== null && (t += ", [" + y.toString(this._level) + "]"), t += "]", t;
569
- }
570
- toJson() {
571
- return {
572
- lat: this.lat,
573
- lng: this.lng,
574
- ...this.alt !== null && { alt: this.alt },
575
- ...this.level !== null && { level: this.level }
576
- };
577
- }
578
- static fromJson(t) {
579
- return new m(t.lat, t.lng, t.alt, t.level);
580
- }
581
- toCompressedJson() {
582
- return this.level !== null ? [this.lat, this.lng, this.alt, this.level] : this.alt !== null ? [this.lat, this.lng, this.alt] : [this.lat, this.lng];
583
- }
584
- static fromCompressedJson(t) {
585
- const e = new m(t[0], t[1]);
586
- return t.length > 2 && (e.alt = t[2]), t.length > 3 && (e.level = t[3]), e;
587
- }
588
- }
589
- class q extends m {
590
- constructor(e, n, r = null, s = null, o = null, a = null, l = null) {
591
- super(e, n, r, s);
592
- c(this, "_time", null);
593
- c(this, "_accuracy", null);
594
- c(this, "_bearing", null);
595
- this.time = o, this.accuracy = a, this.bearing = l;
596
- }
597
- get time() {
598
- return this._time;
599
- }
600
- set time(e) {
601
- this._time = e;
602
- }
603
- get accuracy() {
604
- return this._accuracy;
605
- }
606
- set accuracy(e) {
607
- if (e !== null && e < 0)
608
- throw new Error("accuracy argument is not a positive number");
609
- this._accuracy = e;
610
- }
611
- get bearing() {
612
- return this._bearing;
613
- }
614
- set bearing(e) {
615
- this._bearing = e !== null ? e % (2 * Math.PI) : null;
616
- }
617
- move(e, n, r = null) {
618
- return super.move(e, n, r), this;
619
- }
620
- destinationPoint(e, n, r = null) {
621
- const s = this.clone();
622
- return s.move(e, n, r), s;
623
- }
624
- static fromCoordinates(e) {
625
- return new q(
626
- e.lat,
627
- e.lng,
628
- e.alt,
629
- e.level
630
- );
631
- }
632
- clone() {
633
- const e = q.fromCoordinates(super.clone());
634
- return e.time = this.time, e.accuracy = this.accuracy, e.bearing = this.bearing, e;
635
- }
636
- static equals(e, n, r = X, s = P) {
637
- return e === null && e === n ? !0 : !(e instanceof q) || !(n instanceof q) || !super.equals(e, n, r, s) ? !1 : e.time === n.time && e.accuracy === n.accuracy && e.bearing === n.bearing;
638
- }
639
- equals(e, n = X, r = P) {
640
- return q.equals(this, e, n, r);
641
- }
642
- toJson() {
643
- return {
644
- ...super.toJson(),
645
- ...this.time !== null && { time: this.time },
646
- ...this.accuracy !== null && { accuracy: this.accuracy },
647
- ...this.bearing !== null && { bearing: this.bearing }
648
- };
649
- }
650
- static fromJson(e) {
651
- const n = q.fromCoordinates(m.fromJson(e));
652
- return typeof e.time < "u" && (n.time = e.time), typeof e.accuracy < "u" && (n.accuracy = e.accuracy), typeof e.bearing < "u" && (n.bearing = e.bearing), n;
653
- }
654
- }
655
- function _t(i, t = 0.7, e = 0, n = Number.MAX_VALUE) {
656
- const r = e + n, s = [];
657
- let o, a = 0, l = 0, h = !1;
658
- for (let u = 0; u < i.length - 1; u++) {
659
- const g = i[u], f = i[u + 1], M = g.distanceTo(f), d = g.bearingTo(f);
660
- let _ = 0;
661
- if (!h)
662
- if (e < a + M)
663
- h = !0, l = e - a;
664
- else {
665
- a += M;
666
- continue;
667
- }
668
- for (o = Object.assign(g.clone(), { bearing: d }); _ + l < M && a + l <= r; ) {
669
- const A = o.destinationPoint(l, d);
670
- A.bearing = d, s.push(A), o = A, _ += l, a += l, l = t;
671
- }
672
- if (a + l > r)
673
- break;
674
- const b = M - _;
675
- a += b, l -= b;
676
- }
677
- return s;
678
- }
679
- function Et(i, t = i[0], e = Number.MAX_VALUE) {
680
- const n = [];
681
- let r = null, s, o = 0;
682
- if (i.length <= 1)
683
- throw new Error("Route must have at least 2 points");
684
- for (s = 1; s < i.length; s++) {
685
- const a = i[s - 1], l = i[s];
686
- if (m.equals(t, a)) {
687
- n.push(a), r = a;
688
- break;
689
- }
690
- const h = t.getSegmentProjection(a, l);
691
- if (h && m.equals(t, h) && !h.equals(l)) {
692
- n.push(h), r = h;
693
- break;
694
- }
695
- }
696
- if (!n.length)
697
- throw new Error("startPosition is not on the route");
698
- for (; r && s < i.length; ) {
699
- const a = i[s], l = r.distanceTo(a);
700
- if (o + l >= e || Math.abs(o + l - e) <= P) {
701
- const h = r.bearingTo(a), u = e - o, g = r.destinationPoint(u, h);
702
- n.push(g);
703
- break;
704
- }
705
- n.push(a), r = a, o += l, s++;
706
- }
707
- return n;
708
- }
709
- function bt(i, t = T(5)) {
710
- const e = i[0].equals(i[i.length - 1]);
711
- let n = i.slice(0, i.length - (e ? 1 : 0));
712
- const r = n.length;
713
- for (let s = e ? 0 : 1; s < r; s++) {
714
- const o = i[rt(s - 1, r)], a = i[s], l = i[rt(s + 1, r)], h = o.bearingTo(a), u = a.bearingTo(l);
715
- Math.abs(u - h) < t && (n = n.filter((g) => g !== a));
716
- }
717
- return e && n.push(n[0]), n;
718
- }
719
- function pt(i) {
720
- if (i === null)
721
- return null;
722
- const { latitude: t, longitude: e, accuracy: n, heading: r } = i.coords, s = new q(t, e);
723
- return s.time = i.timestamp, s.accuracy = n, s.bearing = r ? T(r) : null, s;
724
- }
725
- function At(i) {
726
- return i.reduce((t, e, n, r) => t + (n ? r[n - 1].distanceTo(e) : 0), 0);
727
- }
728
- const Ot = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
729
- __proto__: null,
730
- sampleRoute: _t,
731
- trimRoute: Et,
732
- simplifyRoute: bt,
733
- geolocationPositionToUserPosition: pt,
734
- calcDistance: At
735
- }, Symbol.toStringTag, { value: "Module" }));
736
- class W {
737
- constructor(t, e) {
738
- c(this, "northEast");
739
- c(this, "southWest");
740
- if (this.northEast = t, this.southWest = e, this.northEast && this.southWest && this.getNorth() < this.getSouth())
741
- throw new Error("Incorrect bounding box");
742
- }
743
- get center() {
744
- const t = (this.southWest.lat + this.northEast.lat) / 2, e = (this.northEast.lng + this.southWest.lng) / 2;
745
- return new m(t, e);
746
- }
747
- contains(t) {
748
- return t.lat <= this.northEast.lat && t.lat >= this.southWest.lat && t.lng <= this.northEast.lng && t.lng >= this.southWest.lng;
749
- }
750
- extend(t) {
751
- const e = this.southWest, n = this.northEast;
752
- let r, s;
753
- if (t instanceof m)
754
- r = t, s = t;
755
- else if (t instanceof W)
756
- r = t.southWest, s = t.northEast;
757
- else
758
- throw new Error("Unknown parameter");
759
- return this.southWest = new m(
760
- Math.min(r.lat, e.lat),
761
- Math.min(r.lng, e.lng)
762
- ), this.northEast = new m(
763
- Math.max(s.lat, n.lat),
764
- Math.max(s.lng, n.lng)
765
- ), this;
766
- }
767
- extendsWithMeasure(t) {
768
- if (typeof t != "number")
769
- throw new Error("measure is not a number");
770
- return this.northEast = this.northEast.destinationPoint(t, 0).move(t, Math.PI / 2), this.southWest = this.southWest.clone().destinationPoint(t, -Math.PI / 2).destinationPoint(t, Math.PI), this;
771
- }
772
- pad(t) {
773
- const e = this.southWest, n = this.northEast, r = Math.abs(e.lat - n.lat) * t, s = Math.abs(e.lng - n.lng) * t;
774
- return this.southWest = new m(e.lat - r, e.lng - s), this.northEast = new m(n.lat + r, n.lng + s), this;
775
- }
776
- getSouthWest() {
777
- return this.southWest;
778
- }
779
- getNorthEast() {
780
- return this.northEast;
781
- }
782
- getNorthWest() {
783
- return new m(this.getNorth(), this.getWest());
784
- }
785
- getSouthEast() {
786
- return new m(this.getSouth(), this.getEast());
787
- }
788
- getWest() {
789
- return this.southWest.lng;
790
- }
791
- getSouth() {
792
- return this.southWest.lat;
793
- }
794
- getEast() {
795
- return this.northEast.lng;
796
- }
797
- getNorth() {
798
- return this.northEast.lat;
799
- }
800
- static equals(t, e) {
801
- return m.equals(t.northEast, e.northEast) && m.equals(t.southWest, e.southWest);
802
- }
803
- equals(t) {
804
- return W.equals(this, t);
805
- }
806
- static fromArray(t) {
807
- return new W(
808
- new m(t[3], t[2]),
809
- new m(t[1], t[0])
810
- );
811
- }
812
- toArray() {
813
- return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()];
814
- }
815
- }
816
- class C {
817
- constructor(t, e, n, r = null, s = null, o = null) {
818
- c(this, "x");
819
- c(this, "y");
820
- c(this, "z");
821
- c(this, "time", null);
822
- c(this, "_accuracy", null);
823
- c(this, "_bearing", null);
824
- this.x = t, this.y = e, this.z = n, this.time = r, this.accuracy = s, this.bearing = o;
825
- }
826
- get accuracy() {
827
- return this._accuracy;
828
- }
829
- set accuracy(t) {
830
- if (t !== null && t < 0)
831
- throw new Error("accuracy argument is not a positive number");
832
- this._accuracy = t;
833
- }
834
- get bearing() {
835
- return this._bearing;
836
- }
837
- set bearing(t) {
838
- this._bearing = t !== null ? t % (2 * Math.PI) : null;
839
- }
840
- clone() {
841
- return new C(this.x, this.y, this.z, this.time, this.accuracy, this.bearing);
842
- }
843
- static equals(t, e, n = P) {
844
- return t === null && t === e ? !0 : !(t instanceof C) || !(e instanceof C) ? !1 : Math.abs(e.x - t.x) < n && Math.abs(e.y - t.y) < n && Math.abs(e.z - t.z) < n && t.time === e.time && t.accuracy === e.accuracy && t.bearing === e.bearing;
845
- }
846
- equals(t) {
847
- return C.equals(this, t);
848
- }
849
- toJson() {
850
- return {
851
- x: this.x,
852
- y: this.y,
853
- z: this.z,
854
- ...this.time !== null && { time: this.time },
855
- ...this.accuracy !== null && { accuracy: this.accuracy },
856
- ...this.bearing !== null && { bearing: this.bearing }
857
- };
858
- }
859
- static fromJson(t) {
860
- return new C(t.x, t.y, t.z, t.time, t.accuracy, t.bearing);
861
- }
862
- }
863
- class kt extends C {
864
- }
865
- class it {
866
- constructor(t) {
867
- c(this, "origin");
868
- c(this, "scale", 1);
869
- c(this, "heading", 0);
870
- this.origin = t;
871
- }
872
- localToWorld(t) {
873
- const e = w.multiplyScalar(t, this.scale), n = E.fromAxisAngle([0, 0, 1], this.heading), r = E.multiply(n, this.origin.enuToEcefRotation), s = E.rotate(r, e), o = w.sum(this.origin.ecef, s);
874
- return m.fromECEF(o);
875
- }
876
- worldToLocal(t) {
877
- const e = E.fromAxisAngle([0, 0, 1], -this.heading), n = E.multiply(this.origin.ecefToEnuRotation, e), r = w.subtract(t.ecef, this.origin.ecef), s = w.multiplyScalar(r, 1 / this.scale);
878
- return E.rotate(n, s);
879
- }
880
- toJson() {
881
- return {
882
- origin: this.origin.toJson(),
883
- ...this.scale !== 1 && { scale: this.scale },
884
- ...this.heading !== 0 && { heading: this.heading }
885
- };
886
- }
887
- static fromJson(t) {
888
- const e = new it(m.fromJson(t.origin));
889
- return e.scale = typeof t.scale < "u" ? t.scale : 1, e.heading = typeof t.heading < "u" ? t.heading : 0, e;
890
- }
891
- }
892
- class O {
893
- constructor(t, e = null, n = null) {
894
- c(this, "_quaternion", [1, 0, 0, 0]);
895
- c(this, "_heading", null);
896
- c(this, "_eulerAngles", null);
897
- c(this, "_time", null);
898
- c(this, "_accuracy", null);
899
- this.quaternion = t, this.time = e, this.accuracy = n;
900
- }
901
- static unitary() {
902
- return new O([1, 0, 0, 0]);
903
- }
904
- get quaternion() {
905
- return this._quaternion;
906
- }
907
- set quaternion(t) {
908
- if (Math.abs(1 - E.norm(t)) > 1e-4)
909
- throw new Error("quaternion is not a unit quaternion");
910
- this._quaternion = t, this._heading = null, this._eulerAngles = null;
911
- }
912
- get time() {
913
- return this._time;
914
- }
915
- set time(t) {
916
- this._time = t;
917
- }
918
- get accuracy() {
919
- return this._accuracy;
920
- }
921
- set accuracy(t) {
922
- if (t !== null && (t < 0 || t > Math.PI))
923
- throw new Error("accuracy argument (" + t + ") is not in range [0; PI]");
924
- this._accuracy = t;
925
- }
926
- get eulerAngles() {
927
- return this._eulerAngles === null && (this._eulerAngles = x.quaternionToEulerZXY(this.quaternion)), this._eulerAngles;
928
- }
929
- get eulerAnglesDegrees() {
930
- return this.eulerAngles.map((t) => L(t));
931
- }
932
- get heading() {
933
- if (this._heading === null) {
934
- let t = 0;
935
- typeof window < "u" && window && window.orientation && (t = T(window.orientation)), this._heading = x.getHeadingFromQuaternion(this.quaternion) + t;
936
- }
937
- return this._heading;
938
- }
939
- get headingDegrees() {
940
- return L(this.heading);
941
- }
942
- static equals(t, e) {
943
- return t === null && t === e ? !0 : !(t instanceof O) || !(e instanceof O) ? !1 : t === e ? !0 : E.equals(t.quaternion, e.quaternion);
944
- }
945
- equals(t) {
946
- return O.equals(this, t);
947
- }
948
- toJson() {
949
- return this.time === null && this.accuracy === null ? this.quaternion : {
950
- q: this.quaternion,
951
- ...this.time !== null && { time: this.time },
952
- ...this.accuracy !== null && { accuracy: this.accuracy }
953
- };
954
- }
955
- static fromJson(t) {
956
- return Array.isArray(t) ? new O(t, null, null) : new O(t.q, t.time, t.accuracy);
957
- }
958
- clone() {
959
- return new O(this.quaternion.slice(0), this.time, this.accuracy);
960
- }
961
- static diff(t, e) {
962
- const n = E.multiply(
963
- E.inverse(t.quaternion),
964
- e.quaternion
965
- );
966
- let r = null;
967
- e.time !== null && t.time !== null && (r = e.time - t.time);
968
- let s = null;
969
- return t.accuracy !== null && e.accuracy !== null && (s = Math.max(e.accuracy - t.accuracy)), new O(n, r, s);
970
- }
971
- }
972
- class J {
973
- constructor(t, e = null, n = null) {
974
- c(this, "heading");
975
- c(this, "time", null);
976
- c(this, "_accuracy", null);
977
- this.heading = t, this.time = e, this.accuracy = n;
978
- }
979
- get accuracy() {
980
- return this._accuracy;
981
- }
982
- set accuracy(t) {
983
- if (t !== null && (t < 0 || t > Math.PI))
984
- throw new Error("accuracy argument (" + t + ") is not in range [0; PI]");
985
- this._accuracy = t;
986
- }
987
- toAttitude() {
988
- return new O(
989
- E.fromAxisAngle([0, 0, 1], -this.heading),
990
- this.time,
991
- this.accuracy
992
- );
993
- }
994
- static equals(t, e) {
995
- return t === null && t === e ? !0 : !(t instanceof J) || !(e instanceof J) ? !1 : Math.abs(t.heading - e.heading) < 1e-8;
996
- }
997
- equals(t) {
998
- return J.equals(this, t);
999
- }
1000
- toJson() {
1001
- return {
1002
- heading: this.heading,
1003
- ...this.time !== null && { time: this.time },
1004
- ...this.accuracy !== null && { accuracy: this.accuracy }
1005
- };
1006
- }
1007
- static fromJson(t) {
1008
- return new J(t.heading, t.time, t.accuracy);
1009
- }
1010
- clone() {
1011
- return new J(this.heading, this.time, this.accuracy);
1012
- }
1013
- }
1014
- class R {
1015
- constructor(t, e = null) {
1016
- c(this, "coords");
1017
- c(this, "edges", []);
1018
- c(this, "builtFrom");
1019
- c(this, "io", !1);
1020
- this.coords = t, this.builtFrom = e;
1021
- }
1022
- distanceTo(t) {
1023
- return this.coords.distanceTo(t.coords);
1024
- }
1025
- bearingTo(t) {
1026
- return this.coords.bearingTo(t.coords);
1027
- }
1028
- equals(t) {
1029
- return this.coords.equals(t.coords) && this.builtFrom === t.builtFrom;
1030
- }
1031
- clone() {
1032
- const t = new R(this.coords, this.builtFrom);
1033
- return t.edges = this.edges.slice(0), t.io = this.io, t;
1034
- }
1035
- toJson() {
1036
- return this.coords.toCompressedJson();
1037
- }
1038
- static fromJson(t, e = null) {
1039
- return new R(m.fromCompressedJson(t), e);
1040
- }
1041
- _generateLevelFromEdges() {
1042
- let t = null;
1043
- for (let e = 0; e < this.edges.length; e++) {
1044
- const n = this.edges[e];
1045
- if (n.level !== null) {
1046
- if (t === null)
1047
- t = y.clone(n.level);
1048
- else if (t = y.intersection(t, n.level), t === null)
1049
- throw Error("Something bad happend during parsing: We cannot retrieve node level from adjacent ways: " + this.coords);
1050
- }
1051
- }
1052
- this.coords.level = t;
1053
- }
1054
- _inferNodeLevelByRecursion() {
1055
- const { level: t } = this.coords;
1056
- if (t === null || !y.isRange(t) || this.edges.length > 1)
1057
- return;
1058
- const e = (r, s) => {
1059
- if (s.push(r), r.coords.level === null)
1060
- return null;
1061
- if (!y.isRange(r.coords.level))
1062
- return r.coords.level;
1063
- let o = null;
1064
- for (let a = 0; a < r.edges.length; a++) {
1065
- const l = r.edges[a], h = l.node1 === r ? l.node2 : l.node1;
1066
- s.includes(h) || (o = y.union(e(h, s), o));
1067
- }
1068
- return o;
1069
- }, n = e(this, []);
1070
- if (n !== null) {
1071
- if (!y.isRange(n)) {
1072
- this.coords.level = n === t[0] ? t[1] : t[0];
1073
- return;
1074
- }
1075
- throw Error("Level of: " + this.coords.toString() + " cannot be decided");
1076
- }
1077
- }
1078
- _inferNodeLevelByNeighboors() {
1079
- const { level: t } = this.coords;
1080
- if (t === null || !y.isRange(t))
1081
- return !0;
1082
- let e = null;
1083
- for (let n = 0; n < this.edges.length; n++) {
1084
- const r = this.edges[n], s = r.node1 === this ? r.node2 : r.node1;
1085
- e = y.union(s.coords.level, e);
1086
- }
1087
- return (e === null || !y.isRange(e)) && (this.coords.level = e === t[0] ? t[1] : t[0]), !0;
1088
- }
1089
- _checkIO() {
1090
- return this.io = this.coords.level !== null && this.edges.some((t) => t.level === null), !0;
1091
- }
1092
- static generateNodesLevels(t) {
1093
- t.forEach((e) => e._generateLevelFromEdges()), t.forEach((e) => e._inferNodeLevelByNeighboors()), t.forEach((e) => e._inferNodeLevelByRecursion()), t.forEach((e) => e._checkIO());
1094
- }
1095
- }
1096
- class B {
1097
- constructor(t, e, n = null, r = null) {
1098
- c(this, "_node1");
1099
- c(this, "_node2");
1100
- c(this, "_level", null);
1101
- c(this, "_bearing", null);
1102
- c(this, "_length", null);
1103
- c(this, "_computedSizeAndBearing", !1);
1104
- c(this, "builtFrom");
1105
- c(this, "isOneway", !1);
1106
- this.node1 = t, this.node2 = e, this.level = n, this.builtFrom = r;
1107
- }
1108
- get node1() {
1109
- return this._node1;
1110
- }
1111
- set node1(t) {
1112
- if (!(t instanceof R))
1113
- throw new TypeError("node1 is not a GraphNode");
1114
- this._node1 instanceof R && this._node2 !== this._node1 && (this._node1.edges = this._node1.edges.filter((e) => e !== this)), t.edges.push(this), this._node1 = t, this._computedSizeAndBearing = !1;
1115
- }
1116
- get node2() {
1117
- return this._node2;
1118
- }
1119
- set node2(t) {
1120
- if (!(t instanceof R))
1121
- throw new TypeError("node2 is not a GraphNode");
1122
- this._node2 instanceof R && this._node2 !== this._node1 && (this._node2.edges = this._node2.edges.filter((e) => e !== this)), t.edges.push(this), this._node2 = t, this._computedSizeAndBearing = !1;
1123
- }
1124
- get level() {
1125
- return this._level;
1126
- }
1127
- set level(t) {
1128
- y.checkType(t), this._level = t;
1129
- }
1130
- get bearing() {
1131
- return this._computedSizeAndBearing || this._computeSizeAndBearing(), this._bearing;
1132
- }
1133
- get length() {
1134
- return this._computedSizeAndBearing || this._computeSizeAndBearing(), this._length;
1135
- }
1136
- _computeSizeAndBearing() {
1137
- this._length = this.node1.distanceTo(this.node2), this._bearing = this.node1.bearingTo(this.node2), this._computedSizeAndBearing = !0;
1138
- }
1139
- equals(t) {
1140
- return this === t ? !0 : t instanceof B ? t.node1.equals(this.node1) && t.node2.equals(this.node2) && y.equals(t.level, this.level) && t.isOneway === this.isOneway && t.builtFrom === this.builtFrom : !1;
1141
- }
1142
- clone() {
1143
- const t = new B(this.node1, this.node2, this.level, this.builtFrom);
1144
- return t.isOneway = this.isOneway, t;
1145
- }
1146
- }
1147
- function tt(i, t, e) {
1148
- return i.find(
1149
- (n) => t === n.node1 && e === n.node2 || e === n.node1 && t === n.node2
1150
- );
1151
- }
1152
- function Tt(i, t) {
1153
- return i.find((e) => e.coords.equals(t));
1154
- }
1155
- const qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1156
- __proto__: null,
1157
- getEdgeByNodes: tt,
1158
- getNodeByCoords: Tt
1159
- }, Symbol.toStringTag, { value: "Module" }));
1160
- class j {
1161
- constructor(t, e) {
1162
- c(this, "nodes");
1163
- c(this, "edges");
1164
- this.nodes = Array.isArray(t) ? t : [], this.edges = Array.isArray(e) ? e : [];
1165
- }
1166
- getNodeByCoords(t) {
1167
- return this.nodes.find((e) => e.coords.equals(t));
1168
- }
1169
- getEdgeByNodes(t, e) {
1170
- return tt(this.edges, t, e);
1171
- }
1172
- getBoundingBox(t) {
1173
- if (!this.nodes.length)
1174
- return null;
1175
- const e = this.nodes.reduce(
1176
- (n, r) => n.extend(r.coords),
1177
- new W(this.nodes[0].coords, this.nodes[0].coords)
1178
- );
1179
- return t && e.extendsWithMeasure(t), e;
1180
- }
1181
- toDetailedString(t, e) {
1182
- let n = t;
1183
- n || (n = (o) => `${o.builtFrom}`);
1184
- let r = e;
1185
- e || (r = (o) => `${o.builtFrom}`);
1186
- let s = `--- Network ---
1187
- Nodes: ${this.nodes.length}
1188
- Edges: ${this.edges.length}
1189
- ---
1190
- Nodes
1191
- `;
1192
- return this.nodes.forEach((o) => {
1193
- s += `${n(o)} [edges: ${o.edges.length}]
1194
- `;
1195
- }), s += `---
1196
- Edges
1197
- `, this.edges.forEach((o) => {
1198
- s += `${r(o)} `, s += `[${n(o.node1)} -- ${n(o.node2)}]
1199
- `;
1200
- }), s += "---", s;
1201
- }
1202
- toCompressedJson() {
1203
- return {
1204
- nodes: this.nodes.map((t) => t.toJson()),
1205
- edges: this.edges.map((t) => {
1206
- const e = this.nodes.indexOf(t.node1), n = this.nodes.indexOf(t.node2);
1207
- return t.isOneway ? [e, n, t.level, !0] : t.level ? [e, n, t.level] : [e, n];
1208
- })
1209
- };
1210
- }
1211
- static fromCompressedJson(t) {
1212
- const e = new j();
1213
- return e.nodes = t.nodes.map((n) => R.fromJson(n, null)), e.edges = t.edges.map((n) => {
1214
- const r = new B(
1215
- e.nodes[n[0]],
1216
- e.nodes[n[1]],
1217
- n[2],
1218
- null
1219
- );
1220
- return n.length > 3 && n[3] && (r.isOneway = !0), r;
1221
- }), e;
1222
- }
1223
- static fromCoordinates(t) {
1224
- const e = new j(), n = (s) => {
1225
- const o = e.nodes.find((l) => l.coords.equals(s));
1226
- if (o)
1227
- return o;
1228
- const a = new R(s, null);
1229
- return e.nodes.push(a), a;
1230
- }, r = (s, o) => new B(s, o, y.union(s.coords.level, o.coords.level), null);
1231
- for (const s of t) {
1232
- let o = null;
1233
- for (const a of s) {
1234
- const l = n(a);
1235
- if (o) {
1236
- const h = r(l, o);
1237
- e.edges.push(h);
1238
- }
1239
- o = l;
1240
- }
1241
- }
1242
- return e;
1243
- }
1244
- getEdgesAtLevel(t, e = !0) {
1245
- return this.edges.filter(
1246
- ({ level: n }) => e ? y.intersect(t, n) : y.contains(t, n)
1247
- );
1248
- }
1249
- }
1250
- class vt {
1251
- constructor(t, e, n, r) {
1252
- c(this, "origin");
1253
- c(this, "distanceFromNearestElement");
1254
- c(this, "coords");
1255
- c(this, "nearestElement");
1256
- this.origin = t, this.distanceFromNearestElement = e, this.coords = n, this.nearestElement = r;
1257
- }
1258
- }
1259
- const S = class {
1260
- constructor(t = null) {
1261
- c(this, "network", null);
1262
- c(this, "_maxDistance", Number.MAX_VALUE);
1263
- c(this, "_maxAngleBearing", Math.PI);
1264
- this.network = t;
1265
- }
1266
- set maxAngleBearing(t) {
1267
- this._maxAngleBearing = t;
1268
- }
1269
- get maxAngleBearing() {
1270
- return this._maxAngleBearing;
1271
- }
1272
- set maxDistance(t) {
1273
- this._maxDistance = t;
1274
- }
1275
- get maxDistance() {
1276
- return this._maxDistance;
1277
- }
1278
- _shouldProjectOnEdgeAndNodes(t, e, n, r, s) {
1279
- if (!s(t))
1280
- return [!1, !1, !1];
1281
- let o = y.intersect(e.level, t.level), a = y.intersect(e.level, t.node1.coords.level), l = y.intersect(e.level, t.node2.coords.level);
1282
- return a = a || t.node1.io && e.level === null, l = l || t.node2.io && e.level === null, r || (o = o && !y.isRange(t.level), a = a && !y.isRange(t.node1.coords.level), l = l && !y.isRange(t.node2.coords.level)), n && (o && wt(t.bearing, e.bearing) > this._maxAngleBearing && (o = !1), a = !1, l = !1), [o, a, l];
1283
- }
1284
- static _assignLatLngLevel(t, e) {
1285
- e.lat = t.lat, e.lng = t.lng, e.level = y.clone(t.level);
1286
- }
1287
- static _handleLevelsWithIONodes(t, e, n) {
1288
- e.level === null && n.io && (t.level = null);
1289
- }
1290
- getProjection(t, e = !1, n = !1, r = !0, s = () => !0) {
1291
- if (this.network === null)
1292
- throw new Error("Network has not been set yet");
1293
- if (!(t instanceof m))
1294
- throw new TypeError("location is not an instance of Coordinates");
1295
- if (n && (!("bearing" in t && t.bearing !== null) || !this._maxAngleBearing))
1296
- return null;
1297
- let o = Number.MAX_VALUE;
1298
- const a = t.clone();
1299
- let l = null;
1300
- const h = (u) => u < o && (!e || u <= this._maxDistance);
1301
- for (const u of this.network.edges) {
1302
- const [g, f, M] = this._shouldProjectOnEdgeAndNodes(
1303
- u,
1304
- t,
1305
- n,
1306
- r,
1307
- s
1308
- );
1309
- if (f) {
1310
- const d = t.distanceTo(u.node1.coords);
1311
- if ((h(d) || d <= P) && (o = d, l = u.node1, S._assignLatLngLevel(u.node1.coords, a), S._handleLevelsWithIONodes(a, t, u.node1), d <= P))
1312
- break;
1313
- }
1314
- if (M) {
1315
- const d = t.distanceTo(u.node2.coords);
1316
- if ((h(d) || d <= P) && (o = d, l = u.node2, S._assignLatLngLevel(u.node2.coords, a), S._handleLevelsWithIONodes(a, t, u.node2), d <= P))
1317
- break;
1318
- }
1319
- if (g) {
1320
- const d = t.getSegmentProjection(u.node1.coords, u.node2.coords);
1321
- if (d) {
1322
- const _ = t.distanceTo(d);
1323
- h(_) && (o = _, l = u, S._assignLatLngLevel(d, a), S._updateProjectionLevelFromEdge(u, a));
1324
- }
1325
- }
1326
- }
1327
- return l ? (a instanceof q && a.accuracy !== null && (a.accuracy += o), new vt(
1328
- t,
1329
- o,
1330
- a,
1331
- l
1332
- )) : null;
1333
- }
1334
- };
1335
- let $ = S;
1336
- c($, "_updateProjectionLevelFromEdge", (t, e) => {
1337
- e.level = y.clone(t.level);
1338
- });
1339
- var xt = Object.defineProperty, Rt = (i, t, e) => t in i ? xt(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, Y = (i, t, e) => (Rt(i, typeof t != "symbol" ? t + "" : t, e), e);
1340
- const G = [
1341
- "error",
1342
- "ok",
1343
- "warn",
1344
- "flux",
1345
- "deprecated",
1346
- "info",
1347
- "log",
1348
- "debug"
1349
- ];
1350
- function Ft(i) {
1351
- return "wemap" in i;
1352
- }
1353
- const p = class {
1354
- static enable(i) {
1355
- p.ENABLED = Boolean(i);
1356
- }
1357
- static level(i) {
1358
- return arguments.length && (p.LOG_LEVEL = i), p.LOG_LEVEL;
1359
- }
1360
- static clearHistory() {
1361
- p.HISTORY = [];
1362
- }
1363
- static _canUseLog(i) {
1364
- const t = G.indexOf(i), e = G.indexOf(p.LOG_LEVEL);
1365
- return e === -1 ? !1 : t <= e;
1366
- }
1367
- static _getColorByType(i) {
1368
- let t = null;
1369
- switch (i) {
1370
- case "flux":
1371
- t = "background: #0083E0; color: #FFFFFF;";
1372
- break;
1373
- case "ok":
1374
- t = "background: #00FF22; color: #272727;";
1375
- break;
1376
- case "deprecated":
1377
- t = "background: #CA0AFA; color: #FFFFFF;";
1378
- break;
1379
- case "error":
1380
- t = "background: #CC0000; color: #FFFFFF;";
1381
- break;
1382
- case "warn":
1383
- t = "background: #DD7908; color: #FFFFFF;";
1384
- break;
1385
- case "debug":
1386
- t = "background: #999999; color: #FFFFFF;";
1387
- break;
1388
- case "info":
1389
- t = "background: #DCFF4E; color: #000000;";
1390
- break;
1391
- default:
1392
- t = "background: #F4F4F4; color: #999999;";
1393
- break;
1394
- }
1395
- return t;
1396
- }
1397
- static _getOriginByType(i, t) {
1398
- let e = null, n = null, r = t;
1399
- if (arguments.length < 2)
1400
- return "";
1401
- try {
1402
- for (e = "", n = i.stack && i.stack.length ? i.stack.split(`
1403
- `).splice(3) : [], (r < 0 || r >= n.length) && (r = n.length); r; )
1404
- e += `\r
1405
- ` + n[0].trim(), n = n.splice(1), r--;
1406
- return e;
1407
- } catch {
1408
- return "";
1409
- }
1410
- }
1411
- static _log(i, t, e) {
1412
- const n = "color: auto;", r = "color: #6A6A6A;";
1413
- let s, o = null, a = null, l = null, h = null, u = "", g = !1;
1414
- if (o = i, h = new Error(t), a = p._getColorByType(i), l = p._getOriginByType(h, e), o === "deprecated" && (o = "warn", g = "deprecated"), l = p._COLOR_TOKEN + l, s = p._COLOR_TOKEN + " " + h.message, u = p._COLOR_TOKEN, u += p._TYPE_PREFIX, u += g || i, u += p._TYPE_SUFFIX, typeof window < "u" && Ft(window)) {
1415
- const f = performance && performance.now ? performance.now() : new Date().getTime();
1416
- u += "[" + Math.round(f - window.wemap.startTime) + "ms]";
1417
- }
1418
- return s = u + s + l, p.HISTORY.push(s), !this._canUseLog(i) || arguments.length < 2 || !p.ENABLED ? !1 : (console && i !== "ok" && i !== "flux" && i !== "deprecated" && console[i] && G.indexOf(i) <= G.indexOf("info") ? console[i](s, a, n, r) : console.log(s, a, n, r), !0);
1419
- }
1420
- static external(i) {
1421
- return console.log("LIVEMAP :: " + i);
1422
- }
1423
- static flux(i) {
1424
- return p._log("flux", i, 0);
1425
- }
1426
- static ok(i) {
1427
- return p._log("ok", i, 1);
1428
- }
1429
- static error(i, t = -1) {
1430
- return p._log("error", i, t);
1431
- }
1432
- static warn(i, t = 2) {
1433
- return p._log("warn", i, t);
1434
- }
1435
- static deprecated(i, t = 2) {
1436
- return p._log("deprecated", i, t);
1437
- }
1438
- static debug(i, t = -1) {
1439
- return p._log("debug", i, t);
1440
- }
1441
- static info(i, t = 0) {
1442
- return p._log("info", i, t);
1443
- }
1444
- static log(i, t = 1) {
1445
- return p._log("log", i, t);
1446
- }
1447
- };
1448
- let z = p;
1449
- Y(z, "LOG_LEVEL", "debug"), Y(z, "ENABLED", !0), Y(z, "HISTORY", []), Y(z, "_COLOR_TOKEN", "%c"), Y(z, "_TYPE_PREFIX", "<<<< "), Y(z, "_TYPE_SUFFIX", " >>>>");
1450
- class Z {
1451
- constructor(t, e, n, r, s) {
1452
- c(this, "start");
1453
- c(this, "end");
1454
- c(this, "nodes");
1455
- c(this, "edges");
1456
- c(this, "edgesWeights");
1457
- this.start = t, this.end = e, this.nodes = n, this.edges = r, this.edgesWeights = s;
1458
- }
1459
- static fromNetworkNodes(t, e, n, r) {
1460
- const s = n.map((a) => {
1461
- const l = a.clone();
1462
- return l.edges = [], l.io && (l.coords = l.coords.clone(), l.coords.level = null), l;
1463
- }), o = [];
1464
- return n.forEach((a, l, h) => {
1465
- if (l === 0)
1466
- return;
1467
- const u = h[l - 1], g = tt(u.edges, u, a);
1468
- if (!g) {
1469
- z.error("Cannot retrieve edge to create itinerary");
1470
- return;
1471
- }
1472
- const f = new B(
1473
- s[l - 1],
1474
- s[l],
1475
- g.level,
1476
- g.builtFrom
1477
- );
1478
- f.isOneway = g.isOneway, o.push(f);
1479
- }), new Z(t, e, s, o, r);
1480
- }
1481
- }
1482
- class st extends Error {
1483
- constructor(e, n, r) {
1484
- super();
1485
- c(this, "details");
1486
- c(this, "end");
1487
- c(this, "start");
1488
- this.start = e, this.end = n, this.details = r;
1489
- }
1490
- get startStr() {
1491
- return this.start instanceof R ? `GraphNode ${this.start.coords.toString()}` : this.start.toString();
1492
- }
1493
- get endStr() {
1494
- return this.end instanceof R ? `GraphNode ${this.end.coords.toString()}` : this.end.toString();
1495
- }
1496
- get message() {
1497
- let e = `No route found from ${this.startStr} to ${this.endStr}.`;
1498
- return this.details && (e += ` Details: ${this.details}`), e;
1499
- }
1500
- }
1501
- class Nt {
1502
- constructor() {
1503
- c(this, "projectionMaxDistance", 50);
1504
- c(this, "weightEdgeFn", (t) => t.length);
1505
- c(this, "acceptEdgeFn", () => !0);
1506
- }
1507
- }
1508
- class St {
1509
- constructor(t) {
1510
- c(this, "_mapMatching");
1511
- c(this, "_network");
1512
- c(this, "disabledEdges", /* @__PURE__ */ new Set());
1513
- this._network = t, this._mapMatching = new $(t);
1514
- }
1515
- getShortestPath(t, e, n = new Nt()) {
1516
- if (!(t instanceof R) && !(t instanceof m))
1517
- throw new Error("Unknown start type");
1518
- if (!(e instanceof R) && !(e instanceof m))
1519
- throw new Error("Unknown end type");
1520
- const { acceptEdgeFn: r, weightEdgeFn: s, projectionMaxDistance: o } = n;
1521
- this._mapMatching.maxDistance = o;
1522
- const a = [], l = (_) => {
1523
- if (_ instanceof R)
1524
- return _;
1525
- const b = this._network.getNodeByCoords(_);
1526
- if (b)
1527
- return b;
1528
- const A = this._mapMatching.getProjection(_, !0, !1, !1, r);
1529
- if (!A) {
1530
- let N = `Point ${_.toString()} is too far from the network > ${this._mapMatching.maxDistance.toFixed(0)} meters.`;
1531
- throw _.level !== null && (N += ` If it is a multi-level map, please verify if you have a network at level ${y.toString(_.level)}.`), new st(t, e, N);
1532
- }
1533
- if (A.nearestElement instanceof R)
1534
- return A.nearestElement;
1535
- const v = this.createNodeInsideEdge(
1536
- A.nearestElement,
1537
- A.coords
1538
- );
1539
- return a.push(v), v;
1540
- }, h = () => {
1541
- for (; a.length; )
1542
- this.removeNodeFromPreviouslyCreatedEdge(a.pop());
1543
- }, u = l(t), g = l(e), f = t instanceof R ? t.coords : t, M = e instanceof R ? e.coords : e;
1544
- let d;
1545
- if (u === g ? d = Z.fromNetworkNodes(
1546
- f,
1547
- M,
1548
- [u],
1549
- []
1550
- ) : d = this.getShortestPathBetweenGraphNodes(
1551
- u,
1552
- g,
1553
- r,
1554
- s
1555
- ), d.start = f, d.end = M, h(), !d.nodes.length)
1556
- throw new st(t, e);
1557
- return d;
1558
- }
1559
- createNodeInsideEdge(t, e) {
1560
- const n = t.node1, r = t.node2, s = new R(e, t.builtFrom);
1561
- s.coords.level = t.level;
1562
- const o = t.clone();
1563
- o.node1 = n, o.node2 = s;
1564
- const a = t.clone();
1565
- return a.node1 = s, a.node2 = r, n.edges = n.edges.filter((l) => l !== t), r.edges = r.edges.filter((l) => l !== t), this._network.nodes.push(s), this._network.edges.push(o, a), this._network.edges = this._network.edges.filter(
1566
- (l) => l !== t
1567
- ), s;
1568
- }
1569
- removeNodeFromPreviouslyCreatedEdge(t) {
1570
- const e = t.edges[0], n = t.edges[1];
1571
- e.node1.edges = e.node1.edges.filter((s) => s !== e), n.node1.edges = n.node1.edges.filter((s) => s !== n);
1572
- const r = e.clone();
1573
- r.node1 = e.node1, r.node2 = n.node2, this._network.edges.push(r), this._network.nodes = this._network.nodes.filter((s) => s !== t), this._network.edges = this._network.edges.filter(
1574
- (s) => s !== e && s !== n
1575
- );
1576
- }
1577
- getShortestPathBetweenGraphNodes(t, e, n, r) {
1578
- const s = {}, o = {}, a = {}, l = {}, h = {}, u = [];
1579
- let g = 1;
1580
- this._network.nodes.forEach((b) => {
1581
- b.uniqueRouterId = g, l[g] = b, s[g] = 1 / 0, o[g] = null, a[g] = !0, g++;
1582
- });
1583
- const f = Object.values(l).find((b) => t.equals(b)), M = Object.values(l).find((b) => e.equals(b));
1584
- for (s[f.uniqueRouterId] = 0; Object.keys(a).length > 0; ) {
1585
- const b = Object.keys(a).map(Number), A = Number(
1586
- b.reduce((v, N) => s[v] > s[N] ? N : v, b[0])
1587
- );
1588
- this._network.edges.filter((v) => {
1589
- if (!n(v) || this.disabledEdges.has(v))
1590
- return !1;
1591
- const N = v.node1.uniqueRouterId, D = v.node2.uniqueRouterId;
1592
- return N === A || D === A;
1593
- }).forEach((v) => {
1594
- let N, D, et = !1;
1595
- if (v.node1.uniqueRouterId === A ? (N = v.node2.uniqueRouterId, D = v.node1.uniqueRouterId) : (N = v.node1.uniqueRouterId, D = v.node2.uniqueRouterId, et = !0), v.isOneway && et)
1596
- return;
1597
- const nt = s[A] + r(v);
1598
- s[N] > nt && (s[N] = nt, o[N] = A, h[N] = D);
1599
- }), delete a[A];
1600
- }
1601
- const d = [];
1602
- let _ = M.uniqueRouterId;
1603
- for (; h[_]; )
1604
- u.unshift(l[_]), d.unshift(s[_] - s[h[_]]), _ = h[_];
1605
- return u.length !== 0 && u.unshift(t), this._network.nodes.forEach((b) => {
1606
- delete b.uniqueRouterId;
1607
- }), Z.fromNetworkNodes(t.coords, e.coords, u, d);
1608
- }
1609
- }
1610
- export {
1611
- J as AbsoluteHeading,
1612
- O as Attitude,
1613
- W as BoundingBox,
1614
- Pt as Constants,
1615
- m as Coordinates,
1616
- it as GeoRef,
1617
- kt as GeoRelativePosition,
1618
- B as GraphEdge,
1619
- Z as GraphItinerary,
1620
- R as GraphNode,
1621
- vt as GraphProjection,
1622
- St as GraphRouter,
1623
- Nt as GraphRouterOptions,
1624
- qt as GraphUtils,
1625
- y as Level,
1626
- $ as MapMatching,
1627
- j as Network,
1628
- st as NoRouteFoundError,
1629
- C as RelativePosition,
1630
- q as UserPosition,
1631
- Ot as Utils
1632
- };
1633
- //# sourceMappingURL=index.js.map