Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / examples / WMSLayers.java
blobe590bcca4542253daac9f417259b187dfee93247
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.examples;
9 import gov.nasa.worldwind.*;
10 import gov.nasa.worldwind.layers.*;
11 import gov.nasa.worldwind.wms.*;
12 import org.w3c.dom.*;
13 import org.xml.sax.*;
15 import javax.xml.parsers.*;
16 import java.io.*;
17 import java.net.*;
19 /**
20 * Retrieves the capabilities doc from a wms server and adds the named layers described there to the ww model.
22 * @author tag
23 * @version $Id: WMSLayers.java 2131 2007-06-22 22:45:35Z jason $
25 public class WMSLayers extends ApplicationTemplate
27 private static final String[] servers = new String[]
29 "http://neowms.sci.gsfc.nasa.gov/wms/wms"
32 private static class AppFrame extends ApplicationTemplate.AppFrame
34 public AppFrame()
36 try
38 // Retrieve the server's capabilities document and parse it into a DOM.
39 // Set up the DOM.
40 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
41 docBuilderFactory.setNamespaceAware(true);
42 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
43 Document doc;
45 // Request the capabilities document from the server.
46 // The server id here is hardcoded. An interactive example would provide a choice.
47 String server = servers[0];
48 CapabilitiesRequest req = new CapabilitiesRequest(new URI(server));
49 doc = docBuilder.parse(req.toString());
51 // Parse the DOM as a capabilities document.
52 Capabilities caps = Capabilities.parse(doc);
53 System.out.println("wms server version: " + caps.getVersion());
55 // Get all the named layers in the capabilities document.
56 Element[] layerCaps = caps.getNamedLayers();
57 if (layerCaps == null || layerCaps.length == 0)
59 System.out.println("No named layers found.");
60 return;
63 // Just choose the first named layer for this example.
64 // An interactive example would present the available choices to the user.
65 AVListImpl params = new AVListImpl();
66 params.setValue(AVKey.LAYER_NAMES, caps.getLayerName(layerCaps[0]));
68 // For the chosen layer, determine the available styles and pick one.
69 // An interactive example would present the available choices to the user.
70 Element[] styles = caps.getLayerStyles(layerCaps[0]);
71 if (styles != null && styles.length > 0)
72 params.setValue(AVKey.STYLE_NAMES, caps.getStyleName(styles[0]));
74 // Create a World Wind wms layer.
75 Layer layer = WMSLayerFactory.newLayer(caps, params);
77 // The GeoBoost wms server is especially slow, so increase retrieval timeouts
78 // if that's the server.
79 if (server.contains("GeoBoost"))
81 layer.setValue(AVKey.URL_CONNECT_TIMEOUT, 30000);
82 layer.setValue(AVKey.URL_READ_TIMEOUT, 30000);
83 layer.setValue(AVKey.RETRIEVAL_QUEUE_STALE_REQUEST_LIMIT, 60000);
86 // Insert the layer in front of the compass layer in the default layer list.
87 insertBeforePlacenames(this.wwd, layer);
89 // The layer should start appearing on the globe once this constructor returns.
91 catch (ParserConfigurationException e)
93 e.printStackTrace();
95 catch (SAXException e)
97 e.printStackTrace();
99 catch (IOException e)
101 e.printStackTrace();
103 catch (URISyntaxException e)
105 e.printStackTrace();
110 public static void main(String[] args)
112 ApplicationTemplate.start("World Wind Lines In Space", AppFrame.class);