diff --git a/src/ol/format/geojsonformat.js b/src/ol/format/geojsonformat.js index d87be696a4..52939de19f 100644 --- a/src/ol/format/geojsonformat.js +++ b/src/ol/format/geojsonformat.js @@ -408,7 +408,7 @@ ol.format.GeoJSON.prototype.readFeatureFromObject = function( feature.setGeometryName(this.geometryName_); } feature.setGeometry(geometry); - if (geoJSONFeature.id) { + if (geoJSONFeature.id !== undefined) { feature.setId(geoJSONFeature.id); } if (geoJSONFeature.properties) { diff --git a/test/spec/ol/format/geojsonformat.test.js b/test/spec/ol/format/geojsonformat.test.js index 79f18336d6..655bef9ee8 100644 --- a/test/spec/ol/format/geojsonformat.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -27,6 +27,15 @@ describe('ol.format.GeoJSON', function() { } }; + var zeroIdGeoJSON = { + 'type': 'Feature', + 'id': 0, + 'geometry': null, + 'properties': { + 'prop0': 'value0' + } + }; + var lineStringGeoJSON = { 'type': 'Feature', 'geometry': { @@ -166,6 +175,12 @@ describe('ol.format.GeoJSON', function() { expect(feature.get('prop0')).to.be('value0'); }); + it('can read a feature with id equal to 0', function() { + var feature = format.readFeature(zeroIdGeoJSON); + expect(feature).to.be.an(ol.Feature); + expect(feature.getId()).to.be(0); + }); + it('can read a feature collection', function() { var features = format.readFeatures(featureCollectionGeoJSON); expect(features).to.have.length(3);