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 mapRetrieveDone(object sender, Wms.Client.RetrieverDoneArgs ea) { // This event handler is called when the map has been retrieved, or when an error // occurs in the retrieval. Wms.Client.MapRequestBuilder mapRequest = ea.Retriever.Request as Wms.Client.MapRequestBuilder; if (ea.Reason == Wms.Client.RetrieverDoneArgs.CompletionReason.Completed) { System.Drawing.Image image = System.Drawing.Image.FromFile(ea.DestinationFile); for (int i = 0; i < this.mapRequests.Length; i++) { if (this.mapRequests[i] == mapRequest) { this.mapImages[i] = image; } } } }
private void mapRetrieveDone(object sender, Wms.Client.RetrieverDoneArgs ea) { // This event handler is called when the map has been retrieved, or when an error // occurs in the retrieval. Wms.Client.MapRequestBuilder mapRequest = ea.Retriever.Request as Wms.Client.MapRequestBuilder; if (ea.Reason == Wms.Client.RetrieverDoneArgs.CompletionReason.Completed) { if (ea.ContentType.Equals("application/vnd.ogc.se_xml") || ea.ContentType.Equals("application/vnd.ogc.se+xml") || ea.ContentType.Equals("text/xml")) { string msg = "Retrieval of map returned an error:" + System.Environment.NewLine; System.Windows.Forms.MessageBox.Show(msg, "WMS Server Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } else { System.Drawing.Image image = System.Drawing.Image.FromFile(ea.DestinationFile); this.pictureBox.Image = image; this.statusBar.Text = System.String.Empty; } } else if (ea.Reason == Wms.Client.RetrieverDoneArgs.CompletionReason.Error) { System.Windows.Forms.MessageBox.Show("Error retrieving map: " + ea.Message, "Retrieval error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } else if (ea.Reason == RetrieverDoneArgs.CompletionReason.TimedOut) { System.Windows.Forms.MessageBox.Show("Retrieval of map timed out.", "Retrieval error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }