@duoquote/polytini 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +120 -3
- package/dist/deckgl.cjs +250 -0
- package/dist/flexible.cjs +229 -0
- package/dist/google.cjs +232 -0
- package/dist/leaflet-auto.cjs +209 -0
- package/dist/leaflet.cjs +231 -0
- package/dist/mapbox.cjs +185 -0
- package/dist/maplibre.cjs +185 -0
- package/dist/node.cjs +322 -0
- package/dist/presets.cjs +65 -0
- package/dist/turf.cjs +267 -0
- package/dist/types/cli.d.cts +2 -0
- package/dist/types/deckgl.d.cts +60 -0
- package/dist/types/flexible.d.cts +80 -0
- package/dist/types/google.d.cts +48 -0
- package/dist/types/google.jsr.d.cts +60 -0
- package/dist/types/index.d.cts +87 -0
- package/dist/types/leaflet-auto.d.cts +4 -0
- package/dist/types/leaflet-auto.jsr.d.cts +2 -0
- package/dist/types/leaflet.d.cts +39 -0
- package/dist/types/leaflet.jsr.d.cts +13 -0
- package/dist/types/mapbox.d.cts +50 -0
- package/dist/types/maplibre.d.cts +54 -0
- package/dist/types/openlayers.d.cts +23 -0
- package/dist/types/presets.d.cts +66 -0
- package/dist/types/turf.d.cts +33 -0
- package/dist/types/wasm.d.cts +33 -0
- package/dist/web.cjs +231 -0
- package/package.json +200 -6
- package/src/browser.js +15 -0
- package/src/bun.js +4 -0
- package/src/cli-lib.js +160 -0
- package/src/cli.js +7 -0
- package/src/core.js +268 -0
- package/src/deckgl.js +176 -0
- package/src/deno.js +12 -0
- package/src/error.js +15 -0
- package/src/fast.js +179 -0
- package/src/flexible.js +283 -0
- package/src/google.js +70 -0
- package/src/leaflet-auto.js +11 -0
- package/src/leaflet.js +44 -0
- package/src/mapbox.js +10 -0
- package/src/maplibre.js +57 -0
- package/src/node.js +17 -0
- package/src/openlayers.js +172 -0
- package/src/presets.js +242 -0
- package/src/text.js +111 -0
- package/src/turf.js +80 -0
- package/src/wasm-bytes.js +2 -0
- package/src/wasm.js +235 -0
- package/src/web.js +9 -0
- package/types/cli.d.ts +2 -0
- package/types/deckgl.d.ts +60 -0
- package/types/flexible.d.ts +80 -0
- package/types/google.d.ts +48 -0
- package/types/google.jsr.d.ts +60 -0
- package/types/index.d.ts +87 -0
- package/types/leaflet-auto.d.ts +4 -0
- package/types/leaflet-auto.jsr.d.ts +2 -0
- package/types/leaflet.d.ts +39 -0
- package/types/leaflet.jsr.d.ts +13 -0
- package/types/mapbox.d.ts +50 -0
- package/types/maplibre.d.ts +54 -0
- package/types/openlayers.d.ts +23 -0
- package/types/presets.d.ts +66 -0
- package/types/turf.d.ts +33 -0
- package/types/wasm.d.ts +33 -0
- package/wasm/polytini.wasm +0 -0
package/dist/presets.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/presets.js
|
|
20
|
+
var presets_exports = {};
|
|
21
|
+
__export(presets_exports, {
|
|
22
|
+
google: () => google,
|
|
23
|
+
graphhopper: () => graphhopper,
|
|
24
|
+
graphhopper3d: () => graphhopper3d,
|
|
25
|
+
mapbox: () => mapbox,
|
|
26
|
+
mapbox6: () => mapbox6,
|
|
27
|
+
openrouteservice: () => openrouteservice,
|
|
28
|
+
openrouteservice3d: () => openrouteservice3d,
|
|
29
|
+
osrm: () => osrm,
|
|
30
|
+
osrm6: () => osrm6,
|
|
31
|
+
otp: () => otp,
|
|
32
|
+
presets: () => presets,
|
|
33
|
+
stadia: () => stadia,
|
|
34
|
+
strava: () => strava,
|
|
35
|
+
valhalla: () => valhalla
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(presets_exports);
|
|
38
|
+
var google = { precision: 5, order: "latlng" };
|
|
39
|
+
var osrm = { precision: 5, order: "lnglat" };
|
|
40
|
+
var osrm6 = { precision: 6, order: "lnglat" };
|
|
41
|
+
var valhalla = { precision: 6, order: "lnglat" };
|
|
42
|
+
var stadia = { precision: 6, order: "lnglat" };
|
|
43
|
+
var graphhopper = { precision: 5, order: "lnglat" };
|
|
44
|
+
var graphhopper3d = { precision: 5, dimensions: 3, zFactor: 100, order: "lnglat" };
|
|
45
|
+
var openrouteservice = { precision: 5, order: "lnglat" };
|
|
46
|
+
var openrouteservice3d = { precision: 5, dimensions: 3, zFactor: 100, order: "lnglat" };
|
|
47
|
+
var mapbox = { precision: 5, order: "lnglat" };
|
|
48
|
+
var mapbox6 = { precision: 6, order: "lnglat" };
|
|
49
|
+
var strava = { precision: 5, order: "latlng" };
|
|
50
|
+
var otp = { precision: 5, order: "latlng" };
|
|
51
|
+
var presets = {
|
|
52
|
+
google,
|
|
53
|
+
osrm,
|
|
54
|
+
osrm6,
|
|
55
|
+
valhalla,
|
|
56
|
+
stadia,
|
|
57
|
+
graphhopper,
|
|
58
|
+
graphhopper3d,
|
|
59
|
+
openrouteservice,
|
|
60
|
+
openrouteservice3d,
|
|
61
|
+
mapbox,
|
|
62
|
+
mapbox6,
|
|
63
|
+
strava,
|
|
64
|
+
otp
|
|
65
|
+
};
|
package/dist/turf.cjs
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/turf.js
|
|
20
|
+
var turf_exports = {};
|
|
21
|
+
__export(turf_exports, {
|
|
22
|
+
fromGeoJSON: () => fromGeoJSON,
|
|
23
|
+
toFeature: () => toFeature,
|
|
24
|
+
toFeatureCollection: () => toFeatureCollection,
|
|
25
|
+
toPolygonFeature: () => toPolygonFeature
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(turf_exports);
|
|
28
|
+
|
|
29
|
+
// src/error.js
|
|
30
|
+
var PolylineError = class extends Error {
|
|
31
|
+
constructor(code, message, index) {
|
|
32
|
+
super(index == null ? message : message + " at " + index);
|
|
33
|
+
this.name = "PolylineError";
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.index = index;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var fail = (code, message, index) => {
|
|
39
|
+
throw new PolylineError(code, message, index);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/core.js
|
|
43
|
+
var st = { swap: false, strict: true, dims: 2, zf: 1e5 };
|
|
44
|
+
function opts(o) {
|
|
45
|
+
st.swap = false;
|
|
46
|
+
st.strict = true;
|
|
47
|
+
st.dims = 2;
|
|
48
|
+
return o && typeof o == "object" ? objOpts(o) : st.zf = o == null ? 1e5 : pow(o);
|
|
49
|
+
}
|
|
50
|
+
function objOpts(o) {
|
|
51
|
+
const { order, dimensions: d } = o;
|
|
52
|
+
if (order == "lnglat") st.swap = true;
|
|
53
|
+
else if (order != null && order != "latlng") bad("order");
|
|
54
|
+
if (o.strict === false) st.strict = false;
|
|
55
|
+
if (d != null) st.dims = d >= 1 && d <= 16 && d % 1 == 0 ? d : bad("dimensions");
|
|
56
|
+
const f = o.factor != null ? num(o.factor) : pow(o.precision ?? 5);
|
|
57
|
+
st.zf = o.zFactor != null ? num(o.zFactor) : f;
|
|
58
|
+
return f;
|
|
59
|
+
}
|
|
60
|
+
var bad = (name) => fail("option", "Invalid " + name);
|
|
61
|
+
var num = (f) => f > 0 && f < 1 / 0 ? f : bad("factor");
|
|
62
|
+
var pow = (p) => typeof p == "number" && p >= 0 && p <= 15 && p % 1 == 0 ? 10 ** p : bad("precision");
|
|
63
|
+
var LIMIT = 2 ** 29;
|
|
64
|
+
function slowDecode(str, f, flat) {
|
|
65
|
+
if (typeof str != "string") fail("input", "Expected a string");
|
|
66
|
+
const { dims: d, strict, zf } = st, sw = st.swap && d > 1, values = [];
|
|
67
|
+
let v = 0, scale = 1, i = 0, c;
|
|
68
|
+
for (; i < str.length; i++) {
|
|
69
|
+
c = str.charCodeAt(i) - 63;
|
|
70
|
+
if (c < 0 || c > 63) {
|
|
71
|
+
if (strict) fail("char", "Invalid character", i);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
v += (c & 31) * scale;
|
|
75
|
+
scale *= 32;
|
|
76
|
+
if (v > 2 ** 53 && strict) fail("overflow", "Value too large", i);
|
|
77
|
+
if (c < 32) {
|
|
78
|
+
values.push(v % 2 ? -(v + 1) / 2 : v / 2);
|
|
79
|
+
v = 0;
|
|
80
|
+
scale = 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (strict && (scale > 1 || values.length % d)) fail("truncated", "Truncated", i);
|
|
84
|
+
const n = values.length / d | 0, sum = Array(d).fill(0), out = flat ? new Float64Array(n * d) : Array(n);
|
|
85
|
+
for (let j = 0, k = 0; j < n; j++) {
|
|
86
|
+
const p = flat ? out : Array(d);
|
|
87
|
+
for (let a = 0; a < d; a++, k++) {
|
|
88
|
+
sum[a] += values[k];
|
|
89
|
+
p[(flat ? k - a : 0) + (sw && a < 2 ? 1 - a : a)] = sum[a] / (a < 2 ? f : zf);
|
|
90
|
+
}
|
|
91
|
+
if (!flat) out[j] = p;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
function slowEncode(points, f, flat) {
|
|
96
|
+
if (points == null || !(points.length >= 0)) fail("input", "Expected an array");
|
|
97
|
+
const { dims: d, strict, zf } = st, sw = st.swap && d > 1, last = Array(d).fill(0), n = flat ? points.length / d : points.length;
|
|
98
|
+
if (n % 1 && strict) fail("input", "Length not a multiple of " + d);
|
|
99
|
+
let s = "";
|
|
100
|
+
for (let i = 0; i < (n | 0); i++) {
|
|
101
|
+
const p = flat ? 0 : points[i];
|
|
102
|
+
for (let a = 0; a < d; a++) {
|
|
103
|
+
const b = sw && a < 2 ? 1 - a : a;
|
|
104
|
+
let x = flat ? points[i * d + b] : p == null ? p : p.length >= 0 ? p[b] : a ? a > 1 ? p.alt ?? p.altitude : p.lng ?? p.lon ?? p.longitude : p.lat ?? p.latitude;
|
|
105
|
+
x = x == null ? NaN : +x * (a < 2 ? f : zf);
|
|
106
|
+
if (!(x - x == 0)) {
|
|
107
|
+
if (strict) fail("coordinate", "Invalid coordinate", i);
|
|
108
|
+
x = 0;
|
|
109
|
+
}
|
|
110
|
+
x = Math.sign(x) * Math.round(Math.abs(x));
|
|
111
|
+
let z = x - last[a];
|
|
112
|
+
last[a] = x;
|
|
113
|
+
z = z < 0 ? -z * 2 - 1 : z * 2;
|
|
114
|
+
if (z > 2 ** 53 && strict) fail("overflow", "Value too large", i);
|
|
115
|
+
for (; z >= 32; z = Math.floor(z / 32)) s += String.fromCharCode(z % 32 + 95);
|
|
116
|
+
s += String.fromCharCode(z + 63);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return s;
|
|
120
|
+
}
|
|
121
|
+
var decodeWith = (str, o, flat) => {
|
|
122
|
+
const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
|
|
123
|
+
return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
|
|
124
|
+
};
|
|
125
|
+
var flip = (out) => {
|
|
126
|
+
for (const p of out) {
|
|
127
|
+
const t = p[0];
|
|
128
|
+
p[0] = p[1];
|
|
129
|
+
p[1] = t;
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
};
|
|
133
|
+
var decode = (str, o) => decodeWith(str, o, 0);
|
|
134
|
+
function decodeLoop(str, f, sw, flat) {
|
|
135
|
+
const len = str.length, a = +sw;
|
|
136
|
+
let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
|
|
137
|
+
if (flat) {
|
|
138
|
+
for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
|
|
139
|
+
out = new Float64Array(n & ~1);
|
|
140
|
+
i = n = 0;
|
|
141
|
+
} else out = len < 64 ? [] : Array(len >> 1);
|
|
142
|
+
while (i < len) {
|
|
143
|
+
c = str.charCodeAt(i++) - 63;
|
|
144
|
+
bad2 |= c;
|
|
145
|
+
v = c & 31;
|
|
146
|
+
for (s = 5; c >= 32; s += 5) {
|
|
147
|
+
c = str.charCodeAt(i++) - 63;
|
|
148
|
+
bad2 |= c | 25 - s;
|
|
149
|
+
v |= (c & 31) << s;
|
|
150
|
+
}
|
|
151
|
+
lat += v >>> 1 ^ -(v & 1);
|
|
152
|
+
c = str.charCodeAt(i++) - 63;
|
|
153
|
+
bad2 |= c;
|
|
154
|
+
v = c & 31;
|
|
155
|
+
for (s = 5; c >= 32; s += 5) {
|
|
156
|
+
c = str.charCodeAt(i++) - 63;
|
|
157
|
+
bad2 |= c | 25 - s;
|
|
158
|
+
v |= (c & 31) << s;
|
|
159
|
+
}
|
|
160
|
+
lng += v >>> 1 ^ -(v & 1);
|
|
161
|
+
if (flat) {
|
|
162
|
+
out[n + a] = lat / f;
|
|
163
|
+
out[n + 1 - a] = lng / f;
|
|
164
|
+
n += 2;
|
|
165
|
+
} else out[n++] = [lat / f, lng / f];
|
|
166
|
+
}
|
|
167
|
+
if (bad2 & ~63 || i != len) return null;
|
|
168
|
+
if (out.length != n) out.length = n;
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
var CHARS = /* @__PURE__ */ Array.from({ length: 1024 }, (_, z) => chars(z));
|
|
172
|
+
function chars(z) {
|
|
173
|
+
let s = "";
|
|
174
|
+
for (; z >= 32; z >>>= 5) s += String.fromCharCode((z & 31) + 95);
|
|
175
|
+
return s + String.fromCharCode(z + 63);
|
|
176
|
+
}
|
|
177
|
+
var encodeWith = (src, o, flat) => {
|
|
178
|
+
const f = opts(o);
|
|
179
|
+
return (st.dims == 2 && f <= 1e6 && (flat ? src != null && !(src.length % 2) : Array.isArray(src)) ? encodeLoop(src, f, +st.swap, flat) : null) ?? slowEncode(src, f, flat);
|
|
180
|
+
};
|
|
181
|
+
var encode = (points, o) => encodeWith(points, o, 0);
|
|
182
|
+
function encodeLoop(src, f, a, flat) {
|
|
183
|
+
const n = flat ? src.length >> 1 : src.length;
|
|
184
|
+
let s = "", i = 0, la = 0, lb = 0, x, y, p, q, z, pt;
|
|
185
|
+
try {
|
|
186
|
+
for (; i < n; i++) {
|
|
187
|
+
if (flat) {
|
|
188
|
+
x = src[i * 2 + a];
|
|
189
|
+
y = src[i * 2 + 1 - a];
|
|
190
|
+
} else {
|
|
191
|
+
pt = src[i];
|
|
192
|
+
x = pt[a];
|
|
193
|
+
y = pt[1 - a];
|
|
194
|
+
}
|
|
195
|
+
if (typeof x != "number" || typeof y != "number" || !((x *= f) < LIMIT && x > -LIMIT && (y *= f) < LIMIT && y > -LIMIT)) return null;
|
|
196
|
+
p = x < 0 ? -(0.5 - x | 0) : x + 0.5 | 0;
|
|
197
|
+
q = y < 0 ? -(0.5 - y | 0) : y + 0.5 | 0;
|
|
198
|
+
if (x < 0.5 && x > -0.5) p = 0;
|
|
199
|
+
if (y < 0.5 && y > -0.5) q = 0;
|
|
200
|
+
z = p - la;
|
|
201
|
+
z = z << 1 ^ z >> 31;
|
|
202
|
+
s += z < 1024 ? CHARS[z] : chars(z);
|
|
203
|
+
z = q - lb;
|
|
204
|
+
z = z << 1 ^ z >> 31;
|
|
205
|
+
s += z < 1024 ? CHARS[z] : chars(z);
|
|
206
|
+
la = p;
|
|
207
|
+
lb = q;
|
|
208
|
+
}
|
|
209
|
+
} catch {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return s;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/turf.js
|
|
216
|
+
var lngLat = (o) => ({ ...typeof o == "number" ? { precision: o } : o, order: "lnglat" });
|
|
217
|
+
function bbox(c) {
|
|
218
|
+
const b = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
|
|
219
|
+
const walk = (a) => {
|
|
220
|
+
if (typeof a[0] == "number") {
|
|
221
|
+
b[0] = Math.min(b[0], a[0]);
|
|
222
|
+
b[1] = Math.min(b[1], a[1]);
|
|
223
|
+
b[2] = Math.max(b[2], a[0]);
|
|
224
|
+
b[3] = Math.max(b[3], a[1]);
|
|
225
|
+
} else a.forEach(walk);
|
|
226
|
+
};
|
|
227
|
+
walk(c);
|
|
228
|
+
return b;
|
|
229
|
+
}
|
|
230
|
+
function feature(geometry, o, i) {
|
|
231
|
+
const f = { type: "Feature" }, p = o?.properties;
|
|
232
|
+
if (o?.id != null) f.id = Array.isArray(o.id) ? o.id[i] : o.id;
|
|
233
|
+
if (o?.bbox && geometry.coordinates.length) f.bbox = bbox(geometry.coordinates);
|
|
234
|
+
f.properties = (Array.isArray(p) ? p[i] : p) ?? {};
|
|
235
|
+
f.geometry = geometry;
|
|
236
|
+
return f;
|
|
237
|
+
}
|
|
238
|
+
var toFeature = (str, o, i) => feature({ type: "LineString", coordinates: decode(str, lngLat(o)) }, o, i);
|
|
239
|
+
var toFeatureCollection = (strs, o) => ({ type: "FeatureCollection", features: strs.map((s, i) => toFeature(s, o, i)) });
|
|
240
|
+
var toPolygonFeature = (rings, o) => feature({ type: "Polygon", coordinates: rings.map((s) => decode(s, lngLat(o))) }, o, 0);
|
|
241
|
+
function fromGeoJSON(g, o) {
|
|
242
|
+
const out = [], ll = lngLat(o);
|
|
243
|
+
const walk = (g2) => {
|
|
244
|
+
switch (g2?.type) {
|
|
245
|
+
case "Feature":
|
|
246
|
+
return g2.geometry && walk(g2.geometry);
|
|
247
|
+
case "FeatureCollection":
|
|
248
|
+
return g2.features.forEach(walk);
|
|
249
|
+
case "GeometryCollection":
|
|
250
|
+
return g2.geometries.forEach(walk);
|
|
251
|
+
case "LineString":
|
|
252
|
+
return out.push(encode(g2.coordinates, ll));
|
|
253
|
+
case "MultiLineString":
|
|
254
|
+
case "Polygon":
|
|
255
|
+
return g2.coordinates.forEach((c) => out.push(encode(c, ll)));
|
|
256
|
+
case "MultiPolygon":
|
|
257
|
+
return g2.coordinates.forEach((p) => p.forEach((c) => out.push(encode(c, ll))));
|
|
258
|
+
case "Point":
|
|
259
|
+
case "MultiPoint":
|
|
260
|
+
return;
|
|
261
|
+
default:
|
|
262
|
+
fail("input", "Expected GeoJSON");
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
walk(g);
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Types for @duoquote/polytini/deckgl. The results are plain objects in
|
|
2
|
+
// deck.gl's binary data shape, so they need no deck.gl types: they can be
|
|
3
|
+
// passed as `data` to PathLayer, TripsLayer and SolidPolygonLayer.
|
|
4
|
+
import type { Options } from './index.d.ts';
|
|
5
|
+
|
|
6
|
+
export interface BinaryOptions extends Options {
|
|
7
|
+
/** Float32Array instead of Float64Array. Smaller, and enough for most maps; deck.gl uses 64-bit positions only when given them. Default false. */
|
|
8
|
+
float32?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PathOptions extends BinaryOptions {
|
|
12
|
+
/**
|
|
13
|
+
* For TripsLayer: the last value of each point (with dimensions 3 or 4) goes
|
|
14
|
+
* to attributes.getTimestamps instead of the positions. The values are
|
|
15
|
+
* divided by zFactor, like any value after the second, and always come out
|
|
16
|
+
* as a Float32Array, because TripsLayer's timestamp attribute is 32-bit
|
|
17
|
+
* (deck.gl 9.4 drew nothing given Float64Array timestamps). Default false.
|
|
18
|
+
*/
|
|
19
|
+
timestamps?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A deck.gl binary attribute. */
|
|
23
|
+
export interface BinaryAttribute<T extends Float32Array | Float64Array = Float32Array | Float64Array, S extends number = number> {
|
|
24
|
+
value: T;
|
|
25
|
+
size: S;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface BinaryPaths<T extends Float32Array | Float64Array = Float32Array | Float64Array> {
|
|
29
|
+
/** The number of paths, one per string. */
|
|
30
|
+
length: number;
|
|
31
|
+
/** The first vertex of each path, plus the vertex count at the end (length + 1 entries). */
|
|
32
|
+
startIndices: Uint32Array;
|
|
33
|
+
attributes: {
|
|
34
|
+
/** [lng, lat] (size 2) or [lng, lat, z] (size 3) per vertex. */
|
|
35
|
+
getPath: BinaryAttribute<T, 2 | 3>;
|
|
36
|
+
/** One value per vertex, with the timestamps option. Always 32-bit. */
|
|
37
|
+
getTimestamps?: BinaryAttribute<Float32Array, 1>;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface BinaryPolygons<T extends Float32Array | Float64Array = Float32Array | Float64Array> {
|
|
42
|
+
/** The number of polygons, one ring per string. */
|
|
43
|
+
length: number;
|
|
44
|
+
/** The first vertex of each ring, plus the vertex count at the end (length + 1 entries). */
|
|
45
|
+
startIndices: Uint32Array;
|
|
46
|
+
attributes: {
|
|
47
|
+
/** [lng, lat] (size 2) or [lng, lat, z] (size 3) per vertex, every ring closed. */
|
|
48
|
+
getPolygon: BinaryAttribute<T, 2 | 3>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Binary data for PathLayer and TripsLayer, one path per string. Pass _pathType: 'open' to skip deck.gl's normalization. */
|
|
53
|
+
export function binaryPaths(encoded: string | string[], options: PathOptions & { float32: true }): BinaryPaths<Float32Array>;
|
|
54
|
+
export function binaryPaths(encoded: string | string[], options?: number | (PathOptions & { float32?: false })): BinaryPaths<Float64Array>;
|
|
55
|
+
export function binaryPaths(encoded: string | string[], options?: number | PathOptions): BinaryPaths;
|
|
56
|
+
|
|
57
|
+
/** Binary data for SolidPolygonLayer, one closed ring per string (no holes). */
|
|
58
|
+
export function binaryPolygons(encoded: string | string[], options: BinaryOptions & { float32: true }): BinaryPolygons<Float32Array>;
|
|
59
|
+
export function binaryPolygons(encoded: string | string[], options?: number | (BinaryOptions & { float32?: false })): BinaryPolygons<Float64Array>;
|
|
60
|
+
export function binaryPolygons(encoded: string | string[], options?: number | BinaryOptions): BinaryPolygons;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Types for @duoquote/polytini/flexible, HERE's Flexible Polyline format
|
|
2
|
+
// (version 1). Separate from the Google-format entry points.
|
|
3
|
+
import type { ErrorCode } from './index.d.ts';
|
|
4
|
+
|
|
5
|
+
/** Third dimension types, as stored in the header. */
|
|
6
|
+
export const ABSENT: 0;
|
|
7
|
+
export const LEVEL: 1;
|
|
8
|
+
export const ALTITUDE: 2;
|
|
9
|
+
export const ELEVATION: 3;
|
|
10
|
+
/** Reserved by the spec: decode accepts it, encode refuses it. */
|
|
11
|
+
export const RESERVED1: 4;
|
|
12
|
+
/** Reserved by the spec: decode accepts it, encode refuses it. */
|
|
13
|
+
export const RESERVED2: 5;
|
|
14
|
+
export const CUSTOM1: 6;
|
|
15
|
+
export const CUSTOM2: 7;
|
|
16
|
+
|
|
17
|
+
/** Any type a header can hold. */
|
|
18
|
+
export type ThirdDimension = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
19
|
+
/** The types encode accepts. */
|
|
20
|
+
export type EncodableThirdDimension = 0 | 1 | 2 | 3 | 6 | 7;
|
|
21
|
+
|
|
22
|
+
export interface Header {
|
|
23
|
+
/** Decimal places of latitude and longitude, 0 to 15. */
|
|
24
|
+
precision: number;
|
|
25
|
+
/** What the third value means. ABSENT (0) for 2D lines. */
|
|
26
|
+
thirdDim: ThirdDimension;
|
|
27
|
+
/** Decimal places of the third value, 0 to 15. */
|
|
28
|
+
thirdDimPrecision: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DecodedResult extends Header {
|
|
32
|
+
/** [lat, lng] points, or [lat, lng, z] when thirdDim is not ABSENT. */
|
|
33
|
+
polyline: number[][];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface EncodeOptions {
|
|
37
|
+
/** Decimal places of latitude and longitude, an integer from 0 to 15. Default 5. */
|
|
38
|
+
precision?: number;
|
|
39
|
+
/** Type of the third value. Default ABSENT, which ignores any third value. */
|
|
40
|
+
thirdDim?: EncodableThirdDimension;
|
|
41
|
+
/** Decimal places of the third value, an integer from 0 to 15. Default 0. */
|
|
42
|
+
thirdDimPrecision?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** [lat, lng] or [lat, lng, z] points, or one flat array of numbers: [lat0, lng0, lat1, lng1, ...]. */
|
|
46
|
+
export type Points = ArrayLike<ArrayLike<number>> | ArrayLike<number>;
|
|
47
|
+
|
|
48
|
+
/** The argument of @here/flexpolyline's encode. */
|
|
49
|
+
export interface EncodeInput extends EncodeOptions {
|
|
50
|
+
polyline: Points;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Codes of a PolylineError from this entry: the main entry's, plus 'version'
|
|
55
|
+
* for a format version other than 1 or a header with bits set above bit 10.
|
|
56
|
+
*/
|
|
57
|
+
export type FlexibleErrorCode = Exclude<ErrorCode, 'init'> | 'version';
|
|
58
|
+
|
|
59
|
+
/** The same class as the main entry's PolylineError. */
|
|
60
|
+
export class PolylineError extends Error {
|
|
61
|
+
readonly name: 'PolylineError';
|
|
62
|
+
/** What went wrong. */
|
|
63
|
+
readonly code: FlexibleErrorCode;
|
|
64
|
+
/** Character index (decode) or point index (encode), when there is one. */
|
|
65
|
+
readonly index: number | undefined;
|
|
66
|
+
constructor(code: FlexibleErrorCode, message: string, index?: number);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Encodes a line. Takes @here/flexpolyline's argument, or the points with
|
|
71
|
+
* the header fields in `options`, which win over the input object's.
|
|
72
|
+
* Rounds half away from zero.
|
|
73
|
+
*/
|
|
74
|
+
export function encode(input: EncodeInput | Points, options?: EncodeOptions): string;
|
|
75
|
+
|
|
76
|
+
/** Decodes a line, with its header. The same result shape as @here/flexpolyline. */
|
|
77
|
+
export function decode(str: string): DecodedResult;
|
|
78
|
+
|
|
79
|
+
/** Reads only the header. */
|
|
80
|
+
export function header(str: string): Header;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Types for @duoquote/polytini/google, using the google.maps types from
|
|
2
|
+
// @types/google.maps. Those are global declarations, not a module, so they
|
|
3
|
+
// are pulled in with a reference directive: types only, nothing at runtime.
|
|
4
|
+
/// <reference types="google.maps" />
|
|
5
|
+
import type * as P from './index.d.ts';
|
|
6
|
+
import type { Options, Point } from './index.d.ts';
|
|
7
|
+
|
|
8
|
+
export declare const PolylineError: typeof P.PolylineError;
|
|
9
|
+
export type PolylineError = P.PolylineError;
|
|
10
|
+
|
|
11
|
+
/** A LatLng constructor: google.maps.LatLng or anything built the same way. */
|
|
12
|
+
export type LatLngConstructor = new (lat: number, lng: number, noClampNoWrap?: boolean) => google.maps.LatLng;
|
|
13
|
+
|
|
14
|
+
export interface DecodePathOptions extends Omit<Options, 'order'> {
|
|
15
|
+
/**
|
|
16
|
+
* The class to build points with. Default: globalThis.google.maps.LatLng
|
|
17
|
+
* when it exists. false or null returns LatLngLiteral objects.
|
|
18
|
+
*/
|
|
19
|
+
LatLng?: LatLngConstructor | false | null;
|
|
20
|
+
/** Passed to the LatLng constructor. Without it, LatLng clamps latitude and wraps longitude into [-180, 180). */
|
|
21
|
+
noClampNoWrap?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A point encodePath takes: google.maps.LatLng, LatLngLiteral or a [lat, lng] tuple. */
|
|
25
|
+
export type PathPoint = google.maps.LatLng | google.maps.LatLngLiteral | Point;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Decodes an encoded path to LatLngLiteral objects (`LatLng: false`).
|
|
29
|
+
*/
|
|
30
|
+
export function decodePath(encodedPath: string, options: DecodePathOptions & { LatLng: false | null }): google.maps.LatLngLiteral[];
|
|
31
|
+
/**
|
|
32
|
+
* Decodes an encoded path, like google.maps.geometry.encoding.decodePath,
|
|
33
|
+
* to google.maps.LatLng objects. Without a `LatLng` option this uses
|
|
34
|
+
* globalThis.google.maps.LatLng; when the Maps JavaScript API isn't loaded
|
|
35
|
+
* the result is LatLngLiteral objects at runtime, so pass `LatLng: false`
|
|
36
|
+
* there to get that type. Strict by default: a malformed string throws a
|
|
37
|
+
* PolylineError unless `strict: false`.
|
|
38
|
+
*/
|
|
39
|
+
export function decodePath(encodedPath: string, options?: number | (DecodePathOptions & { LatLng?: LatLngConstructor })): google.maps.LatLng[];
|
|
40
|
+
export function decodePath(encodedPath: string, options?: number | DecodePathOptions): google.maps.LatLng[] | google.maps.LatLngLiteral[];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Encodes a path, like google.maps.geometry.encoding.encodePath: an array or
|
|
44
|
+
* MVCArray of google.maps.LatLng, LatLngLiteral or [lat, lng] tuples, mixed
|
|
45
|
+
* or not. Precision 5 by default. `order: 'lnglat'` applies to tuples and
|
|
46
|
+
* LatLng objects; literals are read by name. Strict by default.
|
|
47
|
+
*/
|
|
48
|
+
export function encodePath(path: readonly PathPoint[] | google.maps.MVCArray<PathPoint>, options?: number | Options): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// JSR copy of google.d.ts. JSR's type output can't carry the
|
|
2
|
+
// @types/google.maps reference, so the Maps shapes are described
|
|
3
|
+
// structurally here: anything with lat() and lng() is a LatLng. The npm
|
|
4
|
+
// package's google.d.ts uses the real google.maps types.
|
|
5
|
+
import type * as P from './index.d.ts';
|
|
6
|
+
import type { Options, Point } from './index.d.ts';
|
|
7
|
+
|
|
8
|
+
export interface LatLng {
|
|
9
|
+
lat(): number;
|
|
10
|
+
lng(): number;
|
|
11
|
+
}
|
|
12
|
+
export interface LatLngLiteral {
|
|
13
|
+
lat: number;
|
|
14
|
+
lng: number;
|
|
15
|
+
}
|
|
16
|
+
export interface MVCArrayLike<T> {
|
|
17
|
+
getArray(): T[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare const PolylineError: typeof P.PolylineError;
|
|
21
|
+
export type PolylineError = P.PolylineError;
|
|
22
|
+
|
|
23
|
+
/** A LatLng constructor: LatLng or anything built the same way. */
|
|
24
|
+
export type LatLngConstructor = new (lat: number, lng: number, noClampNoWrap?: boolean) => LatLng;
|
|
25
|
+
|
|
26
|
+
export interface DecodePathOptions extends Omit<Options, 'order'> {
|
|
27
|
+
/**
|
|
28
|
+
* The class to build points with. Default: globalThis.LatLng
|
|
29
|
+
* when it exists. false or null returns LatLngLiteral objects.
|
|
30
|
+
*/
|
|
31
|
+
LatLng?: LatLngConstructor | false | null;
|
|
32
|
+
/** Passed to the LatLng constructor. Without it, LatLng clamps latitude and wraps longitude into [-180, 180). */
|
|
33
|
+
noClampNoWrap?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A point encodePath takes: LatLng, LatLngLiteral or a [lat, lng] tuple. */
|
|
37
|
+
export type PathPoint = LatLng | LatLngLiteral | Point;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Decodes an encoded path to LatLngLiteral objects (`LatLng: false`).
|
|
41
|
+
*/
|
|
42
|
+
export function decodePath(encodedPath: string, options: DecodePathOptions & { LatLng: false | null }): LatLngLiteral[];
|
|
43
|
+
/**
|
|
44
|
+
* Decodes an encoded path, like google.maps.geometry.encoding.decodePath,
|
|
45
|
+
* to LatLng objects. Without a `LatLng` option this uses
|
|
46
|
+
* globalThis.LatLng; when the Maps JavaScript API isn't loaded
|
|
47
|
+
* the result is LatLngLiteral objects at runtime, so pass `LatLng: false`
|
|
48
|
+
* there to get that type. Strict by default: a malformed string throws a
|
|
49
|
+
* PolylineError unless `strict: false`.
|
|
50
|
+
*/
|
|
51
|
+
export function decodePath(encodedPath: string, options?: number | (DecodePathOptions & { LatLng?: LatLngConstructor })): LatLng[];
|
|
52
|
+
export function decodePath(encodedPath: string, options?: number | DecodePathOptions): LatLng[] | LatLngLiteral[];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Encodes a path, like google.maps.geometry.encoding.encodePath: an array or
|
|
56
|
+
* MVCArray of LatLng, LatLngLiteral or [lat, lng] tuples, mixed
|
|
57
|
+
* or not. Precision 5 by default. `order: 'lnglat'` applies to tuples and
|
|
58
|
+
* LatLng objects; literals are read by name. Strict by default.
|
|
59
|
+
*/
|
|
60
|
+
export function encodePath(path: readonly PathPoint[] | MVCArrayLike<PathPoint>, options?: number | Options): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Types for every Google-format entry point of @duoquote/polytini: the
|
|
2
|
+
// default (web), node, bun, deno and wasm entries share this API.
|
|
3
|
+
|
|
4
|
+
/** A point as [lat, lng], or [lng, lat] with `order: 'lnglat'`. More values with `dimensions`. */
|
|
5
|
+
export type Point = [number, number, ...number[]];
|
|
6
|
+
|
|
7
|
+
/** Objects encode reads by name: lat or latitude, lng, lon or longitude, alt or altitude. */
|
|
8
|
+
export interface LatLngLike {
|
|
9
|
+
lat?: number;
|
|
10
|
+
latitude?: number;
|
|
11
|
+
lng?: number;
|
|
12
|
+
lon?: number;
|
|
13
|
+
longitude?: number;
|
|
14
|
+
alt?: number;
|
|
15
|
+
altitude?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Options {
|
|
19
|
+
/** Decimal places, an integer from 0 to 15. Default 5. Google uses 5, OSRM's polyline6 and Valhalla 6. */
|
|
20
|
+
precision?: number;
|
|
21
|
+
/** Multiply by this instead of 10 ** precision. */
|
|
22
|
+
factor?: number;
|
|
23
|
+
/**
|
|
24
|
+
* The order of the tuples you pass in and get back. The encoded string
|
|
25
|
+
* always stores latitude first. Default 'latlng'; GeoJSON uses 'lnglat'.
|
|
26
|
+
*/
|
|
27
|
+
order?: 'latlng' | 'lnglat';
|
|
28
|
+
/**
|
|
29
|
+
* Throw a PolylineError on malformed input. Default true. With false,
|
|
30
|
+
* decode skips invalid characters and drops an incomplete last point, and
|
|
31
|
+
* encode treats missing or non-finite coordinates as 0.
|
|
32
|
+
*/
|
|
33
|
+
strict?: boolean;
|
|
34
|
+
/** Values per point, 1 to 16. Default 2. The third can be elevation, like GraphHopper's. */
|
|
35
|
+
dimensions?: number;
|
|
36
|
+
/** Factor for the third and later values. Defaults to the main factor. */
|
|
37
|
+
zFactor?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Options, or just the precision. */
|
|
41
|
+
export type OptionsArg = number | Options;
|
|
42
|
+
|
|
43
|
+
export type ErrorCode = 'char' | 'truncated' | 'overflow' | 'coordinate' | 'input' | 'option' | 'init';
|
|
44
|
+
|
|
45
|
+
export class PolylineError extends Error {
|
|
46
|
+
readonly name: 'PolylineError';
|
|
47
|
+
/** What went wrong. */
|
|
48
|
+
readonly code: ErrorCode;
|
|
49
|
+
/** Character index (decode) or point index (encode), when there is one. */
|
|
50
|
+
readonly index: number | undefined;
|
|
51
|
+
constructor(code: ErrorCode, message: string, index?: number);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface LineString {
|
|
55
|
+
type: 'LineString';
|
|
56
|
+
coordinates: number[][];
|
|
57
|
+
bbox?: number[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LineStringFeature {
|
|
61
|
+
type: 'Feature';
|
|
62
|
+
geometry: LineString;
|
|
63
|
+
properties: Record<string, unknown> | null;
|
|
64
|
+
id?: string | number;
|
|
65
|
+
bbox?: number[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Encodes points: tuples (or any array-like) or lat/lng objects. */
|
|
69
|
+
export function encode(points: ArrayLike<ArrayLike<number> | LatLngLike>, options?: OptionsArg): string;
|
|
70
|
+
|
|
71
|
+
/** Decodes to tuples, [lat, lng] by default. */
|
|
72
|
+
export function decode(str: string, options?: OptionsArg): Point[];
|
|
73
|
+
|
|
74
|
+
/** Encodes a flat array of numbers: [lat0, lng0, lat1, lng1, ...] (or lng first with order 'lnglat'). */
|
|
75
|
+
export function encodeFlat(values: ArrayLike<number>, options?: OptionsArg): string;
|
|
76
|
+
|
|
77
|
+
/** Decodes to one flat Float64Array, without an array per point. */
|
|
78
|
+
export function decodeFlat(str: string, options?: OptionsArg): Float64Array;
|
|
79
|
+
|
|
80
|
+
/** Decodes to {lat, lng} objects, the shape Google Maps and Leaflet take. */
|
|
81
|
+
export function decodeLatLng(str: string, options?: OptionsArg): { lat: number; lng: number }[];
|
|
82
|
+
|
|
83
|
+
/** Decodes to a GeoJSON LineString, [lng, lat] order. */
|
|
84
|
+
export function toGeoJSON(str: string, options?: OptionsArg): LineString;
|
|
85
|
+
|
|
86
|
+
/** Encodes a GeoJSON LineString, or a Feature with one. */
|
|
87
|
+
export function fromGeoJSON(geojson: LineString | LineStringFeature, options?: OptionsArg): string;
|