Select to view content in your preferred language

Cloased Facility Not Working

1000
1
10-13-2010 10:13 AM
ShaningYu
Honored Contributor
I loaded the sample code from ESRI's http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ClosestFacility
I run debugging.  After I click the 'Add Facilities', it executes Editor_EditCompleted

        private void Editor_EditCompleted(object sender, Editor.EditEventArgs e)
        {
            Editor editor = sender as Editor;

            if (e.Action == Editor.EditAction.Add)
            {
                if (editor.LayerIDs.ElementAt(0) == "MyFacilitiesGraphicsLayer")
                {
                    e.Edits.ElementAt(0).Graphic.Attributes.Add("FacilityNumber",
                        (e.Edits.ElementAt(0).Layer as GraphicsLayer).Graphics.Count);
                }
                else if (editor.LayerIDs.ElementAt(0) == "MyIncidentsGraphicsLayer")
                {
                    e.Edits.ElementAt(0).Graphic.Attributes.Add("IncidentNumber",
                        (e.Edits.ElementAt(0).Layer as GraphicsLayer).Graphics.Count);
                }

                if (facilitiesGraphicsLayer.Graphics.Count > 0 && IncidentsGraphicsLayer.Graphics.Count > 0)
                    SolveButton.IsEnabled = true;
            }
        }

However, I always get the Cancel value for the e.Action.  Anyone knows that is wrong and how to fix it?  Thanks.
0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor
The live sample seems to work fine for me.  There are three editors here, one for each GraphicsLayer, each performs an Add, and each editor may raise EditCompleted everytime you click a button. It is normal for a Cancel EditAction to occur before Add EditAction. Are you saying Add EditAction never gets raised after you add a barrier/point/etc to the map?

Also the best way to know which layer the edit was applied on is to do
  void editor_EditCompleted(object sender, Editor.EditEventArgs e)
        {
            foreach (var edit in e.Edits)
            {
                if (e.Action== Editor.EditAction.Add)
                {                     
                    if (edit.Layer == MyFacilitiesGraphicsLayer)
                    {
                        //do something here
                    }
                 }
            }
        }
0 Kudos