Skip to content

Commit

Permalink
Pass through numerical IDs from GeoJSON
Browse files Browse the repository at this point in the history
Fixes mapbox#7
  • Loading branch information
hannesj committed Aug 15, 2016
1 parent f295045 commit d50ac45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/geojson_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
1 change: 1 addition & 0 deletions test/fixtures/rectangle.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"features": [
{
"type": "Feature",
"id": 123,
"properties": {
"mykey": "myvalue",
"myotherkey": 10
Expand Down

0 comments on commit d50ac45

Please sign in to comment.