@@ -303,60 +303,40 @@ void InputUtils::setExtentToFeature( const FeatureLayerPair &pair, InputMapSetti
303303 mapSettings->setExtent ( currentExtent );
304304}
305305
306- QPointF InputUtils::geometryCenterToScreenCoordinates ( const QgsGeometry &geom, InputMapSettings *mapSettings )
306+ QPointF InputUtils::onScreenGeometryCenterToScreenCoordinates ( const QgsGeometry &geom, InputMapSettings *mapSettings )
307307{
308308 QPointF screenPoint;
309-
309+ QgsPoint target;
310310 if ( !mapSettings || geom.isNull () || !geom.constGet () )
311311 return screenPoint;
312312
313- QgsRectangle bbox = geom.boundingBox ();
314- screenPoint = mapSettings->coordinateToScreen ( QgsPoint ( bbox.center () ) );
315-
316- return screenPoint;
317- }
318- /* *
319- * Returns true if the geometry \a geom is fully contain within the current map extent
320- *
321- * Nota Bene: Assume geometry and map canvas CRS are the same
322- */
323- bool InputUtils::extentContainGeometry ( const QgsGeometry &geom, InputMapSettings *mapSettings )
324- {
325- if ( !mapSettings || geom.isNull () || !geom.constGet () )
326- return false ;
327-
328313 QgsRectangle currentExtent = mapSettings->mapSettings ().visibleExtent ();
329314 QgsRectangle geomBbox = geom.boundingBox ();
330315
331- return currentExtent.contains ( geomBbox );
332- }
316+ qDebug () << " currentExtent:" << currentExtent.xMinimum ()<<" ,"
317+ << currentExtent.yMinimum ()<<" ,"
318+ << currentExtent.xMaximum ()<<" ,"
319+ << currentExtent.yMaximum ();
320+ qDebug () << " geom:" << geom.asWkt ();
333321
334322
335- /* *
336- * Returns the center point of the \a geom currently display on screen
337- *
338- * Nota Bene: Assume geometry and map canvas CRS are the same
339- */
340- QPointF InputUtils::onScreenGeometryCenterToScreenCoordinates ( const QgsGeometry &geom, InputMapSettings *mapSettings )
341- {
342- QPointF screenPoint;
343- if ( !mapSettings || geom.isNull () || !geom.constGet () )
344- return screenPoint;
345-
346- QgsRectangle currentExtent = mapSettings->mapSettings ().visibleExtent ();
347- QgsGeometry currentExtentAsGeom = QgsGeometry::fromRect ( currentExtent );
348-
349- QgsGeometry intersectedGeom = currentExtentAsGeom.intersection ( geom );
350-
351- QgsRectangle bbox = intersectedGeom.boundingBox ();
352- QgsPoint target = QgsPoint ( bbox.center ().x (), bbox.center ().y () );
323+ if (currentExtent.contains ( geomBbox )){
324+ // Keep the geometry as is
325+ target = QgsPoint ( geomBbox.center () );
326+ }
327+ else {
328+ // Cut the geometry to current extent
329+ QgsGeometry currentExtentAsGeom = QgsGeometry::fromRect ( currentExtent );
330+ QgsGeometry intersectedGeom = geom.intersection ( currentExtentAsGeom );
331+ QgsRectangle bbox = intersectedGeom.boundingBox ();
332+ target = QgsPoint ( bbox.center () );
333+ }
353334
354335 screenPoint = mapSettings->coordinateToScreen ( target );
355-
336+ qDebug () << " screenPoint: " << screenPoint;
356337 return screenPoint;
357338}
358339
359-
360340double InputUtils::convertCoordinateString ( const QString &rationalValue )
361341{
362342 QStringList values = rationalValue.split ( " ," );
0 commit comments