Hi,
I'm working on swapping out the sketch editor with the new geometry editor. I have a need to be able to programmatically select the last vertex in the current part of a polyline or polygon geometry. This might be necessary if the user interactively selected another vertex during the sketch. I can't see a straightforward way to accomplish this via existing APIs. Would appreciate a pointer from anyone who is more knowledgeable it this area.
Thanks!
Solved! Go to Solution.
Hello @Mike_Quetel ,
Yes, this is possible. First, determine the index of the last vertex of your multipart (polygon/polyline). Then use the SelectVertex method, passing in your geometry part and that last vertex index. For example:
var lastVertexIndex = ((Multipart)YourGeometryEditor.Geometry).Parts[0].Count - 1;
YourGeometryEditor.SelectVertex(0, lastVertexIndex);
Your calculation of lastVertexIndex might differ depending on the amount of parts of the geometry and if dealing with a polygon or polyline.
-William
Hello @Mike_Quetel ,
Yes, this is possible. First, determine the index of the last vertex of your multipart (polygon/polyline). Then use the SelectVertex method, passing in your geometry part and that last vertex index. For example:
var lastVertexIndex = ((Multipart)YourGeometryEditor.Geometry).Parts[0].Count - 1;
YourGeometryEditor.SelectVertex(0, lastVertexIndex);
Your calculation of lastVertexIndex might differ depending on the amount of parts of the geometry and if dealing with a polygon or polyline.
-William
Appreciate the pointer in the right direction!
You are welcome! Upon consulting our geometry editor expert, a few more details to consider. You'll want to further adjust the index if it is a polygon type with current code, for example
var indexAdjustment = geom.getGeometryType() == GeometryType.POLYLINE ? 0 : 1;
and ensuring that select is not called when geometry has 0 points or index is -1. There is definitely prettier ways to refactor the code, typecasting works here but you also might consider separate cases for polygon vs polyline for easier code readability. Up to you how you would like your implementation of select last vertex 🙂
Feel free to post in ArcGIS Ideas if this a method you would like included in our API.
Thank you again! The reason I was asking is that I am trying to work around some odd behavior I'm seeing (200.2) when trying to insert a vertex at the end of a polyline or polygon. My understanding is that InsertVertex inserts after the currently selected vertex or at the end, if nothing is selected. If I interactively select a vertex that isn't the last one, then call ClearSelection(), InsertVertex() is still inserting after the vertex that was selected prior to calling ClearSelection(). I confirmed that SelectedElement is null before calling insert. Might be a bug.
Hi @Mike_Quetel
We've looked into your bug and haven't been able to reproduce it on our end. Feel free to provide a reproducer and we'll gladly take another look.