Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/support
esri/workers
Class: ArcGISDynamicMapServiceLayer

dojo.require("esri.layers.agsdynamic");

Description

(Added at v1.0)
Allows you to work with a dynamic map service resource exposed by the ArcGIS Server REST API. A dynamic map service generates images on the fly. For cached map services, see ArcGISTiledMapServiceLayer.

If the first layer added to the map is an ArcGISDynamicMapServiceLayer, the map will take on the projection of this layer.

Samples

Search for samples that use this class.

Class hierarchy

esri/layers.Layer
|_esri/layers.DynamicMapServiceLayer
  |_esri/layers.ArcGISDynamicMapServiceLayer

Constructors

NameSummary
new esri.layers.ArcGISDynamicMapServiceLayer(url, options?)Creates a new ArcGISDynamicMapServiceLayer object.

Properties

NameTypeSummary
attributionDataUrlStringThe URL, when available, where the layer's attribution data is stored.
capabilitiesStringCapabilities of the map service, possible values are Map, Query and Data.
classNameStringclass attribute of the layer's node.
copyrightStringCopyright string as defined by the map service.
credentialCredentialProvides credential information for the layer such as userid and token if the layer represents a resource that is secured with token-based authentication.
descriptionStringMap description as defined by the map service.
disableClientCachingBooleanWhen true, images are always requested from the server and the browser's cache is ignored.
dpiNumberThe output dpi of the dynamic map service layer.
dynamicLayerInfosDynamicLayerInfo[]Array of DynamicLayerInfos used to change the layer ordering or redefine the map.
fullExtentExtentFull extent as defined by the map service.
gdbVersionStringThe geodatabase version.
hasAttributionDataBooleanWhen true, the layer has attribution data.
idStringID assigned to the layer.
imageFormatStringThe output image type.
imageTransparencyBooleanWhether or not background of dynamic image is transparent.
infoTemplatesObjectA dictionary from the layer id to the layerInfoTemplateOptions object.
initialExtentExtentInitial extent as defined by the map service.
layerDefinitionsString[]Sets the layer definitions used to filter the features of individual layers in the map service.
layerDrawingOptionsLayerDrawingOptions[]Array of LayerDrawingOptions used to override the way layers are drawn.
layerInfosLayerInfo[]Returns the available layers in service and their default visibility.
layerTimeOptionsLayerTimeOptions[]Returns the current layer time options if applicable.
loadErrorErrorSet if the layer failed to load.
loadedBooleanWhen the layer is loaded, the value becomes "true", and layer properties can be accessed.
maxImageHeightNumberThe maximum image height, in pixels, that the map service will export.
maxImageWidthNumberThe maximum image width, in pixels, that the map service will export.
maxRecordCountNumberThe maximum number of results that can be returned from query, identify and find operations.
maxScaleNumberMaximum visible scale for the layer.
minScaleNumberMinimum visible scale for the layer.
opacityNumberOpacity or transparency of layer.
refreshIntervalNumberRefresh interval of the layer in minutes.
showAttributionBooleanWhen true, the layer's attribution is displayed on the map.
spatialReferenceSpatialReferenceThe spatial reference of the map service.
supportsDynamicLayersBooleanIndicates if the service supports dynamic layers.
suspendedBooleanWhen true, the layer is suspended.
timeInfoTimeInfoTemporal information for the layer, such as time extent.
unitsStringDefault units of the layer as defined by the service.
urlStringURL to the ArcGIS Server REST resource that represents a map service.
useMapImageBooleanWhen true, the image is saved to the server, and a JSON formatted response is sent to the client with the URL location of the image.
versionNumberThe version of ArcGIS Server where the map service is published.
visibleBooleanVisibility of the layer.
visibleAtMapScaleBooleanWhen true, the layer is visible at the current map scale.
visibleLayersNumber[]Gets the visible layers of the exported map.

Methods

NameReturn typeSummary
attr(name, value)LayerAdds a new attribute or changes the value of an existing attribute on the layer's node.
createDynamicLayerInfosFromLayerInfos()DynamicLayerInfo[]Create an array of DynamicLayerInfos based on the current set of LayerInfo.
exportMapImage(imageParameters?, callback?)NoneExports a map using values as specified by ImageParameters.
getAttributionData()DeferredAsynchronously returns custom data for the layer when available.
getImageUrl(extent, width, height, callback)StringMethod to implement when extending DynamicMapServiceLayer.
getMap()MapReturns reference to the map control the layer is added to.
getNode()HTMLElementReturns the layer's DOM node.
hide()NoneSets the visibility of the layer to "false".
isVisibleAtScale(scale)BooleanReturns true if the layer is visible at the given scale.
refresh()NoneRefreshes the map by making a new request to the server.
resume()NoneResumes layer drawing.
setDPI(dpi, doNotRefresh?)NoneSets the dpi of the exported map.
setDefaultLayerDefinitions(doNotRefresh?)NoneResets all layer definitions to those defined in the service.
setDefaultVisibleLayers(doNotRefresh?)NoneClears the visible layers as defined in setVisibleLayers, and resets to the default layers of the map service.
setDisableClientCaching(disable)NoneSets whether images are always requested from the server and the browser's cache is ignored.
setDynamicLayerInfos(dynamicLayerInfos, doNotRefresh?)NoneSpecify an array of DynamicLayerInfos used to change the layer ordering or to redefine the map.
setGDBVersion(gdbVersion, doNotRefresh?)NoneSet the version for the ArcGIS DynamicMapServiceLayer.
setImageFormat(imageFormat, doNotRefresh?)NoneSets the image format of the exported map.
setImageTransparency(transparent, doNotRefresh?)NoneSets the background of a dynamic image to transparent.
setInfoTemplates(infoTemplates)NoneSet the infoTemplates property.
setLayerDefinitions(layerDefinitions, doNotRefresh?)NoneSets the layer definitions used to filter the features of individual layers in the map service.
setLayerDrawingOptions(layerDrawingOptions, doNotRefresh?)NoneSpecify an array of LayerDrawingOptions that override the way the layers are drawn.
setLayerTimeOptions(options, doNotRefresh?)NoneSets the time-related options for the layer.
setMaxScale(scale)NoneSet the maximum scale for the layer.
setMinScale(scale)NoneSet the minimum scale for the layer.
setOpacity(opacity)NoneSets the opacity of the layer.
setRefreshInterval(interval)LayerChanges the layer's refresh interval to the given value (in minutes).
setScaleRange(minScale, maxScale)NoneSet the scale range for the layer.
setUseMapTime(update)NoneDetermine if the layer will update its content based on the map's current time extent.
setVisibility(isVisible)NoneSets the visibility of the layer.
setVisibleLayers(ids, doNotRefresh?)NoneSets the visible layers of the exported map.
show()NoneSets the visibility of the layer to "true".
suspend()NoneSuspends layer drawing.

Events

[ On Style Events | Connect Style Event ]
All On Style event listeners receive a single event object. Additionally, the event object also contains a 'target' property whose value is the object which fired the event.

Events

NameEvent ObjectSummary
error
{
  error: <Error>
}
Fires when there is a problem retrieving a layer.
gdb-version-changeFired when the geodatabase version is switched.
load
{
  layer: <Layer>
}
Fires after layer properties for the layer are successfully populated.
map-image-export
{
  mapImage: <MapImage>
}
Fires when the map export is completed.
opacity-change
{
  opacity: <Number>
}
Fires when the layer opacity has been changed, and returns an object with the opacity value.
refresh-interval-changeThis event is fired when the layer's refreshInterval is modified.
resumeFires when a layer resumes drawing.
scale-range-changeFires when a layer's minScale and/or maxScale is changed.
scale-visibility-changeFires when a layer's scale visibility changes.
suspendFires when a layer suspends drawing.
updateFires any time a layer has finished loading or updating itself.
update-end
{
  error: <Error>
}
Fires when a layer has finished updating its content.
update-startFires when a layer begins to update its content.
visibility-change
{
  visible: <Boolean>
}
Fires when the layer visibility has been changed, and returns an object with a Boolean visible property containing the new visibility value of the layer.
visible-layers-change
{
  visibleLayers: <Number[]>
}
Fires when the visibleLayers property is changed.
Constructor Details

new esri.layers.ArcGISDynamicMapServiceLayer(url, options?)

Creates a new ArcGISDynamicMapServiceLayer object. A URL is a required parameter. This layer also takes some optional parameters. These optional parameters can be included in any order.
Parameters:
<String> url Required URL to the ArcGIS Server REST resource that represents a map service. An example is http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer. For more information on constructing a URL, see The Services Directory and the REST API.
<Object> options Optional Optional parameters. See options list.
options properties:
<String> className Optional Class attribute to set for the layer's node.
<String> gdbVersion Optional Specify the geodatabase version to display. (As of v2.7). Requires ArcGIS Server service 10.1 or greater
<String> id Optional Id to assign to the layer. If not assigned, esri.Map assigns value.
<ImageParameters> imageParameters Optional Represents the image parameter options.
<Object> infoTemplates Optional infoTemplates object. See the infoTemplates property for details.
<Number> opacity Optional Initial opacity or transparency of layer. Values range from 0.0 to 1.0, where 0.0 is 100% transparent and 1.0 has no transparency. The default value is 1.0.
<Number> refreshInterval Optional Refresh interval of the layer in minutes. Non-zero value sets up automatic layer refresh at the specified interval.
<Object> resourceInfo Optional Specify the metadata of the layer.
<Boolean> showAttribution Optional When true, the layer's attribution is displayed on the map. The default value is true. Added at v3.1
require([
  "esri/layers/ArcGISDynamicMapServiceLayer", ... 
], function(ArcGISDynamicMapServiceLayer, ... ) {
  var census = new ArcGISDynamicMapServiceLayer(layerUrl, {
    "showAttribution": false,
    "opacity": 0.5
  });
  ...
});
<Boolean> useMapImage Optional By default, images are exported in MIME format, and the image is streamed to the client. When useMapImage is set to true, the image is saved to the server, and a JSON formatted response is sent to the client with the URL location of the image. A second call is automatically made to the server to retrieve the image. This methodology is required for secure services that go through a proxy server. In this situation, a map image cannot be streamed. (As of v1.2) Deprecated at v2.0. Prior to v2.0 this option was used to configure the map to use the proxy all the time. This is not the optimal behavior so at v2.0 the switch to use the proxy will automatically happen if needed.
<Boolean> useMapTime Optional When true, the layer will update its content based on the map's time extent. The default values is true.
<Boolean> visible Optional Initial visibility of the layer. Default is true.
Sample:

new esri.layers.ArcGISDynamicMapServiceLayer(

  "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer",

  {useMapImage:true});

Property Details

<String> attributionDataUrl

The URL, when available, where the layer's attribution data is stored. (Added at v3.1)

<String> capabilities

Capabilities of the map service, possible values are Map, Query and Data. Only available if the map service is published using ArcGIS Server version 10 or greater. (Added at v2.1)
Sample:

console.log(layer.capabilities);

<String> className

class attribute of the layer's node. (Added at v3.7)

<String> copyright

Copyright string as defined by the map service.

<Credential> credential

Provides credential information for the layer such as userid and token if the layer represents a resource that is secured with token-based authentication. This value is available after the layer has been loaded i.e. layer.loaded is true. (Added at v2.5)

<String> description

Map description as defined by the map service.

<Boolean> disableClientCaching

When true, images are always requested from the server and the browser's cache is ignored. This should be used when the data supporting the map service changes frequently. (Added at v1.2)
Known values: true | false
Default value: false

<Number> dpi

The output dpi of the dynamic map service layer.
Default value: 96
See also: setDPI()

<DynamicLayerInfo[]> dynamicLayerInfos

Array of DynamicLayerInfos used to change the layer ordering or redefine the map. (Added at v2.7)

<Extent> fullExtent

Full extent as defined by the map service.

<String> gdbVersion

The geodatabase version. Only applicable if the layer's data source is registered as versioned in SDE. Only valid with ArcGIS Server services version 10.1 or greater. (Added at v2.7)

<Boolean> hasAttributionData

When true, the layer has attribution data. The default value is false. Use the getAttributionData method to retrieve this data as JSON. (Added at v3.1)
Known values: true | false

<String> id

ID assigned to the layer. If not assigned, esri.Map assigns value. By default, the ID of the layer is "layer" followed by a number. The ID can be user defined only in the layer constructor.
Sample:
  • Setting the layer ID in the layer constructor.
    population = new esri.layers.ArcGISDynamicMapServiceLayer("http://myserver/arcgis/rest/population/MapServer/Layers", {id:"population"});
    
  • Setting the layer ID after a layer is initialized.
    population.id = "population";
  • Retrieving the layer ID.
    function getMapLayers() {
      for (var j=0, jl=myMap.layerIds.length; j<jl; j++) {
        var currentLayer = myMap.getLayer(myMap.layerIds[j]);
        alert("id: " + currentLayer.id);
      }
    }
    

<String> imageFormat

The output image type. As of ArcGIS Server 9.3.1, the list of supported image formats is included in the description of Map Services in Services Directory under "Supported Image Format Types". In addition, as of ArcGIS Server 9.3.1, optimized map services can produce true PNG32 images.
Known values: png | png8 | png24 | png32 | jpg | pdf | bmp | gif | svg
Default value: png8

<Boolean> imageTransparency

Whether or not background of dynamic image is transparent.
Known values: true | false
Default value: true

<Object> infoTemplates

A dictionary from the layer id to the layerInfoTemplateOptions object. See the object specifications table below for properties of the layerInfoTemplateOptions object. (Added at v3.10)
Object Specifications:
<layerInfoTemplateOptions>
<InfoTemplate> infoTemplate Required The infoTemplate for the layer.
<String> layerUrl Required URL to the layer.
<Object> resourceInfo Required Metadata of the layer.
Sample:
var infoTemplates = {
  3: {
    infoTemplate: new InfoTemplate(),
    layerUrl: null
  }
};

<Extent> initialExtent

Initial extent as defined by the map service.

<String[]> layerDefinitions

Sets the layer definitions used to filter the features of individual layers in the map service. Layer definitions with semicolons or colons are supported if using a map service published using ArcGIS Server 10.0. (Added at v1.2)

<LayerDrawingOptions[]> layerDrawingOptions

Array of LayerDrawingOptions used to override the way layers are drawn. (Added at v2.7)

<LayerInfo[]> layerInfos

Returns the available layers in service and their default visibility.

<LayerTimeOptions[]> layerTimeOptions

Returns the current layer time options if applicable. Use the setLayerTimeOptions method to modify the time options. (Added at v2.0)

<Error> loadError

Set if the layer failed to load. (Added at v3.9)

<Boolean> loaded

When the layer is loaded, the value becomes "true", and layer properties can be accessed. The onLoad event is also fired.
Known values: true | false

<Number> maxImageHeight

The maximum image height, in pixels, that the map service will export. Requires ArcGIS Server version 10.1 or greater. (Added at v2.6)

<Number> maxImageWidth

The maximum image width, in pixels, that the map service will export. Requires ArcGIS Server version 10.1 or greater. (Added at v2.6)

<Number> maxRecordCount

The maximum number of results that can be returned from query, identify and find operations. Requires ArcGIS Server version 10.1 or greater. (Added at v2.6)

<Number> maxScale

Maximum visible scale for the layer. If the map is zoomed in beyond this scale, the layer will not be visible. A value of 0 means the layer does not have a maximum scale. The default value is 0. (Added at v3.1)
Default value: 0

<Number> minScale

Minimum visible scale for the layer. If the map is zoomed out beyond this scale, the layer will not be visible. A value of 0 means the layer does not have a visible scale. The default value is 0. (Added at v3.1)
Default value: 0

<Number> opacity

Opacity or transparency of layer. Values range from 0.0 to 1.0, where 0.0 is 100% transparent and 1.0 has no transparency.
Known values: 0.0 - 1.0
Default value: 1.0

<Number> refreshInterval

Refresh interval of the layer in minutes. Non-zero value indicates automatic layer refresh at the specified interval. Value of 0 indicates auto refresh is not enabled. (Added at v3.7)

<Boolean> showAttribution

When true, the layer's attribution is displayed on the map. This attribution can be found as 'Copyright Text' at the REST endpoint. The default value is true. (Added at v3.1)
Known values: true | false

<SpatialReference> spatialReference

The spatial reference of the map service. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.

<Boolean> supportsDynamicLayers

Indicates if the service supports dynamic layers. (Added at v3.11)
Known values: true | false

<Boolean> suspended

When true, the layer is suspended. A layer is considered to be suspended when one of the following is true:
  • The layer is hidden.
  • The layer is not visible at the current map scale.
  • The layer is explicitly suspended by calling the Layer.suspend method.
(Added at v3.1)
Known values: true | false

<TimeInfo> timeInfo

Temporal information for the layer, such as time extent. If this property is null or not specified, then the layer does not support time-related operations. (Added at v2.0)

<String> units

Default units of the layer as defined by the service. If the layer is the base map, the map is in these units.

<String> url

URL to the ArcGIS Server REST resource that represents a map service. To obtain the URL, use Services Directory. An example URL for the Street Map service on ArcGIS Online is:
http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer. (Added at v1.2)

<Boolean> useMapImage

When true, the image is saved to the server, and a JSON formatted response is sent to the client with the URL location of the image. A second call is automatically made to the server to retrieve the image. This value is set in the constructor using useMapImage. Deprecated at v2.0. (Added at v1.2)
Known values: true | false
Default value: false

<Number> version

The version of ArcGIS Server where the map service is published. Examples are 9.3, 9.31, 10. (Added at v2.1)

<Boolean> visible

Visibility of the layer.
Known values: true | false
Default value: true

<Boolean> visibleAtMapScale

When true, the layer is visible at the current map scale. (Added at v3.1)
Known values: true | false

<Number[]> visibleLayers

Gets the visible layers of the exported map. (Added at v1.2)
Method Details

attr(name, value)

Adds a new attribute or changes the value of an existing attribute on the layer's node. Removes the attribute if the value is null or undefined. (Added at v3.7)
Return type: Layer
Parameters:
<String> name Required The name of the attribute.
<String> value Required The value of the attribute. Set this value as null to remove the attribute.

createDynamicLayerInfosFromLayerInfos()

Create an array of DynamicLayerInfos based on the current set of LayerInfo. (Added at v2.7)
Return type: DynamicLayerInfo[]
Sample:
var dynamicLayerInfos = usaLayer.createDynamicLayerInfosFromLayerInfos();

exportMapImage(imageParameters?, callback?)

Exports a map using values as specified by ImageParameters. On completion, MapImage is returned.
Parameters:
<ImageParameters> imageParameters Optional Input parameters assigned before exporting the map image.
<Function> callback Optional The function to call when the method has completed. The arguments in the function are the same as the onMapImageExport event.

getAttributionData()

Asynchronously returns custom data for the layer when available. This attribution can be found as 'Copyright Text' at the REST endpoint. (Added at v3.1)
Return type: Deferred

getImageUrl(extent, width, height, callback)

Method to implement when extending DynamicMapServiceLayer. For more details, see Creating custom layer types. (Added at v1.3)
Return type: String
Parameters:
<Extent> extent Required Current extent of the map.
<Number> width Required Current width of the map in pixels.
<Number> height Required Current height of the map in pixels.
<Function> callback Required The function to call when the method has completed.

getMap()

Returns reference to the map control the layer is added to. Returns null or undefined if it is not added to a map. (Added at v3.7)
Return type: Map

getNode()

Returns the layer's DOM node. (Added at v3.7)
Return type: HTMLElement

hide()

Sets the visibility of the layer to "false". The layer is not removed, but it is hidden from view.

isVisibleAtScale(scale)

Returns true if the layer is visible at the given scale. (Added at v3.1)
Return type: Boolean
Parameters:
<Number> scale Required The scale at which to check if the layer is visible.

refresh()

Refreshes the map by making a new request to the server. In order to refresh the layer in this manner, setDisableClientCaching must be true. This ensures that map images are not cached on the client. (Added at v1.2)

resume()

Resumes layer drawing. (Added at v3.1)

setDPI(dpi, doNotRefresh?)

Sets the dpi of the exported map. The default value is 96.
Parameters:
<Number> dpi Required DPI value.
<Boolean> doNotRefresh Optional Added at version 2.2 When true the layer will not refresh the map image. The default value is false.
See also: dpi

setDefaultLayerDefinitions(doNotRefresh?)

Resets all layer definitions to those defined in the service. (Added at v1.1)
Parameters:
<Boolean> doNotRefresh Optional When true the layer will not refresh the map image. The default value is false. Added at version 2.2.

setDefaultVisibleLayers(doNotRefresh?)

Clears the visible layers as defined in setVisibleLayers, and resets to the default layers of the map service.
Parameters:
<Boolean> doNotRefresh Optional When true the layer will not refresh the map image. The default value is false. Added at version 2.2.

setDisableClientCaching(disable)

Sets whether images are always requested from the server and the browser's cache is ignored. This should be used when the data supporting the map service changes frequently. (Added at v1.2)
Parameters:
<Boolean> disable Required When true, client side caching is disabled.
Sample:

var layer = new esri.layers.ArcGISDynamicMapServiceLayer(

        "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/MapServer");

layer.setDisableClientCaching(true);

setDynamicLayerInfos(dynamicLayerInfos, doNotRefresh?)

Specify an array of DynamicLayerInfos used to change the layer ordering or to redefine the map. (Added at v2.7)
Parameters:
<DynamicLayerInfo[]> dynamicLayerInfos Required An array of dynamic layer infos.
<Boolean> doNotRefresh Optional When true the layer will not refresh the map image. The default value is false.
Sample:
var dynamicLayerInfos = [];
var dynamicLayerInfo = new esri.layers.DynamicLayerInfo();
dynamicLayerInfo.id = 1;
var dataSource = new esri.layers.QueryDataSource();
dataSource.workspaceId = "d203_db";
dataSource.query = "SELECT * FROM sde.sde.states_geom";

var layerSource = new esri.layers.LayerDataSource();
layerSource.dataSource = dataSource;
dynamicLayerInfo.source = layerSource;
dynamicLayerInfos.push(dynamicLayerInfo);

dynamicData.setDynamicLayerInfos(dynamicLayerInfos);

setGDBVersion(gdbVersion, doNotRefresh?)

Set the version for the ArcGIS DynamicMapServiceLayer. Requires an ArcGIS Server service 10.1 or greater (Added at v2.7)
Parameters:
<String> gdbVersion Required The name of the version to display.
<Boolean> doNotRefresh Optional When true the layer will not refresh the map image. The default value is false. Added at version 2.7.
Sample:
layer.setGDBVersion("sde.dynamicLayers");

setImageFormat(imageFormat, doNotRefresh?)

Sets the image format of the exported map.
Parameters:
<String> imageFormat Required Valid values are png | png8 | png24 | png32 | jpg | pdf | bmp | gif | svg.

Note: The png32 image format is only supported by msd based services published with version 10 or greater. View the service's 'Supported image Format Types' value for the map service to determine which formats are supported. The map server performs antialiasing when requesting png32 for an optimized map service.

<Boolean> doNotRefresh Optional Added at version 2.2 When true the layer will not refresh the map image. The default value is false.
See also: imageFormat

setImageTransparency(transparent, doNotRefresh?)

Sets the background of a dynamic image to transparent.
Parameters:
<Boolean> transparent Required Valid values are true | false. The default is "true".
<Boolean> doNotRefresh Optional Added at version 2.2 When true the layer will not refresh the map image. The default value is false.

setInfoTemplates(infoTemplates)

Set the infoTemplates property. (Added at v3.10)
Parameters:
<Object> infoTemplates Required infoTemplates object. See the infoTemplates property for details. See also: Add two dynamic maps.

setLayerDefinitions(layerDefinitions, doNotRefresh?)

Sets the layer definitions used to filter the features of individual layers in the map service. If the layer definition expression is longer than approximately 2000 characters you will need to set up a proxy page.

Layer definitions with semicolons or colons are supported if using a map service published using ArcGIS Server 10.
Parameters:
<String[]> layerDefinitions Required An array containing each layer's definition.
<Boolean> doNotRefresh Optional Added at version 2.2 When true the layer will not refresh the map image. The default value is false.
Sample:

The layerDefinitions argument is an array of layer definition expressions such as in the code snippet below.

var layerDefinitions = [];
layerDefinitions[0] = "POPULATION > 5000000";
layerDefinitions[5] = "AREA > 100000";
dynamicMapServiceLayer.setLayerDefinitions(layerDefinitions);

Note that the array indices 0 and 5 are valid layer IDs, and POPULATION and AREA are valid attribute fields associated with the respective layers. Definition expressions for layers that are currently not visible will be ignored by the server.

setLayerDrawingOptions(layerDrawingOptions, doNotRefresh?)

Specify an array of LayerDrawingOptions that override the way the layers are drawn. (Added at v2.7)
Parameters:
<LayerDrawingOptions[]> layerDrawingOptions Required An array of layer drawing options.
<Boolean> doNotRefresh Optional When true the layer will not refresh the map image. The default value is false.
Sample:
var layerDrawingOptions = [];
var layerDrawingOption = new esri.layers.LayerDrawingOptions();

layerDrawingOption.renderer = new esri.renderer.SimpleRenderer(mySymbol);

layerDrawingOptions[1] = layerDrawingOption;
dynamicData.setLayerDrawingOptions(layerDrawingOptions);

setLayerTimeOptions(options, doNotRefresh?)

Sets the time-related options for the layer. (Added at v2.0)
Parameters:
<LayerTimeOptions[]> options Required Array of LayerTimeOptions objects that allow you to override how a layer is exported in reference to the map's time extent. There is one object per sub-layer. In the following example, array indices 2 and 5 are valid sub-layer IDs.
require([
  "esri/layers/LayerTimeOptions", "esri/layers/TimeInfo", ... 
], function(LayerTimeOptions, TimeInfo, ... ) {
  var timeOption1 = new LayerTimeOptions();
  timeOption1.timeOffset = 4;
  timeOption1.timeOffsetUnits = TimeInfo.UNIT_YEARS;

  var options = [];
  options[2]= timeOption1;
  options[5] = timeOption2;
  imageParameters.layerTimeOptions = options;
  ...
});
<Boolean> doNotRefresh Optional When true the layer will not refresh the map image. The default value is false. Added at version 2.2.

setMaxScale(scale)

Set the maximum scale for the layer. (Added at v3.1)
Parameters:
<Number> scale Required The maximum scale at which the layer is visible.

setMinScale(scale)

Set the minimum scale for the layer. (Added at v3.1)
Parameters:
<Number> scale Required The minimum scale at which the layer is visible.

setOpacity(opacity)

Sets the opacity of the layer. Values range from 0.0 to 1.0, where 0.0 is 100% transparent and 1.0 has no transparency.
Parameters:
<Number> opacity Required Value from 0 to 1, where 0 is 100% transparent and 1 has no transparency. The default value is 1.
Sample:

layer.setOpacity(0.5);

setRefreshInterval(interval)

Changes the layer's refresh interval to the given value (in minutes). Non-zero value sets up automatic layer refresh at the specified interval. Value of 0 stops auto refresh. (Added at v3.7)
Return type: Layer
Parameters:
<Number> interval Required Refresh interval of the layer in minutes. Non-zero value indicates automatic layer refresh at the specified interval. Value of 0 indicates auto refresh is not enabled.

setScaleRange(minScale, maxScale)

Set the scale range for the layer. If minScale and maxScale are set to 0 then the layer will be visible at all scales. (Added at v3.1)
Parameters:
<Number> minScale Required The minimum scale at which the layer is visible.
<Number> maxScale Required The maximum scale at which the layer is visible.

setUseMapTime(update)

Determine if the layer will update its content based on the map's current time extent. Default value is true. (Added at v2.2)
Parameters:
<Boolean> update Required When false the layer will not update its content based on the map's time extent. Default value is true.

setVisibility(isVisible)

Sets the visibility of the layer. When true, the layer is visible.
Parameters:
<Boolean> isVisible Required Set the visibility of the layer.

setVisibleLayers(ids, doNotRefresh?)

Sets the visible layers of the exported map. By default, the visible layers are as defined by the default visibility in LayerInfo. To display no visible layers specify an array with a value of -1.
   

if(visible.length === 0){

  visible.push(-1);

}

layer.setVisibleLayers(visible);

Parameters:
<Number[]> ids Required Array of layer IDs.
<Boolean> doNotRefresh Optional When true the layer will not refresh the map image. The default value is false. Added at version 2.2.
Sample:

var inputs = dojo.query(".list_item"), input;

visible = [];

for (var i=0, il=inputs.length; i< il; i++) {

  if (inputs[i].checked) {

    visible.push(inputs[i].id);

  }

}

layer.setVisibleLayers(visible);

See also: visibleLayers

show()

Sets the visibility of the layer to "true".

suspend()

Suspends layer drawing. (Added at v3.1)
Event Details
[ On Style Events | Connect Style Event ]

error

Fires when there is a problem retrieving a layer. Should be used in favor of onError. (Added at v3.5)
Event Object Properties:
<Error> error ArcGIS Server error message returned in a JavaScript error object.

gdb-version-change

Fired when the geodatabase version is switched. (Added at v3.6)

load

Fires after layer properties for the layer are successfully populated. This event must be successful before the layer can be added to the map. Should be used in favor of onLoad. (Added at v3.5)
Event Object Properties:
<Layer> layer The loaded layer.

map-image-export

Fires when the map export is completed. (Added at v3.6)
Event Object Properties:
<MapImage> mapImage Contains the properties of a dynamically generated map image.

opacity-change

Fires when the layer opacity has been changed, and returns an object with the opacity value. Should be used in favor of onOpacityChange. (Added at v3.5)
Event Object Properties:
<Number> opacity Fires when the layer opacity (transparency) changes. A number property named opacity that indicates the new opacity. Values range from 0.0 to 1.0, where 0.0 is 100% transparent and 1.0 has no transparency.

refresh-interval-change

This event is fired when the layer's refreshInterval is modified. (Added at v3.7)

resume

Fires when a layer resumes drawing. (Added at v3.6)

scale-range-change

Fires when a layer's minScale and/or maxScale is changed. (Added at v3.6)

scale-visibility-change

Fires when a layer's scale visibility changes. The scale visibility changes when a layer is initially visible and becomes invisible because the map scale does not intersect the layer's scale range or vice versa. (Added at v3.6)

suspend

Fires when a layer suspends drawing. (Added at v3.6)

update

Fires any time a layer has finished loading or updating itself. For an ArcGISTiledMapServiceLayer, the event fires when all required tiles have been retrieved and displayed. For an ArcGISDynamicMapServiceLayer or ArcGISImageServiceLayer, the event fires when the map image has been retrieved and displayed. For a GraphicsLayer, the event fires when all graphics have been redrawn after a pan or zoom. Deprecated at v2.0. Use update-start and update-end instead. (Added at v3.6)

update-end

Fires when a layer has finished updating its content. It is the responsibility of the subclass to determine when this event is fired. Should be used in favor of onUpdateEnd. (Added at v3.5)
Event Object Properties:
<Error> error Optional argument. The error object is available when an error occurs during the update.

update-start

Fires when a layer begins to update its content. It is the responsibility of the subclass to determine when this event is fired. Should be used in favor of onUpdateStart. (Added at v3.5)

visibility-change

Fires when the layer visibility has been changed, and returns an object with a Boolean visible property containing the new visibility value of the layer. Should be used in favor of onVisibilityChange. (Added at v3.5)
Event Object Properties:
<Boolean> visible Fires when the layer visibility changes. A boolean property named visible indicates whether or not the layer is visible after visibility changed.

visible-layers-change

Fires when the visibleLayers property is changed. (Added at v3.13)
Event Object Properties:
<Number[]> visibleLayers An array of visibleLayers by index.
Sample:
require([
...
], function(...)
  layer.on('visible-layers-change', function(e) {
    console.log ('The layer(s) changed: ', e.visibleLayers.join(', '));
  });
  ...
});
Show Modal