Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not center to geometry when highlighting when geometry does not fit the screen #3665

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,25 @@ QPointF InputUtils::geometryCenterToScreenCoordinates( const QgsGeometry &geom,
return screenPoint;
}

bool InputUtils::canExtentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to rename canExtentContainGeometry to extentContainGeometry

{
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( "," );
Expand Down
7 changes: 7 additions & 0 deletions app/inpututils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe worth to have simple unit test ?


// 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)
Expand Down
4 changes: 4 additions & 0 deletions app/qml/map/MMMapController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Loading