ThinkGeo.com    |     Documentation    |     Premium Support

Updating Features and having the Map update

Hello again,


I have my Map in an update Panel.  I have a custom FeatureCache, FeatureSource and Feature Layer.  I added some column values and custome symbology.  It compiles and run but now I want to change the values in the Features (the column values)


I just created a radio button list to select some alarm values and in the code below, I get the collection of features for the layer and I iterate through the feature collection until I hit a specific column value.  I am not trying anything special.  I am just trying to clear the GeoCache... and the GeoCache does clear.. I have verified that with breakpoints... But the map does not update.  I do an update on the panel but the map doesnt refresh.


As I was saying, I have debugged this code, it returns the correct collection of features and it clears tehm from the GeoCache.  I have verified that. 


I think I am missing something simple on how to make the Map refresh.  Any help as usually is greatly appreciate.  I think my evaluation is going well and this will all work out but I need to get a prototype going to approve the purchase.


see Code below



  else if (rblStn1.SelectedValue == "Level2")
            {
                EyascoFeatureCache test = new EyascoFeatureCache();
                Collection<Feature> fc = ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.GetFeatures(test.getBounds());

                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        
                        ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.Clear();
 
                    }
                }
               
                UpdatePanel1.Update();
            }

 


 


 


 



 


Leon,
Do you set the IsActive of FeatureSource to true? Please use the “DrawingFeatures” event of FeatureLayer to check that how many features are available before drawing the features. I think it can help you find something.
Additionally, please try the redraw method of the Overlay if the UpdatePanel.Update doesn’t take effect.
Thanks,
Johnny

Hello Johnny, 
  
 Thanks for the info.  I added a line to my code below calling the redraw method and my map does update and the features disappear.  see code 
  
 
 else if (rblStn1.SelectedValue == "Level2")
            {
                EyascoFeatureCache test = new EyascoFeatureCache();
                Collection<Feature> fc = ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.GetFeatures(test.getBounds());

                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.Clear();
                        ((LayerOverlay)Map1.CustomOverlays[1]).Redraw();
                    }
                }
               
                UpdatePanel1.Update();
            }
 
 
  
 This is not what I want to accomplish programmatically, I was merely trying to test out updating the map and having it update.  What I want to do is update a column value and then redraw the map.  If you have any code examples using c# that updates column values, that would be great.  I am going to work on it now that I know how to update the map. 
  
 Thanks again for the help, I appreciate everyones quick response.  It makes the evaluation much smoother. 
  
 Leon

Hello Johnny, 



Thanks for the info. I added a line to my code below calling the redraw method and my map does update and the features disappear. see code 



 
else if (rblStn1.SelectedValue == "Level2") 

EyascoFeatureCache test = new EyascoFeatureCache();
Collection<feature> fc = ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.GetFeatures(test.getBounds()); 

foreach (Feature f in fc) 

if (f.ColumnValues["stnID"] == "1") 

((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.Clear(); 
((LayerOverlay)Map1.CustomOverlays[1]).Redraw(); 



UpdatePanel1.Update(); 
}

 



This is not what I want to accomplish programmatically, I was merely trying to test out updating the map and having it update. What I want to do is update a column value and then redraw the map. If you have any code examples using c# that updates column values, that would be great. I am going to work on it now that I know how to update the map.


About the IsActive property of the the FeatureSource... I do not see it in Intellisense when I am in code behind.  How do I reference it?



Thanks again for the help, I appreciate everyones quick response. It makes the evaluation much smoother. 



Leon



Hello Again,


Ok I have been trying to edit my features.  I can not find a "IsActive" property of FeatureSource.  Here is my code below.  When I run this code, i get a message that the FeatureSource is not Editable.


Code Below



else if (rblStn1.SelectedValue == "Level2")
            {
                EyascoFeatureCache test = new EyascoFeatureCache();
                Collection<Feature> fc = ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.GetFeatures(test.getBounds());

                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level2";
                        //((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GeoCache.Clear();
                        ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.BeginTransaction();
                        ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.UpdateFeature(f);
                        ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.CommitTransaction();
                        ((LayerOverlay)Map1.CustomOverlays[1]).Redraw();
                    }
                }
               
                UpdatePanel1.Update();
            }

 Thanks, leon


 


 



Hello Again, 



I am looking over some of the sample code in more detail. do I need to use an InMemoryfeatureLayer to be able to edit? Can you edit a FeatureLayer? 



Leon


Update: Changed it to an InMemoryfeatureLayer and got the same error.


Update: I found an "IsActive" property in FeatureCache but setting that to "true" did not change anything.  I still receive the error "FEatureSource is not Editable"


Update: based on some code in the samples, I change my code to the code below



 foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level2";
                        EyascoFeatureLayer efl = ((EyascoFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]);
                        efl.Open();
                        efl.EditTools.BeginTransaction();
                        efl.EditTools.Update(f);
                        efl.EditTools.CommitTransaction();
                        efl.Close();
                        ((LayerOverlay)Map1.CustomOverlays[1]).Redraw();
                    }
                }

However I still get the "Featuresource is not Editable" error.


Update: I adde the folling line of code;  tb = efl.FeatureSource.IsEditable;

right after the Open() method and put a breakpoint in the function.  It confirms that the Editable prperty is set to False for the FeatureSource.  However, I can't find a way to set it to True.



bool



Y-Reee-Ka 
  
 Ok looks like my problems were being cause by using my own Featurelayer/FeatureSource/FeatureCache classes.  I got rise of those and used an InMemoryFeatureLayer instead.  It is working now… I can search through the feature for specific column values and update colume values and then update the map which then changes the symbols.  
  
 Here is the code I used to get the features collection and update the feature 
  
 
 Collection<string> getCol = new Collection<string>();
            getCol.Add("stnId");
            getCol.Add("alarm");
            ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).Open();
            RectangleShape bounds = ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).GetBoundingBox();
            Collection<Feature> fc = ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GetAllFeatures(getCol);

            if (rblStn1.SelectedValue == "Level1")
            {
                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level1";
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.BeginTransaction();
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.Update(f);
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.CommitTransaction();
                    }
                }
            }
            else if (rblStn1.SelectedValue == "Level2")
            {
                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level2";
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.BeginTransaction();
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.Update(f);
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.CommitTransaction();
                    }
                } 
            }
            else if (rblStn1.SelectedValue == "Level3")
            {
                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level3";
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.BeginTransaction();
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.Update(f);
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.CommitTransaction();
                    }
                } 
            }

            ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).Close();
            ((LayerOverlay)Map1.CustomOverlays[1]).Redraw();
            UpdatePanel1.Update();
 


Y-Reee-Ka 
  
 Ok looks like my problems were being cause by using my own Featurelayer/FeatureSource/FeatureCache classes.  I got rise of those and used an InMemoryFeatureLayer instead.  It is working now… I can search through the feature for specific column values and update colume values and then update the map which then changes the symbols.  
  
 Here is the code I used to get the features collection and update the feature 
  
 
 Collection<string> getCol = new Collection<string>();
            getCol.Add("stnId");
            getCol.Add("alarm");
            ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).Open();
            RectangleShape bounds = ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).GetBoundingBox();
            Collection<Feature> fc = ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).FeatureSource.GetAllFeatures(getCol);

            if (rblStn1.SelectedValue == "Level1")
            {
                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level1";
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.BeginTransaction();
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.Update(f);
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.CommitTransaction();
                    }
                }
            }
            else if (rblStn1.SelectedValue == "Level2")
            {
                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level2";
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.BeginTransaction();
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.Update(f);
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.CommitTransaction();
                    }
                } 
            }
            else if (rblStn1.SelectedValue == "Level3")
            {
                foreach (Feature f in fc)
                {
                    if (f.ColumnValues["stnID"] == "1")
                    {
                        f.ColumnValues["alarm"] = "Level3";
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.BeginTransaction();
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.Update(f);
                        ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).EditTools.CommitTransaction();
                    }
                } 
            }

            ((InMemoryFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers[1]).Close();
            ((LayerOverlay)Map1.CustomOverlays[1]).Redraw();
            UpdatePanel1.Update();
 


Hi, Leon 
  
 If you want to implement your own FeatureSource and avoid “Featuresource is not Editable” error, and you need to override the IsEditable property which is virtual method, by default it will return false so that the error occurs. 
  
 Also if you want to update the feature using transaction using your own FeatureSource and you need to implement your own “CommitTransactionCore” method. However, all of these have been prepared for you in the InMemoryFeatureSource. If you don’t have other special requirements and I suggest you choose InMemoryFeatureLayer. 
  
 Please let us know if you have any questions. 
  
 Thanks, 
  
 Khalil