Select to view content in your preferred language

Issue with committing edits to graphics

873
7
04-13-2011 03:13 PM
AndyWright
Frequent Contributor
I am having an interesting problem when trying to commit an edit I just performed on a polygon graphic.  The only way I know of to commit an edit to a graphic is to click on the graphic that was just edited or another graphic in the map (as long as it's not a point?!?).  This works fine as long as the initial edit on that graphic was initiated by a click on the graphic when the editor is placed into EditVertices mode with the following command:

Editor.EditVertices.Execute(null);

If I try to use that same command to place a specific graphic into edit mode automatically, the commit stuff starts to get whacked out.  Here's the command I use:

Editor.EditVertices.Execute([graphic object]);

That puts the edit handles on the polygon just fine.  So then I can move that graphic to a new location, but when I click on it to commit the edit the polygon goes back to its original location.  When I click on it again it moves back to the location it was at after the first move.  Weird behavior, no?  So this seems like a bug, but I wanted to see if anyone else has experienced a similar issue and knows how to get around it.  This is obviously not desired behavior.  I am including my stripped down XAML and C# code so the problem can be recreated. 

Here are the steps to recreate:

1)  Click the Add Poly button and draw a polygon on the map
2)  Click the Edit Vertices button to place that polygon into edit mode
3)  Move the polygon to a new location
4)  Click it to commit the edit.  The polygon should move back to where it was originally.
5)  Click it again. The polygon should now move back to where you first moved it.

Thanks in advance for any help with this.

Here's the XAML code:

<UserControl x:Class="ESRIEditingTest.MainPage"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
    
    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <esri:Editor x:Name="MyEditor" ContinuousMode="True"
                         Map="{Binding ElementName=MyMap}" 
                         LayerIDs="Graphics"
                         GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer" />
        </Grid.Resources>

        <esri:Map x:Name="MyMap" Extent="-13054165,3850112,-13027133,3863559" esri:Editor.SnapDistance="20" esri:Editor.SnapKey="S">
            <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
            <esri:GraphicsLayer ID="Graphics" />
        </esri:Map>

        <Border Background="#FF919191" BorderThickness="1" CornerRadius="5"
             HorizontalAlignment="Right"  VerticalAlignment="Top"
             Padding="5" BorderBrush="Black" Margin="0,5,5,0"
                DataContext="{StaticResource MyEditor}">

            <StackPanel x:Name="EditorTools" Orientation="Vertical">
                <StackPanel Orientation="Horizontal">
                    <Button x:Name="AddPolyButton" Margin="2" Click="AddPolyButton_Click">
                        <TextBlock>Add Poly</TextBlock>
                    </Button>
                    <Button x:Name="EditVertices" Margin="2" Click="EditVerticesButton_Click">
                        <TextBlock>Edit Vertices</TextBlock>
                    </Button>
                    <Button x:Name="ClearGRaphics" Margin="2" Click="ClearGraphicsButton_Click">
                        <TextBlock>Clear Graphics</TextBlock>
                    </Button>
                </StackPanel>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>


Here's the C# code:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Symbols;

namespace ESRIEditingTest
{
    public partial class MainPage : UserControl
    {
        GraphicsLayer _gl;
        private Draw _drawObject = new Draw();

        public MainPage()
        {
            InitializeComponent();
            MyMap.Loaded += new RoutedEventHandler(MyMap_Loaded);
        }

        void MyMap_Loaded(object sender, RoutedEventArgs e)
        {
            _drawObject.Map = MyMap;
            _drawObject.DrawComplete += new EventHandler<DrawEventArgs>(_drawObject_DrawComplete);
            _gl = MyMap.Layers["Graphics"] as GraphicsLayer;
        }

        void _drawObject_DrawComplete(object sender, DrawEventArgs e)
        {           
            Graphic gr = new Graphic();

            SimpleFillSymbol sfs = new SimpleFillSymbol();
            sfs.Fill = new SolidColorBrush(Colors.Red);

            Polygon p = e.Geometry as Polygon;
            gr = new Graphic
            {
                Geometry = p,
                Symbol = sfs
            };

            _gl.Graphics.Add(gr);

            _drawObject.IsEnabled = false;
        }

        private void AddPolyButton_Click(object sender, RoutedEventArgs e)
        {
            _drawObject.IsEnabled = true;
            _drawObject.DrawMode = DrawMode.Polygon;
        }

        private void EditVerticesButton_Click(object sender, RoutedEventArgs e)
        {
            _drawObject.IsEnabled = false;
            MyEditor.EditVertices.Execute(_gl.Graphics[0]);
        }

        private void ClearGraphicsButton_Click(object sender, RoutedEventArgs e)
        {
            _gl.Graphics.Clear();
        }
    }
}
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
Editing Graphics in GraphicsLayer is similar to editing Graphics in FeatureLayer.

The simplest way is to use Editor.Add and Editor.EditVertices. This requires no code-behind unless you want to activate Editor commands using button click event.
    <Grid x:Name="LayoutRoot" Background="White">
  <Grid.Resources>
   <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Style="Circle" Size="15"/>
   <esri:SimpleLineSymbol x:Key="RedLineSymbol" Color="Red" Style="DashDot" Width="5"/>
   <esri:SimpleFillSymbol x:Key="RedFillSymbol" Fill="Red" BorderBrush="DarkRed" BorderThickness="2" />
   <esri:Editor x:Key="MyEditor" Map="{Binding ElementName=MyMap}"/>
  </Grid.Resources>
  <esri:Map x:Name="MyMap" Background="White">
   <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer"/>
   <esri:GraphicsLayer ID="MyGraphicsLayer" />
  </esri:Map>
  <StackPanel VerticalAlignment="Top" HorizontalAlignment="Center" Orientation="Horizontal" DataContext="{StaticResource MyEditor}">
   <Button Content="Add Point" Command="{Binding Add}" CommandParameter="{StaticResource RedMarkerSymbol}"/>
   <Button Content="Add Line" Command="{Binding Add}" CommandParameter="{StaticResource RedLineSymbol}"/>
   <Button Content="Add Area" Command="{Binding Add}" CommandParameter="{StaticResource RedFillSymbol}"/>
   <Button Content="Edit" Command="{Binding EditVertices}"/>
   <!--<Button Content="Edit" Click="Button_Click"/>-->
  </StackPanel>
 </Grid>


The following only edits the first graphic in the layer. To finalize this edit, you need to click onto the same graphic. If you want to start edit on another graphic and complete the previous edit, you should not be passing graphic as CommandParameter to EditVertices command. This also does not let you move points. When CommandParameter is null, there's more flexibility in that you are not limited to editing a single graphic, the Editor will listen to all layers' MouseLeftButtonDown event.
private void Button_Click(object sender, RoutedEventArgs e)
{
 Editor editor = (sender as Button).DataContext as Editor;
 GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 if (editor.EditVertices.CanExecute(layer.Graphics[0]))
  editor.EditVertices.Execute(layer.Graphics[0]);
}
0 Kudos
AndyWright
Frequent Contributor
Jennifer,

What I provided you here is an extremely stripped down version of my application, so that you would be able to replicate the issue I described.  I am using the methods you described in my application, but I do also have a context menu that allows the user to right-click on a particular graphic and place it into edit mode.  That's where I run into the problem I describe in my original post.  Were you able to replicate that issue in the code I supplied here?  It happens to me every time.

1)  I put a specific graphic into edit mode

MyEditor.EditVertices.Execute(_gl.Graphics[0]);

2)  I move it
3)  I click on it to commit the edit, and it goes back to its original location.
4)  Only after I click it again does the edit get committed

Why do I need 2 clicks to commit my edit here?
0 Kudos
JenniferNery
Esri Regular Contributor
Thank you for reporting this. I think the issue here is Editor is in Continuous mode so the active command is activated again with the same graphic as CommandParameter. We'll definitely look into getting this bug fixed.
0 Kudos
AndyWright
Frequent Contributor
Thanks Jennifer.  Do you want me to submit this to the 2.2 beta team?
0 Kudos
JenniferNery
Esri Regular Contributor
I already created a work item for it. I believe this also exists in v2.1 Final. We'll try to include the fix in the future releases. Thanks 🙂
0 Kudos
AndyWright
Frequent Contributor
Great.  Thanks Jennifer ...
0 Kudos
NareshPuripanda
Emerging Contributor
Great.  Thanks Jennifer ...


Hi Jennifer,

I to have the same problem, let me know the other alternative of saving the edited graphics.

Thanks,
Naresh
0 Kudos