Select to view content in your preferred language

Refresh WMS Layer

4635
12
06-15-2010 12:30 PM
BrianGustafson
Occasional Contributor
I have a timer set up so that at each tick the WMS layer(weather radar) will update.  When I use the refresh method the WMS is not updated until I pan the map.  Is there some other way to update WMS layers without needing to pan the map?
0 Kudos
12 Replies
dotMorten_esri
Esri Notable Contributor
That's likely because your browser is caching the response.
A trick to make it work is to add a value to the request that changes each time to trick the browser to think its a new request. For example:
      + "&t=" + DateTime.Now.Ticks.ToString()
0 Kudos
BrianGustafson
Occasional Contributor
I am not sure where in the application to add the date time.  When I take the code and put it at the back of a url from fiddler I am getting the correct response.  Below is the code from the tick method, does it need to go in the proxy handler?   

WMS.WMSMapServiceLayer AGSWMSLayer = MyMap.Layers["AGSWMSLayer"] as WMSMapServiceLayer;
AGSWMSLayer.url = http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi" + "&t=" + DateTime.Now.Ticks.ToString();
AGSWMSLayer.Refresh();
0 Kudos
BrianGustafson
Occasional Contributor
I added the code to the proxy handler and in fiddler I can see that each request is different.  However, a request is not made until the map is moved, not when the refresh method is called.
0 Kudos
DanielWalton
Frequent Contributor
Did you use a System.Windows.Threading.DispatcherTimer or a System.Threading.Timer?

-Dan
0 Kudos
DominiqueBroux
Esri Frequent Contributor
If it's just a display issue, you can try to change the layer visiblity to false and then true.

I did that in one of my code (but there is probably a better way:) )
featureLayer.Update();
featureLayer.Visible = false;
featureLayer.Visible = true;
0 Kudos
BrianGustafson
Occasional Contributor
I am using a DispatchTimer.  It looks like the issue is now that when the tick method is run a call is not made to the WMS service when it refreshes, I still need to pan the map to get the new info to download. 

        private void weatherTimer_Tick(object sender, EventArgs e)
        {
            WMSMapServiceLayer AGSWMSLayer = MyMap.Layers["AGSWMSLayer"] as WMSMapServiceLayer;
            AGSWMSLayer.Refresh(); 
         }
0 Kudos
DanielWalton
Frequent Contributor
Morten's workaround worked for me. Inside the GetUrl() method of the WMS layer class, add the following line:

mapURL.AppendFormat("&t={0:hhmmss}", DateTime.Now);


Edit: One problem with this feature is that the browser will queue the WMS requests while the app window is not visible (minimized or on a hidden tab) and execute all of them when you make the app visible. You might want to add some Javascript to your host page to help you stop the refresh timer when the app is not visible.

-Dan
0 Kudos
BrianGustafson
Occasional Contributor
Thats what I needed to do. 

Thanks,

Brian
0 Kudos
samulineuvonen
Deactivated User
Hello,

I'm trying to accomplish a similar thing (refresh WMS containing moving vehicles) and this thread seems promising. However, I am not sure where exactly should I append the row

mapURL.AppendFormat("&t={0:hhmmss}", DateTime.Now);


mentioned by Daniel Walton. Am I to edit the source code of ESRI Silverlight Toolkit and build my own version of it? Sounds scary...

Also, if someone should have an example of how to make Javascript and Silverlight interact to stop the timer, this too would be appreciated. I have experimented with

HtmlPage.Window.AttachEvent("onblur", stopAutoRefresh);


in App.xaml.cs but this seems to work for Mozilla but not IE...

Thanks,
Samuli
0 Kudos