Select to view content in your preferred language

FeatureLayer refresh issue.

2250
3
04-04-2012 07:10 AM
SanajyJadhav
Deactivated User
Hi all,

I have issue regarding refreshing the feature layer.

This feature layer comes from FeatureService, so it is editable.I have set definition query on it by string "isactive != 'f'".So, features which do not have "f" value in "isactive" field do not show up in the map.

In the application, I modify the graphic attributes of this feature layer and change value of to "isactive = f".Then I call FeatureLayer::SaveEdits, FeatureLayer::Update and FeatureLayer::Refresh.

Now, this graphic should be invisible since it has value "isactive = 'f'".But it shows up in the map.If close the browser ad re run the application, then it would disappear.

I have set FeatureLayer:DisableClientCaching = true and FeatureLayer::AutoSave = false.So, how do I refresh the map when call FeatureLayer::SaveEdits and ::Update method.I tried clearing brwoser cache ( this may be non applicable) but no luck. I am using API V 2.4.

Am i missing some thing? Any help would be appreciated.

Thanks.
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
Can you subscribe to EndSaveEdits and SaveEditsFailed event? Also, you can monitor web requests using Fiddler to see if either save (applyEdits) or update (query) requests failed. You don't need to call Refresh after Update, update will re-draw the layer as it refreshes the GraphicCollection.

I could not reproduce with the following code. I am using FeatureDataForm from EditorWidget to update the attribute (Category to Infestation should make fcode == 11001) so on Update click, the feature should disappear from my view.
  xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid x:Name="LayoutRoot" Background="White">
        <esri:Map x:Name="MyMap">
            <esri:ArcGISTiledMapServiceLayer ID="MyLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
            <esri:FeatureLayer ID="Test" DisableClientCaching="True" OutFields="*" AutoSave="False"  Where="fcode != 11001"                            
                               Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/0">
                <esri:FeatureLayer.MapTip>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <ItemsControl ItemsSource="{Binding Keys}" Grid.Column="0" />
                        <ItemsControl ItemsSource="{Binding Values}" Grid.Column="1" />
                    </Grid>
                </esri:FeatureLayer.MapTip>
            </esri:FeatureLayer>
        </esri:Map>
        <StackPanel     VerticalAlignment="Top" HorizontalAlignment="Center">
            <Button Content="Update" Click="Button_Click"/>
        <esri:EditorWidget Map="{Binding ElementName=MyMap}"
                      />
        </StackPanel>
    </Grid>


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var l = MyMap.Layers["Test"] as FeatureLayer;
            l.Update();
        }
0 Kudos
SanajyJadhav
Deactivated User
Jennifer,

Thanks for getting back to me.

I had already subscribed to EndSaveEdits event and I could execute code inside it.So, changes are getting saved, I cross verified it in ArcMap also.In this event, I refreshed my dynamic base map as well, but no luck.

As per your suggestions, I monitored the web traffic in Fiddler and I got result 200.That means, here also, it is fine ( please see the attached screen shot).

Please go through my code as below.
 FeatureLayer tagsLyr = currentApps.MapControl.Layers["Tags Feature Layer"] as FeatureLayer;
                                tagsLyr.UpdateCompleted -= tagsLyr_UpdateCompleted;
                                tagsLyr.UpdateCompleted += new EventHandler(tagsLyr_UpdateCompleted);
                                tagsLyr.EndSaveEdits += new EventHandler<EndEditEventArgs>(tagsLyr_EndSaveEdits);

                                //get graphics in the current extent of the tags feature layer
                                GraphicCollection gl = tagsLyr.Graphics;

                                //get graphisc in the list which have tag_id that are in the parameter
                                var x = from t1 in gl
                                        join t2 in listOfTagIDs
                                        on t1.Attributes["tag_id"] equals t2.ToString()
                                        select t1;
                                List<Graphic> graphicsToBeModified = x.ToList();

                                foreach (Graphic item in graphicsToBeModified)
                                {
                                        item.Attributes["isactive"] = "f";
                                }

                                if (tagsLyr.HasEdits)
                                {
                                        tagsLyr.SaveEdits();
                                        tagsLyr.Where = "isactive = 't'";
                                        tagsLyr.Update();                                        
                                }
                                tagsQryGrLayer.ClearGraphics();               


 void tagsLyr_UpdateCompleted(object sender, EventArgs e)
                {
                        FeatureLayer fl = sender as FeatureLayer;

                        GraphicCollection gl2 = fl.Graphics;
                        IList<Graphic> src = fl.GraphicsSource as IList<Graphic>;

                        fl.Refresh();

                }

                void tagsLyr_EndSaveEdits(object sender, EndEditEventArgs e)
                {
                        ArcGISDynamicMapServiceLayer srvc = McgmMap.Layers["Ghatkopar Map Service"] as ArcGISDynamicMapServiceLayer;                        
                        srvc.Refresh(); 
                }


I am really out of ideas now, can you think of any reasons for this weird behavior?

Thanks for your concern.
0 Kudos
JenniferNery
Esri Regular Contributor
I believe it's this code: x.ToList(), this creates a different list so you are not affecting the graphic from layer. You can test that before you call layer.SaveEdits(), layer.HasEdits is false. Try to iterate through x instead of x.ToList().
0 Kudos