Skip to content

Commit

Permalink
Merge pull request #848 from OpenGeoscience/annotation-geojson-coordi…
Browse files Browse the repository at this point in the history
…nate-reuse

Don't modify geojson object coordinates.
  • Loading branch information
manthey authored Jun 15, 2018
2 parents 7063449 + b7502ab commit 8d91bcc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,16 @@ var annotationLayer = function (args) {
if (!position || position.length < 2) {
return;
}
// make a copy of the position array to avoid mutating the original.
position = position.slice();
break;
case 'polygon':
position = feature.polygon()(data, data_idx);
if (!position || !position.outer || position.outer.length < 3) {
return;
}
position = position.outer;
// make a copy of the position array to avoid mutating the original.
position = position.outer.slice();
if (position[position.length - 1][0] === position[0][0] &&
position[position.length - 1][1] === position[0][1]) {
position.splice(position.length - 1, 1);
Expand Down
4 changes: 4 additions & 0 deletions tests/cases/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ describe('geo.annotationLayer', function () {
}
};
expect(layer.geojson(lineString)).toBe(1);
// expect that the original coordinates are still in place
expect(lineString.geometry.coordinates[1][0]).toBe(-73.79);
lineString.properties.annotationType = 'polygon';
expect(layer.geojson(lineString)).toBe(2);
var sample = {
Expand Down Expand Up @@ -729,6 +731,8 @@ describe('geo.annotationLayer', function () {
}]
};
expect(layer.geojson(sample)).toBe(5);
// expect that the original coordinates are still in place
expect(sample.features[1].geometry.coordinates[0][6][0]).toBe(-118.915853);
var badpoly = {
type: 'Feature',
geometry: {
Expand Down

0 comments on commit 8d91bcc

Please sign in to comment.