protected virtual SnapInfo ComputeSnappedLocation(GeoMouseArgs e, Coordinate coordinate) { SnapInfo snapInfo = null; if (coordinate == null) { return(snapInfo); } snapInfo = ComputeSnappedLocation(e); if (snapInfo == null) { return(snapInfo); } coordinate.X = snapInfo.Coordinate.X; coordinate.Y = snapInfo.Coordinate.Y; coordinate.Z = snapInfo.Coordinate.Z; coordinate.M = snapInfo.Coordinate.M; return(snapInfo); }
/// <summary> /// Computes a snapped coordinate. If the mouse is near a snappable object, the output /// location of the mouse will be the coordinates of the object rather than the actual /// mouse coords. /// </summary> /// <param name="e">The event args.</param> /// <returns>SnapInfo</returns> protected virtual SnapInfo ComputeSnappedLocation(GeoMouseArgs e) { SnapInfo snapInfo = null; if (SnapLayers == null || e == null || Map == null || SnapMode == SnapMode.None) { return(snapInfo); } Rectangle mouseRect = new Rectangle(e.X - SnapTol, e.Y - SnapTol, SnapTol * 2, SnapTol * 2); Extent extent = Map.PixelToProj(mouseRect); if (extent == null) { return(snapInfo); } if (SnapMode == SnapMode.None) { return(snapInfo); } Tuple <IFeature, Coordinate> tuple = null; SnapMode snapMode = SnapMode.None; if ((SnapMode & SnapMode.Point) > 0) { foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible)) { tuple = ComputSnapPointModeFeature(layer, extent); if (tuple != null) { snapMode = SnapMode.Point; goto Success; } } } if ((SnapMode & SnapMode.End) > 0) { foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible)) { tuple = ComputSnapEndModeFeature(layer, extent); if (tuple != null) { snapMode = SnapMode.End; goto Success; } } } if ((SnapMode & SnapMode.Vertex) > 0) { foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible)) { tuple = ComputSnapVertexModeFeature(layer, extent); if (tuple != null) { snapMode = SnapMode.Vertex; goto Success; } } } if ((SnapMode & SnapMode.Edege) > 0) { foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible)) { tuple = ComputSnapEdegeModeFeature(layer, extent, e.GeographicLocation); if (tuple != null) { snapMode = SnapMode.Edege; goto Success; } } } Success: if (tuple != null) { snapInfo = new SnapInfo() { Feature = tuple.Item1, Coordinate = tuple.Item2, SnapMode = snapMode }; } return(snapInfo); }