Merge pull request #11913 from mike-000/patch-20

Handle null geometry in TopoJSON
This commit is contained in:
Andreas Hocevar
2021-01-15 14:22:46 +01:00
committed by GitHub
2 changed files with 34 additions and 10 deletions
+10 -10
View File
@@ -368,18 +368,18 @@ function readFeatureFromGeometry(
name, name,
opt_options opt_options
) { ) {
let geometry; let geometry = null;
const type = object.type; const type = object.type;
const geometryReader = GEOMETRY_READERS[type]; if (type) {
if (type === 'Point' || type === 'MultiPoint') { const geometryReader = GEOMETRY_READERS[type];
geometry = geometryReader(object, scale, translate); if (type === 'Point' || type === 'MultiPoint') {
} else { geometry = geometryReader(object, scale, translate);
geometry = geometryReader(object, arcs); } else {
geometry = geometryReader(object, arcs);
}
geometry = transformGeometryWithOptions(geometry, false, opt_options);
} }
const feature = new Feature(); const feature = new Feature({geometry: geometry});
feature.setGeometry(
transformGeometryWithOptions(geometry, false, opt_options)
);
if (object.id !== undefined) { if (object.id !== undefined) {
feature.setId(object.id); feature.setId(object.id);
} }
+24
View File
@@ -48,6 +48,19 @@ const zeroId = {
}, },
}; };
const nullGeometry = {
type: 'Topology',
objects: {
foobar: {
type: null,
properties: {
prop0: 'value0',
},
id: 533,
},
},
};
describe('ol.format.TopoJSON', function () { describe('ol.format.TopoJSON', function () {
let format; let format;
before(function () { before(function () {
@@ -93,6 +106,17 @@ describe('ol.format.TopoJSON', function () {
expect(feature).to.be.a(Feature); expect(feature).to.be.a(Feature);
expect(feature.getId()).to.be(0); expect(feature.getId()).to.be(0);
}); });
it('can read a feature with null geometry', function () {
const features = format.readFeaturesFromObject(nullGeometry);
expect(features).to.have.length(1);
const feature = features[0];
expect(feature).to.be.a(Feature);
expect(feature.getGeometry()).to.be(null);
expect(feature.getId()).to.be(533);
expect(feature.get('prop0')).to.be('value0');
});
}); });
describe('#readFeatures()', function () { describe('#readFeatures()', function () {