From 0b4fc9fa160d38bd90e852a730d4599de836053f Mon Sep 17 00:00:00 2001 From: Jason Baker Date: Wed, 3 Feb 2021 09:41:02 -0600 Subject: [PATCH] Add geojson compliant decoding parameter Signed-off-by: Jason Baker --- javascript/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/javascript/index.js b/javascript/index.js index d0fcca9..3b72921 100644 --- a/javascript/index.js +++ b/javascript/index.js @@ -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]); @@ -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; } }