Handle multipolygons with empty polygons

This commit is contained in:
Andreas Hocevar
2022-07-20 13:18:41 +02:00
parent 14041e490f
commit c8508bcf97
4 changed files with 58 additions and 7 deletions

View File

@@ -516,6 +516,26 @@ describe('ol/format/GeoJSON.js', function () {
expect(array[1]).to.be.a(LineString);
expect(array[1].getLayout()).to.eql('XY');
});
it('works with empty coordinate arrays', function () {
const coordinates = [
[
[
[1, 2],
[3, 4],
[5, 6],
[1, 2],
],
],
[],
];
const geojson = {
type: 'MultiPolygon',
coordinates: coordinates,
};
const geometry = format.readGeometry(geojson);
expect(geometry.getCoordinates()).to.eql(coordinates);
});
});
describe('#readProjection', function () {
@@ -1025,5 +1045,28 @@ describe('ol/format/GeoJSON.js', function () {
[43, 39],
]);
});
it('works with empty coordinate arrays', function () {
const coordinates = [
[
[
[1, 2],
[3, 4],
[5, 6],
[1, 2],
],
],
[],
];
const geometry = new MultiPolygon([
new Polygon(coordinates[0]),
new Polygon(coordinates[1]),
]);
const geojson = format.writeGeometryObject(geometry);
expect(geojson).to.eql({
type: 'MultiPolygon',
coordinates: coordinates,
});
});
});
});