Allow GeoJSON features with id equal to 0

fixes #4326
This commit is contained in:
Frederic Junod
2015-10-28 11:20:46 +01:00
parent 2f06d214f5
commit 7cf12d1c12
2 changed files with 16 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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);