Handle multipolygons with empty polygons
This commit is contained in:
@@ -94,6 +94,9 @@ export function deflateMultiCoordinatesArray(
|
||||
stride,
|
||||
endss[i]
|
||||
);
|
||||
if (ends.length === 0) {
|
||||
ends[0] = offset;
|
||||
}
|
||||
endss[i++] = ends;
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
|
||||
@@ -79,13 +79,16 @@ export function inflateMultiCoordinatesArray(
|
||||
let i = 0;
|
||||
for (let j = 0, jj = endss.length; j < jj; ++j) {
|
||||
const ends = endss[j];
|
||||
coordinatesss[i++] = inflateCoordinatesArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
coordinatesss[i]
|
||||
);
|
||||
coordinatesss[i++] =
|
||||
ends.length === 1 && ends[0] === offset
|
||||
? []
|
||||
: inflateCoordinatesArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
coordinatesss[i]
|
||||
);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
coordinatesss.length = i;
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -322,6 +322,7 @@ describe('ol/geom/MultiPolygon.js', function () {
|
||||
[cw, ccw],
|
||||
[cw2, ccw2],
|
||||
]);
|
||||
const withEmptyPolygon = new MultiPolygon([[ccw], []]);
|
||||
|
||||
it('returns coordinates as they were constructed', function () {
|
||||
expect(right.getCoordinates()).to.eql([
|
||||
@@ -332,6 +333,7 @@ describe('ol/geom/MultiPolygon.js', function () {
|
||||
[cw, ccw],
|
||||
[cw2, ccw2],
|
||||
]);
|
||||
expect(withEmptyPolygon.getCoordinates()).to.eql([[ccw], []]);
|
||||
});
|
||||
|
||||
it('can return coordinates with right-hand orientation', function () {
|
||||
|
||||
Reference in New Issue
Block a user