The OpenGIS® Web Map Service (WMS
standard) Implementation Specification produces maps of spatially
referenced data dynamically from geographic information. This
international standard defines a map to be a portrayal of
geographic information as a digital image file suitable for
display on a computer screen. The OpenGIS standard provides three
operations (
GetCapabilities
,
GetMap
, and
GetFeatureInfo
) in support of the creation and display of registered and
superimposed map-like views of information that come
simultaneously from multiple remote and heterogeneous sources. For
more information about the OpenGIS standard, see http://www.opengeospatial.org/.
There are two ways of reading images from a
Web Map Server (WMS):
- Using an IlvWMSReader instance directly. In this case, you must write all the code required to render the WMS features into graphic objects and add them to the manager.
- Using an IlvWMSDataSource. This is a convenient way of performing all the above operations at once and is more integrated with the data model of the map.
The source code for the Map Builder demonstration, which contains
all the code described in this section, can be found at <installdir> /jviews-maps810/samples/mapbuilder/index.html.
The IlvWMSReader class reads image features from
a specified Web Map Server URL. It implements the IlvMapFeatureIterator interface to iterate
over the read features.
The IlvWMSDataSource class provides a convenient
way of creating a set of layers containing images retrieved from a
Web Map Server in a manager.
To read WMS features from a Web Map Server using the IlvWMSReader class and create raster
data:
-
Create an
IlvWMSReader
instance from a server URL. A WMS server URL can be the full http WMS request for capabilities, or at least the WMS request URL for this server. This information is dependent on the server itself and is usually available in the server's documentation. For instance :URL url = new URL("http://wms.jpl.nasa.gov/wms.cgi?request=GetCapabilities"); // "http://wms.jpl.nasa.gov/wms.cgi" will work as well IlvWMSReader reader = new IlvWMSReader(url);
-
Set the name of the layers to be rendered. The layer names can be retrieved from the server capabilities:
String[] layers = reader.getAvailableLayers(); reader.setLayerNames(new String[]{layers[0]});
-
Set the transformation to use to render WMS images, for example:
IlvCoordinateSystem cs = IlvCoordinateSystemProperty. GetCoordinateSystem(manager); reader.setTransformation(IlvCoordinateTransformation.CreateTransformation (cs, IlvGeographicCoordinateSystem.KERNEL));
-
Iterate over the features, render them with an appropriate IlvFeatureRenderer, and assign them to a manager:
IlvMapFeature feature = reader.getNextFeature(); IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer(); while(feature != null) { // Render the map feature into a graphic object. IlvGraphic graphic = renderer.makeGraphic(feature,null); // Add this object to the first layer of the manager. manager.addObject(graphic, 0, false); feature = reader.getNextFeature(); }
To read WMS features using the IlvWMSDataSource class :
-
Create an
IlvWMSDataSource
instance from a server URL. A WMS server URL can be the full http WMS request for capabilities, or at least the WMS request URL for this server. This information is dependent on the server itself and is usually available in the server's documentation. For instance:URL url = new URL("http://wms.jpl.nasa.gov/wms.cgi?request=GetCapabilities"); // "http://wms.jpl.nasa.gov/wms.cgi" will work as well IlvWMSDataSource source = new IlvWMSDataSource(url);
-
Set the layers to be retrieved:
IlvWMSReader reader = source.getReader(); String[] layers = reader.getAvailableLayers(); source.setLayers(new String[]{layers[0]});
-
Optionally set tiling parameters, to enable load-on-demand and better image resolution when zooming in:
source.setTilingParameters(true,5,5);
-
Connect this data source with the manager of the view:
source.setManager(manager);
-
Finally, start the WMS data source:
source.start();