diff --git a/app/inpututils.cpp b/app/inpututils.cpp index 218c024e1..774187469 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 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..07e9c5b11 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 )