Select to view content in your preferred language

Defining new vertex distance while editing

1577
9
01-12-2012 07:26 AM
RafaelCarvalho
Emerging Contributor
Hi Everyone,

I'm trying to reproduce on a Silverlight Application the "Length" resource availiable while editing/adding to a feature class on ArcMap Desktop Software. Is there a way to constraint the length of the line that identifies where the new vertex for a polygon is going to be fixed?

I would appreciate any help! Thanks!!! 🙂
0 Kudos
9 Replies
RafaelCarvalho
Emerging Contributor
Hello again!

I've been trying to find a solution to this since yesterday, but I couldn't find none that would suit well for my project. I also couldn't find the class responsable to handle the line representation that indicates where the new vertex is going to be fixed while creating a geometric figure. Isn't there a event or a property where I can limit the length of this new line?

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
I'm not sure if this works for you but you can try updating this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsGeometry

VertexAdded is one of GeometryEdit action, you can compare the distance between vertices then and if the shortest distance is still outside the max distance, you can Undo the last edit.
        private void EditGeometry_GeometryEdit(object sender, EditGeometry.GeometryEditEventArgs e)
        {
   if (e.Action == EditGeometry.Action.VertexAdded)
   {
    var graphic = e.Graphic as Graphic;
    var polyline = graphic.Geometry as Polyline;
    var distance = double.NaN;
    var vertex = e.NewItems[0] as MapPoint;
    foreach (var p in polyline.Paths[0])
    {
     if (!double.IsNaN(distance)) break;
     var d = Math.Sqrt(Math.Pow(Math.Abs(vertex.X - p.X), 2) + Math.Pow(Math.Abs(vertex.Y - p.Y), 2));
     if (double.IsNaN(distance) || d < distance)
      distance = d;   
    }
    if (distance > maxDistance)
     editGeometry.UndoLastEdit();
   }
0 Kudos
RafaelCarvalho
Emerging Contributor
Hi Jennifer,

I already knew this event "VertexAdded", but what I wanted to do is to manipulate the line before the user click. Let me explain exactly what I want to do.

The user begins drawing a Geometry, and while adding new vertexes, he might click on an option named by "Define Length". Then, a modal pops up and asks him the length, in meters, that he wants to constrain. After that, he informs a Double value in a textbox and click ok. The line that shows up at the user interface ( The one that follows the mouse and represent the distance between the latest vertex added and where the new one is going to be ) should have EXACTLY the length the user typed.

I literally want to recreate the "Length" feature supported on ArcGIS Desktop while Editing. Is there a way I can manipulate the "Line" that follows the mouse? The one that indicates where the new vertex is going to be added... If so, this will help me a LOT, because I also need to implement the "parallel" and "perperndicular" features while editing.

Thank you so much!
0 Kudos
JenniferNery
Esri Regular Contributor
The code-snippet I posted is for editing.

If the graphic does not exist yet and you want to intercept the draw, you can use Draw.VertexAdded event, Draw.UndoLastVertex(), calculate new MapPoint, and Draw.AddVertex(newPoint). After the vertex was removed (UndoLastVertex), endpoint will be the start point from which you need to calculate the next point given the desired distance. Once you have this new point, you can AddVertex(newPoint).
PointCollection pnts = (_graphic.Geometry as Polyline).Paths[0];
MapPoint endPoint = pnts[pnts.Count - 1];
0 Kudos
RafaelCarvalho
Emerging Contributor
Hi Jennifer,

I'm developing this function to new graphics on the map, using the Draw class.  I'm not being able to detect the first vertex added position to refer myself. The vertexAdded event only works for the second vertex added and on... I tryed to get the mapPoint throught the mapClick event of my map, but it seens that when I'm on DrawMode, the mapClick event doesn't trigger.

        private void drawObjectVertexAdded(object sender, VertexAddedEventArgs args)
        {
            _drawingObjectMapPointCollection.Add(args.Vertex.Extent.GetCenter());
            _drawingObjectSpatialReferenceCollection.Add(args.Vertex.SpatialReference);
        }


The code above doesn't work on the first vertex added to the graphic 😞 . How can I get those references, considering that mapClick doesn't trigger while drawing?

I'm stucked, any help is welcome. Thank you.
0 Kudos
JenniferNery
Esri Regular Contributor
What version of the API are you using? v2.3 and up will raise VertexAdded even for the first point. You can quickly try the following code, VertexAdded is raised immediately after DrawBegin for the first point and then for every vertex added.
   
Draw d = new Draw(MyMap){DrawMode= ESRI.ArcGIS.Client.DrawMode.Polygon, IsEnabled = true};
   d.DrawBegin += (s, e) =>
    { 
     
    };
   d.DrawComplete += (s, e) =>
    {
    };
   d.VertexAdded += (s, e) =>
    {
    };
0 Kudos
RafaelCarvalho
Emerging Contributor
Hi Jennifer,

I'm using the version 3.0 of the API. The vertexAdded isn't triggered on the first vertex. I tryed using your code snippet, but I've encoutered the same problem using it. The drawBegin method gets triggered on the first vertex, but it can't handle the 2 parameters like you did on your code snippet "(s, e)", so I can't get the mapPoint.

[ATTACH=CONFIG]11415[/ATTACH]

You can see what I'm trying to do on the image above. I need the mapPoint reference for the first vertex circled in red. Thank you once again!
0 Kudos
JaredWhite
Regular Contributor
Did anyone ever solve this? It would be a very useful tool.
0 Kudos
JenniferNery
Esri Regular Contributor
EditGeometry will allow you to UndoLastEdit/RedoLastEdit but not add a vertex. However, draw will allow you to AddVertex to a specific location and UndoLastVertex.
0 Kudos