Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 9 additions & 10 deletions src/protobuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
export function readVarInt64 (ta_struct) {
let cursor = ta_struct.cursor
let nVal = 0
let nShift = 0
let multiplier = 1
let nByte

while (true) {
nByte = ta_struct.buffer[cursor]
cursor++
nVal += (nByte & 0x7f) * multiplier
if ((nByte & 0x80) === 0) {
cursor++
ta_struct.cursor = cursor
return nVal | (nByte << nShift)
return nVal
}
nVal = nVal | (nByte & 0x7f) << nShift
cursor++
nShift += 7
multiplier *= 128
}
}

Expand All @@ -28,7 +27,7 @@ export function readVarSInt64 (ta_struct) {
}

export function unzigzag (nVal) {
if ((nVal & 1) === 0)
return nVal >> 1
return -(nVal >> 1) - 1
}
if ((nVal % 2) === 0)
return nVal / 2
return -((nVal + 1) / 2)
}
17 changes: 17 additions & 0 deletions test/twkb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ describe('twkb', function () {
})
})

it('should decode precision=7 point in east Asia longitude range', function () {
// POINT(141.961144 35.681234) with precision 7
var g = twkb.toGeoJSON(Buffer.from('e100e0b4ecc90ae898a4d402', 'hex'))
assert.deepEqual(g, {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [141.961144, 35.681234]
}
}
]
})
})

it('should decode linestring to geojson', function () {
var g = twkb.toGeoJSON(Buffer.from('02000202020808', 'hex'))
assert.deepEqual(g, {
Expand Down