Skip to content

Commit

Permalink
check snapping tolerance of both layers before validating intersectio…
Browse files Browse the repository at this point in the history
…n snapping
  • Loading branch information
leyan committed May 15, 2014
1 parent 156dc55 commit d99dd8e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/gui/qgsmapcanvassnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,27 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QPoint& p, QList<QgsSnapp
QgsGeometry* intersectionPoint = lineA->intersection( lineB );
if ( intersectionPoint->type() == QGis::Point )
{
iSegIt->snappedVertex = intersectionPoint->asPoint();
myResults.append( *iSegIt );
//We have to check the intersection point is inside the tolerance distance for both layers
double toleranceA, toleranceB;
for ( int i = 0 ;i < snapLayers.size();++i )
{
if ( snapLayers[i].mLayer == oSegIt->layer )
{
toleranceA = QgsTolerance::toleranceInMapUnits( snapLayers[i].mTolerance, snapLayers[i].mLayer, mMapCanvas->mapSettings(), snapLayers[i].mUnitType );
}
if ( snapLayers[i].mLayer == iSegIt->layer )
{
toleranceB = QgsTolerance::toleranceInMapUnits( snapLayers[i].mTolerance, snapLayers[i].mLayer, mMapCanvas->mapSettings(), snapLayers[i].mUnitType );
}
}
QgsPoint point = mMapCanvas->getCoordinateTransform()->toMapCoordinates( p );
QgsGeometry* cursorPoint = QgsGeometry::fromPoint( point );
double distance = intersectionPoint->distance( *cursorPoint );
if ( distance < toleranceA && distance < toleranceB )
{
iSegIt->snappedVertex = intersectionPoint->asPoint();
myResults.append( *iSegIt );
}
}
}
}
Expand Down

0 comments on commit d99dd8e

Please sign in to comment.