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
8 changes: 6 additions & 2 deletions src/feature_types/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ Polygon.prototype.removeCoordinate = function(path) {

Polygon.prototype.getCoordinate = function(path) {
const ids = path.split('.').map(x => parseInt(x, 10));
const ring = this.coordinates[ids[0]];
const coords = this.coordinates[ids[0]];
const ring = coords.concat([coords[0]]);
return JSON.parse(JSON.stringify(ring[ids[1]]));
};

Polygon.prototype.getCoordinates = function() {
return this.coordinates.map(coords => coords.concat([coords[0]]));
return this.coordinates.map((coords) => {
const ring = coords.concat([coords[0]]);
return ring;
});
};

Polygon.prototype.updateCoordinate = function(path, lng, lat) {
Expand Down
11 changes: 11 additions & 0 deletions test/polygon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ test('Polygon#isValid', (t) => {
t.end();
});

test('Polygon#getCoordinate', (t) => {
const rawPolygon = createFeature('polygon');
rawPolygon.geometry.coordinates = [[[1, 2], [3, 4], [5, 6], [1, 2]]];
const polygon = new Polygon(createMockCtx(), rawPolygon);

t.deepEqual(polygon.getCoordinate('0.0'), [1, 2], 'getCoordinate returns the first coordinate');
t.deepEqual(polygon.getCoordinate('0.3'), [1, 2], 'getCoordinate returns the first coordinate as the last coordinate');

t.end();
});

test('Polygon#incomingCoords, Polygon#getCoordinates', (t) => {
const rawPolygon = createFeature('polygon');
const polygon = new Polygon(createMockCtx(), rawPolygon);
Expand Down