Skip to content

Commit

Permalink
Add geojson compliant decoding parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbaker committed Feb 3, 2021
1 parent 338359c commit 2ad5f58
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const CUSTOM2 = 7;

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

function decode(encoded) {
function decode(encoded, params = {geojson: false}) {
const { geojson } = params
const decoder = decodeUnsignedValues(encoded);
const header = decodeHeader(decoder[0], decoder[1]);

Expand All @@ -46,14 +47,22 @@ function decode(encoded) {
const deltaLng = toSigned(decoder[i + 1]) / factorDegree;
lastLat += deltaLat;
lastLng += deltaLng;

let point

if (geojson) {
point = [lastLng, lastLat]
} else {
point = [lastLat, lastLng]
}

if (thirdDim) {
const deltaZ = toSigned(decoder[i + 2]) / factorZ;
lastZ += deltaZ;
res.push([lastLat, lastLng, lastZ]);
res.push([...point, lastZ]);
i += 3;
} else {
res.push([lastLat, lastLng]);
res.push(point);
i += 2;
}
}
Expand Down

0 comments on commit 2ad5f58

Please sign in to comment.