Skip To Content ArcGIS for Developers Sign In Dashboard

Dynamic map service layer

An ArcGIS dynamic map service layer displays map content from an ArcGIS Server Map service. The Map service must not have been cached (tiled). The service generates map images when requested by the layer. As the user navigates the map, the layer requests new map images to be displayed. Because the map images are created dynamically, the contents of the map images can be customized by modifying some layer properties. If a dynamic layer's spatial reference does not match the map's spatial reference, the dynamic layer will automatically re-project its map contents to match the map's spatial reference.

ArcGIS Server Map services are based on map documents (*.mxd or *.msd files). A map document contains the features that need to displayed in a map. Features are real world entities such as buildings, pipes, and parcels. Features are organized into layers. For example, the map document of a national park may contain separate layers for hiking trails, picnic areas, campgrounds, and major roads. The map document also contains information that controls the appearance of the map, such as the symbology, visibility, scale ranges of layers, and so on. Map documents can be published to an ArcGIS Server to create Map services.

ArcGIS Server Map services are accessible on the web as SOAP and REST web services. You can find the URL of these web service endpoints using the ArcGIS Server Service Directory.

To instantiate an AGSDynamicMapServiceLayer, you need to provide a URL to the map service's REST web service endpoint. This URL is usually of the form http://<server:port>/<instance>/rest/services/<service>/MapServer.

let url = NSURL(string: "")
let layer = AGSDynamicMapServiceLayer(URL: url)

Another way to create the layer is by using an AGSMapServiceInfo object. You first create AGSMapServerInfo, then use it to create a layer. This is useful if you want to inspect the properties of the Map service before creating the layer, or if you want the layer to use different default settings, such as layer definitions or layer visibility, right from the start.

let url = NSURL(string: " Specialty/ESRI_StateCityHighway_USA/MapServer")
var error:NSError?
let info = AGSMapServiceInfo(URL:url, error: &error)
//inspect or modify the info object if you want
let layer = AGSDynamicMapServiceLayer(mapServiceInfo: info)

Creating an AGSMapServiceInfo is synchronous, which means that it will block the calling thread. You should not call this method on the main application thread, as it will prevent your application from responding to user input and, making it appear sluggish. Instead, call this method on a background thread.

After creating the layer, you can add it to the map to display its contents. When the layer is ready, its loaded property will be enabled. You can then safely access its properties.

if layer.loaded {
    println("Initial Envelope : \(layer.initialEnvelope)")

You can alter the map contents of the layer by modifying some properties. For example, you can specify which layers in the service should be visible by modifying the visibleLayer property.

//only display ‘ushigh’ (id=0) and ‘states’ (id=1) layer
layer.visibleLayers = [0, 1]

You can also choose to display only a subset of features in your dataset by specifying a layer definition.

//only display states beginning with 'C'
let layerID = 1
let defString = "STATE_NAME like 'C%'"
let layerDef = AGSLayerDefinition(layerId: 1, definition: defString)
layer.layerDefinitions = [layerDef]