From 8131815bef01f10c7184b55097061404458b5ffb Mon Sep 17 00:00:00 2001 From: Arindam Bose Date: Mon, 30 Mar 2020 20:28:45 -0700 Subject: [PATCH] Ensure padding is not propagated from fitBounds to transform padding (#9481) (cherry picked from commit 7431c959d62119e63b1fa57320313bd7a7edc82b) --- src/ui/camera.js | 2 ++ test/unit/ui/camera.test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/ui/camera.js b/src/ui/camera.js index 4f02cf6763e..b830914a782 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -599,6 +599,8 @@ class Camera extends Evented { if (!calculatedOptions) return this; options = extend(calculatedOptions, options); + // Explictly remove the padding field because, calculatedOptions already accounts for padding by setting zoom and center accordingly. + delete options.padding; return options.linear ? this.easeTo(options, eventData) : diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index fe656b558ff..ba23f8b9c9f 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -1889,6 +1889,21 @@ test('camera', (t) => { t.end(); }); + t.test('padding does not get propagated to transform.padding', (t) => { + const camera = createCamera(); + const bb = [[-133, 16], [-68, 50]]; + + camera.fitBounds(bb, {padding: {top: 10, right: 75, bottom: 50, left: 25}, duration:0}); + const padding = camera.transform.padding; + t.deepEqual(padding, { + left: 0, + right: 0, + top: 0, + bottom: 0 + }); + t.end(); + }); + t.end(); });