I have a polygonshape., Inside this polygon I am drawing a line. When I get near any spot along the polygon (not just the vertices) I need the end of the line being drawn to snap to the line on the polygonshape. I am able to successfully get the spot on the line. My problem is I cannot snap it correctly. I have tried two different ways:
- Set the end of the lineshape to the new position., When I try this using the below code, it actually adds a vertex to the lineshape and then the line won’t move at all until I click the left mouse button, which starts the line moving again with the new vertex as the second point.
var lineShape = Map.TrackOverlay.TrackShapeLayer.InternalFeatures[Map.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1].GetShape() as LineShape;
lineShape.Vertices[lineShape.Vertices.Count - 1] = newVertex;
Map.TrackOverlay.Refresh();
2. Set the cursor position to a pointshape. The second option was moving the cursor to the new position using the code below. The problem with this one is that the cursor never moves to the correct position on the screen…it’s always way off. I also tried using “ExtentHelper.ToScreenCoordinate” but that moves the cursor to the same position as the Map.ToScreenCoordinate does.
var ps = new PointShape(newVertex);
var screen = Map.ToScreenCoordinate(ps);
NativeMethods.SetCursorPos((int)screen.X, (int)screen.Y);
Map.TrackOverlay.Refresh();
public partial class NativeMethods
{
/// Return Type: BOOL->int
///X: int
///Y: int
[System.Runtime.InteropServices.DllImportAttribute(“user32.dll”, EntryPoint = “SetCursorPos”)]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool SetCursorPos(int X, int Y);
}
Does anyone know how I can either set the end of the line to the new vertex without actually adding it as a vertex, thus allowing the user to continue moving the cursor around as they normally would before they add a second point, OR how to set the cursor to the correct screen coordinates?