Select to view content in your preferred language

Refreshing map or layer display

2719
2
05-26-2011 01:45 PM
TerryGiles
Frequent Contributor
I have an application which contains a map service of point locations.  The point data in the map service are from a Query Layer with the data coming from Sql Server (not SDE).  I don't have control of the server and can only update the lat/longs and geometry column of the data via a stored procedure in SQL Server.  This wasn't too hard - I just pass the facility ID and x/y of the MapPoint where the user clicks to a WCF service which then runs the stored proc in the database. 

Where I'm stuck is once the asynch WCF call is complete I'm trying to refresh the map display and have tried this -
(_Layer as ArcGISDynamicMapServiceLayer).Refresh();

and this
Map.Zoom(1.0);

but neither actually refreshes the data.  The point the user moved is still in the old location until they pan or zoom out. 

The code below works, but is there a better/easier way that I'm not seeing?
            TimeSpan zd = _Map.ZoomDuration;
            _Map.ZoomDuration = new TimeSpan(0, 0, 0, 0);
            _Map.Zoom(0.99);
            _Map.Zoom(1.01);
            _Map.ZoomDuration = zd;



Thanks, Terry
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
'Refresh' should do the trick but set 'DisableClientCaching' to true in order to avoid issue with images in the browser cache.
0 Kudos
TerryGiles
Frequent Contributor
Thank you Dominique, simply setting DisableClientCaching = true and Refresh() works.  Since the user can move more than one point at a time and the the WCF service runs asynch I added a little logic to reset client caching after all points have been updated as shown below in case it helps any one else.

TG


In my DrawComplete event handler
 
            //turn off browser caching so updates show w/out needing to move the map
            (_QueryLayer as ArcGISDynamicMapServiceLayer).DisableClientCaching = true; 
            UpdateCount = graphics.Count();
            UpdateCount_Completed = 0;

            foreach (Graphic g in graphics)
            {                
                client.UpdateLocationAsync((int)g.Attributes["ID"], pt );
            }


Then in the UpdateLocationAsync handler
            (_QueryLayer as ArcGISDynamicMapServiceLayer).Refresh();

            UpdateCount_Completed++;
            if (UpdateCount_Completed == UpdateCount)
            {
                (_QueryLayer as ArcGISDynamicMapServiceLayer).DisableClientCaching = false;    
            }
0 Kudos