WMS Layer

A Web Map Service (WMS) layer is based on data from an Open Geospatial Consortium (OGC), WMS server. OGC WMS is an OpenGIS standard specification for interactive mapping based on requesting map images from a server over the Internet. The WMS layer allows you to access these services over the Internet and add their content to a map. The layer supports only WMS versions 1.3, 1.1.1, and 1.1.

The online resource of each operation supported by a compliant WMS server is an HTTP uniform resource locator (URL), so a WMS service can be considered as a Representational State Transfer (REST) service. Unlike a standard Web service, a SOAP client is not necessary for consuming a WMS service. You can get a WMS service's service level metadata, a map image, or attribute values of a feature by sending a URL request to the server and viewing the corresponding responses in the browser either as an XML document or an image.

The WMS layer is represented by the class AGSWMSLayer. This class is a sub-class of AGSDynamicLayer.

Instantiating a WMS Layer

To instantiate an AGSWMSLayer, you need to provide a URL to the WMS service, not the map service's REST endpoint. This is usually of the form:

http://<server:port>/<instance>/services/<service>/MapServer/WMSServer

For example, if you have a folder Japan containing the map service Tokyo, running on myServer with the default instance arcgis, the URL of your WMS service would look like this:

http://myServer/arcgis/services/Japan/Tokyo/MapServer/WMSServer

NoteNote:

The structure of the URL would depend on the type of server. Hence, if you are consuming WMS services from servers other than ArcGIS, refer to the corresponding documentation for the URL structure.

//Instantiate the layer and add it to the mapView.
NSURL* url = [NSURL URLWithString: @"http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StateCityHighway_USA/MapServer/WMSServer"];  
AGSWMSLayer* wmsLayer = [[AGSWMSLayer alloc] initWithURL:url] autorelease];
[mapview addMapLayer:wmsLayer withName:@”Highways];

Verifying the Layer was loaded

When the layer is ready, its loaded property will be enabled. You can then safely access its properties. The following code shows you how to determine if the layer has loaded.

if(layer.loaded)
{   
  NSLog(@"Initial Envelope : %@", layer.initialEnvelope);  
}

Configuring WMS Layers

You can alter the visibility of the sub-layers of the WMS layer by modifying some properties. For example, you can specify which layers in the service should be visible by modifying the visibleLayers property.

//only display US highways and states layer in the above service
layer.visibleLayers = [NSArray arrayWithObjects:@”ushigh, @”states, nil];

Unsupported Coordinate Systems

There might be situations when the spatial reference that you are requesting the WMS Layer may be unsupported by your WMS Server. In this case, the mapView loads the layerView but does not draw the WMS map images. You can troubleshoot this by using the Key-Value Observer on the error property of AGSLayerView. You should remove it once the layer view has been verified to have the drawing error.

#pragma mark - Set KVO To Check Layer Drawing Errors

//assuming that the name of the layer is “WMS Layer”
- (void) addObserverToCheckLayerDrawingErrors {  
    
 UIView <AGSLayerView> *view = [mapView.mapLayerViews objectForKey:@”WMS Layer];
 [view addObserver:self forKeyPath:@"error" options:0 context:nil]; 
   
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
	
	UIView<AGSLayerView> *view = (UIView<AGSLayerView>*)object;
 NSLog(@”Layer View Drawing Error: %@”, view.error];
	[view removeObserver:self forKeyPath:@"error"];

}

5/9/2012