Adding a WMS layer to your map

About WMS layers

The Open Geospatial Consortium, Inc. (OGC), Web Map Service (WMS) specification is an international specification for serving and consuming dynamic maps on the Web. WMS services are useful if you want to make your maps available online in an open, recognized way across different platforms and clients.

ArcGIS Runtime supports v1.1.1 and v1.3.0 of the WMS specification. You can consume WMS services hosted by any server including ArcGIS Server. ArcGIS Runtime supports the GetMap operation of WMS services. The maps returned by a WMS service are images only - they do not contain actual data.

ESRI maintains an Interoperability and Standards Web page detailing its support for OGC services in ArcGIS.

Adding WMS layers to your map

You can add a WMS Layer to your map as a basemap; in which case the map takes its spatial reference and extent from the WMS Layer. Alternatively, the WMS layer can be added on top of another layer being used as a basemap, such as an ArcGISTiledMapServiceLayer. Add a WMS layer and its sublayers as follows:

WmsDynamicMapServiceLayer esriStates = new WmsDynamicMapServiceLayer(
   "http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer");
map.getLayers().add(esriStates);

The number of layers in the WMS service layer directly affects the amount of time it takes to add the layer to the map. You can reduce this time by adding only the layers you require to the map. Add specific WMS layers as follows:

// the service has layers "0", "1", and "2", but here we only add layers "1" and "2"
WmsDynamicMapServiceLayer esriStates = new WmsDynamicMapServiceLayer(
				"http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer",
    new String[] {"1", "2"});
map.getLayers().add(esriStates);

In order to add specific WMS layers, you can use the GetCapabilities operation in a web browser to view the layers and styles to choose from. For example, use the following URL to determine which layers correspond to the ids used in the above example:

http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?REQUEST=GetCapabilities

You can also toggle the visibility of the sublayers in your WMS layer on the fly once the layer is already added to a map and initialized, as in the example below:

// show only the sublayer "2" of our WMS layer 'esriStates'
esriStates.setVisibleLayers(new String[]{"2"});
esriStates.refresh();
2/7/2013