Why does the ArcGISLocalFeatureLayer.UpdateCompleted event fire twice?

2434
4
08-14-2013 07:41 AM
ReneeCammarere
Occasional Contributor
I have the following routine that gets the local feature layer service that is used for editing a feature class.  For some reason, it goes through the arcGISLocalFeatureLayer.UpdateCompleted  event twice.  This causes a runtime error due to the lines in which I re-project the aGraphic object.  I don't understand why this is happening.

       private void EditMyFeatureLayer()
        {
            // Get the Local Feature Layer service that is used for editing the Result feature class (map package)
            string mpkPath_features = ConfigurationManager.AppSettings["EsriRuntimeEditMapPackageLocation"];

            LocalFeatureService localFeatureService = LocalFeatureService.GetService(mpkPath_features);
            //CoverAreasResult Feature
            arcGISLocalFeatureLayer = new ArcGISLocalFeatureLayer();
            arcGISLocalFeatureLayer.Service = localFeatureService;
            arcGISLocalFeatureLayer.Editable = true;
            arcGISLocalFeatureLayer.ValidateEdits = true;
            arcGISLocalFeatureLayer.LayerId = 0;
            arcGISLocalFeatureLayer.ID = "CoverAreasResult";
            arcGISLocalFeatureLayer.Path = mpkPath_features;
            arcGISLocalFeatureLayer.DisableClientCaching = true;
            arcGISLocalFeatureLayer.AutoSave = true;
            arcGISLocalFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.Snapshot;
            arcGISLocalFeatureLayer.ShowLegend = true;
           
            GraphicCollection aGCollection = arcGISLocalFeatureLayer.Graphics;
             
            arcGISLocalFeatureLayer.Initialized += (sender, eventArgs) =>
            {
                arcGISLocalFeatureLayer.Update();
            };

            arcGISLocalFeatureLayer.UpdateCompleted += (sender, e) =>
            {
                ESRI.ArcGIS.Client.Projection.WebMercator aProjector = new WebMercator(); // constructor for easy client projection (102100 <-> 4326)
                foreach (Graphic aGraphic in _gpFeatureRecordSetLayer.FeatureSet.Features)
                {
                    aGraphic.Geometry = aProjector.ToGeographic(aGraphic.Geometry); // project graphic geometry to WGS84
                    aGCollection.Add(aGraphic);                // add projected graphic to graphic collection
                }
                arcGISLocalFeatureLayer.Graphics = aGCollection;

                arcGISLocalFeatureLayer.SaveEdits();
                //  http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html
                //  See above reference - don't need to project layer if going between WGS84 and Web Mercator

                _map.Layers.Insert(1, arcGISLocalFeatureLayer);
               
            };

             arcGISLocalFeatureLayer.Initialize();           

        }
0 Kudos
4 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

The reason it fires twice could be because you're explicitly calling Update, but you're also adding the layer to the Map, which you may find initiates a 2nd query and a subsequent UpdateCompleted event (i.e. the second one you're seeing).

Note that another option for you might be to put the FeatureLayer in SelectionOnly mode in the Map and add the DynamicLayer equivalent for display.

Cheers

Mike
ReneeCammarere
Occasional Contributor
Hi,

The reason it fires twice could be because you're explicitly calling Update, but you're also adding the layer to the Map, which you may find initiates a 2nd query and a subsequent UpdateCompleted event (i.e. the second one you're seeing).

Note that another option for you might be to put the FeatureLayer in SelectionOnly mode in the Map and add the DynamicLayer equivalent for display.

Cheers

Mike


Thanks so much for the response.  Regarding your suggestion . . . "Note that another option for you might be to put the FeatureLayer in SelectionOnly mode in the Map and add the DynamicLayer equivalent for display."  I changed the one line to arcGISLocalFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.SelectionOnly;
However, I'm not sure how to make the dynamic layer equivalent to the local feature layer  . . ArcGISLocalDynamicMapServiceLayer dynamicLayer = new ArcGISLocalDynamicMapServiceLayer().  I tried something like . . dynamicLayer.Layers[0] = ?  . . but then don't know what to do after that.  Thanks!
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

When creating feature services (local or online) there's always a map service with the same content. Therefore - on the LocalFeatureService class there are UrlMapService and UrlFeatureService properties. You can create an ArcGISLocalDynamicMapServiceLayer using the UrlMapService property and an ArcGISLocalFeatureLayer using the UrlFeatureService property.

Cheers

Mike
ReneeCammarere
Occasional Contributor
Hi,

When creating feature services (local or online) there's always a map service with the same content. Therefore - on the LocalFeatureService class there are UrlMapService and UrlFeatureService properties. You can create an ArcGISLocalDynamicMapServiceLayer using the UrlMapService property and an ArcGISLocalFeatureLayer using the UrlFeatureService property.

Cheers

Mike


Thank you.  That cleared it up for me. I've changed my code and am trying it out again.
I was successful in using the ArcGISLocalDynamicMapServiceLayer for displaying the feature on the map.  Thanks again!
0 Kudos