ThinkGeo.com    |     Documentation    |     Premium Support

WMSRasterLayer on occassionally-disconnected remote devices

How well-suited is the WPF desktop control for use on remote devices that are occassionally-disconnected? I know we can use client-side caching of images to mitigate some of the inherent performance and reliability problems, but there are times when the application is required to fetch an image. So:


1) recoverability - using the latest edition, the WMSRasterLayer throws an error and the map control ceases to work when there is a network error. What is the best way to recover from this condition so the fetch request can be retried?


2) Notification - while fetching an image, what is the best way of setting a progress indicator so the user knows the map layers are being updated? I've tried the "layers loading/loaded" event but that seems to be called whenever you refresh the map, even if the data comes from the local cache.


Thanks!



bump!

Gregory, 
  
 I think one way is to override the GetImageCore method of WmsRasterSource, eat the network exception there and do the reconnect. Here as following is the simpliest code just showing the idea how to do it.  
  
 
 class MyWmsRasterLayer : WmsRasterLayer
    {
        protected override void DrawCore(GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
        {
            base.DrawCore(canvas, labelsInAllLayers);
        }

        public MyWmsRasterLayer(Uri uri)
            :base(uri)
        {
            this.ImageSource = new MyWmsRasterSource(uri);     
        }
    }

 class MyWmsRasterSource : WmsRasterSource
    {
        protected override GeoImage GetImageCore(RectangleShape worldExtent, int canvasWidth, int canvasHeight)
        {
            GeoImage geoImage = null;
            try
            {
                 geoImage= base.GetImageCore(worldExtent, canvasWidth, canvasHeight);
            }
            catch
            { 
                // eat the exception and do the reconnection here
            }
            return geoImage;
        }

        public MyWmsRasterSource(Uri uri)
            : base(uri)
        { }
    }
 
  
 When you call the following code 
 <code lang=“csharp”> 
  MyWmsRasterLayer wmsRasterLayer = new MyWmsRasterLayer(new Uri(“wmssamples.thinkgeo.com/WmsServer.aspx”)); 
 </code> 
  
 it will first call MyWmsRasterLayer.DrawCore which will then call MyWmsRasterSource.GetImageCore, you can eat the network exception there and do the cleanup work, you can also notify other parts of your code there is a network error and we need to do the reconnection, for example you can raise an ConectingServerWithError event there for notifing and passed all the required information out in the event arguments for reconnection.   
                
 For your 2nd question, that’s similar that you can create your own event in your new class and raise it for example after getting image from the remote server in the GetImageCore method.  It is very flexible in this way that you can have whole control of it. 
  
 Let me know if you have any issues. 
  
 Thanks, 
  
 Ben

Thanks, I will give it a try!

Gregory,


From the following post you can also find how to make a progress bar just as your 2nd question, please have a look if you are interested.


Thanks,


Ben



I think Ben forget to attach the link of that post, it is here:


gis.thinkgeo.com/Support/Dis...fault.aspx
Any more questions please let us know.
Thanks,
sun