Programming with JViews Maps > Introducing the Main Classes > Readers and Writers > The Web Map Server Reader

The OpenGIS® Web Map Service (WMS) 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 Sever (WMS):

This section contains the following topics:

The source code for the Map Builder demonstration, which contains all the code described in this section, can be found at <installdir>/jviews-maps81/samples/mapbuilder/index.html.

The IlvWMSReader Class

This class reads image features from a specified Web Map Server URL. It implements the IlvMapFeatureIterator interface to iterate over the read features.

Using the IlvWMSReader Class to Create Raster Data

To read WMS features from a Web Map Server using the IlvWMSReader object:

  1. Create an IlvWMSReader instance from a server URL:
URL url = new URL("a URL to a Web Map Server");
IlvWMSReader reader = new IlvWMSReader(url);
  1. 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]});
  1. Set the transformation to use to render WMS images, for example:
IlvCoordinateSystem cs = IlvCoordinateSystemProperty.
   GetCoordinateSystem(manager);
reader.setTransformation(IlvCoordinateTransformation.CreateTransformation
   (cs, IlvGeographicCoordinateSystem.KERNEL));
  1. 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();
}

The IlvWMSDataSource Class

The IlvWMSDataSource class provides a convenient way of creating a set of layers containing images retrieved from a Web Map Server in a manager.

Using the IlvWMSDataSource Class to Create Raster Data

To read WMS features using the IlvWMSDataSource:

  1. Create an IlvWMSDataSource:
URL url = new URL(("a URL to a Web Map Server");
IlvWMSDataSource source = new IlvWMSDataSource(url);
  1. Set the layers to be retrieved:
IlvWMSReader reader = source.getReader();
String[] layers = reader.getAvailableLayers();
source.setLayers(new String[]{layers[0]});
  1. Connect this data source with the manager of the view:
source.setManager(manager);
  1. Finally, start the WMS data source:
source.start();