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

fix: Use proper length for number of total cells in area encoder #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 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