Skip to content

Commit bde3837

Browse files
committed
cleanup for review
1 parent 4720e4f commit bde3837

3 files changed

Lines changed: 13 additions & 56 deletions

File tree

app/inpututils.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ QPointF InputUtils::geometryCenterToScreenCoordinates( const QgsGeometry &geom,
320320
*
321321
* Nota Bene: Assume geometry and map canvas CRS are the same
322322
*/
323-
bool InputUtils::canExtentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings )
323+
bool InputUtils::extentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings )
324324
{
325325
QPointF screenPoint;
326326

@@ -329,54 +329,32 @@ bool InputUtils::canExtentContainGeometry( const QgsGeometry &geom, InputMapSett
329329

330330
QgsRectangle currentExtent = mapSettings->mapSettings().visibleExtent();
331331
QgsRectangle geomBbox = geom.boundingBox();
332-
qDebug() << "canExtentContainGeometry:geomBbox: " << QgsGeometry::fromRect(geomBbox).asWkt();
333-
QgsRectangle currentExtent = mapSettings->mapSettings().extent();
334-
qDebug() << "canExtentContainGeometry:currentExtent: " << QgsGeometry::fromRect(currentExtent).asWkt();
335332

336333
return currentExtent.contains(geomBbox);
337334
}
338335

339336

340337
/**
341-
* Returns true if the geometry \a geom is fully contain within the current map extent
338+
* Returns the center point of the \a geom currently display on screen
342339
*
343340
* Nota Bene: Assume geometry and map canvas CRS are the same
344341
*/
345-
QPointF InputUtils::centerOnScreenHighligtedGeom( const QgsGeometry &geom, InputMapSettings *mapSettings )
342+
QPointF InputUtils::onScreenGeometryCenterToScreenCoordinates( const QgsGeometry &geom, InputMapSettings *mapSettings )
346343
{
347-
348344
QPointF screenPoint;
349345
if ( !mapSettings || geom.isNull() || !geom.constGet() )
350-
// return screenPoint;
351346
return screenPoint;
352-
// return false;
353-
354347

355348
QgsRectangle currentExtent = mapSettings->mapSettings().visibleExtent();
356349
QgsGeometry currentExtentAsGeom = QgsGeometry::fromRect(currentExtent);
357350

358-
qDebug() << "geomExtend: " << currentExtentAsGeom.asWkt();
359-
360-
QgsGeometry intersected_geom = currentExtentAsGeom.intersection(geom);
361-
362-
qDebug() << "inter sected_geom: " << intersected_geom.asWkt();
363-
364-
365-
366-
// QgsPoint centroid = QgsPoint( intersected_geom.centroid().asPoint() );
367-
368-
369-
QgsRectangle bbox = intersected_geom.boundingBox();
370-
351+
QgsGeometry intersectedGeom = currentExtentAsGeom.intersection(geom);
371352

353+
QgsRectangle bbox = intersectedGeom.boundingBox();
372354
QgsPoint target = QgsPoint(bbox.center().x(), bbox.center().y());
373355

374-
QPoint pt = QPoint(bbox.center().x(), bbox.yMaximum());
375-
376356
screenPoint = mapSettings->coordinateToScreen( target );
377357

378-
379-
// return screenPoint.y();
380358
return screenPoint;
381359
}
382360

app/inpututils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class InputUtils: public QObject
9494
* Returns the true if the geometry could fully be contained in the current screen otherwise false
9595
* Geometry must be in canvas CRS
9696
*/
97-
Q_INVOKABLE bool canExtentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings );
98-
Q_INVOKABLE QPointF centerOnScreenHighligtedGeom( const QgsGeometry &geom, InputMapSettings *mapSettings );
97+
Q_INVOKABLE bool extentContainGeometry( const QgsGeometry &geom, InputMapSettings *mapSettings );
98+
Q_INVOKABLE QPointF onScreenGeometryCenterToScreenCoordinates( const QgsGeometry &geom, InputMapSettings *mapSettings );
9999

100100
// utility functions to extract information from map settings
101101
// (in theory this data should be directly available from .MapTransform

app/qml/map/MMMapController.qml

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,37 +1202,16 @@ Item {
12021202
function jumpToHighlighted( mapOffset ) {
12031203
if ( identifyHighlight.geometry === null )
12041204
return
1205-
1206-
if ( __inputUtils.canExtentContainGeometry( identifyHighlight.geometry, mapCanvas.mapSettings ) ){
1207-
let screenPt = __inputUtils.geometryCenterToScreenCoordinates( identifyHighlight.geometry, mapCanvas.mapSettings )
1208-
screenPt.y += mapOffset / 2
1209-
mapCanvas.jumpTo( screenPt )
1205+
let screenPt
1206+
if ( __inputUtils.extentContainGeometry( identifyHighlight.geometry, mapCanvas.mapSettings ) ){
1207+
screenPt = __inputUtils.geometryCenterToScreenCoordinates( identifyHighlight.geometry, mapCanvas.mapSettings )
12101208
}
12111209
else{
1212-
console.log("EXTENT CANNOT CONTAIN GEOMETRY");
1213-
1214-
// let distanceBottom = __inputUtils.centerOnScreenHighligtedGeom( identifyHighlight.geometry, mapCanvas.mapSettings )
1215-
let screenPt = __inputUtils.centerOnScreenHighligtedGeom( identifyHighlight.geometry, mapCanvas.mapSettings )
1216-
// console.log("distanceBottom")
1217-
// console.log(distanceBottom)
1218-
1219-
console.log("offset")
1220-
console.log((mapOffset / 2) )
1221-
1222-
//very bad
1223-
// let screenPt = Qt.point( Screen.width / 2 - width / 2 , Screen.height / 2 - height / 2 )
1224-
1225-
// if (distanceBottom > (mapOffset / 2) ) {
1226-
// return
1227-
// }
1228-
1229-
// screenPt.y += (mapOffset / 2) - distanceBottom
1230-
screenPt.y += mapOffset / 2
1231-
mapCanvas.jumpTo( screenPt )
1232-
1210+
screenPt = __inputUtils.onScreenGeometryCenterToScreenCoordinates( identifyHighlight.geometry, mapCanvas.mapSettings )
12331211
}
12341212

1235-
1213+
screenPt.y += mapOffset / 2
1214+
mapCanvas.jumpTo( screenPt )
12361215
}
12371216

12381217
function highlightPair( pair ) {

0 commit comments

Comments
 (0)