//------------------------------------------------------------------------- public void ChangeServer(string url, string layer, int maxLevel) { Wms.Client.Server service = null; try { service = Wms.Client.Server.CreateService(url, WMSTileServer.CachePath); } catch (Exception ex) { RaiseDataSourceChangedEvent(new DataSourceChangedEventArgs(null, null, DataSourceChangedEventArgs.EStatus.FAIL, ex.Message)); service = null; } if (service != null) { Application.Current.Dispatcher.Invoke(() => { try { var wmsServer = new WMSTileServer(service, layer, maxLevel); if (wmsServer.Layer != null && wmsServer.SRSConverter != null) { RaiseDataSourceChangedEvent(new DataSourceChangedEventArgs(wmsServer, wmsServer.SRSConverter.DataTransform, DataSourceChangedEventArgs.EStatus.SUCCESS)); OnPropertyChanged(nameof(MapTransform)); OnPropertyChanged(nameof(CoordinateTransform)); } } catch (Exception ex) { RaiseDataSourceChangedEvent(new DataSourceChangedEventArgs(null, null, DataSourceChangedEventArgs.EStatus.FAIL, ex.Message)); } }); } }
private void initiateMapRequest(Wms.Client.Server server) { this.statusBar.Text = "Retrieving Map "; // Create a GetMap request for the layers COASTLINES and RATMIN (min temperatures). Wms.Client.MapRequestBuilder mapRequest = new Wms.Client.MapRequestBuilder( new System.Uri(server.Capabilities.GetCapabilitiesRequestUri)); mapRequest.Layers = "COASTLINES,RATMIN"; mapRequest.Styles = ","; // use default style for each layer mapRequest.Format = "image/gif"; mapRequest.Srs = "EPSG:4326"; mapRequest.BoundingBox = "-180.0,-90.0,180.0,90.0"; mapRequest.Height = 300; mapRequest.Width = 600; mapRequest.Transparent = false; // Create a retriever to execute the request. Wms.Client.MapRetriever mapRetriever = new Wms.Client.MapRetriever(this); mapRetriever.ProgressInterval = new System.TimeSpan(0, 0, 0, 0, 500); mapRetriever.Done += new Wms.Client.RetrieverDoneEventHandler(this.mapRetrieveDone); mapRetriever.Progress += new Wms.Client.RetrieverProgressEventHandler(this.showMapProgress); mapRetriever.Request = mapRequest; mapRetriever.Destination = System.IO.Path.GetTempFileName(); // Start the retrieval. mapRetriever.Start(); }
static void Main(string[] args) { // Create a request to get the capabilities document from the server. System.UriBuilder serverUri = new System.UriBuilder(@"http://viz.globe.gov/viz-bin/wmt.cgi"); Wms.Client.CapabilitiesRequestBuilder capsRequest = new Wms.Client.CapabilitiesRequestBuilder(serverUri.Uri); // Retrieve the capabilities document and cache it locally. System.Net.WebRequest wr = System.Net.WebRequest.Create(capsRequest.Uri); // Handle any proxy the system may have defined. System.Net.WebProxy proxy = System.Net.WebProxy.GetDefaultProxy(); if (proxy.Address != null) { wr.Proxy = proxy; } System.Net.WebResponse response = wr.GetResponse(); string fileName = System.IO.Path.GetTempPath() + @"capabilities.xml"; copyStreamToFile(response.GetResponseStream(), fileName); // Parse the capabilities document and create a capabilities object // for reading the parsed information. This is done by creating a Server // object to represent the server associated with the capabilities. Wms.Client.Server server = new Wms.Client.Server(fileName); Wms.Client.Capabilities caps = server.Capabilities; // Create a GetMap request using the MapRequestBuilder class. When // creating the request, use the URI given in the server's capabilities // document. This URI may be different than the one used to get the // capabilities document. Wms.Client.MapRequestBuilder mapRequest = new Wms.Client.MapRequestBuilder(new System.Uri(caps.GetMapRequestUri)); mapRequest.Layers = "COASTLINES,RATMIN"; mapRequest.Styles = ","; // use default style for each layer mapRequest.Format = "image/gif"; mapRequest.Srs = "EPSG:4326"; mapRequest.BoundingBox = "-180.0,-90.0,180.0,90.0"; mapRequest.Height = 300; mapRequest.Width = 600; mapRequest.Transparent = false; // Retrieve the map and cache it locally. System.Net.WebRequest mwr = System.Net.WebRequest.Create(mapRequest.Uri); if (proxy.Address != null) { mwr.Proxy = proxy; } System.Net.WebResponse mresponse = mwr.GetResponse(); string mapFileName = System.IO.Path.GetTempPath() + @"wmsmap.gif"; copyStreamToFile(mresponse.GetResponseStream(), mapFileName); // Use Internet Explorer to display the map. invokeIe(mapFileName); }
private void initiateMapRequest(Wms.Client.Server server) { this.statusBar.Text = "Retrieving Maps "; for (int i = 0; i < this.mapRequests.Length; i++) { // Create a GetMap request for the layers COASTLINES and Cloud Cover. this.mapRequests[i] = new Wms.Client.MapRequestBuilder( new System.Uri(server.Capabilities.GetCapabilitiesRequestUri)); this.mapRequests[i].Layers = "COASTLINES,RCOXXR"; this.mapRequests[i].Styles = ","; // use default style for each layer this.mapRequests[i].Format = "image/gif"; this.mapRequests[i].Srs = "EPSG:4326"; this.mapRequests[i].BoundingBox = "-180.0,-90.0,180.0,90.0"; this.mapRequests[i].Height = 300; this.mapRequests[i].Width = 600; this.mapRequests[i].Transparent = false; this.mapRequests[i].Time = System.String.Format("2004-05-{0:D2}", i + 1); // Create a retriever to execute the request. Wms.Client.MapRetriever mapRetriever = new Wms.Client.MapRetriever(this); mapRetriever.ProgressInterval = new System.TimeSpan(0, 0, 0, 0, 500); mapRetriever.Done += new Wms.Client.RetrieverDoneEventHandler(this.mapRetrieveDone); mapRetriever.Request = this.mapRequests[i]; mapRetriever.Destination = System.IO.Path.GetTempFileName(); // Slow connections may require more than the default 60 second // timeout period for map requests, so increase it to 180 seconds. mapRetriever.TimeoutInterval = System.TimeSpan.FromSeconds(180); // Start the retrieval. mapRetriever.Start(); // Initialize the progress bar and start the progress timer. this.statusBar.Text = "Retrieving Maps"; this.progressBar.Visible = true; this.timer.Start(); } }