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