@maplat/transform 0.5.1 → 0.5.2
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/maplat_transform.js +237 -233
- package/dist/maplat_transform.umd.js +1 -1
- package/package.json +6 -6
package/dist/maplat_transform.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
var mt = (r, t, e) => t in r ? yt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
-
var w = (r, t, e) => mt(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
function at(r, t, e = {}) {
|
|
1
|
+
function ot(r, t, e = {}) {
|
|
5
2
|
const n = { type: "Feature" };
|
|
6
3
|
return (e.id === 0 || e.id) && (n.id = e.id), e.bbox && (n.bbox = e.bbox), n.properties = t || {}, n.geometry = r, n;
|
|
7
4
|
}
|
|
8
|
-
function
|
|
5
|
+
function X(r, t, e = {}) {
|
|
9
6
|
if (!r)
|
|
10
7
|
throw new Error("coordinates is required");
|
|
11
8
|
if (!Array.isArray(r))
|
|
12
9
|
throw new Error("coordinates must be an Array");
|
|
13
10
|
if (r.length < 2)
|
|
14
11
|
throw new Error("coordinates must be at least 2 numbers long");
|
|
15
|
-
if (!
|
|
12
|
+
if (!j(r[0]) || !j(r[1]))
|
|
16
13
|
throw new Error("coordinates must contain numbers");
|
|
17
|
-
return
|
|
14
|
+
return ot({
|
|
18
15
|
type: "Point",
|
|
19
16
|
coordinates: r
|
|
20
17
|
}, t, e);
|
|
21
18
|
}
|
|
22
|
-
function
|
|
19
|
+
function D(r, t, e = {}) {
|
|
23
20
|
for (const s of r) {
|
|
24
21
|
if (s.length < 4)
|
|
25
22
|
throw new Error(
|
|
@@ -31,19 +28,19 @@ function Y(r, t, e = {}) {
|
|
|
31
28
|
if (s[s.length - 1][i] !== s[0][i])
|
|
32
29
|
throw new Error("First and last Position are not equivalent.");
|
|
33
30
|
}
|
|
34
|
-
return
|
|
31
|
+
return ot({
|
|
35
32
|
type: "Polygon",
|
|
36
33
|
coordinates: r
|
|
37
34
|
}, t, e);
|
|
38
35
|
}
|
|
39
|
-
function
|
|
36
|
+
function U(r, t = {}) {
|
|
40
37
|
const e = { type: "FeatureCollection" };
|
|
41
38
|
return t.id && (e.id = t.id), t.bbox && (e.bbox = t.bbox), e.features = r, e;
|
|
42
39
|
}
|
|
43
|
-
function
|
|
40
|
+
function j(r) {
|
|
44
41
|
return !isNaN(r) && r !== null && !Array.isArray(r);
|
|
45
42
|
}
|
|
46
|
-
function
|
|
43
|
+
function lt(r) {
|
|
47
44
|
if (!r)
|
|
48
45
|
throw new Error("coord is required");
|
|
49
46
|
if (!Array.isArray(r)) {
|
|
@@ -56,7 +53,7 @@ function gt(r) {
|
|
|
56
53
|
return [...r];
|
|
57
54
|
throw new Error("coord must be GeoJSON Point or an Array of numbers");
|
|
58
55
|
}
|
|
59
|
-
function
|
|
56
|
+
function J(r) {
|
|
60
57
|
if (Array.isArray(r))
|
|
61
58
|
return r;
|
|
62
59
|
if (r.type === "Feature") {
|
|
@@ -68,11 +65,11 @@ function Q(r) {
|
|
|
68
65
|
"coords must be GeoJSON Feature, Geometry Object or an Array"
|
|
69
66
|
);
|
|
70
67
|
}
|
|
71
|
-
function
|
|
68
|
+
function dt(r) {
|
|
72
69
|
return r.type === "Feature" ? r.geometry : r;
|
|
73
70
|
}
|
|
74
|
-
const
|
|
75
|
-
function
|
|
71
|
+
const N = 11102230246251565e-32, E = 134217729, yt = (3 + 8 * N) * N;
|
|
72
|
+
function Y(r, t, e, n, s) {
|
|
76
73
|
let i, o, u, d, f = t[0], m = n[0], a = 0, l = 0;
|
|
77
74
|
m > f == m > -f ? (i = f, f = t[++a]) : (i = m, m = n[++l]);
|
|
78
75
|
let g = 0;
|
|
@@ -85,34 +82,34 @@ function q(r, t, e, n, s) {
|
|
|
85
82
|
o = i + m, d = o - i, u = i - (o - d) + (m - d), m = n[++l], i = o, u !== 0 && (s[g++] = u);
|
|
86
83
|
return (i !== 0 || g === 0) && (s[g++] = i), g;
|
|
87
84
|
}
|
|
88
|
-
function
|
|
85
|
+
function mt(r, t) {
|
|
89
86
|
let e = t[0];
|
|
90
87
|
for (let n = 1; n < r; n++) e += t[n];
|
|
91
88
|
return e;
|
|
92
89
|
}
|
|
93
|
-
function
|
|
90
|
+
function V(r) {
|
|
94
91
|
return new Float64Array(r);
|
|
95
92
|
}
|
|
96
|
-
const
|
|
97
|
-
function
|
|
98
|
-
let u, d, f, m, a, l, g, b, y, h, c, x,
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
function
|
|
93
|
+
const gt = (3 + 16 * N) * N, bt = (2 + 12 * N) * N, xt = (9 + 64 * N) * N * N, W = V(4), K = V(8), Q = V(12), H = V(16), A = V(4);
|
|
94
|
+
function pt(r, t, e, n, s, i, o) {
|
|
95
|
+
let u, d, f, m, a, l, g, b, y, h, c, x, w, M, v, p, _, T;
|
|
96
|
+
const S = r - s, B = e - s, C = t - i, P = n - i;
|
|
97
|
+
M = S * P, l = E * S, g = l - (l - S), b = S - g, l = E * P, y = l - (l - P), h = P - y, v = b * h - (M - g * y - b * y - g * h), p = C * B, l = E * C, g = l - (l - C), b = C - g, l = E * B, y = l - (l - B), h = B - y, _ = b * h - (p - g * y - b * y - g * h), c = v - _, a = v - c, W[0] = v - (c + a) + (a - _), x = M + c, a = x - M, w = M - (x - a) + (c - a), c = w - p, a = w - c, W[1] = w - (c + a) + (a - p), T = x + c, a = T - x, W[2] = x - (T - a) + (c - a), W[3] = T;
|
|
98
|
+
let k = mt(4, W), F = bt * o;
|
|
99
|
+
if (k >= F || -k >= F || (a = r - S, u = r - (S + a) + (a - s), a = e - B, f = e - (B + a) + (a - s), a = t - C, d = t - (C + a) + (a - i), a = n - P, m = n - (P + a) + (a - i), u === 0 && d === 0 && f === 0 && m === 0) || (F = xt * o + yt * Math.abs(k), k += S * m + P * u - (C * f + B * d), k >= F || -k >= F)) return k;
|
|
100
|
+
M = u * P, l = E * u, g = l - (l - u), b = u - g, l = E * P, y = l - (l - P), h = P - y, v = b * h - (M - g * y - b * y - g * h), p = d * B, l = E * d, g = l - (l - d), b = d - g, l = E * B, y = l - (l - B), h = B - y, _ = b * h - (p - g * y - b * y - g * h), c = v - _, a = v - c, A[0] = v - (c + a) + (a - _), x = M + c, a = x - M, w = M - (x - a) + (c - a), c = w - p, a = w - c, A[1] = w - (c + a) + (a - p), T = x + c, a = T - x, A[2] = x - (T - a) + (c - a), A[3] = T;
|
|
101
|
+
const ut = Y(4, W, 4, A, K);
|
|
102
|
+
M = S * m, l = E * S, g = l - (l - S), b = S - g, l = E * m, y = l - (l - m), h = m - y, v = b * h - (M - g * y - b * y - g * h), p = C * f, l = E * C, g = l - (l - C), b = C - g, l = E * f, y = l - (l - f), h = f - y, _ = b * h - (p - g * y - b * y - g * h), c = v - _, a = v - c, A[0] = v - (c + a) + (a - _), x = M + c, a = x - M, w = M - (x - a) + (c - a), c = w - p, a = w - c, A[1] = w - (c + a) + (a - p), T = x + c, a = T - x, A[2] = x - (T - a) + (c - a), A[3] = T;
|
|
103
|
+
const ft = Y(ut, K, 4, A, Q);
|
|
104
|
+
M = u * m, l = E * u, g = l - (l - u), b = u - g, l = E * m, y = l - (l - m), h = m - y, v = b * h - (M - g * y - b * y - g * h), p = d * f, l = E * d, g = l - (l - d), b = d - g, l = E * f, y = l - (l - f), h = f - y, _ = b * h - (p - g * y - b * y - g * h), c = v - _, a = v - c, A[0] = v - (c + a) + (a - _), x = M + c, a = x - M, w = M - (x - a) + (c - a), c = w - p, a = w - c, A[1] = w - (c + a) + (a - p), T = x + c, a = T - x, A[2] = x - (T - a) + (c - a), A[3] = T;
|
|
105
|
+
const ht = Y(ft, Q, 4, A, H);
|
|
106
|
+
return H[ht - 1];
|
|
107
|
+
}
|
|
108
|
+
function wt(r, t, e, n, s, i) {
|
|
112
109
|
const o = (t - i) * (e - s), u = (r - s) * (n - i), d = o - u, f = Math.abs(o + u);
|
|
113
|
-
return Math.abs(d) >=
|
|
110
|
+
return Math.abs(d) >= gt * f ? d : -pt(r, t, e, n, s, i, f);
|
|
114
111
|
}
|
|
115
|
-
function
|
|
112
|
+
function Mt(r, t) {
|
|
116
113
|
var e, n, s = 0, i, o, u, d, f, m, a, l = r[0], g = r[1], b = t.length;
|
|
117
114
|
for (e = 0; e < b; e++) {
|
|
118
115
|
n = 0;
|
|
@@ -124,7 +121,7 @@ function Et(r, t) {
|
|
|
124
121
|
if (d <= 0 && o >= 0 || o <= 0 && d >= 0)
|
|
125
122
|
return 0;
|
|
126
123
|
} else if (f >= 0 && u <= 0 || f <= 0 && u >= 0) {
|
|
127
|
-
if (i =
|
|
124
|
+
if (i = wt(o, d, u, f, 0, 0), i === 0)
|
|
128
125
|
return 0;
|
|
129
126
|
(i > 0 && f > 0 && u <= 0 || i < 0 && f <= 0 && u > 0) && s++;
|
|
130
127
|
}
|
|
@@ -133,84 +130,84 @@ function Et(r, t) {
|
|
|
133
130
|
}
|
|
134
131
|
return s % 2 !== 0;
|
|
135
132
|
}
|
|
136
|
-
function
|
|
133
|
+
function L(r, t, e = {}) {
|
|
137
134
|
if (!r)
|
|
138
135
|
throw new Error("point is required");
|
|
139
136
|
if (!t)
|
|
140
137
|
throw new Error("polygon is required");
|
|
141
|
-
const n =
|
|
138
|
+
const n = lt(r), s = dt(t), i = s.type, o = t.bbox;
|
|
142
139
|
let u = s.coordinates;
|
|
143
|
-
if (o &&
|
|
140
|
+
if (o && _t(n, o) === !1)
|
|
144
141
|
return !1;
|
|
145
142
|
i === "Polygon" && (u = [u]);
|
|
146
143
|
let d = !1;
|
|
147
144
|
for (var f = 0; f < u.length; ++f) {
|
|
148
|
-
const m =
|
|
145
|
+
const m = Mt(n, u[f]);
|
|
149
146
|
if (m === 0) return !e.ignoreBoundary;
|
|
150
147
|
m && (d = !0);
|
|
151
148
|
}
|
|
152
149
|
return d;
|
|
153
150
|
}
|
|
154
|
-
function
|
|
151
|
+
function _t(r, t) {
|
|
155
152
|
return t[0] <= r[0] && t[1] <= r[1] && t[2] >= r[0] && t[3] >= r[1];
|
|
156
153
|
}
|
|
157
|
-
function
|
|
154
|
+
function $(r, t) {
|
|
158
155
|
for (let e = 0; e < t.features.length; e++)
|
|
159
|
-
if (
|
|
156
|
+
if (L(r, t.features[e]))
|
|
160
157
|
return t.features[e];
|
|
161
158
|
}
|
|
162
|
-
function
|
|
159
|
+
function it(r, t, e) {
|
|
163
160
|
const n = t.geometry.coordinates[0][0], s = t.geometry.coordinates[0][1], i = t.geometry.coordinates[0][2], o = r.geometry.coordinates, u = t.properties.a.geom, d = t.properties.b.geom, f = t.properties.c.geom, m = [s[0] - n[0], s[1] - n[1]], a = [i[0] - n[0], i[1] - n[1]], l = [o[0] - n[0], o[1] - n[1]], g = [d[0] - u[0], d[1] - u[1]], b = [f[0] - u[0], f[1] - u[1]];
|
|
164
161
|
let y = (a[1] * l[0] - a[0] * l[1]) / (m[0] * a[1] - m[1] * a[0]), h = (m[0] * l[1] - m[1] * l[0]) / (m[0] * a[1] - m[1] * a[0]);
|
|
165
162
|
if (e) {
|
|
166
|
-
const c = e[t.properties.a.index], x = e[t.properties.b.index],
|
|
167
|
-
let
|
|
163
|
+
const c = e[t.properties.a.index], x = e[t.properties.b.index], w = e[t.properties.c.index];
|
|
164
|
+
let M;
|
|
168
165
|
if (y < 0 || h < 0 || 1 - y - h < 0) {
|
|
169
|
-
const
|
|
170
|
-
|
|
166
|
+
const v = y / (y + h), p = h / (y + h);
|
|
167
|
+
M = y / x / (v / x + p / w), h = h / w / (v / x + p / w);
|
|
171
168
|
} else
|
|
172
|
-
|
|
173
|
-
y =
|
|
169
|
+
M = y / x / (y / x + h / w + (1 - y - h) / c), h = h / w / (y / x + h / w + (1 - y - h) / c);
|
|
170
|
+
y = M;
|
|
174
171
|
}
|
|
175
172
|
return [
|
|
176
173
|
y * g[0] + h * b[0] + u[0],
|
|
177
174
|
y * g[1] + h * b[1] + u[1]
|
|
178
175
|
];
|
|
179
176
|
}
|
|
180
|
-
function
|
|
181
|
-
const s = r.geometry.coordinates, i = e.geometry.coordinates, o = Math.atan2(s[0] - i[0], s[1] - i[1]), u =
|
|
177
|
+
function vt(r, t, e, n) {
|
|
178
|
+
const s = r.geometry.coordinates, i = e.geometry.coordinates, o = Math.atan2(s[0] - i[0], s[1] - i[1]), u = Et(o, t[0]);
|
|
182
179
|
if (u === void 0)
|
|
183
180
|
throw new Error("Unable to determine vertex index");
|
|
184
181
|
const d = t[1][u];
|
|
185
|
-
return
|
|
182
|
+
return it(r, d.features[0], n);
|
|
186
183
|
}
|
|
187
|
-
function
|
|
184
|
+
function Tt(r, t, e, n, s, i, o, u) {
|
|
188
185
|
let d;
|
|
189
|
-
if (o && (d =
|
|
186
|
+
if (o && (d = $(r, U([o]))), !d)
|
|
190
187
|
if (e) {
|
|
191
|
-
const f = r.geometry.coordinates, m = e.gridNum, a = e.xOrigin, l = e.yOrigin, g = e.xUnit, b = e.yUnit, y = e.gridCache, h =
|
|
192
|
-
d =
|
|
188
|
+
const f = r.geometry.coordinates, m = e.gridNum, a = e.xOrigin, l = e.yOrigin, g = e.xUnit, b = e.yUnit, y = e.gridCache, h = O(f[0], a, g, m), c = O(f[1], l, b, m), x = y[h] ? y[h][c] ? y[h][c] : [] : [], w = U(x.map((M) => t.features[M]));
|
|
189
|
+
d = $(r, w);
|
|
193
190
|
} else
|
|
194
|
-
d =
|
|
195
|
-
return u && u(d), d ?
|
|
191
|
+
d = $(r, t);
|
|
192
|
+
return u && u(d), d ? it(r, d, i) : vt(r, n, s, i);
|
|
196
193
|
}
|
|
197
|
-
function
|
|
194
|
+
function O(r, t, e, n) {
|
|
198
195
|
let s = Math.floor((r - t) / e);
|
|
199
196
|
return s < 0 && (s = 0), s >= n && (s = n - 1), s;
|
|
200
197
|
}
|
|
201
|
-
function
|
|
202
|
-
let e =
|
|
198
|
+
function Et(r, t) {
|
|
199
|
+
let e = tt(r - t[0]), n = Math.PI * 2, s;
|
|
203
200
|
for (let i = 0; i < t.length; i++) {
|
|
204
|
-
const o = (i + 1) % t.length, u =
|
|
201
|
+
const o = (i + 1) % t.length, u = tt(r - t[o]), d = Math.min(Math.abs(e), Math.abs(u));
|
|
205
202
|
e * u <= 0 && d < n && (n = d, s = i), e = u;
|
|
206
203
|
}
|
|
207
204
|
return s;
|
|
208
205
|
}
|
|
209
|
-
function
|
|
206
|
+
function tt(r, t = !1) {
|
|
210
207
|
const e = 2 * Math.PI, n = r - Math.floor(r / e) * e;
|
|
211
208
|
return t ? n : n > Math.PI ? n - e : n;
|
|
212
209
|
}
|
|
213
|
-
function
|
|
210
|
+
function Vt(r) {
|
|
214
211
|
const t = r.features;
|
|
215
212
|
for (let e = 0; e < t.length; e++) {
|
|
216
213
|
const n = t[e];
|
|
@@ -272,7 +269,7 @@ function zt(r) {
|
|
|
272
269
|
}
|
|
273
270
|
return r;
|
|
274
271
|
}
|
|
275
|
-
function
|
|
272
|
+
function Dt(r) {
|
|
276
273
|
const t = ["a", "b", "c", "a"].map(
|
|
277
274
|
(i) => r.properties[i].geom
|
|
278
275
|
), e = r.geometry.coordinates[0], n = r.properties, s = {
|
|
@@ -280,20 +277,20 @@ function Gt(r) {
|
|
|
280
277
|
b: { geom: e[1], index: n.b.index },
|
|
281
278
|
c: { geom: e[2], index: n.c.index }
|
|
282
279
|
};
|
|
283
|
-
return
|
|
280
|
+
return D([t], s);
|
|
284
281
|
}
|
|
285
|
-
function
|
|
282
|
+
function At(r) {
|
|
286
283
|
const t = [0, 1, 2, 0].map((n) => r[n][0][0]), e = {
|
|
287
284
|
a: { geom: r[0][0][1], index: r[0][1] },
|
|
288
285
|
b: { geom: r[1][0][1], index: r[1][1] },
|
|
289
286
|
c: { geom: r[2][0][1], index: r[2][1] }
|
|
290
287
|
};
|
|
291
|
-
return
|
|
288
|
+
return D([t], e);
|
|
292
289
|
}
|
|
293
|
-
function
|
|
290
|
+
function G(r, t, e, n, s, i = !1, o) {
|
|
294
291
|
const u = r.map(
|
|
295
292
|
(d) => {
|
|
296
|
-
(!o || o < 2.00703) && (d =
|
|
293
|
+
(!o || o < 2.00703) && (d = at(d));
|
|
297
294
|
const f = isFinite(d) ? t[d] : d === "c" ? n : (function() {
|
|
298
295
|
const m = d.match(/^b(\d+)$/);
|
|
299
296
|
if (m) return s[parseInt(m[1])];
|
|
@@ -304,33 +301,33 @@ function j(r, t, e, n, s, i = !1, o) {
|
|
|
304
301
|
return i ? [[f[1], f[0]], d] : [[f[0], f[1]], d];
|
|
305
302
|
}
|
|
306
303
|
);
|
|
307
|
-
return
|
|
304
|
+
return At(u);
|
|
308
305
|
}
|
|
309
|
-
function
|
|
306
|
+
function at(r) {
|
|
310
307
|
return typeof r == "number" ? r : r.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/, "$1$2");
|
|
311
308
|
}
|
|
312
|
-
function
|
|
309
|
+
function It(r, t) {
|
|
313
310
|
return t && t >= 2.00703 || Array.isArray(r[0]) ? r : r.map((e) => [
|
|
314
311
|
e.illstNodes,
|
|
315
312
|
e.mercNodes,
|
|
316
313
|
e.startEnd
|
|
317
314
|
]);
|
|
318
315
|
}
|
|
319
|
-
const
|
|
320
|
-
function
|
|
316
|
+
const Z = 2.00703;
|
|
317
|
+
function St(r) {
|
|
321
318
|
return !!(r.version !== void 0 || !r.tins && r.points && r.tins_points);
|
|
322
319
|
}
|
|
323
|
-
function
|
|
320
|
+
function Bt(r) {
|
|
324
321
|
return {
|
|
325
322
|
points: r.points,
|
|
326
|
-
pointsWeightBuffer:
|
|
327
|
-
strictStatus:
|
|
328
|
-
verticesParams:
|
|
329
|
-
centroid:
|
|
330
|
-
edges:
|
|
323
|
+
pointsWeightBuffer: Pt(r),
|
|
324
|
+
strictStatus: Ot(r),
|
|
325
|
+
verticesParams: Rt(r),
|
|
326
|
+
centroid: kt(r),
|
|
327
|
+
edges: It(r.edges || []),
|
|
331
328
|
edgeNodes: r.edgeNodes || [],
|
|
332
|
-
tins:
|
|
333
|
-
kinks:
|
|
329
|
+
tins: Nt(r),
|
|
330
|
+
kinks: Xt(r.kinks_points),
|
|
334
331
|
yaxisMode: r.yaxisMode ?? "invert",
|
|
335
332
|
strictMode: r.strictMode ?? "auto",
|
|
336
333
|
vertexMode: r.vertexMode,
|
|
@@ -340,12 +337,12 @@ function Rt(r) {
|
|
|
340
337
|
xy: r.xy ?? [0, 0]
|
|
341
338
|
};
|
|
342
339
|
}
|
|
343
|
-
function
|
|
344
|
-
const t =
|
|
340
|
+
function Ct(r) {
|
|
341
|
+
const t = Wt(r), e = t.tins;
|
|
345
342
|
return {
|
|
346
343
|
compiled: t,
|
|
347
344
|
tins: e,
|
|
348
|
-
points:
|
|
345
|
+
points: Lt(e),
|
|
349
346
|
strictStatus: t.strict_status,
|
|
350
347
|
pointsWeightBuffer: t.weight_buffer,
|
|
351
348
|
verticesParams: t.vertices_params,
|
|
@@ -353,49 +350,49 @@ function kt(r) {
|
|
|
353
350
|
kinks: t.kinks
|
|
354
351
|
};
|
|
355
352
|
}
|
|
356
|
-
function
|
|
357
|
-
return !r.version || r.version <
|
|
353
|
+
function Pt(r) {
|
|
354
|
+
return !r.version || r.version < Z ? ["forw", "bakw"].reduce((t, e) => {
|
|
358
355
|
const n = r.weight_buffer[e];
|
|
359
356
|
return n && (t[e] = Object.keys(n).reduce((s, i) => {
|
|
360
|
-
const o =
|
|
357
|
+
const o = at(i);
|
|
361
358
|
return s[o] = n[i], s;
|
|
362
359
|
}, {})), t;
|
|
363
360
|
}, {}) : r.weight_buffer;
|
|
364
361
|
}
|
|
365
|
-
function
|
|
362
|
+
function Ot(r) {
|
|
366
363
|
return r.strict_status ? r.strict_status : r.kinks_points ? "strict_error" : r.tins_points.length === 2 ? "loose" : "strict";
|
|
367
364
|
}
|
|
368
|
-
function
|
|
365
|
+
function Rt(r) {
|
|
369
366
|
const t = {
|
|
370
367
|
forw: [r.vertices_params[0]],
|
|
371
368
|
bakw: [r.vertices_params[1]]
|
|
372
369
|
};
|
|
373
|
-
return t.forw[1] =
|
|
370
|
+
return t.forw[1] = rt(r, !1), t.bakw[1] = rt(r, !0), t;
|
|
374
371
|
}
|
|
375
|
-
function
|
|
372
|
+
function rt(r, t) {
|
|
376
373
|
const e = r.vertices_points.length;
|
|
377
374
|
return Array.from({ length: e }, (n, s) => {
|
|
378
|
-
const i = (s + 1) % e, o =
|
|
375
|
+
const i = (s + 1) % e, o = G(
|
|
379
376
|
["c", `b${s}`, `b${i}`],
|
|
380
377
|
r.points,
|
|
381
378
|
r.edgeNodes || [],
|
|
382
379
|
r.centroid_point,
|
|
383
380
|
r.vertices_points,
|
|
384
381
|
t,
|
|
385
|
-
|
|
382
|
+
Z
|
|
386
383
|
);
|
|
387
|
-
return
|
|
384
|
+
return U([o]);
|
|
388
385
|
});
|
|
389
386
|
}
|
|
390
|
-
function
|
|
387
|
+
function kt(r) {
|
|
391
388
|
return {
|
|
392
|
-
forw:
|
|
389
|
+
forw: X(r.centroid_point[0], {
|
|
393
390
|
target: {
|
|
394
391
|
geom: r.centroid_point[1],
|
|
395
392
|
index: "c"
|
|
396
393
|
}
|
|
397
394
|
}),
|
|
398
|
-
bakw:
|
|
395
|
+
bakw: X(r.centroid_point[1], {
|
|
399
396
|
target: {
|
|
400
397
|
geom: r.centroid_point[0],
|
|
401
398
|
index: "c"
|
|
@@ -403,12 +400,12 @@ function Lt(r) {
|
|
|
403
400
|
})
|
|
404
401
|
};
|
|
405
402
|
}
|
|
406
|
-
function
|
|
403
|
+
function Nt(r) {
|
|
407
404
|
const t = r.tins_points.length === 1 ? 0 : 1;
|
|
408
405
|
return {
|
|
409
|
-
forw:
|
|
406
|
+
forw: U(
|
|
410
407
|
r.tins_points[0].map(
|
|
411
|
-
(e) =>
|
|
408
|
+
(e) => G(
|
|
412
409
|
e,
|
|
413
410
|
r.points,
|
|
414
411
|
r.edgeNodes || [],
|
|
@@ -419,9 +416,9 @@ function Ut(r) {
|
|
|
419
416
|
)
|
|
420
417
|
)
|
|
421
418
|
),
|
|
422
|
-
bakw:
|
|
419
|
+
bakw: U(
|
|
423
420
|
r.tins_points[t].map(
|
|
424
|
-
(e) =>
|
|
421
|
+
(e) => G(
|
|
425
422
|
e,
|
|
426
423
|
r.points,
|
|
427
424
|
r.edgeNodes || [],
|
|
@@ -434,20 +431,20 @@ function Ut(r) {
|
|
|
434
431
|
)
|
|
435
432
|
};
|
|
436
433
|
}
|
|
437
|
-
function
|
|
434
|
+
function Xt(r) {
|
|
438
435
|
if (r)
|
|
439
436
|
return {
|
|
440
|
-
bakw:
|
|
441
|
-
r.map((t) =>
|
|
437
|
+
bakw: U(
|
|
438
|
+
r.map((t) => X(t))
|
|
442
439
|
)
|
|
443
440
|
};
|
|
444
441
|
}
|
|
445
|
-
function
|
|
442
|
+
function Wt(r) {
|
|
446
443
|
return JSON.parse(
|
|
447
444
|
JSON.stringify(r).replace('"cent"', '"c"').replace(/"bbox(\d+)"/g, '"b$1"')
|
|
448
445
|
);
|
|
449
446
|
}
|
|
450
|
-
function
|
|
447
|
+
function Lt(r) {
|
|
451
448
|
const t = [], e = r.forw.features;
|
|
452
449
|
for (let n = 0; n < e.length; n++) {
|
|
453
450
|
const s = e[n];
|
|
@@ -458,41 +455,56 @@ function Dt(r) {
|
|
|
458
455
|
}
|
|
459
456
|
return t;
|
|
460
457
|
}
|
|
461
|
-
const
|
|
458
|
+
const Yt = Z;
|
|
459
|
+
class I {
|
|
460
|
+
/**
|
|
461
|
+
* 各種モードの定数定義
|
|
462
|
+
* すべてreadonlyで、型安全性を確保
|
|
463
|
+
*/
|
|
464
|
+
static VERTEX_PLAIN = "plain";
|
|
465
|
+
static VERTEX_BIRDEYE = "birdeye";
|
|
466
|
+
static MODE_STRICT = "strict";
|
|
467
|
+
static MODE_AUTO = "auto";
|
|
468
|
+
static MODE_LOOSE = "loose";
|
|
469
|
+
static STATUS_STRICT = "strict";
|
|
470
|
+
static STATUS_ERROR = "strict_error";
|
|
471
|
+
static STATUS_LOOSE = "loose";
|
|
472
|
+
static YAXIS_FOLLOW = "follow";
|
|
473
|
+
static YAXIS_INVERT = "invert";
|
|
474
|
+
points = [];
|
|
475
|
+
pointsWeightBuffer;
|
|
476
|
+
strict_status;
|
|
477
|
+
vertices_params;
|
|
478
|
+
centroid;
|
|
479
|
+
edgeNodes;
|
|
480
|
+
edges;
|
|
481
|
+
tins;
|
|
482
|
+
kinks;
|
|
483
|
+
yaxisMode = I.YAXIS_INVERT;
|
|
484
|
+
strictMode = I.MODE_AUTO;
|
|
485
|
+
vertexMode = I.VERTEX_PLAIN;
|
|
486
|
+
bounds;
|
|
487
|
+
boundsPolygon;
|
|
488
|
+
wh;
|
|
489
|
+
xy;
|
|
490
|
+
indexedTins;
|
|
491
|
+
stateFull = !1;
|
|
492
|
+
stateTriangle;
|
|
493
|
+
stateBackward;
|
|
494
|
+
/**
|
|
495
|
+
* Optional properties for MaplatCore extension
|
|
496
|
+
* These properties allow consuming applications to extend Transform instances
|
|
497
|
+
* with additional metadata without requiring Module Augmentation
|
|
498
|
+
*/
|
|
499
|
+
/** Layer priority for rendering order */
|
|
500
|
+
priority;
|
|
501
|
+
/** Layer importance for display decisions */
|
|
502
|
+
importance;
|
|
503
|
+
/** Bounds in XY (source) coordinate system */
|
|
504
|
+
xyBounds;
|
|
505
|
+
/** Bounds in Mercator (Web Mercator) coordinate system */
|
|
506
|
+
mercBounds;
|
|
462
507
|
constructor() {
|
|
463
|
-
w(this, "points", []);
|
|
464
|
-
w(this, "pointsWeightBuffer");
|
|
465
|
-
w(this, "strict_status");
|
|
466
|
-
w(this, "vertices_params");
|
|
467
|
-
w(this, "centroid");
|
|
468
|
-
w(this, "edgeNodes");
|
|
469
|
-
w(this, "edges");
|
|
470
|
-
w(this, "tins");
|
|
471
|
-
w(this, "kinks");
|
|
472
|
-
w(this, "yaxisMode", E.YAXIS_INVERT);
|
|
473
|
-
w(this, "strictMode", E.MODE_AUTO);
|
|
474
|
-
w(this, "vertexMode", E.VERTEX_PLAIN);
|
|
475
|
-
w(this, "bounds");
|
|
476
|
-
w(this, "boundsPolygon");
|
|
477
|
-
w(this, "wh");
|
|
478
|
-
w(this, "xy");
|
|
479
|
-
w(this, "indexedTins");
|
|
480
|
-
w(this, "stateFull", !1);
|
|
481
|
-
w(this, "stateTriangle");
|
|
482
|
-
w(this, "stateBackward");
|
|
483
|
-
/**
|
|
484
|
-
* Optional properties for MaplatCore extension
|
|
485
|
-
* These properties allow consuming applications to extend Transform instances
|
|
486
|
-
* with additional metadata without requiring Module Augmentation
|
|
487
|
-
*/
|
|
488
|
-
/** Layer priority for rendering order */
|
|
489
|
-
w(this, "priority");
|
|
490
|
-
/** Layer importance for display decisions */
|
|
491
|
-
w(this, "importance");
|
|
492
|
-
/** Bounds in XY (source) coordinate system */
|
|
493
|
-
w(this, "xyBounds");
|
|
494
|
-
/** Bounds in Mercator (Web Mercator) coordinate system */
|
|
495
|
-
w(this, "mercBounds");
|
|
496
508
|
}
|
|
497
509
|
/**
|
|
498
510
|
* コンパイルされた設定を適用します
|
|
@@ -507,14 +519,14 @@ const Zt = J, E = class E {
|
|
|
507
519
|
* 4. インデックスの作成
|
|
508
520
|
*/
|
|
509
521
|
setCompiled(t) {
|
|
510
|
-
if (
|
|
511
|
-
this.applyModernState(
|
|
522
|
+
if (St(t)) {
|
|
523
|
+
this.applyModernState(Bt(t));
|
|
512
524
|
return;
|
|
513
525
|
}
|
|
514
|
-
this.applyLegacyState(
|
|
526
|
+
this.applyLegacyState(Ct(t));
|
|
515
527
|
}
|
|
516
528
|
applyModernState(t) {
|
|
517
|
-
this.points = t.points, this.pointsWeightBuffer = t.pointsWeightBuffer, this.strict_status = t.strictStatus, this.vertices_params = t.verticesParams, this.centroid = t.centroid, this.edges = t.edges, this.edgeNodes = t.edgeNodes || [], this.tins = t.tins, this.addIndexedTin(), this.kinks = t.kinks, this.yaxisMode = t.yaxisMode ??
|
|
529
|
+
this.points = t.points, this.pointsWeightBuffer = t.pointsWeightBuffer, this.strict_status = t.strictStatus, this.vertices_params = t.verticesParams, this.centroid = t.centroid, this.edges = t.edges, this.edgeNodes = t.edgeNodes || [], this.tins = t.tins, this.addIndexedTin(), this.kinks = t.kinks, this.yaxisMode = t.yaxisMode ?? I.YAXIS_INVERT, this.vertexMode = t.vertexMode ?? I.VERTEX_PLAIN, this.strictMode = t.strictMode ?? I.MODE_AUTO, t.bounds ? (this.bounds = t.bounds, this.boundsPolygon = t.boundsPolygon, this.xy = t.xy, this.wh = t.wh) : (this.bounds = void 0, this.boundsPolygon = void 0, this.xy = t.xy ?? [0, 0], t.wh && (this.wh = t.wh));
|
|
518
530
|
}
|
|
519
531
|
applyLegacyState(t) {
|
|
520
532
|
this.tins = t.tins, this.addIndexedTin(), this.strict_status = t.strictStatus, this.pointsWeightBuffer = t.pointsWeightBuffer, this.vertices_params = t.verticesParams, this.centroid = t.centroid, this.kinks = t.kinks, this.points = t.points;
|
|
@@ -535,32 +547,32 @@ const Zt = J, E = class E {
|
|
|
535
547
|
let i = [], o = [];
|
|
536
548
|
const u = e.features.map((y) => {
|
|
537
549
|
let h = [];
|
|
538
|
-
return
|
|
550
|
+
return J(y)[0].map((c) => {
|
|
539
551
|
i.length === 0 ? i = [Array.from(c), Array.from(c)] : (c[0] < i[0][0] && (i[0][0] = c[0]), c[0] > i[1][0] && (i[1][0] = c[0]), c[1] < i[0][1] && (i[0][1] = c[1]), c[1] > i[1][1] && (i[1][1] = c[1])), h.length === 0 ? h = [Array.from(c), Array.from(c)] : (c[0] < h[0][0] && (h[0][0] = c[0]), c[0] > h[1][0] && (h[1][0] = c[0]), c[1] < h[0][1] && (h[0][1] = c[1]), c[1] > h[1][1] && (h[1][1] = c[1]));
|
|
540
552
|
}), h;
|
|
541
553
|
}), d = (i[1][0] - i[0][0]) / s, f = (i[1][1] - i[0][1]) / s, m = u.reduce(
|
|
542
554
|
(y, h, c) => {
|
|
543
|
-
const x =
|
|
544
|
-
for (let p = x; p <=
|
|
555
|
+
const x = O(h[0][0], i[0][0], d, s), w = O(h[1][0], i[0][0], d, s), M = O(h[0][1], i[0][1], f, s), v = O(h[1][1], i[0][1], f, s);
|
|
556
|
+
for (let p = x; p <= w; p++) {
|
|
545
557
|
y[p] || (y[p] = []);
|
|
546
|
-
for (let
|
|
547
|
-
y[p][
|
|
558
|
+
for (let _ = M; _ <= v; _++)
|
|
559
|
+
y[p][_] || (y[p][_] = []), y[p][_].push(c);
|
|
548
560
|
}
|
|
549
561
|
return y;
|
|
550
562
|
},
|
|
551
563
|
[]
|
|
552
564
|
), a = n.features.map((y) => {
|
|
553
565
|
let h = [];
|
|
554
|
-
return
|
|
566
|
+
return J(y)[0].map((c) => {
|
|
555
567
|
o.length === 0 ? o = [Array.from(c), Array.from(c)] : (c[0] < o[0][0] && (o[0][0] = c[0]), c[0] > o[1][0] && (o[1][0] = c[0]), c[1] < o[0][1] && (o[0][1] = c[1]), c[1] > o[1][1] && (o[1][1] = c[1])), h.length === 0 ? h = [Array.from(c), Array.from(c)] : (c[0] < h[0][0] && (h[0][0] = c[0]), c[0] > h[1][0] && (h[1][0] = c[0]), c[1] < h[0][1] && (h[0][1] = c[1]), c[1] > h[1][1] && (h[1][1] = c[1]));
|
|
556
568
|
}), h;
|
|
557
569
|
}), l = (o[1][0] - o[0][0]) / s, g = (o[1][1] - o[0][1]) / s, b = a.reduce(
|
|
558
570
|
(y, h, c) => {
|
|
559
|
-
const x =
|
|
560
|
-
for (let p = x; p <=
|
|
571
|
+
const x = O(h[0][0], o[0][0], l, s), w = O(h[1][0], o[0][0], l, s), M = O(h[0][1], o[0][1], g, s), v = O(h[1][1], o[0][1], g, s);
|
|
572
|
+
for (let p = x; p <= w; p++) {
|
|
561
573
|
y[p] || (y[p] = []);
|
|
562
|
-
for (let
|
|
563
|
-
y[p][
|
|
574
|
+
for (let _ = M; _ <= v; _++)
|
|
575
|
+
y[p][_] || (y[p][_] = []), y[p][_].push(c);
|
|
564
576
|
}
|
|
565
577
|
return y;
|
|
566
578
|
},
|
|
@@ -598,18 +610,18 @@ const Zt = J, E = class E {
|
|
|
598
610
|
transform(t, e, n) {
|
|
599
611
|
if (!this.tins)
|
|
600
612
|
throw new Error("setCompiled() must be called before transform()");
|
|
601
|
-
if (e && this.strict_status ==
|
|
613
|
+
if (e && this.strict_status == I.STATUS_ERROR)
|
|
602
614
|
throw new Error('Backward transform is not allowed if strict_status == "strict_error"');
|
|
603
|
-
this.yaxisMode ==
|
|
604
|
-
const s =
|
|
605
|
-
if (this.bounds && !e && !n && !
|
|
615
|
+
this.yaxisMode == I.YAXIS_FOLLOW && e && (t = [t[0], -1 * t[1]]);
|
|
616
|
+
const s = X(t);
|
|
617
|
+
if (this.bounds && !e && !n && !L(s, this.boundsPolygon))
|
|
606
618
|
return !1;
|
|
607
619
|
const i = e ? this.tins.bakw : this.tins.forw, o = e ? this.indexedTins.bakw : this.indexedTins.forw, u = e ? this.vertices_params.bakw : this.vertices_params.forw, d = e ? this.centroid.bakw : this.centroid.forw, f = e ? this.pointsWeightBuffer.bakw : this.pointsWeightBuffer.forw;
|
|
608
620
|
let m, a;
|
|
609
621
|
this.stateFull && (this.stateBackward == e ? m = this.stateTriangle : (this.stateBackward = e, this.stateTriangle = void 0), a = (g) => {
|
|
610
622
|
this.stateTriangle = g;
|
|
611
623
|
});
|
|
612
|
-
let l =
|
|
624
|
+
let l = Tt(
|
|
613
625
|
s,
|
|
614
626
|
i,
|
|
615
627
|
o,
|
|
@@ -620,29 +632,23 @@ const Zt = J, E = class E {
|
|
|
620
632
|
a
|
|
621
633
|
);
|
|
622
634
|
if (this.bounds && e && !n) {
|
|
623
|
-
const g =
|
|
624
|
-
if (!
|
|
625
|
-
} else this.yaxisMode ==
|
|
635
|
+
const g = X(l);
|
|
636
|
+
if (!L(g, this.boundsPolygon)) return !1;
|
|
637
|
+
} else this.yaxisMode == I.YAXIS_FOLLOW && !e && (l = [l[0], -1 * l[1]]);
|
|
626
638
|
return l;
|
|
627
639
|
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
* 各種モードの定数定義
|
|
631
|
-
* すべてreadonlyで、型安全性を確保
|
|
632
|
-
*/
|
|
633
|
-
w(E, "VERTEX_PLAIN", "plain"), w(E, "VERTEX_BIRDEYE", "birdeye"), w(E, "MODE_STRICT", "strict"), w(E, "MODE_AUTO", "auto"), w(E, "MODE_LOOSE", "loose"), w(E, "STATUS_STRICT", "strict"), w(E, "STATUS_ERROR", "strict_error"), w(E, "STATUS_LOOSE", "loose"), w(E, "YAXIS_FOLLOW", "follow"), w(E, "YAXIS_INVERT", "invert");
|
|
634
|
-
let $ = E;
|
|
635
|
-
const k = 20037508342789244e-9, Yt = [
|
|
640
|
+
}
|
|
641
|
+
const R = 20037508342789244e-9, Ut = [
|
|
636
642
|
[0, 0],
|
|
637
643
|
[0, 1],
|
|
638
644
|
[1, 0],
|
|
639
645
|
[0, -1],
|
|
640
646
|
[-1, 0]
|
|
641
647
|
];
|
|
642
|
-
function
|
|
643
|
-
return Math.floor(Math.min(r[0], r[1]) / 4) *
|
|
648
|
+
function ct(r, t) {
|
|
649
|
+
return Math.floor(Math.min(r[0], r[1]) / 4) * R / 128 / Math.pow(2, t);
|
|
644
650
|
}
|
|
645
|
-
function
|
|
651
|
+
function Ft(r, t) {
|
|
646
652
|
const e = [];
|
|
647
653
|
for (let n = 0; n < r.length; n++) {
|
|
648
654
|
const s = r[n], i = s[0] * Math.cos(t) - s[1] * Math.sin(t), o = s[0] * Math.sin(t) + s[1] * Math.cos(t);
|
|
@@ -650,14 +656,14 @@ function $t(r, t) {
|
|
|
650
656
|
}
|
|
651
657
|
return e;
|
|
652
658
|
}
|
|
653
|
-
function
|
|
654
|
-
const s =
|
|
655
|
-
return
|
|
659
|
+
function et(r, t, e, n) {
|
|
660
|
+
const s = ct(n, t);
|
|
661
|
+
return Ft(Ut, e).map((u) => [
|
|
656
662
|
u[0] * s + r[0],
|
|
657
663
|
u[1] * s + r[1]
|
|
658
664
|
]);
|
|
659
665
|
}
|
|
660
|
-
function
|
|
666
|
+
function nt(r, t) {
|
|
661
667
|
const e = r[0], s = r.slice(1, 5).map((g) => [
|
|
662
668
|
g[0] - e[0],
|
|
663
669
|
g[1] - e[1]
|
|
@@ -673,27 +679,25 @@ function ot(r, t) {
|
|
|
673
679
|
o += h;
|
|
674
680
|
const c = b[0] * y[1] - b[1] * y[0], x = Math.acos(
|
|
675
681
|
(b[0] * y[0] + b[1] * y[1]) / h
|
|
676
|
-
),
|
|
677
|
-
u += Math.cos(
|
|
682
|
+
), w = c > 0 ? -1 * x : x;
|
|
683
|
+
u += Math.cos(w), d += Math.sin(w);
|
|
678
684
|
}
|
|
679
|
-
const f = o / 4, m = Math.atan2(d, u), a = Math.floor(Math.min(t[0], t[1]) / 4), l = Math.log(a *
|
|
685
|
+
const f = o / 4, m = Math.atan2(d, u), a = Math.floor(Math.min(t[0], t[1]) / 4), l = Math.log(a * R / 128 / f) / Math.log(2);
|
|
680
686
|
return { center: e, zoom: l, rotation: m };
|
|
681
687
|
}
|
|
682
|
-
function
|
|
683
|
-
const e = r[0] * (2 *
|
|
688
|
+
function q(r, t) {
|
|
689
|
+
const e = r[0] * (2 * R) / t - R, n = -1 * (r[1] * (2 * R) / t - R);
|
|
684
690
|
return [e, n];
|
|
685
691
|
}
|
|
686
|
-
function
|
|
687
|
-
const e = (r[0] +
|
|
692
|
+
function st(r, t) {
|
|
693
|
+
const e = (r[0] + R) * t / (2 * R), n = (-r[1] + R) * t / (2 * R);
|
|
688
694
|
return [e, n];
|
|
689
695
|
}
|
|
690
|
-
const
|
|
691
|
-
class
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
w(this, "_maxxy", 0);
|
|
696
|
-
}
|
|
696
|
+
const z = 256;
|
|
697
|
+
class $t {
|
|
698
|
+
mainTin = null;
|
|
699
|
+
subTins = [];
|
|
700
|
+
_maxxy = 0;
|
|
697
701
|
// ─── 初期化 ────────────────────────────────────────────────────────────────
|
|
698
702
|
/**
|
|
699
703
|
* 地図データ(コンパイル済み TIN + sub_maps)をロードする
|
|
@@ -701,16 +705,16 @@ class jt {
|
|
|
701
705
|
* @param mapData - メイン TIN と sub_maps の情報
|
|
702
706
|
*/
|
|
703
707
|
setMapData(t) {
|
|
704
|
-
const e = new
|
|
708
|
+
const e = new I();
|
|
705
709
|
if (e.setCompiled(t.compiled), this.mainTin = e, t.maxZoom !== void 0)
|
|
706
|
-
this._maxxy = Math.pow(2, t.maxZoom) *
|
|
710
|
+
this._maxxy = Math.pow(2, t.maxZoom) * z;
|
|
707
711
|
else if (t.compiled.wh) {
|
|
708
|
-
const n = Math.max(t.compiled.wh[0], t.compiled.wh[1]), s = Math.ceil(Math.log2(n /
|
|
709
|
-
this._maxxy = Math.pow(2, s) *
|
|
712
|
+
const n = Math.max(t.compiled.wh[0], t.compiled.wh[1]), s = Math.ceil(Math.log2(n / z));
|
|
713
|
+
this._maxxy = Math.pow(2, s) * z;
|
|
710
714
|
}
|
|
711
715
|
if (this.subTins = [], t.sub_maps)
|
|
712
716
|
for (const n of t.sub_maps) {
|
|
713
|
-
const s = new
|
|
717
|
+
const s = new I();
|
|
714
718
|
s.setCompiled(n.compiled);
|
|
715
719
|
const i = n.bounds ?? n.compiled.bounds;
|
|
716
720
|
if (!i)
|
|
@@ -726,8 +730,8 @@ class jt {
|
|
|
726
730
|
tin: s,
|
|
727
731
|
priority: n.priority,
|
|
728
732
|
importance: n.importance,
|
|
729
|
-
xyBounds:
|
|
730
|
-
mercBounds:
|
|
733
|
+
xyBounds: D([o]),
|
|
734
|
+
mercBounds: D([u])
|
|
731
735
|
});
|
|
732
736
|
}
|
|
733
737
|
}
|
|
@@ -764,7 +768,7 @@ class jt {
|
|
|
764
768
|
const e = this._getTinsSortedByPriority();
|
|
765
769
|
for (let n = 0; n < e.length; n++) {
|
|
766
770
|
const { index: s, isMain: i } = e[n];
|
|
767
|
-
if (i ||
|
|
771
|
+
if (i || L(X(t), this.subTins[s - 1].xyBounds)) {
|
|
768
772
|
const o = this._transformByIndex(t, s, !1);
|
|
769
773
|
if (o === !1) continue;
|
|
770
774
|
return [s, o];
|
|
@@ -786,7 +790,7 @@ class jt {
|
|
|
786
790
|
merc2XyWithLayer(t) {
|
|
787
791
|
return this._assertMapData(), this._getAllTinsWithIndex().map(({ index: o, tin: u, isMain: d }) => {
|
|
788
792
|
const f = this._transformByIndex(t, o, !0);
|
|
789
|
-
return f === !1 ? [u, o] : d ||
|
|
793
|
+
return f === !1 ? [u, o] : d || L(X(f), this.subTins[o - 1].xyBounds) ? [u, o, f] : [u, o];
|
|
790
794
|
}).sort((o, u) => {
|
|
791
795
|
const d = o[0].priority ?? 0, f = u[0].priority ?? 0;
|
|
792
796
|
return d < f ? 1 : -1;
|
|
@@ -796,13 +800,13 @@ class jt {
|
|
|
796
800
|
if (!l) return o;
|
|
797
801
|
for (let g = 0; g < d; g++) {
|
|
798
802
|
const b = f[g][1], y = b === 0;
|
|
799
|
-
if (f[g][2] && (y ||
|
|
803
|
+
if (f[g][2] && (y || L(X(l), this.subTins[b - 1].xyBounds)))
|
|
800
804
|
if (o.length) {
|
|
801
|
-
const h = !o[0], c = h ? o[1][2] : o[0][2], x = m.importance ?? 0,
|
|
802
|
-
return h ? x <
|
|
805
|
+
const h = !o[0], c = h ? o[1][2] : o[0][2], x = m.importance ?? 0, w = c.importance ?? 0;
|
|
806
|
+
return h ? x < w ? o : [void 0, [a, l, m]] : [...o.filter(
|
|
803
807
|
(p) => p !== void 0
|
|
804
808
|
), [a, l, m]].sort(
|
|
805
|
-
(p,
|
|
809
|
+
(p, _) => (p[2].importance ?? 0) < (_[2].importance ?? 0) ? 1 : -1
|
|
806
810
|
).slice(0, 2);
|
|
807
811
|
} else
|
|
808
812
|
return [[a, l, m]];
|
|
@@ -849,7 +853,7 @@ class jt {
|
|
|
849
853
|
*/
|
|
850
854
|
viewpoint2Mercs(t, e) {
|
|
851
855
|
this._assertMapData(), this._assertMaxxy();
|
|
852
|
-
const s =
|
|
856
|
+
const s = et(t.center, t.zoom, t.rotation, e).map((f) => st(f, this._maxxy)), i = this.xy2MercWithLayer(s[0]);
|
|
853
857
|
if (!i) throw new Error("viewpoint2Mercs: center point is out of bounds");
|
|
854
858
|
const o = i[0], u = i[1];
|
|
855
859
|
return s.map((f, m) => {
|
|
@@ -876,29 +880,29 @@ class jt {
|
|
|
876
880
|
const a = this._transformByIndex(f, i, !0);
|
|
877
881
|
if (a === !1) throw new Error(`mercs2Viewpoint: point ${m} is out of bounds`);
|
|
878
882
|
return a;
|
|
879
|
-
}).map((f) =>
|
|
880
|
-
return
|
|
883
|
+
}).map((f) => q(f, this._maxxy));
|
|
884
|
+
return nt(d, e);
|
|
881
885
|
}
|
|
882
886
|
// ─── ユーティリティ(静的メソッド)────────────────────────────────────────
|
|
883
887
|
/** zoom2Radius の静的ラッパー */
|
|
884
888
|
static zoom2Radius(t, e) {
|
|
885
|
-
return
|
|
889
|
+
return ct(t, e);
|
|
886
890
|
}
|
|
887
891
|
/** mercViewpoint2Mercs の静的ラッパー */
|
|
888
892
|
static mercViewpoint2Mercs(t, e, n, s) {
|
|
889
|
-
return
|
|
893
|
+
return et(t, e, n, s);
|
|
890
894
|
}
|
|
891
895
|
/** mercs2MercViewpoint の静的ラッパー */
|
|
892
896
|
static mercs2MercViewpoint(t, e) {
|
|
893
|
-
return
|
|
897
|
+
return nt(t, e);
|
|
894
898
|
}
|
|
895
899
|
/** xy2SysCoord の静的ラッパー */
|
|
896
900
|
static xy2SysCoord(t, e) {
|
|
897
|
-
return
|
|
901
|
+
return q(t, e);
|
|
898
902
|
}
|
|
899
903
|
/** sysCoord2Xy の静的ラッパー */
|
|
900
904
|
static sysCoord2Xy(t, e) {
|
|
901
|
-
return
|
|
905
|
+
return st(t, e);
|
|
902
906
|
}
|
|
903
907
|
// ─── 内部ヘルパー ──────────────────────────────────────────────────────────
|
|
904
908
|
_assertMapData() {
|
|
@@ -962,23 +966,23 @@ class jt {
|
|
|
962
966
|
}
|
|
963
967
|
/** 内部用 xy2SysCoord(_maxxy を使用) */
|
|
964
968
|
xy2SysCoordInternal(t) {
|
|
965
|
-
return
|
|
969
|
+
return q(t, this._maxxy);
|
|
966
970
|
}
|
|
967
971
|
}
|
|
968
972
|
export {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
973
|
+
Ut as MERC_CROSSMATRIX,
|
|
974
|
+
R as MERC_MAX,
|
|
975
|
+
$t as MapTransform,
|
|
976
|
+
I as Transform,
|
|
977
|
+
Dt as counterTri,
|
|
978
|
+
Yt as format_version,
|
|
979
|
+
et as mercViewpoint2Mercs,
|
|
980
|
+
nt as mercs2MercViewpoint,
|
|
981
|
+
It as normalizeEdges,
|
|
982
|
+
Ft as rotateMatrix,
|
|
983
|
+
Vt as rotateVerticesTriangle,
|
|
984
|
+
st as sysCoord2Xy,
|
|
985
|
+
Tt as transformArr,
|
|
986
|
+
q as xy2SysCoord,
|
|
987
|
+
ct as zoom2Radius
|
|
984
988
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(T,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(T=typeof globalThis<"u"?globalThis:T||self,B(T.maplat_transform={}))})(this,(function(T){"use strict";var Gt=Object.defineProperty;var Zt=(T,B,O)=>B in T?Gt(T,B,{enumerable:!0,configurable:!0,writable:!0,value:O}):T[B]=O;var x=(T,B,O)=>Zt(T,typeof B!="symbol"?B+"":B,O);function B(e,t,r={}){const n={type:"Feature"};return(r.id===0||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function O(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!nt(e[0])||!nt(e[1]))throw new Error("coordinates must contain numbers");return B({type:"Point",coordinates:e},t,r)}function q(e,t,r={}){for(const s of e){if(s.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(s[s.length-1].length!==s[0].length)throw new Error("First and last Position are not equivalent.");for(let i=0;i<s[s.length-1].length;i++)if(s[s.length-1][i]!==s[0][i])throw new Error("First and last Position are not equivalent.")}return B({type:"Polygon",coordinates:e},t,r)}function U(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function nt(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}function gt(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if(e.type==="Feature"&&e.geometry!==null&&e.geometry.type==="Point")return[...e.geometry.coordinates];if(e.type==="Point")return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function st(e){if(Array.isArray(e))return e;if(e.type==="Feature"){if(e.geometry!==null)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function bt(e){return e.type==="Feature"?e.geometry:e}const V=11102230246251565e-32,S=134217729,pt=(3+8*V)*V;function G(e,t,r,n,s){let i,o,u,l,f=t[0],m=n[0],a=0,d=0;m>f==m>-f?(i=f,f=t[++a]):(i=m,m=n[++d]);let g=0;if(a<e&&d<r)for(m>f==m>-f?(o=f+i,u=i-(o-f),f=t[++a]):(o=m+i,u=i-(o-m),m=n[++d]),i=o,u!==0&&(s[g++]=u);a<e&&d<r;)m>f==m>-f?(o=i+f,l=o-i,u=i-(o-l)+(f-l),f=t[++a]):(o=i+m,l=o-i,u=i-(o-l)+(m-l),m=n[++d]),i=o,u!==0&&(s[g++]=u);for(;a<e;)o=i+f,l=o-i,u=i-(o-l)+(f-l),f=t[++a],i=o,u!==0&&(s[g++]=u);for(;d<r;)o=i+m,l=o-i,u=i-(o-l)+(m-l),m=n[++d],i=o,u!==0&&(s[g++]=u);return(i!==0||g===0)&&(s[g++]=i),g}function wt(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}function Y(e){return new Float64Array(e)}const xt=(3+16*V)*V,Mt=(2+12*V)*V,_t=(9+64*V)*V*V,F=Y(4),ot=Y(8),it=Y(12),at=Y(16),I=Y(4);function Tt(e,t,r,n,s,i,o){let u,l,f,m,a,d,g,b,y,h,c,p,M,_,E,w,v,C;const R=e-s,X=r-s,k=t-i,N=n-i;_=R*N,d=S*R,g=d-(d-R),b=R-g,d=S*N,y=d-(d-N),h=N-y,E=b*h-(_-g*y-b*y-g*h),w=k*X,d=S*k,g=d-(d-k),b=k-g,d=S*X,y=d-(d-X),h=X-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,F[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,F[1]=M-(c+a)+(a-w),C=p+c,a=C-p,F[2]=p-(C-a)+(c-a),F[3]=C;let L=wt(4,F),z=Mt*o;if(L>=z||-L>=z||(a=e-R,u=e-(R+a)+(a-s),a=r-X,f=r-(X+a)+(a-s),a=t-k,l=t-(k+a)+(a-i),a=n-N,m=n-(N+a)+(a-i),u===0&&l===0&&f===0&&m===0)||(z=_t*o+pt*Math.abs(L),L+=R*m+N*u-(k*f+X*l),L>=z||-L>=z))return L;_=u*N,d=S*u,g=d-(d-u),b=u-g,d=S*N,y=d-(d-N),h=N-y,E=b*h-(_-g*y-b*y-g*h),w=l*X,d=S*l,g=d-(d-l),b=l-g,d=S*X,y=d-(d-X),h=X-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,I[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,I[1]=M-(c+a)+(a-w),C=p+c,a=C-p,I[2]=p-(C-a)+(c-a),I[3]=C;const zt=G(4,F,4,I,ot);_=R*m,d=S*R,g=d-(d-R),b=R-g,d=S*m,y=d-(d-m),h=m-y,E=b*h-(_-g*y-b*y-g*h),w=k*f,d=S*k,g=d-(d-k),b=k-g,d=S*f,y=d-(d-f),h=f-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,I[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,I[1]=M-(c+a)+(a-w),C=p+c,a=C-p,I[2]=p-(C-a)+(c-a),I[3]=C;const qt=G(zt,ot,4,I,it);_=u*m,d=S*u,g=d-(d-u),b=u-g,d=S*m,y=d-(d-m),h=m-y,E=b*h-(_-g*y-b*y-g*h),w=l*f,d=S*l,g=d-(d-l),b=l-g,d=S*f,y=d-(d-f),h=f-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,I[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,I[1]=M-(c+a)+(a-w),C=p+c,a=C-p,I[2]=p-(C-a)+(c-a),I[3]=C;const jt=G(qt,it,4,I,at);return at[jt-1]}function vt(e,t,r,n,s,i){const o=(t-i)*(r-s),u=(e-s)*(n-i),l=o-u,f=Math.abs(o+u);return Math.abs(l)>=xt*f?l:-Tt(e,t,r,n,s,i,f)}function Et(e,t){var r,n,s=0,i,o,u,l,f,m,a,d=e[0],g=e[1],b=t.length;for(r=0;r<b;r++){n=0;var y=t[r],h=y.length-1;if(m=y[0],m[0]!==y[h][0]&&m[1]!==y[h][1])throw new Error("First and last coordinates in a ring must be the same");for(o=m[0]-d,u=m[1]-g,n;n<h;n++){if(a=y[n+1],l=a[0]-d,f=a[1]-g,u===0&&f===0){if(l<=0&&o>=0||o<=0&&l>=0)return 0}else if(f>=0&&u<=0||f<=0&&u>=0){if(i=vt(o,l,u,f,0,0),i===0)return 0;(i>0&&f>0&&u<=0||i<0&&f<=0&&u>0)&&s++}m=a,u=f,o=l}}return s%2!==0}function D(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=gt(e),s=bt(t),i=s.type,o=t.bbox;let u=s.coordinates;if(o&&At(n,o)===!1)return!1;i==="Polygon"&&(u=[u]);let l=!1;for(var f=0;f<u.length;++f){const m=Et(n,u[f]);if(m===0)return!r.ignoreBoundary;m&&(l=!0)}return l}function At(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}function Z(e,t){for(let r=0;r<t.features.length;r++)if(D(e,t.features[r]))return t.features[r]}function ct(e,t,r){const n=t.geometry.coordinates[0][0],s=t.geometry.coordinates[0][1],i=t.geometry.coordinates[0][2],o=e.geometry.coordinates,u=t.properties.a.geom,l=t.properties.b.geom,f=t.properties.c.geom,m=[s[0]-n[0],s[1]-n[1]],a=[i[0]-n[0],i[1]-n[1]],d=[o[0]-n[0],o[1]-n[1]],g=[l[0]-u[0],l[1]-u[1]],b=[f[0]-u[0],f[1]-u[1]];let y=(a[1]*d[0]-a[0]*d[1])/(m[0]*a[1]-m[1]*a[0]),h=(m[0]*d[1]-m[1]*d[0])/(m[0]*a[1]-m[1]*a[0]);if(r){const c=r[t.properties.a.index],p=r[t.properties.b.index],M=r[t.properties.c.index];let _;if(y<0||h<0||1-y-h<0){const E=y/(y+h),w=h/(y+h);_=y/p/(E/p+w/M),h=h/M/(E/p+w/M)}else _=y/p/(y/p+h/M+(1-y-h)/c),h=h/M/(y/p+h/M+(1-y-h)/c);y=_}return[y*g[0]+h*b[0]+u[0],y*g[1]+h*b[1]+u[1]]}function St(e,t,r,n){const s=e.geometry.coordinates,i=r.geometry.coordinates,o=Math.atan2(s[0]-i[0],s[1]-i[1]),u=Ct(o,t[0]);if(u===void 0)throw new Error("Unable to determine vertex index");const l=t[1][u];return ct(e,l.features[0],n)}function ut(e,t,r,n,s,i,o,u){let l;if(o&&(l=Z(e,U([o]))),!l)if(r){const f=e.geometry.coordinates,m=r.gridNum,a=r.xOrigin,d=r.yOrigin,g=r.xUnit,b=r.yUnit,y=r.gridCache,h=W(f[0],a,g,m),c=W(f[1],d,b,m),p=y[h]?y[h][c]?y[h][c]:[]:[],M=U(p.map(_=>t.features[_]));l=Z(e,M)}else l=Z(e,t);return u&&u(l),l?ct(e,l,i):St(e,n,s,i)}function W(e,t,r,n){let s=Math.floor((e-t)/r);return s<0&&(s=0),s>=n&&(s=n-1),s}function Ct(e,t){let r=ft(e-t[0]),n=Math.PI*2,s;for(let i=0;i<t.length;i++){const o=(i+1)%t.length,u=ft(e-t[o]),l=Math.min(Math.abs(r),Math.abs(u));r*u<=0&&l<n&&(n=l,s=i),r=u}return s}function ft(e,t=!1){const r=2*Math.PI,n=e-Math.floor(e/r)*r;return t?n:n>Math.PI?n-r:n}function It(e){const t=e.features;for(let r=0;r<t.length;r++){const n=t[r];`${n.properties.a.index}`.substring(0,1)==="b"&&`${n.properties.b.index}`.substring(0,1)==="b"?t[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1],n.geometry.coordinates[0][2]]]},properties:{a:{geom:n.properties.c.geom,index:n.properties.c.index},b:{geom:n.properties.a.geom,index:n.properties.a.index},c:{geom:n.properties.b.geom,index:n.properties.b.index}},type:"Feature"}:`${n.properties.c.index}`.substring(0,1)==="b"&&`${n.properties.a.index}`.substring(0,1)==="b"&&(t[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][1],n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1]]]},properties:{a:{geom:n.properties.b.geom,index:n.properties.b.index},b:{geom:n.properties.c.geom,index:n.properties.c.index},c:{geom:n.properties.a.geom,index:n.properties.a.index}},type:"Feature"})}return e}function Bt(e){const t=["a","b","c","a"].map(i=>e.properties[i].geom),r=e.geometry.coordinates[0],n=e.properties,s={a:{geom:r[0],index:n.a.index},b:{geom:r[1],index:n.b.index},c:{geom:r[2],index:n.c.index}};return q([t],s)}function Ot(e){const t=[0,1,2,0].map(n=>e[n][0][0]),r={a:{geom:e[0][0][1],index:e[0][1]},b:{geom:e[1][0][1],index:e[1][1]},c:{geom:e[2][0][1],index:e[2][1]}};return q([t],r)}function J(e,t,r,n,s,i=!1,o){const u=e.map(l=>{(!o||o<2.00703)&&(l=ht(l));const f=isFinite(l)?t[l]:l==="c"?n:(function(){const m=l.match(/^b(\d+)$/);if(m)return s[parseInt(m[1])];const a=l.match(/^e(\d+)$/);if(a)return r[parseInt(a[1])];throw new Error("Bad index value for indexesToTri")})();return i?[[f[1],f[0]],l]:[[f[0],f[1]],l]});return Ot(u)}function ht(e){return typeof e=="number"?e:e.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}function dt(e,t){return t&&t>=2.00703||Array.isArray(e[0])?e:e.map(r=>[r.illstNodes,r.mercNodes,r.startEnd])}const K=2.00703;function Pt(e){return!!(e.version!==void 0||!e.tins&&e.points&&e.tins_points)}function Rt(e){return{points:e.points,pointsWeightBuffer:kt(e),strictStatus:Nt(e),verticesParams:Wt(e),centroid:Vt(e),edges:dt(e.edges||[]),edgeNodes:e.edgeNodes||[],tins:Lt(e),kinks:Ut(e.kinks_points),yaxisMode:e.yaxisMode??"invert",strictMode:e.strictMode??"auto",vertexMode:e.vertexMode,bounds:e.bounds,boundsPolygon:e.boundsPolygon,wh:e.wh,xy:e.xy??[0,0]}}function Xt(e){const t=Ft(e),r=t.tins;return{compiled:t,tins:r,points:Dt(r),strictStatus:t.strict_status,pointsWeightBuffer:t.weight_buffer,verticesParams:t.vertices_params,centroid:t.centroid,kinks:t.kinks}}function kt(e){return!e.version||e.version<K?["forw","bakw"].reduce((t,r)=>{const n=e.weight_buffer[r];return n&&(t[r]=Object.keys(n).reduce((s,i)=>{const o=ht(i);return s[o]=n[i],s},{})),t},{}):e.weight_buffer}function Nt(e){return e.strict_status?e.strict_status:e.kinks_points?"strict_error":e.tins_points.length===2?"loose":"strict"}function Wt(e){const t={forw:[e.vertices_params[0]],bakw:[e.vertices_params[1]]};return t.forw[1]=lt(e,!1),t.bakw[1]=lt(e,!0),t}function lt(e,t){const r=e.vertices_points.length;return Array.from({length:r},(n,s)=>{const i=(s+1)%r,o=J(["c",`b${s}`,`b${i}`],e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,t,K);return U([o])})}function Vt(e){return{forw:O(e.centroid_point[0],{target:{geom:e.centroid_point[1],index:"c"}}),bakw:O(e.centroid_point[1],{target:{geom:e.centroid_point[0],index:"c"}})}}function Lt(e){const t=e.tins_points.length===1?0:1;return{forw:U(e.tins_points[0].map(r=>J(r,e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,!1,e.version))),bakw:U(e.tins_points[t].map(r=>J(r,e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,!0,e.version)))}}function Ut(e){if(e)return{bakw:U(e.map(t=>O(t)))}}function Ft(e){return JSON.parse(JSON.stringify(e).replace('"cent"','"c"').replace(/"bbox(\d+)"/g,'"b$1"'))}function Dt(e){const t=[],r=e.forw.features;for(let n=0;n<r.length;n++){const s=r[n];["a","b","c"].forEach((i,o)=>{const u=s.geometry.coordinates[0][o],l=s.properties[i].geom,f=s.properties[i].index;typeof f=="number"&&(t[f]=[u,l])})}return t}const Yt=K,A=class A{constructor(){x(this,"points",[]);x(this,"pointsWeightBuffer");x(this,"strict_status");x(this,"vertices_params");x(this,"centroid");x(this,"edgeNodes");x(this,"edges");x(this,"tins");x(this,"kinks");x(this,"yaxisMode",A.YAXIS_INVERT);x(this,"strictMode",A.MODE_AUTO);x(this,"vertexMode",A.VERTEX_PLAIN);x(this,"bounds");x(this,"boundsPolygon");x(this,"wh");x(this,"xy");x(this,"indexedTins");x(this,"stateFull",!1);x(this,"stateTriangle");x(this,"stateBackward");x(this,"priority");x(this,"importance");x(this,"xyBounds");x(this,"mercBounds")}setCompiled(t){if(Pt(t)){this.applyModernState(Rt(t));return}this.applyLegacyState(Xt(t))}applyModernState(t){this.points=t.points,this.pointsWeightBuffer=t.pointsWeightBuffer,this.strict_status=t.strictStatus,this.vertices_params=t.verticesParams,this.centroid=t.centroid,this.edges=t.edges,this.edgeNodes=t.edgeNodes||[],this.tins=t.tins,this.addIndexedTin(),this.kinks=t.kinks,this.yaxisMode=t.yaxisMode??A.YAXIS_INVERT,this.vertexMode=t.vertexMode??A.VERTEX_PLAIN,this.strictMode=t.strictMode??A.MODE_AUTO,t.bounds?(this.bounds=t.bounds,this.boundsPolygon=t.boundsPolygon,this.xy=t.xy,this.wh=t.wh):(this.bounds=void 0,this.boundsPolygon=void 0,this.xy=t.xy??[0,0],t.wh&&(this.wh=t.wh))}applyLegacyState(t){this.tins=t.tins,this.addIndexedTin(),this.strict_status=t.strictStatus,this.pointsWeightBuffer=t.pointsWeightBuffer,this.vertices_params=t.verticesParams,this.centroid=t.centroid,this.kinks=t.kinks,this.points=t.points}addIndexedTin(){const t=this.tins,r=t.forw,n=t.bakw,s=Math.ceil(Math.sqrt(r.features.length));if(s<3){this.indexedTins=void 0;return}let i=[],o=[];const u=r.features.map(y=>{let h=[];return st(y)[0].map(c=>{i.length===0?i=[Array.from(c),Array.from(c)]:(c[0]<i[0][0]&&(i[0][0]=c[0]),c[0]>i[1][0]&&(i[1][0]=c[0]),c[1]<i[0][1]&&(i[0][1]=c[1]),c[1]>i[1][1]&&(i[1][1]=c[1])),h.length===0?h=[Array.from(c),Array.from(c)]:(c[0]<h[0][0]&&(h[0][0]=c[0]),c[0]>h[1][0]&&(h[1][0]=c[0]),c[1]<h[0][1]&&(h[0][1]=c[1]),c[1]>h[1][1]&&(h[1][1]=c[1]))}),h}),l=(i[1][0]-i[0][0])/s,f=(i[1][1]-i[0][1])/s,m=u.reduce((y,h,c)=>{const p=W(h[0][0],i[0][0],l,s),M=W(h[1][0],i[0][0],l,s),_=W(h[0][1],i[0][1],f,s),E=W(h[1][1],i[0][1],f,s);for(let w=p;w<=M;w++){y[w]||(y[w]=[]);for(let v=_;v<=E;v++)y[w][v]||(y[w][v]=[]),y[w][v].push(c)}return y},[]),a=n.features.map(y=>{let h=[];return st(y)[0].map(c=>{o.length===0?o=[Array.from(c),Array.from(c)]:(c[0]<o[0][0]&&(o[0][0]=c[0]),c[0]>o[1][0]&&(o[1][0]=c[0]),c[1]<o[0][1]&&(o[0][1]=c[1]),c[1]>o[1][1]&&(o[1][1]=c[1])),h.length===0?h=[Array.from(c),Array.from(c)]:(c[0]<h[0][0]&&(h[0][0]=c[0]),c[0]>h[1][0]&&(h[1][0]=c[0]),c[1]<h[0][1]&&(h[0][1]=c[1]),c[1]>h[1][1]&&(h[1][1]=c[1]))}),h}),d=(o[1][0]-o[0][0])/s,g=(o[1][1]-o[0][1])/s,b=a.reduce((y,h,c)=>{const p=W(h[0][0],o[0][0],d,s),M=W(h[1][0],o[0][0],d,s),_=W(h[0][1],o[0][1],g,s),E=W(h[1][1],o[0][1],g,s);for(let w=p;w<=M;w++){y[w]||(y[w]=[]);for(let v=_;v<=E;v++)y[w][v]||(y[w][v]=[]),y[w][v].push(c)}return y},[]);this.indexedTins={forw:{gridNum:s,xOrigin:i[0][0],yOrigin:i[0][1],xUnit:l,yUnit:f,gridCache:m},bakw:{gridNum:s,xOrigin:o[0][0],yOrigin:o[0][1],xUnit:d,yUnit:g,gridCache:b}}}transform(t,r,n){if(!this.tins)throw new Error("setCompiled() must be called before transform()");if(r&&this.strict_status==A.STATUS_ERROR)throw new Error('Backward transform is not allowed if strict_status == "strict_error"');this.yaxisMode==A.YAXIS_FOLLOW&&r&&(t=[t[0],-1*t[1]]);const s=O(t);if(this.bounds&&!r&&!n&&!D(s,this.boundsPolygon))return!1;const i=r?this.tins.bakw:this.tins.forw,o=r?this.indexedTins.bakw:this.indexedTins.forw,u=r?this.vertices_params.bakw:this.vertices_params.forw,l=r?this.centroid.bakw:this.centroid.forw,f=r?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let m,a;this.stateFull&&(this.stateBackward==r?m=this.stateTriangle:(this.stateBackward=r,this.stateTriangle=void 0),a=g=>{this.stateTriangle=g});let d=ut(s,i,o,u,l,f,m,a);if(this.bounds&&r&&!n){const g=O(d);if(!D(g,this.boundsPolygon))return!1}else this.yaxisMode==A.YAXIS_FOLLOW&&!r&&(d=[d[0],-1*d[1]]);return d}};x(A,"VERTEX_PLAIN","plain"),x(A,"VERTEX_BIRDEYE","birdeye"),x(A,"MODE_STRICT","strict"),x(A,"MODE_AUTO","auto"),x(A,"MODE_LOOSE","loose"),x(A,"STATUS_STRICT","strict"),x(A,"STATUS_ERROR","strict_error"),x(A,"STATUS_LOOSE","loose"),x(A,"YAXIS_FOLLOW","follow"),x(A,"YAXIS_INVERT","invert");let $=A;const P=20037508342789244e-9,yt=[[0,0],[0,1],[1,0],[0,-1],[-1,0]];function Q(e,t){return Math.floor(Math.min(e[0],e[1])/4)*P/128/Math.pow(2,t)}function mt(e,t){const r=[];for(let n=0;n<e.length;n++){const s=e[n],i=s[0]*Math.cos(t)-s[1]*Math.sin(t),o=s[0]*Math.sin(t)+s[1]*Math.cos(t);r.push([i,o])}return r}function H(e,t,r,n){const s=Q(n,t);return mt(yt,r).map(u=>[u[0]*s+e[0],u[1]*s+e[1]])}function tt(e,t){const r=e[0],s=e.slice(1,5).map(g=>[g[0]-r[0],g[1]-r[1]]),i=[[0,1],[1,0],[0,-1],[-1,0]];let o=0,u=0,l=0;for(let g=0;g<4;g++){const b=s[g],y=i[g],h=Math.sqrt(Math.pow(b[0],2)+Math.pow(b[1],2));o+=h;const c=b[0]*y[1]-b[1]*y[0],p=Math.acos((b[0]*y[0]+b[1]*y[1])/h),M=c>0?-1*p:p;u+=Math.cos(M),l+=Math.sin(M)}const f=o/4,m=Math.atan2(l,u),a=Math.floor(Math.min(t[0],t[1])/4),d=Math.log(a*P/128/f)/Math.log(2);return{center:r,zoom:d,rotation:m}}function j(e,t){const r=e[0]*(2*P)/t-P,n=-1*(e[1]*(2*P)/t-P);return[r,n]}function et(e,t){const r=(e[0]+P)*t/(2*P),n=(-e[1]+P)*t/(2*P);return[r,n]}const rt=256;class $t{constructor(){x(this,"mainTin",null);x(this,"subTins",[]);x(this,"_maxxy",0)}setMapData(t){const r=new $;if(r.setCompiled(t.compiled),this.mainTin=r,t.maxZoom!==void 0)this._maxxy=Math.pow(2,t.maxZoom)*rt;else if(t.compiled.wh){const n=Math.max(t.compiled.wh[0],t.compiled.wh[1]),s=Math.ceil(Math.log2(n/rt));this._maxxy=Math.pow(2,s)*rt}if(this.subTins=[],t.sub_maps)for(const n of t.sub_maps){const s=new $;s.setCompiled(n.compiled);const i=n.bounds??n.compiled.bounds;if(!i)throw new Error("SubMapData must have bounds or compiled.bounds to create xyBounds polygon");const o=[...i,i[0]],u=o.map(l=>{const f=s.transform(l,!1);if(!f)throw new Error("Failed to transform sub-map bounds to mercator");return f});this.subTins.push({tin:s,priority:n.priority,importance:n.importance,xyBounds:q([o]),mercBounds:q([u])})}}xy2Merc(t){const r=this.xy2MercWithLayer(t);return r?r[1]:!1}merc2Xy(t){const r=this.merc2XyWithLayer(t),n=r[0]||r[1];return n?n[1]:!1}xy2MercWithLayer(t){this._assertMapData();const r=this._getTinsSortedByPriority();for(let n=0;n<r.length;n++){const{index:s,isMain:i}=r[n];if(i||D(O(t),this.subTins[s-1].xyBounds)){const o=this._transformByIndex(t,s,!1);if(o===!1)continue;return[s,o]}}return!1}merc2XyWithLayer(t){return this._assertMapData(),this._getAllTinsWithIndex().map(({index:o,tin:u,isMain:l})=>{const f=this._transformByIndex(t,o,!0);return f===!1?[u,o]:l||D(O(f),this.subTins[o-1].xyBounds)?[u,o,f]:[u,o]}).sort((o,u)=>{const l=o[0].priority??0,f=u[0].priority??0;return l<f?1:-1}).reduce((o,u,l,f)=>{const m=u[0],a=u[1],d=u[2];if(!d)return o;for(let g=0;g<l;g++){const b=f[g][1],y=b===0;if(f[g][2]&&(y||D(O(d),this.subTins[b-1].xyBounds)))if(o.length){const h=!o[0],c=h?o[1][2]:o[0][2],p=m.importance??0,M=c.importance??0;return h?p<M?o:[void 0,[a,d,m]]:[...o.filter(w=>w!==void 0),[a,d,m]].sort((w,v)=>(w[2].importance??0)<(v[2].importance??0)?1:-1).slice(0,2)}else return[[a,d,m]]}return!o.length||!o[0]?[[a,d,m]]:(o.push([a,d,m]),o.sort((g,b)=>{const y=g[2].importance??0,h=b[2].importance??0;return y<h?1:-1}).filter((g,b)=>b<2))},[]).map(o=>{if(o)return[o[0],o[1]]})}mercs2SysCoords(t){this._assertMapData();const r=this.merc2XyWithLayer(t[0]);let n=!1;return r.map((s,i)=>{if(!s){n=!0;return}const o=s[0],u=s[1];return i!==0&&!n?[this.xy2SysCoordInternal(u)]:t.map((f,m)=>m===0?u:this._transformByIndex(f,o,!0)).map(f=>this.xy2SysCoordInternal(f))})}viewpoint2Mercs(t,r){this._assertMapData(),this._assertMaxxy();const s=H(t.center,t.zoom,t.rotation,r).map(f=>et(f,this._maxxy)),i=this.xy2MercWithLayer(s[0]);if(!i)throw new Error("viewpoint2Mercs: center point is out of bounds");const o=i[0],u=i[1];return s.map((f,m)=>{if(m===0)return u;const a=this._transformByIndex(f,o,!1);if(a===!1)throw new Error(`viewpoint2Mercs: point ${m} is out of bounds`);return a})}mercs2Viewpoint(t,r){this._assertMapData(),this._assertMaxxy();const n=this.merc2XyWithLayer(t[0]),s=n[0]||n[1];if(!s)throw new Error("mercs2Viewpoint: center point is out of bounds");const i=s[0],o=s[1],l=t.map((f,m)=>{if(m===0)return o;const a=this._transformByIndex(f,i,!0);if(a===!1)throw new Error(`mercs2Viewpoint: point ${m} is out of bounds`);return a}).map(f=>j(f,this._maxxy));return tt(l,r)}static zoom2Radius(t,r){return Q(t,r)}static mercViewpoint2Mercs(t,r,n,s){return H(t,r,n,s)}static mercs2MercViewpoint(t,r){return tt(t,r)}static xy2SysCoord(t,r){return j(t,r)}static sysCoord2Xy(t,r){return et(t,r)}_assertMapData(){if(!this.mainTin)throw new Error("setMapData() must be called before transformation")}_assertMaxxy(){if(this._maxxy===0)throw new Error("MapData.maxZoom or compiled.wh must be set for viewpoint conversion (xy2SysCoord / sysCoord2Xy)")}getLayerTransform(t){if(t===0)return this.mainTin;const r=this.subTins[t-1];return r?r.tin:null}get layerCount(){return 1+this.subTins.length}get maxxy(){return this._maxxy}_getTinsSortedByPriority(){return this._getAllTinsWithIndex().sort((r,n)=>{const s=r.tin.priority??0,i=n.tin.priority??0;return s<i?1:-1})}_getAllTinsWithIndex(){const t=[{index:0,tin:this.mainTin,isMain:!0}];return this.subTins.forEach((r,n)=>{r.tin.priority=r.priority,r.tin.importance=r.importance,t.push({index:n+1,tin:r.tin,isMain:!1})}),t}_transformByIndex(t,r,n){if(r===0)return this.mainTin.transform(t,n);const s=this.subTins[r-1];return s?s.tin.transform(t,n,!0):!1}xy2SysCoordInternal(t){return j(t,this._maxxy)}}T.MERC_CROSSMATRIX=yt,T.MERC_MAX=P,T.MapTransform=$t,T.Transform=$,T.counterTri=Bt,T.format_version=Yt,T.mercViewpoint2Mercs=H,T.mercs2MercViewpoint=tt,T.normalizeEdges=dt,T.rotateMatrix=mt,T.rotateVerticesTriangle=It,T.sysCoord2Xy=et,T.transformArr=ut,T.xy2SysCoord=j,T.zoom2Radius=Q,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(v,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(v=typeof globalThis<"u"?globalThis:v||self,V(v.maplat_transform={}))})(this,(function(v){"use strict";function V(e,t,r={}){const n={type:"Feature"};return(r.id===0||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function W(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!et(e[0])||!et(e[1]))throw new Error("coordinates must contain numbers");return V({type:"Point",coordinates:e},t,r)}function $(e,t,r={}){for(const s of e){if(s.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(s[s.length-1].length!==s[0].length)throw new Error("First and last Position are not equivalent.");for(let i=0;i<s[s.length-1].length;i++)if(s[s.length-1][i]!==s[0][i])throw new Error("First and last Position are not equivalent.")}return V({type:"Polygon",coordinates:e},t,r)}function L(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function et(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}function mt(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if(e.type==="Feature"&&e.geometry!==null&&e.geometry.type==="Point")return[...e.geometry.coordinates];if(e.type==="Point")return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function rt(e){if(Array.isArray(e))return e;if(e.type==="Feature"){if(e.geometry!==null)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function yt(e){return e.type==="Feature"?e.geometry:e}const k=11102230246251565e-32,E=134217729,gt=(3+8*k)*k;function q(e,t,r,n,s){let i,o,u,l,f=t[0],y=n[0],a=0,d=0;y>f==y>-f?(i=f,f=t[++a]):(i=y,y=n[++d]);let g=0;if(a<e&&d<r)for(y>f==y>-f?(o=f+i,u=i-(o-f),f=t[++a]):(o=y+i,u=i-(o-y),y=n[++d]),i=o,u!==0&&(s[g++]=u);a<e&&d<r;)y>f==y>-f?(o=i+f,l=o-i,u=i-(o-l)+(f-l),f=t[++a]):(o=i+y,l=o-i,u=i-(o-l)+(y-l),y=n[++d]),i=o,u!==0&&(s[g++]=u);for(;a<e;)o=i+f,l=o-i,u=i-(o-l)+(f-l),f=t[++a],i=o,u!==0&&(s[g++]=u);for(;d<r;)o=i+y,l=o-i,u=i-(o-l)+(y-l),y=n[++d],i=o,u!==0&&(s[g++]=u);return(i!==0||g===0)&&(s[g++]=i),g}function bt(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}function D(e){return new Float64Array(e)}const pt=(3+16*k)*k,wt=(2+12*k)*k,xt=(9+64*k)*k*k,U=D(4),nt=D(8),st=D(12),ot=D(16),S=D(4);function Mt(e,t,r,n,s,i,o){let u,l,f,y,a,d,g,b,m,h,c,p,x,M,T,w,_,A;const B=e-s,O=r-s,P=t-i,R=n-i;M=B*R,d=E*B,g=d-(d-B),b=B-g,d=E*R,m=d-(d-R),h=R-m,T=b*h-(M-g*m-b*m-g*h),w=P*O,d=E*P,g=d-(d-P),b=P-g,d=E*O,m=d-(d-O),h=O-m,_=b*h-(w-g*m-b*m-g*h),c=T-_,a=T-c,U[0]=T-(c+a)+(a-_),p=M+c,a=p-M,x=M-(p-a)+(c-a),c=x-w,a=x-c,U[1]=x-(c+a)+(a-w),A=p+c,a=A-p,U[2]=p-(A-a)+(c-a),U[3]=A;let N=bt(4,U),Y=wt*o;if(N>=Y||-N>=Y||(a=e-B,u=e-(B+a)+(a-s),a=r-O,f=r-(O+a)+(a-s),a=t-P,l=t-(P+a)+(a-i),a=n-R,y=n-(R+a)+(a-i),u===0&&l===0&&f===0&&y===0)||(Y=xt*o+gt*Math.abs(N),N+=B*y+R*u-(P*f+O*l),N>=Y||-N>=Y))return N;M=u*R,d=E*u,g=d-(d-u),b=u-g,d=E*R,m=d-(d-R),h=R-m,T=b*h-(M-g*m-b*m-g*h),w=l*O,d=E*l,g=d-(d-l),b=l-g,d=E*O,m=d-(d-O),h=O-m,_=b*h-(w-g*m-b*m-g*h),c=T-_,a=T-c,S[0]=T-(c+a)+(a-_),p=M+c,a=p-M,x=M-(p-a)+(c-a),c=x-w,a=x-c,S[1]=x-(c+a)+(a-w),A=p+c,a=A-p,S[2]=p-(A-a)+(c-a),S[3]=A;const Yt=q(4,U,4,S,nt);M=B*y,d=E*B,g=d-(d-B),b=B-g,d=E*y,m=d-(d-y),h=y-m,T=b*h-(M-g*m-b*m-g*h),w=P*f,d=E*P,g=d-(d-P),b=P-g,d=E*f,m=d-(d-f),h=f-m,_=b*h-(w-g*m-b*m-g*h),c=T-_,a=T-c,S[0]=T-(c+a)+(a-_),p=M+c,a=p-M,x=M-(p-a)+(c-a),c=x-w,a=x-c,S[1]=x-(c+a)+(a-w),A=p+c,a=A-p,S[2]=p-(A-a)+(c-a),S[3]=A;const $t=q(Yt,nt,4,S,st);M=u*y,d=E*u,g=d-(d-u),b=u-g,d=E*y,m=d-(d-y),h=y-m,T=b*h-(M-g*m-b*m-g*h),w=l*f,d=E*l,g=d-(d-l),b=l-g,d=E*f,m=d-(d-f),h=f-m,_=b*h-(w-g*m-b*m-g*h),c=T-_,a=T-c,S[0]=T-(c+a)+(a-_),p=M+c,a=p-M,x=M-(p-a)+(c-a),c=x-w,a=x-c,S[1]=x-(c+a)+(a-w),A=p+c,a=A-p,S[2]=p-(A-a)+(c-a),S[3]=A;const zt=q($t,st,4,S,ot);return ot[zt-1]}function _t(e,t,r,n,s,i){const o=(t-i)*(r-s),u=(e-s)*(n-i),l=o-u,f=Math.abs(o+u);return Math.abs(l)>=pt*f?l:-Mt(e,t,r,n,s,i,f)}function Tt(e,t){var r,n,s=0,i,o,u,l,f,y,a,d=e[0],g=e[1],b=t.length;for(r=0;r<b;r++){n=0;var m=t[r],h=m.length-1;if(y=m[0],y[0]!==m[h][0]&&y[1]!==m[h][1])throw new Error("First and last coordinates in a ring must be the same");for(o=y[0]-d,u=y[1]-g,n;n<h;n++){if(a=m[n+1],l=a[0]-d,f=a[1]-g,u===0&&f===0){if(l<=0&&o>=0||o<=0&&l>=0)return 0}else if(f>=0&&u<=0||f<=0&&u>=0){if(i=_t(o,l,u,f,0,0),i===0)return 0;(i>0&&f>0&&u<=0||i<0&&f<=0&&u>0)&&s++}y=a,u=f,o=l}}return s%2!==0}function F(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=mt(e),s=yt(t),i=s.type,o=t.bbox;let u=s.coordinates;if(o&&vt(n,o)===!1)return!1;i==="Polygon"&&(u=[u]);let l=!1;for(var f=0;f<u.length;++f){const y=Tt(n,u[f]);if(y===0)return!r.ignoreBoundary;y&&(l=!0)}return l}function vt(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}function j(e,t){for(let r=0;r<t.features.length;r++)if(F(e,t.features[r]))return t.features[r]}function it(e,t,r){const n=t.geometry.coordinates[0][0],s=t.geometry.coordinates[0][1],i=t.geometry.coordinates[0][2],o=e.geometry.coordinates,u=t.properties.a.geom,l=t.properties.b.geom,f=t.properties.c.geom,y=[s[0]-n[0],s[1]-n[1]],a=[i[0]-n[0],i[1]-n[1]],d=[o[0]-n[0],o[1]-n[1]],g=[l[0]-u[0],l[1]-u[1]],b=[f[0]-u[0],f[1]-u[1]];let m=(a[1]*d[0]-a[0]*d[1])/(y[0]*a[1]-y[1]*a[0]),h=(y[0]*d[1]-y[1]*d[0])/(y[0]*a[1]-y[1]*a[0]);if(r){const c=r[t.properties.a.index],p=r[t.properties.b.index],x=r[t.properties.c.index];let M;if(m<0||h<0||1-m-h<0){const T=m/(m+h),w=h/(m+h);M=m/p/(T/p+w/x),h=h/x/(T/p+w/x)}else M=m/p/(m/p+h/x+(1-m-h)/c),h=h/x/(m/p+h/x+(1-m-h)/c);m=M}return[m*g[0]+h*b[0]+u[0],m*g[1]+h*b[1]+u[1]]}function Et(e,t,r,n){const s=e.geometry.coordinates,i=r.geometry.coordinates,o=Math.atan2(s[0]-i[0],s[1]-i[1]),u=At(o,t[0]);if(u===void 0)throw new Error("Unable to determine vertex index");const l=t[1][u];return it(e,l.features[0],n)}function at(e,t,r,n,s,i,o,u){let l;if(o&&(l=j(e,L([o]))),!l)if(r){const f=e.geometry.coordinates,y=r.gridNum,a=r.xOrigin,d=r.yOrigin,g=r.xUnit,b=r.yUnit,m=r.gridCache,h=X(f[0],a,g,y),c=X(f[1],d,b,y),p=m[h]?m[h][c]?m[h][c]:[]:[],x=L(p.map(M=>t.features[M]));l=j(e,x)}else l=j(e,t);return u&&u(l),l?it(e,l,i):Et(e,n,s,i)}function X(e,t,r,n){let s=Math.floor((e-t)/r);return s<0&&(s=0),s>=n&&(s=n-1),s}function At(e,t){let r=ct(e-t[0]),n=Math.PI*2,s;for(let i=0;i<t.length;i++){const o=(i+1)%t.length,u=ct(e-t[o]),l=Math.min(Math.abs(r),Math.abs(u));r*u<=0&&l<n&&(n=l,s=i),r=u}return s}function ct(e,t=!1){const r=2*Math.PI,n=e-Math.floor(e/r)*r;return t?n:n>Math.PI?n-r:n}function St(e){const t=e.features;for(let r=0;r<t.length;r++){const n=t[r];`${n.properties.a.index}`.substring(0,1)==="b"&&`${n.properties.b.index}`.substring(0,1)==="b"?t[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1],n.geometry.coordinates[0][2]]]},properties:{a:{geom:n.properties.c.geom,index:n.properties.c.index},b:{geom:n.properties.a.geom,index:n.properties.a.index},c:{geom:n.properties.b.geom,index:n.properties.b.index}},type:"Feature"}:`${n.properties.c.index}`.substring(0,1)==="b"&&`${n.properties.a.index}`.substring(0,1)==="b"&&(t[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][1],n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1]]]},properties:{a:{geom:n.properties.b.geom,index:n.properties.b.index},b:{geom:n.properties.c.geom,index:n.properties.c.index},c:{geom:n.properties.a.geom,index:n.properties.a.index}},type:"Feature"})}return e}function Ct(e){const t=["a","b","c","a"].map(i=>e.properties[i].geom),r=e.geometry.coordinates[0],n=e.properties,s={a:{geom:r[0],index:n.a.index},b:{geom:r[1],index:n.b.index},c:{geom:r[2],index:n.c.index}};return $([t],s)}function It(e){const t=[0,1,2,0].map(n=>e[n][0][0]),r={a:{geom:e[0][0][1],index:e[0][1]},b:{geom:e[1][0][1],index:e[1][1]},c:{geom:e[2][0][1],index:e[2][1]}};return $([t],r)}function G(e,t,r,n,s,i=!1,o){const u=e.map(l=>{(!o||o<2.00703)&&(l=ut(l));const f=isFinite(l)?t[l]:l==="c"?n:(function(){const y=l.match(/^b(\d+)$/);if(y)return s[parseInt(y[1])];const a=l.match(/^e(\d+)$/);if(a)return r[parseInt(a[1])];throw new Error("Bad index value for indexesToTri")})();return i?[[f[1],f[0]],l]:[[f[0],f[1]],l]});return It(u)}function ut(e){return typeof e=="number"?e:e.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}function ft(e,t){return t&&t>=2.00703||Array.isArray(e[0])?e:e.map(r=>[r.illstNodes,r.mercNodes,r.startEnd])}const Z=2.00703;function Bt(e){return!!(e.version!==void 0||!e.tins&&e.points&&e.tins_points)}function Ot(e){return{points:e.points,pointsWeightBuffer:Rt(e),strictStatus:Xt(e),verticesParams:kt(e),centroid:Nt(e),edges:ft(e.edges||[]),edgeNodes:e.edgeNodes||[],tins:Wt(e),kinks:Vt(e.kinks_points),yaxisMode:e.yaxisMode??"invert",strictMode:e.strictMode??"auto",vertexMode:e.vertexMode,bounds:e.bounds,boundsPolygon:e.boundsPolygon,wh:e.wh,xy:e.xy??[0,0]}}function Pt(e){const t=Lt(e),r=t.tins;return{compiled:t,tins:r,points:Ut(r),strictStatus:t.strict_status,pointsWeightBuffer:t.weight_buffer,verticesParams:t.vertices_params,centroid:t.centroid,kinks:t.kinks}}function Rt(e){return!e.version||e.version<Z?["forw","bakw"].reduce((t,r)=>{const n=e.weight_buffer[r];return n&&(t[r]=Object.keys(n).reduce((s,i)=>{const o=ut(i);return s[o]=n[i],s},{})),t},{}):e.weight_buffer}function Xt(e){return e.strict_status?e.strict_status:e.kinks_points?"strict_error":e.tins_points.length===2?"loose":"strict"}function kt(e){const t={forw:[e.vertices_params[0]],bakw:[e.vertices_params[1]]};return t.forw[1]=ht(e,!1),t.bakw[1]=ht(e,!0),t}function ht(e,t){const r=e.vertices_points.length;return Array.from({length:r},(n,s)=>{const i=(s+1)%r,o=G(["c",`b${s}`,`b${i}`],e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,t,Z);return L([o])})}function Nt(e){return{forw:W(e.centroid_point[0],{target:{geom:e.centroid_point[1],index:"c"}}),bakw:W(e.centroid_point[1],{target:{geom:e.centroid_point[0],index:"c"}})}}function Wt(e){const t=e.tins_points.length===1?0:1;return{forw:L(e.tins_points[0].map(r=>G(r,e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,!1,e.version))),bakw:L(e.tins_points[t].map(r=>G(r,e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,!0,e.version)))}}function Vt(e){if(e)return{bakw:L(e.map(t=>W(t)))}}function Lt(e){return JSON.parse(JSON.stringify(e).replace('"cent"','"c"').replace(/"bbox(\d+)"/g,'"b$1"'))}function Ut(e){const t=[],r=e.forw.features;for(let n=0;n<r.length;n++){const s=r[n];["a","b","c"].forEach((i,o)=>{const u=s.geometry.coordinates[0][o],l=s.properties[i].geom,f=s.properties[i].index;typeof f=="number"&&(t[f]=[u,l])})}return t}const Ft=Z;class C{static VERTEX_PLAIN="plain";static VERTEX_BIRDEYE="birdeye";static MODE_STRICT="strict";static MODE_AUTO="auto";static MODE_LOOSE="loose";static STATUS_STRICT="strict";static STATUS_ERROR="strict_error";static STATUS_LOOSE="loose";static YAXIS_FOLLOW="follow";static YAXIS_INVERT="invert";points=[];pointsWeightBuffer;strict_status;vertices_params;centroid;edgeNodes;edges;tins;kinks;yaxisMode=C.YAXIS_INVERT;strictMode=C.MODE_AUTO;vertexMode=C.VERTEX_PLAIN;bounds;boundsPolygon;wh;xy;indexedTins;stateFull=!1;stateTriangle;stateBackward;priority;importance;xyBounds;mercBounds;constructor(){}setCompiled(t){if(Bt(t)){this.applyModernState(Ot(t));return}this.applyLegacyState(Pt(t))}applyModernState(t){this.points=t.points,this.pointsWeightBuffer=t.pointsWeightBuffer,this.strict_status=t.strictStatus,this.vertices_params=t.verticesParams,this.centroid=t.centroid,this.edges=t.edges,this.edgeNodes=t.edgeNodes||[],this.tins=t.tins,this.addIndexedTin(),this.kinks=t.kinks,this.yaxisMode=t.yaxisMode??C.YAXIS_INVERT,this.vertexMode=t.vertexMode??C.VERTEX_PLAIN,this.strictMode=t.strictMode??C.MODE_AUTO,t.bounds?(this.bounds=t.bounds,this.boundsPolygon=t.boundsPolygon,this.xy=t.xy,this.wh=t.wh):(this.bounds=void 0,this.boundsPolygon=void 0,this.xy=t.xy??[0,0],t.wh&&(this.wh=t.wh))}applyLegacyState(t){this.tins=t.tins,this.addIndexedTin(),this.strict_status=t.strictStatus,this.pointsWeightBuffer=t.pointsWeightBuffer,this.vertices_params=t.verticesParams,this.centroid=t.centroid,this.kinks=t.kinks,this.points=t.points}addIndexedTin(){const t=this.tins,r=t.forw,n=t.bakw,s=Math.ceil(Math.sqrt(r.features.length));if(s<3){this.indexedTins=void 0;return}let i=[],o=[];const u=r.features.map(m=>{let h=[];return rt(m)[0].map(c=>{i.length===0?i=[Array.from(c),Array.from(c)]:(c[0]<i[0][0]&&(i[0][0]=c[0]),c[0]>i[1][0]&&(i[1][0]=c[0]),c[1]<i[0][1]&&(i[0][1]=c[1]),c[1]>i[1][1]&&(i[1][1]=c[1])),h.length===0?h=[Array.from(c),Array.from(c)]:(c[0]<h[0][0]&&(h[0][0]=c[0]),c[0]>h[1][0]&&(h[1][0]=c[0]),c[1]<h[0][1]&&(h[0][1]=c[1]),c[1]>h[1][1]&&(h[1][1]=c[1]))}),h}),l=(i[1][0]-i[0][0])/s,f=(i[1][1]-i[0][1])/s,y=u.reduce((m,h,c)=>{const p=X(h[0][0],i[0][0],l,s),x=X(h[1][0],i[0][0],l,s),M=X(h[0][1],i[0][1],f,s),T=X(h[1][1],i[0][1],f,s);for(let w=p;w<=x;w++){m[w]||(m[w]=[]);for(let _=M;_<=T;_++)m[w][_]||(m[w][_]=[]),m[w][_].push(c)}return m},[]),a=n.features.map(m=>{let h=[];return rt(m)[0].map(c=>{o.length===0?o=[Array.from(c),Array.from(c)]:(c[0]<o[0][0]&&(o[0][0]=c[0]),c[0]>o[1][0]&&(o[1][0]=c[0]),c[1]<o[0][1]&&(o[0][1]=c[1]),c[1]>o[1][1]&&(o[1][1]=c[1])),h.length===0?h=[Array.from(c),Array.from(c)]:(c[0]<h[0][0]&&(h[0][0]=c[0]),c[0]>h[1][0]&&(h[1][0]=c[0]),c[1]<h[0][1]&&(h[0][1]=c[1]),c[1]>h[1][1]&&(h[1][1]=c[1]))}),h}),d=(o[1][0]-o[0][0])/s,g=(o[1][1]-o[0][1])/s,b=a.reduce((m,h,c)=>{const p=X(h[0][0],o[0][0],d,s),x=X(h[1][0],o[0][0],d,s),M=X(h[0][1],o[0][1],g,s),T=X(h[1][1],o[0][1],g,s);for(let w=p;w<=x;w++){m[w]||(m[w]=[]);for(let _=M;_<=T;_++)m[w][_]||(m[w][_]=[]),m[w][_].push(c)}return m},[]);this.indexedTins={forw:{gridNum:s,xOrigin:i[0][0],yOrigin:i[0][1],xUnit:l,yUnit:f,gridCache:y},bakw:{gridNum:s,xOrigin:o[0][0],yOrigin:o[0][1],xUnit:d,yUnit:g,gridCache:b}}}transform(t,r,n){if(!this.tins)throw new Error("setCompiled() must be called before transform()");if(r&&this.strict_status==C.STATUS_ERROR)throw new Error('Backward transform is not allowed if strict_status == "strict_error"');this.yaxisMode==C.YAXIS_FOLLOW&&r&&(t=[t[0],-1*t[1]]);const s=W(t);if(this.bounds&&!r&&!n&&!F(s,this.boundsPolygon))return!1;const i=r?this.tins.bakw:this.tins.forw,o=r?this.indexedTins.bakw:this.indexedTins.forw,u=r?this.vertices_params.bakw:this.vertices_params.forw,l=r?this.centroid.bakw:this.centroid.forw,f=r?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let y,a;this.stateFull&&(this.stateBackward==r?y=this.stateTriangle:(this.stateBackward=r,this.stateTriangle=void 0),a=g=>{this.stateTriangle=g});let d=at(s,i,o,u,l,f,y,a);if(this.bounds&&r&&!n){const g=W(d);if(!F(g,this.boundsPolygon))return!1}else this.yaxisMode==C.YAXIS_FOLLOW&&!r&&(d=[d[0],-1*d[1]]);return d}}const I=20037508342789244e-9,dt=[[0,0],[0,1],[1,0],[0,-1],[-1,0]];function J(e,t){return Math.floor(Math.min(e[0],e[1])/4)*I/128/Math.pow(2,t)}function lt(e,t){const r=[];for(let n=0;n<e.length;n++){const s=e[n],i=s[0]*Math.cos(t)-s[1]*Math.sin(t),o=s[0]*Math.sin(t)+s[1]*Math.cos(t);r.push([i,o])}return r}function K(e,t,r,n){const s=J(n,t);return lt(dt,r).map(u=>[u[0]*s+e[0],u[1]*s+e[1]])}function Q(e,t){const r=e[0],s=e.slice(1,5).map(g=>[g[0]-r[0],g[1]-r[1]]),i=[[0,1],[1,0],[0,-1],[-1,0]];let o=0,u=0,l=0;for(let g=0;g<4;g++){const b=s[g],m=i[g],h=Math.sqrt(Math.pow(b[0],2)+Math.pow(b[1],2));o+=h;const c=b[0]*m[1]-b[1]*m[0],p=Math.acos((b[0]*m[0]+b[1]*m[1])/h),x=c>0?-1*p:p;u+=Math.cos(x),l+=Math.sin(x)}const f=o/4,y=Math.atan2(l,u),a=Math.floor(Math.min(t[0],t[1])/4),d=Math.log(a*I/128/f)/Math.log(2);return{center:r,zoom:d,rotation:y}}function z(e,t){const r=e[0]*(2*I)/t-I,n=-1*(e[1]*(2*I)/t-I);return[r,n]}function H(e,t){const r=(e[0]+I)*t/(2*I),n=(-e[1]+I)*t/(2*I);return[r,n]}const tt=256;class Dt{mainTin=null;subTins=[];_maxxy=0;setMapData(t){const r=new C;if(r.setCompiled(t.compiled),this.mainTin=r,t.maxZoom!==void 0)this._maxxy=Math.pow(2,t.maxZoom)*tt;else if(t.compiled.wh){const n=Math.max(t.compiled.wh[0],t.compiled.wh[1]),s=Math.ceil(Math.log2(n/tt));this._maxxy=Math.pow(2,s)*tt}if(this.subTins=[],t.sub_maps)for(const n of t.sub_maps){const s=new C;s.setCompiled(n.compiled);const i=n.bounds??n.compiled.bounds;if(!i)throw new Error("SubMapData must have bounds or compiled.bounds to create xyBounds polygon");const o=[...i,i[0]],u=o.map(l=>{const f=s.transform(l,!1);if(!f)throw new Error("Failed to transform sub-map bounds to mercator");return f});this.subTins.push({tin:s,priority:n.priority,importance:n.importance,xyBounds:$([o]),mercBounds:$([u])})}}xy2Merc(t){const r=this.xy2MercWithLayer(t);return r?r[1]:!1}merc2Xy(t){const r=this.merc2XyWithLayer(t),n=r[0]||r[1];return n?n[1]:!1}xy2MercWithLayer(t){this._assertMapData();const r=this._getTinsSortedByPriority();for(let n=0;n<r.length;n++){const{index:s,isMain:i}=r[n];if(i||F(W(t),this.subTins[s-1].xyBounds)){const o=this._transformByIndex(t,s,!1);if(o===!1)continue;return[s,o]}}return!1}merc2XyWithLayer(t){return this._assertMapData(),this._getAllTinsWithIndex().map(({index:o,tin:u,isMain:l})=>{const f=this._transformByIndex(t,o,!0);return f===!1?[u,o]:l||F(W(f),this.subTins[o-1].xyBounds)?[u,o,f]:[u,o]}).sort((o,u)=>{const l=o[0].priority??0,f=u[0].priority??0;return l<f?1:-1}).reduce((o,u,l,f)=>{const y=u[0],a=u[1],d=u[2];if(!d)return o;for(let g=0;g<l;g++){const b=f[g][1],m=b===0;if(f[g][2]&&(m||F(W(d),this.subTins[b-1].xyBounds)))if(o.length){const h=!o[0],c=h?o[1][2]:o[0][2],p=y.importance??0,x=c.importance??0;return h?p<x?o:[void 0,[a,d,y]]:[...o.filter(w=>w!==void 0),[a,d,y]].sort((w,_)=>(w[2].importance??0)<(_[2].importance??0)?1:-1).slice(0,2)}else return[[a,d,y]]}return!o.length||!o[0]?[[a,d,y]]:(o.push([a,d,y]),o.sort((g,b)=>{const m=g[2].importance??0,h=b[2].importance??0;return m<h?1:-1}).filter((g,b)=>b<2))},[]).map(o=>{if(o)return[o[0],o[1]]})}mercs2SysCoords(t){this._assertMapData();const r=this.merc2XyWithLayer(t[0]);let n=!1;return r.map((s,i)=>{if(!s){n=!0;return}const o=s[0],u=s[1];return i!==0&&!n?[this.xy2SysCoordInternal(u)]:t.map((f,y)=>y===0?u:this._transformByIndex(f,o,!0)).map(f=>this.xy2SysCoordInternal(f))})}viewpoint2Mercs(t,r){this._assertMapData(),this._assertMaxxy();const s=K(t.center,t.zoom,t.rotation,r).map(f=>H(f,this._maxxy)),i=this.xy2MercWithLayer(s[0]);if(!i)throw new Error("viewpoint2Mercs: center point is out of bounds");const o=i[0],u=i[1];return s.map((f,y)=>{if(y===0)return u;const a=this._transformByIndex(f,o,!1);if(a===!1)throw new Error(`viewpoint2Mercs: point ${y} is out of bounds`);return a})}mercs2Viewpoint(t,r){this._assertMapData(),this._assertMaxxy();const n=this.merc2XyWithLayer(t[0]),s=n[0]||n[1];if(!s)throw new Error("mercs2Viewpoint: center point is out of bounds");const i=s[0],o=s[1],l=t.map((f,y)=>{if(y===0)return o;const a=this._transformByIndex(f,i,!0);if(a===!1)throw new Error(`mercs2Viewpoint: point ${y} is out of bounds`);return a}).map(f=>z(f,this._maxxy));return Q(l,r)}static zoom2Radius(t,r){return J(t,r)}static mercViewpoint2Mercs(t,r,n,s){return K(t,r,n,s)}static mercs2MercViewpoint(t,r){return Q(t,r)}static xy2SysCoord(t,r){return z(t,r)}static sysCoord2Xy(t,r){return H(t,r)}_assertMapData(){if(!this.mainTin)throw new Error("setMapData() must be called before transformation")}_assertMaxxy(){if(this._maxxy===0)throw new Error("MapData.maxZoom or compiled.wh must be set for viewpoint conversion (xy2SysCoord / sysCoord2Xy)")}getLayerTransform(t){if(t===0)return this.mainTin;const r=this.subTins[t-1];return r?r.tin:null}get layerCount(){return 1+this.subTins.length}get maxxy(){return this._maxxy}_getTinsSortedByPriority(){return this._getAllTinsWithIndex().sort((r,n)=>{const s=r.tin.priority??0,i=n.tin.priority??0;return s<i?1:-1})}_getAllTinsWithIndex(){const t=[{index:0,tin:this.mainTin,isMain:!0}];return this.subTins.forEach((r,n)=>{r.tin.priority=r.priority,r.tin.importance=r.importance,t.push({index:n+1,tin:r.tin,isMain:!1})}),t}_transformByIndex(t,r,n){if(r===0)return this.mainTin.transform(t,n);const s=this.subTins[r-1];return s?s.tin.transform(t,n,!0):!1}xy2SysCoordInternal(t){return z(t,this._maxxy)}}v.MERC_CROSSMATRIX=dt,v.MERC_MAX=I,v.MapTransform=Dt,v.Transform=C,v.counterTri=Ct,v.format_version=Ft,v.mercViewpoint2Mercs=K,v.mercs2MercViewpoint=Q,v.normalizeEdges=ft,v.rotateMatrix=lt,v.rotateVerticesTriangle=St,v.sysCoord2Xy=H,v.transformArr=at,v.xy2SysCoord=z,v.zoom2Radius=J,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.5.
|
|
7
|
+
"version": "0.5.2",
|
|
8
8
|
"description": "A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"engines": {
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@eslint/js": "^9.39.2",
|
|
49
|
-
"@maplat/tin": "
|
|
49
|
+
"@maplat/tin": "0.14.0",
|
|
50
50
|
"@types/geojson": "^7946.0.16",
|
|
51
|
-
"@types/node": "^
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
53
|
-
"@typescript-eslint/parser": "^8.
|
|
51
|
+
"@types/node": "^25.5.1",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^8.58.0",
|
|
53
|
+
"@typescript-eslint/parser": "^8.58.0",
|
|
54
54
|
"@vitest/coverage-v8": "^3.2.4",
|
|
55
55
|
"cross-env": "^10.1.0",
|
|
56
56
|
"eslint": "^9.39.2",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"jsdom": "^27.4.0",
|
|
60
60
|
"prettier": "^3.7.4",
|
|
61
61
|
"typescript": "^5.9.3",
|
|
62
|
-
"vite": "^
|
|
62
|
+
"vite": "^7.3.0",
|
|
63
63
|
"vite-plugin-dts": "^4.5.4",
|
|
64
64
|
"vitest": "^3.2.4"
|
|
65
65
|
},
|