What I would like is for the user to click on the map to create a starting point on the map and then continue click on points on the map to add vertices to the line. I would like to use the class DragInteractiveOverlay which is a custom class I found in one of the samples, it inherits EditInteractiveOverlay Class.
DragInteractiveOverlay dragInteractiveOverlay = new DragInteractiveOverlay();
LineShape line1 = new LineShape();
Vertex vb = new Vertex(-97.7591, 30.3126);
Vertex vb1 = new Vertex(-97.7591, 30.3);
line1.Vertices.Add(vb);
line1.Vertices.Add(vb1);
line1.Id = "line1";
dragInteractiveOverlay.EditShapesLayer.InternalFeatures.Add(new Feature(line1));
dragInteractiveOverlay.CanAddVertex = false;
dragInteractiveOverlay.CanDrag = true;
dragInteractiveOverlay.CanRemoveVertex = false;
dragInteractiveOverlay.CanResize = false;
dragInteractiveOverlay.CanRotate = false;
dragInteractiveOverlay.CalculateAllControlPoints();
winformsMap1.EditOverlay = dragInteractiveOverlay;
This will create a line on the map with the two points specified, and if I try to extend the line by adding the following code to the mapclick event handler, nothing happens. (note I declared the line in the class so it can be accessed by any method)
Vertex v = new Vertex(e.WorldLocation);
line1.Vertices.Add(v);
dragInteractiveOverlay.EditShapesLayer.Open();
dragInteractiveOverlay.EditShapesLayer.EditTools.BeginTransaction();
dragInteractiveOverlay.EditShapesLayer.EditTools.Update(line1);
dragInteractiveOverlay.EditShapesLayer.EditTools.CommitTransaction();
dragInteractiveOverlay.EditShapesLayer.Close();
This updating worked for gps tracking when I wanted to show the movement of a moving object, if there is a better way to add a line I try something else but I like the way this line works.