Select to view content in your preferred language

How to Cancel Editing?

1033
6
10-06-2010 12:31 PM
FrancoisChartrand
Emerging Contributor
Hi,

Is it possible add logic to decide whether or not (based on some conditions) if it is allowed to start editing a particular graphic and cancel edition if needed? I would like to do something like this:

public MyClass()
{
    MyEditor.EditStarting += OnEditStarting;
    MyEditor.EditCompleted += OnEditCompleted;
}

private void OnEditStarting(object sender, Editor.EditEventArgs e)
{
    if (!IsEditAllowed(e.Graphic))
    {
        e.Cancel = true;
    }
    else
    {
        ...
    }
}

private void OnEditCompleted(object sender, Editor.EditEventArgs e)
{
    ...
}

private bool IsEditAllowed(Graphic graphic)
{
    ...
}
0 Kudos
6 Replies
JenniferNery
Esri Regular Contributor
There is a CancelActive command in the Editor that will let you do the following:
 if (MyEditor.CancelActive.CanExecute(null))
  MyEditor.CancelActive.Execute(null);

I'm not sure if this is sufficient for your use case, but this lets you cancel the active command (i.e. EditVertices, Select, etc.).

If you need to perform check on the graphic before EditVertices command is activated, you can activate EditVertices in code-behind instead.
 private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
 {
  bool canEdit = IsEditAllowed(e.Graphic);
  if (canEdit && MyEditor.EditVertices.CanExecute(e.Graphic))
   MyEditor.EditVertices.Execute(e.Graphic);
 }
0 Kudos
FrancoisChartrand
Emerging Contributor

If you need to perform check on the graphic before EditVertices command is activated, you can activate EditVertices in code-behind instead.
 private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
 {
  bool canEdit = IsEditAllowed(e.Graphic);
  if (canEdit && MyEditor.EditVertices.CanExecute(e.Graphic))
   MyEditor.EditVertices.Execute(e.Graphic);
 }


This solution works fine except for MapPoints. I'm using a GraphicsLayer. When passing a graphic that uses a MapPoint geometry to the EditVertices command, it doesn't work.

However, when passing null and then the user clicks on the graphic, it is possible to move it. This means that the only way to move a MapPoint is to use the EditVertices.Execute(null) with null parameter. Then the user will be able to move the MapPoint using mouse drag and drop.

Is this a bug? If this is the expected behaviour, how should I perform check on the graphic before EditVertices command is activated?
0 Kudos
JenniferNery
Esri Regular Contributor
This is by design and noted in our documentation: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor~Edi...

While polyline, polygon, point share the same Editor.Command EditVertices, editing geometry on a polyline or polygon is a different operation from moving a point.

With CommandParameter not set or null, EditVertices will act on all graphics found in Editor.Layers (All geometry types are supported in this case).

If CommandParameter is a graphic, then EditVertices will act only on the specified graphic (Points are not supported in this case).
0 Kudos
FrancoisChartrand
Emerging Contributor
If CommandParameter is a graphic, then EditVertices will act only on the specified graphic (Points are not supported in this case).


ok but then I'm back to my initial concern: how could I perform check on the graphics (using MapPoints) before EditVertices command is activated?
0 Kudos
JenniferNery
Esri Regular Contributor
The only operation you can really do with point geometry is to move them. This is why Editor.EditVertices does not make sense to activate on a graphic with point geometry.

What you can do is only activate EditVertices for polyline and polygon geometries. And handle the move on point geometries by providing offset to its X,Y values using MouseMove and MouseLeftButtonUp events or you can listen to the next MouseClick that sets the new location of the point geometry.
0 Kudos
FrancoisChartrand
Emerging Contributor
The only operation you can really do with point geometry is to move them. This is why Editor.EditVertices does not make sense to activate on a graphic with point geometry.


I agree. It doesn't make sense to use EditVertices for points. But then, what is the proper way for moving points? Are you planning to add an Editor.Move command for points?

What you can do is only activate EditVertices for polyline and polygon geometries. And handle the move on point geometries by providing offset to its X,Y values using MouseMove and MouseLeftButtonUp events or you can listen to the next MouseClick that sets the new location of the point geometry.


I'll do that as a workaround 😞
Thank you
0 Kudos