@@ -990,8 +990,39 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer *layer )
990
990
}
991
991
992
992
rect = mapSettings ().layerExtentToOutputExtent ( layer, rect );
993
+
994
+ // zoom in if point cannot be distinguish from others
995
+ // also check that rect is empty, as it might not in case of multi points
996
+ if ( layer->geometryType () == QgsWkbTypes::PointGeometry && rect.isEmpty () )
997
+ {
998
+ QgsPointXY center = mSettings .mapToLayerCoordinates ( layer, rect.center () );
999
+ QgsRectangle extentRect = mSettings .mapToLayerCoordinates ( layer, extent () );
1000
+ QgsFeatureRequest req = QgsFeatureRequest ().setFilterRect ( extentRect ).setLimit ( 1000 ).setNoAttributes ();
1001
+ QgsFeatureIterator fit = layer->getFeatures ( req );
1002
+ QgsFeature f;
1003
+ QgsPointXY closestPoint;
1004
+ double closestSquaredDistance = extentRect.width () + extentRect.height ();
1005
+ bool pointFound = false ;
1006
+ while ( fit.nextFeature ( f ) )
1007
+ {
1008
+ QgsPointXY point = f.geometry ().asPoint ();
1009
+ double sqrDist = point.sqrDist ( center );
1010
+ if ( sqrDist > closestSquaredDistance || sqrDist < 4 * std::numeric_limits<double >::epsilon () )
1011
+ continue ;
1012
+ pointFound = true ;
1013
+ closestPoint = point;
1014
+ closestSquaredDistance = sqrDist;
1015
+ }
1016
+ if ( pointFound )
1017
+ {
1018
+ // combine selected point with closest point and scale this rect
1019
+ rect.combineExtentWith ( mSettings .layerToMapCoordinates ( layer, closestPoint ) );
1020
+ rect.scale ( 5 , ¢er );
1021
+ }
1022
+ }
1023
+
993
1024
zoomToFeatureExtent ( rect );
994
- } // zoomToSelected
1025
+ }
995
1026
996
1027
void QgsMapCanvas::zoomToFeatureExtent ( QgsRectangle &rect )
997
1028
{
0 commit comments