From 3988764dd20d59a2631de300cbf91e2d769b1800 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Mon, 2 May 2022 15:43:20 +1000 Subject: [PATCH] account for global padding in popup auto-anchoring --- debug/popup.html | 7 +++++++ src/ui/popup.js | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/debug/popup.html b/debug/popup.html index 9cd27258731..e6f583447bd 100644 --- a/debug/popup.html +++ b/debug/popup.html @@ -25,6 +25,13 @@ style: 'mapbox://styles/mapbox/streets-v10', hash: true }); +map.showPadding = true; +map.setPadding({ + left: 10, + right: 20, + top: 30, + bottom: 40 +}); var popup = new mapboxgl.Popup({closeButton: false, closeOnClick: false}) .trackPointer() diff --git a/src/ui/popup.js b/src/ui/popup.js index c040a7f9335..b61fe4b4b1b 100644 --- a/src/ui/popup.js +++ b/src/ui/popup.js @@ -555,10 +555,10 @@ export default class Popup extends Evented { const width = container.offsetWidth; const height = container.offsetHeight; - const isTop = pos.y + bottomY < height; - const isBottom = pos.y > map.transform.height - height; - const isLeft = pos.x < width / 2; - const isRight = pos.x > map.transform.width - width / 2; + const isTop = pos.y + bottomY < height + map.transform.padding.top; + const isBottom = pos.y > map.transform.height - height - map.transform.padding.bottom; + const isLeft = pos.x < width / 2 + map.transform.padding.left; + const isRight = pos.x > map.transform.width - width / 2 - map.transform.padding.right; if (isTop) { if (isLeft) return 'top-left';