From 22e967255deff708a547591e369f2118730b3315 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Fri, 25 Oct 2024 11:33:08 +0200 Subject: [PATCH] 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 )