From 1c0a5edd2e911a2cea529cc719df155f8f5ec29a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 1 Sep 2024 14:23:16 -0400 Subject: [PATCH] LocationHelper: Move clamp from zoomToFit to QML The OSM plugin has a different zoom tolerance than what we're hardcoding here. This fixes the map looking funky from being too zoomed while trying to fit multiple location points at once. (cherry picked from commit 15d62879950e6233d1503c58d357f88ab860137a) --- src/locationhelper.cpp | 2 +- src/qml/LocationsPage.qml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/locationhelper.cpp b/src/locationhelper.cpp index 8614bdab8..f58a73cc0 100644 --- a/src/locationhelper.cpp +++ b/src/locationhelper.cpp @@ -40,7 +40,7 @@ float LocationHelper::zoomToFit(const QRectF &r, float mapWidth, float mapHeight const auto zy = std::log2((mapHeight / (p2.y() - p1.y()))); const auto z = std::min(zx, zy); - return std::clamp(z, 5.0, 18.0); + return z; } #include "moc_locationhelper.cpp" diff --git a/src/qml/LocationsPage.qml b/src/qml/LocationsPage.qml index bc08a50fd..7eb1f70dc 100644 --- a/src/qml/LocationsPage.qml +++ b/src/qml/LocationsPage.qml @@ -27,7 +27,10 @@ Kirigami.Page { let c = LocationHelper.center(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox)); return QtPositioning.coordinate(c.y, c.x); } - map.zoomLevel: LocationHelper.zoomToFit(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox), mapView.width, mapView.height) + map.zoomLevel: { + const zoom = LocationHelper.zoomToFit(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox), mapView.width, mapView.height) + return Math.min(Math.max(zoom, map.minimumZoomLevel), map.maximumZoomLevel); + } MapItemView { Component.onCompleted: mapView.map.addMapItemView(this)