From 51d61dda277fff18359a7f04be8f32cefb099d13 Mon Sep 17 00:00:00 2001 From: "James P. Javery" Date: Tue, 2 Feb 2021 04:22:44 -0600 Subject: [PATCH] Fix argument mutation and incorrect result when attempting to reuse PathOverlay 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 --- services/static.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static.js b/services/static.js index bb4c382..c3773df 100644 --- a/services/static.js +++ b/services/static.js @@ -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) + ')';