From 5c453951e1a28fdfbf37f2b4535cab00125a6106 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 18 Jul 2016 13:57:47 -0700 Subject: [PATCH] Make VectorTileFeature#id a public property --- README.md | 1 + lib/vectortilefeature.js | 6 +++--- test/parse.test.js | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e9c4dfc..6a7428b 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ An object that contains the data for a single feature. - **type** (`Number`) — type of the feature (also see `VectorTileFeature.types`) - **extent** (`Number`) — feature extent size +- **id** (`Number`) — feature identifier, if present - **properties** (`Object`) — object literal with feature properties #### Methods diff --git a/lib/vectortilefeature.js b/lib/vectortilefeature.js index 916053a..0deef28 100644 --- a/lib/vectortilefeature.js +++ b/lib/vectortilefeature.js @@ -20,7 +20,7 @@ function VectorTileFeature(pbf, end, extent, keys, values) { } function readFeature(tag, feature, pbf) { - if (tag == 1) feature._id = pbf.readVarint(); + if (tag == 1) feature.id = pbf.readVarint(); else if (tag == 2) readTag(pbf, feature); else if (tag == 3) feature.type = pbf.readVarint(); else if (tag == 4) feature._geometry = pbf.pos; @@ -185,8 +185,8 @@ VectorTileFeature.prototype.toGeoJSON = function(x, y, z) { properties: this.properties }; - if ('_id' in this) { - result.id = this._id; + if ('id' in this) { + result.id = this.id; } return result; diff --git a/test/parse.test.js b/test/parse.test.js index 6ecba23..7a5a998 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -58,6 +58,8 @@ test('parsing vector tiles', function(t) { var park = tile.layers.poi_label.feature(1e9); }, 'throws on reading a feature out of bounds'); + t.equal(park.id, 3000003150561); + t.equal(park.properties.name, 'Mauerpark'); t.equal(park.properties.type, 'Park');