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 84bc485
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function (item, deps) {
var labelLen = getLabelLen(item.tags)
var buf = Buffer.alloc(9 + typeLen + idLen + labelLen)
var offset = 0
buf.writeUInt8(0x01, offset)
buf.writeUInt8(0x01, offset)
offset+=1
varint.encode(type, buf, offset)
offset+=varint.encode.bytes
Expand All @@ -47,16 +47,11 @@ 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(cells.length/3)
var cLenData = cells.reduce((acc, cell) => acc + varint.encodingLength(cell), 0)
var labelLen = getLabelLen(item.tags)
var buf = Buffer.alloc(1 + typeLen + idLen + pCount + cLen + n*4*2
+ (n-2)*3*2 + labelLen)
+ cLenData + labelLen)
var offset = 0
buf.writeUInt8(0x03, 0)
offset+=1
Expand All @@ -74,8 +69,8 @@ module.exports = function (item, deps) {
})
varint.encode(cells.length/3, 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 Expand Up @@ -117,7 +112,7 @@ function getLabelLen (tags) {
if (!/^([^:]+_|)name($|:)/.test(key)) { return }
var pre = key.replace(/^(|[^:]+_)name($|:)/,'')
var dataLen = Buffer.byteLength(pre) + 1
+ Buffer.byteLength(tags[key])
+ Buffer.byteLength(tags[key])
labelLen += varint.encodingLength(dataLen) + dataLen
})
return labelLen
Expand Down
2 changes: 1 addition & 1 deletion example/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs')
var through = require('through2')
var parseOSM = require('osm-pbf-parser')
var georenderPack = require('../encode.js')

var osm = parseOSM()
var allItems = {}
var itemsRefsObject = {}
Expand Down

0 comments on commit 84bc485

Please sign in to comment.