Skip to content

Commit

Permalink
Fix argument mutation and incorrect result when attempting to reuse P…
Browse files Browse the repository at this point in the history
…athOverlay coordinates in getStaticImage config (#413)

Array.prototype.reverse() reverses an array in place. This results in the (unintended) mutation of the coordinates property of the overlay param. Instead, create a new array and initialize it with the reversed lat and long.

 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
  • Loading branch information
jjavery authored Feb 2, 2021
1 parent 63d60ed commit 51d61dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion services/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function encodePathOverlay(o) {
}
// polyline expects each coordinate to be in reversed order: [lat, lng]
var reversedCoordinates = o.coordinates.map(function(c) {
return c.reverse();
return [c[1], c[0]];
});
var encodedPolyline = polyline.encode(reversedCoordinates);
result += '(' + encodeURIComponent(encodedPolyline) + ')';
Expand Down

0 comments on commit 51d61dd

Please sign in to comment.