From 22e967255deff708a547591e369f2118730b3315 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Fri, 25 Oct 2024 11:33:08 +0200 Subject: [PATCH 1/4] Do not pan to the feature if the currrent extend can't contain the geometry --- app/inpututils.cpp | 19 +++++++++++++++++++ app/inpututils.h | 7 +++++++ app/qml/map/MMMapController.qml | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/app/inpututils.cpp b/app/inpututils.cpp index 218c024e1..0ec88d012 100644 --- a/app/inpututils.cpp +++ b/app/inpututils.cpp @@ -316,6 +316,25 @@ QPointF InputUtils::geometryCenterToScreenCoordinates( const QgsGeometry &geom, return screenPoint; } +bool InputUtils::canExtentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings ) +{ + QPointF screenPoint; + + if ( !mapSettings || geom.isNull() || !geom.constGet() ) + // return screenPoint; + return false; + + QgsRectangle geomBbox = geom.boundingBox(); + QgsRectangle currentExtent = mapSettings->mapSettings().extent(); + + if (currentExtent.width() > geomBbox.width() + && currentExtent.height() > geomBbox.height()) { + return true; + } + return false; +} + + double InputUtils::convertCoordinateString( const QString &rationalValue ) { QStringList values = rationalValue.split( "," ); diff --git a/app/inpututils.h b/app/inpututils.h index 83be81f39..bd7819d1a 100644 --- a/app/inpututils.h +++ b/app/inpututils.h @@ -89,6 +89,13 @@ class InputUtils: public QObject */ Q_INVOKABLE QPointF geometryCenterToScreenCoordinates( const QgsGeometry &geom, InputMapSettings *mapSettings ); + + /** + * Returns the true if the geometry could fully be contained in the current screen otherwise false + * Geometry must be in canvas CRS + */ + Q_INVOKABLE bool canExtentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings ); + // utility functions to extract information from map settings // (in theory this data should be directly available from .MapTransform // but they are not currently, so this is a workaround we need for display of markers) diff --git a/app/qml/map/MMMapController.qml b/app/qml/map/MMMapController.qml index 43f76d8af..fa6a0d187 100644 --- a/app/qml/map/MMMapController.qml +++ b/app/qml/map/MMMapController.qml @@ -1182,6 +1182,10 @@ Item { if ( identifyHighlight.geometry === null ) return + if (! __inputUtils.canExtentContainGeometry( identifyHighlight.geometry, mapCanvas.mapSettings )){ + return + } + let screenPt = __inputUtils.geometryCenterToScreenCoordinates( identifyHighlight.geometry, mapCanvas.mapSettings ) screenPt.y += mapOffset / 2 mapCanvas.jumpTo( screenPt ) From c296d7b9126be95394e9ebc8c7e94b4dffdbac92 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Fri, 25 Oct 2024 11:50:21 +0200 Subject: [PATCH 2/4] format --- app/inpututils.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/inpututils.cpp b/app/inpututils.cpp index 0ec88d012..37724832e 100644 --- a/app/inpututils.cpp +++ b/app/inpututils.cpp @@ -318,20 +318,21 @@ QPointF InputUtils::geometryCenterToScreenCoordinates( const QgsGeometry &geom, bool InputUtils::canExtentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings ) { - QPointF screenPoint; + QPointF screenPoint; - if ( !mapSettings || geom.isNull() || !geom.constGet() ) - // return screenPoint; - return false; + if ( !mapSettings || geom.isNull() || !geom.constGet() ) + // return screenPoint; + return false; - QgsRectangle geomBbox = geom.boundingBox(); - QgsRectangle currentExtent = mapSettings->mapSettings().extent(); + QgsRectangle geomBbox = geom.boundingBox(); + QgsRectangle currentExtent = mapSettings->mapSettings().extent(); - if (currentExtent.width() > geomBbox.width() - && currentExtent.height() > geomBbox.height()) { - return true; - } - return false; + if ( currentExtent.width() > geomBbox.width() + && currentExtent.height() > geomBbox.height() ) + { + return true; + } + return false; } From 6dc8788aecb37d7fd9885ef4afb80cc3c30d4ccc Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Mon, 28 Oct 2024 10:09:07 +0100 Subject: [PATCH 3/4] useless comment --- app/inpututils.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/app/inpututils.cpp b/app/inpututils.cpp index 37724832e..774187469 100644 --- a/app/inpututils.cpp +++ b/app/inpututils.cpp @@ -321,7 +321,6 @@ bool InputUtils::canExtentContainGeometry( const QgsGeometry &geom, InputMapSett QPointF screenPoint; if ( !mapSettings || geom.isNull() || !geom.constGet() ) - // return screenPoint; return false; QgsRectangle geomBbox = geom.boundingBox(); From 1a50a030edaee1d416579a2e224797614862c47b Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Mon, 28 Oct 2024 15:32:35 +0100 Subject: [PATCH 4/4] format qml --- app/qml/map/MMMapController.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/qml/map/MMMapController.qml b/app/qml/map/MMMapController.qml index fa6a0d187..07e9c5b11 100644 --- a/app/qml/map/MMMapController.qml +++ b/app/qml/map/MMMapController.qml @@ -1182,7 +1182,7 @@ Item { if ( identifyHighlight.geometry === null ) return - if (! __inputUtils.canExtentContainGeometry( identifyHighlight.geometry, mapCanvas.mapSettings )){ + if ( !__inputUtils.canExtentContainGeometry( identifyHighlight.geometry, mapCanvas.mapSettings ) ){ return }