Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geojson compliant decoding parameter #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link

@Jordan-Work Jordan-Work Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(L31,54,56)
Hey may want to toss a ; on these I've got caught doing that too

} 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