Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1353 from leyan/snapping_intersection
Check snapping tolerance of both layers before validating intersection snapping
  • Loading branch information
3nids committed May 16, 2014
2 parents 0f0a094 + d99dd8e commit f194822
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/gui/qgsmapcanvassnapper.cpp
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 f194822

Please sign in to comment.