Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/externalClients/layersClient/geometryParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function geographyToGeoJSON(geography: RawGeography): Geometry {
return lineString(coords.map(toPosition)).geometry as LineString;

case 'POLYGON':
case 'AREA':
if (coords.length < 4) {
throw new Error(`Polygon requires >=4 coordinates (closed ring), got ${coords.length}`);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/externalClients/geometryParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ describe('geographyToGeoJSON', () => {
];
expect(() => geographyToGeoJSON(geo('POLYGON', ring))).toThrow(/Polygon requires >=4/);
});

it('accepts AREA alias as Polygon', () => {
const ring = [
{ latitude: 0, longitude: 0 },
{ latitude: 0, longitude: 1 },
{ latitude: 1, longitude: 1 },
{ latitude: 0, longitude: 0 },
];
const result = geographyToGeoJSON(geo('AREA', ring));
expect(result).toEqual({
type: 'Polygon',
coordinates: [
[
[0, 0],
[1, 0],
[1, 1],
[0, 0],
],
],
});
});
});

describe('error cases', () => {
Expand Down
Loading