Select to view content in your preferred language

Using the Editor class to Edit Graphics from a GraphicsLayer

1094
7
09-21-2010 02:19 PM
FrancoisChartrand
Emerging Contributor
Hi,

I'm using a GraphicsLayer with some polygons. I want to be able to edit the vertices of these polygons.

Can I do it using the ESRI.ArcGIS.Client.Editor set of commands (Add, CancelActive, ClearSelection, Cut, DeleteSelected, EditVertices, Move, Reshape, Save and Union) ?

All the selection commands seem to work fine but the EditVertices is not. Do I need a Geometry Service even if I'm working with a GraphicsLayer ?

Thank you
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
All the Editor commands should also work on your GraphicsLayer provided that this layer belongs to the Map, has a specified ID and is not excluded in the LayerIDs property. And yes, you need to set GeometryServiceUrl in order to perform Cut, Reshape, Union, AutoComplete Add, and AutoSelect.

For EditVertices, make sure CommandParameter is set to null.
0 Kudos
FrancoisChartrand
Emerging Contributor
It doesn't work... Here is my checklist:
- The GraphicsLayer has an ID
- The GraphicsLayer belongs to the Map
- The GraphicsLayer's ID is the only ID in LayerIDs
- The GeometryServiceUrl is not set (but it is not required for the EditVertices command, right?)
- Editor.EditVertices.CanExecute(null) returns true
- Editor.EditVertices.Execute(null) is called with no paramater

Result: I can move the graphics, but I cannot edit the vertices.

To draw the polygons, I'm using the Draw class as shown in this sample. The FillSymbol has a custom ControlTemplate. Could it be related?

Thank you
0 Kudos
JenniferNery
Esri Regular Contributor
Using the same SDK sample link that you provided, I added the following:
Under Grid.Resources:
<esri:Editor x:Key="MyEditor"  Map="{Binding ElementName=MyMap}"/>
And inserted this before the Grid closes:
<Button Content="EditVertices" HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{StaticResource MyEditor}" Command="{Binding EditVertices}" CommandParameter="{x:Null}"/>

I'm able to Move/Edit geometry using EditVertices command. I do notice that if you added a rectangle, you're only allowed to move the graphic. If you added a polygon, you should be able to edit the vertices of the graphic.
0 Kudos
FrancoisChartrand
Emerging Contributor
You are right 😮 I was using rectangles...

Is there any reason why it is not possible to edit rectangles?
0 Kudos
JenniferNery
Esri Regular Contributor
Thank you for your post. We just found out after reproducing your issue that we currently do not support editing vertices of an Envelope geometry (or Rectangle). However, this is something we might look into after 2.1.
0 Kudos
FrancoisChartrand
Emerging Contributor
As a workaround, I'm converting the Envelope geometry to a Polygon. This allows moving and editing the rectangles. However, the rectangles are loosing their right angles when editing them.

private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)
{
    GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

    Envelope envelope = (Envelope)args.Geometry;

    Polygon rectangle = new Polygon();
    PointCollection pointCollection = new PointCollection
    {
        new MapPoint(envelope.XMin, envelope.YMin),
        new MapPoint(envelope.XMin, envelope.YMax),
        new MapPoint(envelope.XMax, envelope.YMax),
        new MapPoint(envelope.XMax, envelope.YMin),
        new MapPoint(envelope.XMin, envelope.YMin)
    };
    rectangle.Rings.Add(pointCollection);

    ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
    {
        Geometry = rectangle,
        Symbol = _activeSymbol,
    };

    graphicsLayer.Graphics.Add(graphic);
}
0 Kudos
JenniferNery
Esri Regular Contributor
I just came across this forum thread. If you are interested to try out v2.2 beta: http://help.arcgis.com/en/webapi/silverlight/2.2/samples/start.htm#DrawGraphics. EditVertices now support Envelope geometry through scaling.
0 Kudos