Skip to content

Commit 5ea2d24

Browse files
committed
Don't covert all property values to strings
1 parent 7e2c622 commit 5ea2d24

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {type VectorTileLayer, type VectorTile, VectorTileFeature} from '@mapbox/
55

66
interface Context {
77
keys: string[];
8-
values: string[];
8+
values: (string | boolean | number)[];
99
keycache: Record<string, number>;
1010
valuecache: Record<string, number>;
1111
feature?: VectorTileFeature;
@@ -112,7 +112,7 @@ function writeProperties(context: Context, pbf: Pbf) {
112112
const valueKey = typeof value + ':' + value;
113113
let valueIndex = context.valuecache[valueKey];
114114
if (typeof valueIndex === 'undefined') {
115-
context.values.push(value as string);
115+
context.values.push(value);
116116
valueIndex = context.values.length - 1;
117117
context.valuecache[valueKey] = valueIndex;
118118
}

test/properties.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ describe('property encoding', function () {
3434
a: 'two',
3535
b: 2,
3636
c: { goodbye: 'planet' },
37-
d: { hello: 'world' }
37+
d: { hello: 'world' },
38+
e: false
3839
},
3940
geometry: {
4041
type: 'Point',
@@ -52,11 +53,13 @@ describe('property encoding', function () {
5253

5354
const first = layer.feature(0).properties
5455
const second = layer.feature(1).properties
55-
expect(first.c).toEqual('{"hello":"world"}')
56-
expect(first.d).toEqual('[1,2,3]')
57-
expect(first.e).toEqual(undefined)
58-
expect(second.c).toEqual('{"goodbye":"planet"}')
59-
expect(second.d).toEqual('{"hello":"world"}')
56+
expect(first.b).toStrictEqual(1)
57+
expect(first.c).toStrictEqual('{"hello":"world"}')
58+
expect(first.d).toStrictEqual('[1,2,3]')
59+
expect(first.e).toStrictEqual(undefined)
60+
expect(second.c).toStrictEqual('{"goodbye":"planet"}')
61+
expect(second.d).toStrictEqual('{"hello":"world"}')
62+
expect(second.e).toStrictEqual(false)
6063
})
6164

6265
test('number encoding https://github.com/mapbox/vt-pbf/pull/11', function () {
@@ -121,7 +124,7 @@ test('id encoding', function () {
121124
const layer = vt.layers.geojsonLayer
122125
expect(layer.feature(0).id).toEqual(123)
123126
expect(layer.feature(1).id).toBeFalsy() // 'Non-integer values should not be saved'
124-
expect(layer.feature(2).id).toBeFalsy()
127+
expect(layer.feature(2).id).toBeUndefined()
125128
})
126129

127130
test('accept geojson-vt options https://github.com/mapbox/vt-pbf/pull/21', function () {

0 commit comments

Comments
 (0)