Select to view content in your preferred language

How do I delete a vertex from an existing polyline?

3215
3
Jump to solution
10-09-2015 11:30 AM
TomRippetoe
Deactivated User

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?

  • There is a private property (m_VertexPosition) on the MapView.Editor object that I would like to access but can't get to directly. Ideally, that should be a public property that I could get to.
  • There is a VertexPosition property in the GeometryEditStatus event object that is passed into the 'Progess.ProgressChanged' event, but that event seems to be raised only after some edit action, e.g. move, etc, has been performed. And I am not sure how to manually raise the event with a fully populated GeometryEditStatus
  • I though about using a 'mousedown' event when the vertex is selected, and iterating over the Editor's input geometry to find a matching coordinate pair, but what happens if the user wants to delete a vertex that was added as part of the edit action and is not part of the input geometry

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);
       }
}
0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Honored Contributor

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.

View solution in original post

0 Kudos
3 Replies
FreddieGibson
Honored Contributor

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.

0 Kudos
TomRippetoe
Deactivated User

Thank you for the tip. I will give it a try and let you know how it goes.

0 Kudos
TomRippetoe
Deactivated User

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.

0 Kudos