public void OnSnapPointRequested(SnapPointRequestedEventArgs e) { // If there are no restrictions active, don't interfere if (!activeRestrictions.Any()) { return; } double tolerance = MapConfig.GetProjectedMouseTolerance(_context.Map); var snapPointChecker = new SnapPointCandidateChecker(new Coordinate(e.PointX, e.PointY), tolerance); // First try to snap to an intersection of two restrictions (if possible) bool success = snapPointChecker.ContainsBetterCandidate(c => GetIntersectionBetweenRestrictions(c, tolerance)); // Then try to snap to an intersection of a restriction with layer geometries if (!success) { success = snapPointChecker.ContainsBetterCandidate(c => GetIntersectionsWithLayerFeatures(c, tolerance)); } // Try a regular snap to the restrictions if (!success) { success = snapPointChecker.ContainsBetterCandidateWithoutTolerance(GetSnapPoints); } e.SnappedX = snapPointChecker.BestSnapPoint.X; e.SnappedY = snapPointChecker.BestSnapPoint.Y; e.IsFinal = true; e.IsFound = true; }
public void SnapSlope(ICoordinate anchor, double slope, ICoordinate offsetAnchor = null, bool needsUserInput = true, int handle = 0) { var restriction = new LinearRestriction(anchor, slope, handle); double offset = 0; if (offsetAnchor != null) { double tolerance = MapConfig.GetProjectedMouseTolerance(_context.Map); offset = restriction.GetOffsetDistance(offsetAnchor, tolerance); restriction.OffsetByDistance(offset); } AddRestriction(restriction); if (!needsUserInput) { return; } void inputAction(double value) { restriction.OffsetByDistance(value); restriction.RefreshGuideline(_context.Map as IMap); } // Show input box to end-user to enter the bearing // live updating the map with the snap line RequestUserInput( inputAction, "Offset:", offset, anchor ); }