From d50ac45ab90298086d1c60a27bb887f6159d39df Mon Sep 17 00:00:00 2001 From: Hannes Junnila Date: Mon, 15 Aug 2016 13:47:55 +0300 Subject: [PATCH] Pass through numerical IDs from GeoJSON Fixes #7 --- lib/geojson_wrapper.js | 1 + test/basic.js | 19 +++++++++++++++++++ test/fixtures/rectangle.geojson | 1 + 3 files changed, 21 insertions(+) diff --git a/lib/geojson_wrapper.js b/lib/geojson_wrapper.js index aaf224c..9a2d987 100644 --- a/lib/geojson_wrapper.js +++ b/lib/geojson_wrapper.js @@ -16,6 +16,7 @@ GeoJSONWrapper.prototype.feature = function (i) { } function FeatureWrapper (feature) { + this.id = typeof feature.id === 'number' ? feature.id : undefined this.type = feature.type this.rawGeometry = feature.type === 1 ? [feature.geometry] : feature.geometry this.properties = feature.tags diff --git a/test/basic.js b/test/basic.js index cd7cd09..e7f9300 100644 --- a/test/basic.js +++ b/test/basic.js @@ -69,3 +69,22 @@ test('JSON.stringify non-primitive properties', function (t) { t.end() }) +test('Pass through integer ids', function (t) { + var orig = JSON.parse(fs.readFileSync(__dirname + '/fixtures/rectangle.geojson')) + orig.features[1].id = 'Hello' + var tileindex = geojsonVt(orig) + var tile = tileindex.getTile(1, 0, 0) + var buff = serialize.fromGeojsonVt({ 'geojsonLayer': tile }) + + var vt = new VectorTile(new Pbf(buff)) + var layer = vt.layers['geojsonLayer'] + var feat0 = layer.feature(0) + var feat1 = layer.feature(1) + var feat2 = layer.feature(2) + + t.same(feat0.id, 123) + t.notOk(feat1.id, 'Non-integer values should not be saved') + t.notOk(feat2.id) + + t.end() +}) diff --git a/test/fixtures/rectangle.geojson b/test/fixtures/rectangle.geojson index 401084d..0d2f923 100644 --- a/test/fixtures/rectangle.geojson +++ b/test/fixtures/rectangle.geojson @@ -3,6 +3,7 @@ "features": [ { "type": "Feature", + "id": 123, "properties": { "mykey": "myvalue", "myotherkey": 10