Merge pull request #4327 from fredj/geojson_id_0
Allow GeoJSON features with id equal to 0
This commit is contained in:
@@ -408,7 +408,7 @@ ol.format.GeoJSON.prototype.readFeatureFromObject = function(
|
|||||||
feature.setGeometryName(this.geometryName_);
|
feature.setGeometryName(this.geometryName_);
|
||||||
}
|
}
|
||||||
feature.setGeometry(geometry);
|
feature.setGeometry(geometry);
|
||||||
if (geoJSONFeature.id) {
|
if (geoJSONFeature.id !== undefined) {
|
||||||
feature.setId(geoJSONFeature.id);
|
feature.setId(geoJSONFeature.id);
|
||||||
}
|
}
|
||||||
if (geoJSONFeature.properties) {
|
if (geoJSONFeature.properties) {
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var zeroIdGeoJSON = {
|
||||||
|
'type': 'Feature',
|
||||||
|
'id': 0,
|
||||||
|
'geometry': null,
|
||||||
|
'properties': {
|
||||||
|
'prop0': 'value0'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var lineStringGeoJSON = {
|
var lineStringGeoJSON = {
|
||||||
'type': 'Feature',
|
'type': 'Feature',
|
||||||
'geometry': {
|
'geometry': {
|
||||||
@@ -166,6 +175,12 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
expect(feature.get('prop0')).to.be('value0');
|
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() {
|
it('can read a feature collection', function() {
|
||||||
var features = format.readFeatures(featureCollectionGeoJSON);
|
var features = format.readFeatures(featureCollectionGeoJSON);
|
||||||
expect(features).to.have.length(3);
|
expect(features).to.have.length(3);
|
||||||
|
|||||||
Reference in New Issue
Block a user