Select to view content in your preferred language

Silverlight Editing:  Add Polygon to a feature layer

4126
6
02-16-2012 09:47 AM
LuisPenedo
Emerging Contributor
I want to add the capability of adding a polygon to a layer in an ArcGIS server Silverlight application.  The only way I have found is using the editor toolkit.  It has a command "ADD" that I can bind to an icon and it allows to draw a polygon on the map.  What I want is to find out what commands this toolkit is based on and use them to send a set of points from another command or click event and get the polygon on the map through code.  I have seen some solutions out there (honestly only one) that does that which is a proof that this is doable.

Any suggestions?

Thanks in advance.
0 Kudos
6 Replies
SelçukTınaz
Occasional Contributor
Do you mean what other commands can be used with editor or else,

can you explain little more
0 Kudos
JenniferNery
Esri Regular Contributor
This SDK sample might help: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave and API reference: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor.htm...

The Toolkit.EditorWidget is using Toolkit.TemplatePicker and Editor (Select, EditVertices, Cut, Reshape, Union, DeleteSelected, ClearSelection, SaveEdits). TemplatePicker is also using Editor (Add). This becomes more apparent when you get the EditorWidget or TemplatePicker style using the following blog post: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/05/28/Localizing-ArcGIS-Controls.aspx.
0 Kudos
LuisPenedo
Emerging Contributor
Thanks for replying.  Those links are helpful but what I am looking for is a way to do what those widgets do but with code and not by implementing their functions.  Instead of using the commands in the Editor, I want to build editing commands.  My interest is building these commands with some extra functionality.  For example, when adding a polygon:  If I add a polygon that intersects an existing polygon, I mean, there is a common intersection area, then I want to trim this intersection polygon off of the newly added polygon.    

Thanks for any help.
0 Kudos
JenniferNery
Esri Regular Contributor
Editor has EditorActivated and EditCompleted events, which you can use to do the additional operation you wish to do.

If you want these commands triggered in code-behind, you can do:
if(editor.Cut.CanExecute(null))
     editor.Cut.Execute(null); //where null is the Command parameter
0 Kudos
OrlandoCarvajal
Deactivated User
You should be able to use a Draw object with any shape to obtain a polygon or a rectangle, then add a Graphic object to the layer and save it. Something like this:


                graphic = new Graphic();
                graphic.Attributes.Add("USER", Application.Current.GetUserName());
                // Set other attributes
                ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon();
                poly.Rings.Add(new ESRI.ArcGIS.Client.Geometry.PointCollection());
                poly.Rings[0].Add(new MapPoint(rect.XMin, rect.YMin));
                poly.Rings[0].Add(new MapPoint(rect.XMin, rect.YMax));
                poly.Rings[0].Add(new MapPoint(rect.XMax, rect.YMax));
                poly.Rings[0].Add(new MapPoint(rect.XMax, rect.YMin));
                graphic.Geometry = poly;
                featureLayer.Graphics.Add(graphic);
                featureLayer.SaveEdits();


Cheers
0 Kudos
JenniferNery
Esri Regular Contributor
Reading back to your question, I think what you want to do is AutoComplete against existing features? If yes, you can try this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave. Check AutoSelect and AutoComplete, before you add a Polygon that will overlap existing features. After adding the feature, you will see by selecting (using Select) or moving it (using EditVertices), that it completed the draw against neighboring features.

The same properties AutoComplete and AutoSelect are available in EditorWidget and TemplatePicker.
0 Kudos