summaryrefslogtreecommitdiff
path: root/src/mbgl/map/map.cpp
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-03-25 14:22:35 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-03-25 17:53:55 +0100
commit419bfbe0eb12db8144bc5361bcc90b419e28f429 (patch)
treee56aa357e26d5f22f660aeac1a6b9f0db1554159 /src/mbgl/map/map.cpp
parent10114c85bba9c2c0e62aa6361b887717f9f05921 (diff)
downloadqtlocation-mapboxgl-419bfbe0eb12db8144bc5361bcc90b419e28f429.tar.gz
[core] harden fetching camera for bounds when padding is excessive
Diffstat (limited to 'src/mbgl/map/map.cpp')
-rw-r--r--src/mbgl/map/map.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 24b2435923..54a95ceaeb 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -205,8 +205,13 @@ CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transfo
scaleY -= (padding.top() + padding.bottom()) / height;
minScale = util::min(scaleX, scaleY);
}
- double zoom = transform.getZoom() + util::log2(minScale);
- zoom = util::clamp(zoom, transform.getState().getMinZoom(), transform.getState().getMaxZoom());
+
+ double zoom = transform.getZoom();
+ if (minScale > 0) {
+ zoom = util::clamp(zoom + util::log2(minScale), transform.getState().getMinZoom(), transform.getState().getMaxZoom());
+ } else {
+ Log::Error(Event::General, "Unable to calculate appropriate zoom level for bounds. Vertical or horizontal padding is greater than map's height or width.");
+ }
// Calculate the center point of a virtual bounds that is extended in all directions by padding.
ScreenCoordinate centerPixel = nePixel + swPixel;