Hello,
I am trying to delete a vertex from an existing polyline, and I cannot seem to figure out the workflow to do it. From a UX perspective, my idealized version of the workflow would be to start an edit operation on a polyline, select a particular vertex, right click to open a context menu, and then click a 'Delete' button. That part of the workflow I can do, but I can't figure out what to do in the code after the 'Delete' button has been clicked.
How do I get access to selected vertex?
So it seems like i am not on quite on the right path for now. Any help or guidance would be greatly appreciated.
Thank you.
Sample Code
Progress<GeometryEditStatus> progress = new Progress<GeometryEditStatus>(); progress.ProgressChanged += progress_ProgressChanged; Geometry.Geometry newPolyline = await mv.Editor.EditGeometryAsync(g.Geometry, null, progress); progress.ProgressChanged -= progress_ProgressChanged; void progress_ProgressChanged(object sender, GeometryEditStatus e) { if (e.GeometryEditAction == GeometryEditAction.MovedVertex) { ICommand delete = mv.Editor.DeleteVertex; delete.Execute(e.VertexPosition); } }
Solved! Go to Solution.
Have you tried extending the Editor class? I'm able to accomplish this with the logic shown below:
public class MyEditor : Editor { private VertexPosition _vertexPosition ; public VertexPosition MyPosition { get { return this._vertexPosition; } set { this._vertexPosition = value; } } public MyEditor() { _vertexPosition = null; } protected override Symbol OnGenerateSymbol(GenerateSymbolInfo generateSymbolInfo) { if (generateSymbolInfo.GenerateSymbolType == GenerateSymbolType.SelectedVertex) _vertexPosition = generateSymbolInfo.VertexPosition; return base.OnGenerateSymbol(generateSymbolInfo); } }
As a result of geometries being immutable I don't believe you would be able to modify an existing geometry's vertices. Instead, you should be able to use the builder to create a new line or polygon with your needed change. For example, I use this approach to move the vertices for polygons to the current gps location. I use the following line to get an array of the vertices for my selected polygon.
var points = ((Polygon) EditGeometry).Parts[0].GetPoints().ToArray();
Once I have the array of points I then use the index of the selected vertex to manipulate this array prior to calling the PolygonBuilder and creating a new polygon with my needed geometry.
Have you tried extending the Editor class? I'm able to accomplish this with the logic shown below:
public class MyEditor : Editor { private VertexPosition _vertexPosition ; public VertexPosition MyPosition { get { return this._vertexPosition; } set { this._vertexPosition = value; } } public MyEditor() { _vertexPosition = null; } protected override Symbol OnGenerateSymbol(GenerateSymbolInfo generateSymbolInfo) { if (generateSymbolInfo.GenerateSymbolType == GenerateSymbolType.SelectedVertex) _vertexPosition = generateSymbolInfo.VertexPosition; return base.OnGenerateSymbol(generateSymbolInfo); } }
As a result of geometries being immutable I don't believe you would be able to modify an existing geometry's vertices. Instead, you should be able to use the builder to create a new line or polygon with your needed change. For example, I use this approach to move the vertices for polygons to the current gps location. I use the following line to get an array of the vertices for my selected polygon.
var points = ((Polygon) EditGeometry).Parts[0].GetPoints().ToArray();
Once I have the array of points I then use the index of the selected vertex to manipulate this array prior to calling the PolygonBuilder and creating a new polygon with my needed geometry.
Thank you for the tip. I will give it a try and let you know how it goes.
Hi Freddie,
Extending the Editor class worked like a charm. Thank you.
And fortunately there was no real additional code I needed to write to Delete the vertex. I just passed in the VertexPosition object from the extended Editor to the Delete command, and the selected vertex was deleted.