ThinkGeo.com    |     Documentation    |     Premium Support

How to refresh map when the data is updated directly in the database?

Hello


Wich can be the easiest and best way to refresh the map when data fields (used for labeling) and geometry fileds are updated directly in the database, I'm using SQL server 2008?


Obiously the refresh method doesn't work becouse the changes are not tracked via the overlay class.



Yuri,


Thanks for your post and questions!
 
No matter you changed anything (render style, data or columnValues) in the layer, you have to refresh the map control to update it. Following is the basic structure for this:

winformsMap1.Overlays["LayerOverlay"].Lock.EnterWriteLock();
try
{
    //Here click a button to update the data base.
}
finally
{                  
    winformsMap1.Overlays["LayerOverlay"].Lock.ExitWriteLock();
}

winformsMap1.Refresh();

 

While as you said, the data changed seems not tracked via the overlay class, but it was hooked up by adding layers corresponding to the table in the sql server 2008 database.

MsSql2008FeatureLayer featureLayer = new MsSql2008FeatureLayer(connectString, tableName, featureId);
featureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
featureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Country1("CNTRY_NAME");
featureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("WorldShapeLayer", featureLayer);

winformsMap1.Overlays.Add("LayerOverlay", staticOverlay);

 
Feel free to let me know if any more questions.

 
Thanks.
 
Yale

 


Yale  
  
 Thanks for your replay, your code helps me in some case. When some attribute is changed in the database and this attribute is used to label the features it’s work ok. But when some feature is deleted or created the Lock class dosen’t works. After the refresh the deleted features remains on the map. 
  
 Other scenario is when the features are modified, added or delated by another user. So my question remains what is the best method to refresh the map when the database is updated direcltly?  (maybe by other user in the network)

Yuri, 
  
 How do you think in your application we have to timer to refresh the MapControl in a given interval? In this way, no matter how the data in the database is changed, it will be refreshed in the Map view. 
  
 Any more questions please feel free to let me know. 
  
 Thanks. 
  
 Yale 


Yale 
  
 The problem is that clearing and adding the layers again to the overlay is very very slow and can be complex. is there an other way?

Yuri, 
  
   I want to make sure I understand what you have done, tried etc.  As far as I know when you lock an overlay and then unlock it that will cause the cache to be cleared and then when you refresh the sql query will get called again.  I also want to make sure you have not set the GeoCache in the feature source.   
  
   I find this hard to imagine as if you see the attributes changing then the SQL statement was executed again and we get the features from the SQL statement so if there are changes we will get them.  Are you sure there is nothing else special you are doing like the GeoCache or using an InMemeoryLayer or something like that?  The attributes and the features are all tied together in that SQL statement. 
  
 David