Select to view content in your preferred language

About Editor_EditCompleted ...

5505
31
02-23-2011 06:47 AM
MarcoRosa
Emerging Contributor
Hi to all,
i'm using the editor tool and Editor_EditCompleted event: after selection this event it's fired 2 times , the first time e.Action value is "Select" , the second time the value is "Cancel".
It's correct this behaviour ?

Thank u very much
GP
0 Kudos
31 Replies
MarcoRosa
Emerging Contributor
ok , with behind code this means to use

_editor.Select.Execute("DeleteSelected");

insead of

_editor.Select.Execute("Remove");

? Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
In code-behind it is:

if(_editor.DeleteSelected.CanExecute(null))
     _editor.DeleteSelected.Execute(null);
0 Kudos
MarcoRosa
Emerging Contributor
Hi Jennifer,
iìve tried your code: maybe i wasn't able to explain u my request.
Let me try to explain u better:

What i want to do is NOT the delete selected polygon , simple the deselect the polygon selected.
I try to write u the steps :

1) Put 2 feature layers ( L1 and L2 ) on map. (i have set the editor by code).
2) Press a button to start selection session:

       private void Button_Click(object sender, RoutedEventArgs e)
        {
                _editor = new Editor();
                _editor.Map = MyMap;
                _editor.SelectionMode = DrawMode.Point;
                _editor.Select.Execute("New");
                _editor.ContinuousMode = true;
                _editor.EditCompleted += new EventHandler<Editor.EditEventArgs>(Editor_EditCompleted);
        }

3)  by clicking on the map i can select features on both layers L1 & L2 and obtain information about  layers i'm working through the Editor_EditCompleted.

In the Editor_EditCompleted event i can understand on which layer i'm working because the properties e.Edits it's never null , and all it's ok.

4) Now i want to add selected polygons to current selection: i do that with keyboards in this way:
Press shif , click on map and new selected features are added

        void MainPage_KeyDown(object sender, KeyEventArgs e)
        {
            if (_editor == null) return;
            if (e.Key == Key.Ctrl)
                _editor.Select.Execute("Remove");
            else if (e.Key == Key.Shift)
                _editor.Select.Execute("Add");
            else if (e.Key == Key.Escape)
                _editor.CancelActive.Execute(null);
        }

.... and all it's ok

5) Now ( this is the trouble case ) i would like to deselect some objects from existing selection.
..Press ctrl and click on map.
The features are correctly deselected , but now the question is:

If i check the e.edits value in Editor_EditCompleted, i have this value null.
This means that i'm not be able to understand on which layer the selected object are deselected.

Let me know if i was clear in my explanation

Ciao Giorgio









when i click on map i can salect a poligon on each layer. I would like to understand on which layer im' working against not when i select a poligon but when i deselecte objects from one of 2 layer.
Infact, the e.edits return a Layer not null when i add the selection , null when i remove the selection.
0 Kudos
JenniferNery
Esri Regular Contributor
Kindly look at Remove from Selection button in this sample:http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave

This is how you set up the Button It inherits its container's DataContext="{StaticResource MyEditor}"
 <Button x:Name="RemoveSelectButton" Margin="2"                             
                            Command="{Binding Select}"
                            CommandParameter="Remove" >


If you use the code above, you will not need to execute the command in code-behind.

The code-behind equivalent, should you choose to not use the code above is:
if(editor.Select.CanExecute("Remove")) editor.Select.Execute("Remove");


I can see where the confusion is now. The command used by new selection, add to selection and remove from selection is the same - Select. This is the same EditAction. When you iterate through the graphics, you can check for edit.Graphic.Selected property. If it is false, it must be caused by New Selection or Remove from Selection.
If you placed the following in Editor.EditCompleted event handler:
private void Editor_EditCompleted(object sender, Editor.EditEventArgs e)
{
 System.Diagnostics.Debug.WriteLine(e.Action);
 foreach (var edit in e.Edits)
 {
  if (edit.Graphic.Selected)
   System.Diagnostics.Debug.WriteLine("{0}-{1}", edit.Graphic.Attributes["ObjectID"], edit.Layer.ID);
 }
}
0 Kudos
MarcoRosa
Emerging Contributor
HI Jennifer,
tried your suggest:

when i try to remove from selection il loop i have the same behaviour :
i'm passing from selection = true to selection = false ... then edit.Graphic.Selected in this moment is true.
In the same moment edit.Layer is null.


Thank u again ....


private void Editor_EditCompleted(object sender, Editor.EditEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Action);
foreach (var edit in e.Edits)
{
  if (edit.Graphic.Selected)
   System.Diagnostics.Debug.WriteLine("{0}-{1}", edit.Graphic.Attributes["ObjectID"], edit.Layer.ID);
}
}




If it is false, it must be caused by New Selection or Remove from Selection.
If you placed the following in Editor.EditCompleted event handler:
0 Kudos
JenniferNery
Esri Regular Contributor
What version of the API are you using? I have tested the attached sample with v2.1 Final. Kindly try the sample.

To describe the sample project:
It uses Editor.Add and Editor.Select. When Add completes, I assign the graphic some attribute so I can display it's information when Select completes. This should demonstrate that I am able to get both the graphic and layer from Editor.EditCompleted event.

I could not reproduce the issue when edit.Layer is null. Please send me steps to reproduce the issue using this sample. Thanks!
0 Kudos
MarcoRosa
Emerging Contributor
Hi Jennifer , i saw your code ... there's a little differences between mine and your code.
I don't use Graphics layer , but only feature layers on which simulate the objects selection.
My case is like this esri sample:

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerSelection

I verified inside this code the behaviour of edit_completed events and happens the same thing.
edit.Layer in the Remove session is null , u can verify that using the pages i've attached to u.
This is a strange behaviour , bacause if u have more than one feature layer on map u cannot know from which layer u are removing objects.

Please Try the code attached to u and let me know.
Thanks as usual ciao Giorgio
0 Kudos
MarcoRosa
Emerging Contributor
forgot attach
0 Kudos
JenniferNery
Esri Regular Contributor
Ah! The difference is that your FeatureLayer.Mode is SelectionOnly, which means selection can cause features to be added to and/or removed from your layer. In this case, once you remove the graphic from your selection, it is no longer associated to your layer - this is why edit.Layer is null. I will check with our Dev Lead if this is something we need to update.

Thanks for sharing this to us. If I may comment on your code, KeyDown event will fire continuously, which means editor.Select.Execute("Remove") will be called a bunch of times until you let go of Ctrl key. If you choose to use Keyboard. Remove your KeyDown eventhandler and on StartSelection_Click, use editor.Select.Execute("Keyboard") instead.

EDIT: Thank you for reporting this bug: EditCompleted event should still report the affected layer. We'll try to get it fixed in future releases.
0 Kudos
MarcoRosa
Emerging Contributor
Hi Jennifer , thank u for all .. i hope your team will fix this bug. I tried to use editor.Select.Execute("Keyboard") ... Good , for the edit_completed event the behaviour is the same than previous method.

Anyway ... When your dev. team think to released the next final release of silverlight api ?

Thank u , see u

ciaso Giorgio
0 Kudos