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

Skip encoding null values altogether #43

Merged
merged 1 commit into from
Jun 4, 2021
Merged
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
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,20 @@ function writeProperties (context, pbf) {
var valuecache = context.valuecache

for (var key in feature.properties) {
var value = feature.properties[key]

var keyIndex = keycache[key]
if (value === null) continue // don't encode null value properties

if (typeof keyIndex === 'undefined') {
keys.push(key)
keyIndex = keys.length - 1
keycache[key] = keyIndex
}
pbf.writeVarint(keyIndex)

var value = feature.properties[key]
var type = typeof value
if (value !== null && type !== 'string' && type !== 'boolean' && type !== 'number') {
if (type !== 'string' && type !== 'boolean' && type !== 'number') {
value = JSON.stringify(value)
}
var valueKey = type + ':' + value
Expand Down
2 changes: 1 addition & 1 deletion test/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test('property encoding', function (t) {
var second = layer.feature(1).properties
t.same(first.c, '{"hello":"world"}')
t.same(first.d, '[1,2,3]')
t.equals(first.e, null)
t.equals(first.e, undefined)
t.same(second.c, '{"goodbye":"planet"}')
t.same(second.d, '{"hello":"world"}')
t.end()
Expand Down