Merge pull request #1705 from tonio/geojson_null_geometry
Allow GeoJSON features to have `null` geometries.
This commit is contained in:
@@ -57,6 +57,9 @@ ol.format.GeoJSON.EXTENSIONS_ = ['.geojson'];
|
|||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.readGeometry_ = function(object) {
|
ol.format.GeoJSON.readGeometry_ = function(object) {
|
||||||
|
if (goog.isNull(object)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type];
|
var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type];
|
||||||
goog.asserts.assert(goog.isDef(geometryReader));
|
goog.asserts.assert(goog.isDef(geometryReader));
|
||||||
return geometryReader(object);
|
return geometryReader(object);
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var nullGeometryGeoJSON = {
|
||||||
|
'type': 'Feature',
|
||||||
|
'geometry': null,
|
||||||
|
'properties': {
|
||||||
|
'prop0': 'value0'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var lineStringGeoJSON = {
|
var lineStringGeoJSON = {
|
||||||
'type': 'Feature',
|
'type': 'Feature',
|
||||||
'geometry': {
|
'geometry': {
|
||||||
@@ -150,6 +158,14 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
expect(feature.get('prop1')).to.eql({'this': 'that'});
|
expect(feature.get('prop1')).to.eql({'this': 'that'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can read a feature with null geometry', function() {
|
||||||
|
var feature = format.readFeature(nullGeometryGeoJSON);
|
||||||
|
expect(feature).to.be.an(ol.Feature);
|
||||||
|
var geometry = feature.getGeometry();
|
||||||
|
expect(geometry).to.eql(null);
|
||||||
|
expect(feature.get('prop0')).to.be('value0');
|
||||||
|
});
|
||||||
|
|
||||||
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