Skip to content

Commit 2ad5f58

Browse files
authored
Add geojson compliant decoding parameter
1 parent 338359c commit 2ad5f58

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

javascript/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const CUSTOM2 = 7;
2727

2828
const Num = typeof BigInt !== "undefined" ? BigInt : Number;
2929

30-
function decode(encoded) {
30+
function decode(encoded, params = {geojson: false}) {
31+
const { geojson } = params
3132
const decoder = decodeUnsignedValues(encoded);
3233
const header = decodeHeader(decoder[0], decoder[1]);
3334

@@ -46,14 +47,22 @@ function decode(encoded) {
4647
const deltaLng = toSigned(decoder[i + 1]) / factorDegree;
4748
lastLat += deltaLat;
4849
lastLng += deltaLng;
50+
51+
let point
52+
53+
if (geojson) {
54+
point = [lastLng, lastLat]
55+
} else {
56+
point = [lastLat, lastLng]
57+
}
4958

5059
if (thirdDim) {
5160
const deltaZ = toSigned(decoder[i + 2]) / factorZ;
5261
lastZ += deltaZ;
53-
res.push([lastLat, lastLng, lastZ]);
62+
res.push([...point, lastZ]);
5463
i += 3;
5564
} else {
56-
res.push([lastLat, lastLng]);
65+
res.push(point);
5766
i += 2;
5867
}
5968
}

0 commit comments

Comments
 (0)