From c6803838ab04b5266d6d0a2d07517a7740d51357 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 28 Oct 2015 14:55:43 +0100 Subject: [PATCH] Allow TopoJSON features with id equal to 0 --- src/ol/format/topojsonformat.js | 2 +- test/spec/ol/format/topojson.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ol/format/topojsonformat.js b/src/ol/format/topojsonformat.js index 1a4cdb87b8..c5c14b0b3e 100644 --- a/src/ol/format/topojsonformat.js +++ b/src/ol/format/topojsonformat.js @@ -260,7 +260,7 @@ ol.format.TopoJSON.readFeatureFromGeometry_ = function(object, arcs, var feature = new ol.Feature(); feature.setGeometry(/** @type {ol.geom.Geometry} */ ( ol.format.Feature.transformWithOptions(geometry, false, opt_options))); - if (object.id) { + if (object.id !== undefined) { feature.setId(object.id); } if (object.properties) { diff --git a/test/spec/ol/format/topojson.test.js b/test/spec/ol/format/topojson.test.js index 47f0ac7acd..df876986b0 100644 --- a/test/spec/ol/format/topojson.test.js +++ b/test/spec/ol/format/topojson.test.js @@ -22,6 +22,16 @@ var aruba = { ] }; +var zeroId = { + type: 'Topology', + objects: { + foobar: { + type: 'Point', + id: 0, + coordinates: [0, 42] + } + } +}; describe('ol.format.TopoJSON', function() { @@ -60,6 +70,15 @@ describe('ol.format.TopoJSON', function() { ]); }); + it('can read a feature with id equal to 0', function() { + var features = format.readFeaturesFromObject(zeroId); + expect(features).to.have.length(1); + + var feature = features[0]; + expect(feature).to.be.a(ol.Feature); + expect(feature.getId()).to.be(0); + }); + }); describe('#readFeatures()', function() {