Skip to content

Commit

Permalink
fix: Use proper length for number of total cells in area encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
okdistribute committed Nov 21, 2020
1 parent 26d399d commit 4301104
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,10 @@ module.exports = function (item, deps) {
coords.push(deps[ref].lat)
})
var cells = earcut(coords)
var coords = []
item.refs.forEach(function (ref) {
coords.push(deps[ref].lon)
coords.push(deps[ref].lat)
})
var cells = earcut(coords)
var cLen = varint.encodingLength(earcut.length/3)
var cLen = varint.encodingLength(earcut.length)
var labelLen = getLabelLen(item.tags)
var buf = Buffer.alloc(1 + typeLen + idLen + pCount + cLen + n*4*2
+ (n-2)*3*2 + labelLen)
+ cells.length + labelLen)
var offset = 0
buf.writeUInt8(0x03, 0)
offset+=1
Expand All @@ -72,10 +66,10 @@ module.exports = function (item, deps) {
buf.writeFloatLE(deps[ref].lat, offset)
offset+=4
})
varint.encode(cells.length/3, buf, offset)
varint.encode(earcut.length, buf, offset)
offset+=varint.encode.bytes
cells.forEach(function (item) {
varint.encode(item, buf, offset)
cells.forEach(function (cell) {
varint.encode(cell, buf, offset)
offset+=varint.encode.bytes
})
writeLabelData(item.tags, buf, offset)
Expand Down

0 comments on commit 4301104

Please sign in to comment.