Skip to content

Commit f194822

Browse files
committed
Merge pull request #1353 from leyan/snapping_intersection
Check snapping tolerance of both layers before validating intersection snapping
2 parents 0f0a094 + d99dd8e commit f194822

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/gui/qgsmapcanvassnapper.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,27 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
304304
QgsGeometry* intersectionPoint = lineA->intersection( lineB );
305305
if ( intersectionPoint->type() == QGis::Point )
306306
{
307-
iSegIt->snappedVertex = intersectionPoint->asPoint();
308-
myResults.append( *iSegIt );
307+
//We have to check the intersection point is inside the tolerance distance for both layers
308+
double toleranceA, toleranceB;
309+
for ( int i = 0 ;i < snapLayers.size();++i )
310+
{
311+
if ( snapLayers[i].mLayer == oSegIt->layer )
312+
{
313+
toleranceA = QgsTolerance::toleranceInMapUnits( snapLayers[i].mTolerance, snapLayers[i].mLayer, mMapCanvas->mapSettings(), snapLayers[i].mUnitType );
314+
}
315+
if ( snapLayers[i].mLayer == iSegIt->layer )
316+
{
317+
toleranceB = QgsTolerance::toleranceInMapUnits( snapLayers[i].mTolerance, snapLayers[i].mLayer, mMapCanvas->mapSettings(), snapLayers[i].mUnitType );
318+
}
319+
}
320+
QgsPoint point = mMapCanvas->getCoordinateTransform()->toMapCoordinates( p );
321+
QgsGeometry* cursorPoint = QgsGeometry::fromPoint( point );
322+
double distance = intersectionPoint->distance( *cursorPoint );
323+
if ( distance < toleranceA && distance < toleranceB )
324+
{
325+
iSegIt->snappedVertex = intersectionPoint->asPoint();
326+
myResults.append( *iSegIt );
327+
}
309328
}
310329
}
311330
}

0 commit comments

Comments
 (0)