Class: LayerE-mail This Topic Printable Version Give Us Feedback

Description

The base class for all layers that can be added to a map.

Layer has no constructor. Use ArcGISDynamicMapServiceLayer or ArcGISTiledMapServiceLayer.

Class hierarchy

esri.layers.Layer

Subclasses

DynamicMapServiceLayer  GraphicsLayer  TiledMapServiceLayer  

Properties

Property Type Description
id String 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.
loaded Boolean When the layer is loaded, the value becomes "true", and layer properties can be accessed. The onLoad event is also fired.
opacity Number 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.
url String 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.
visible Boolean Visibility of the layer.

Methods

Method Return Value Description
hide() none Sets the visibility of the layer to "false". The layer is not removed, but it is hidden from view.
setOpacity(opacity) none 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.
show() none Sets the visibility of the layer to "true".

Events

Event Description
onError(error) Fires when there is a problem retrieving a layer.
onLoad(layer) Fires after layer properties for the layer are successfully populated. This event must be successful before the layer can be added to the map.
onOpacityChange(opacity) Fires when the layer opacity has been changed, and returns the opacity value.
onUpdate() 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.
onVisibilityChange(visbility) Fires when the layer visibilty has been changed, and returns the new visibility.
Properties Detail

<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.
Code snippets:
  • 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);
      }
    }
    

<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
See also:
onLoad  

<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
See also:
setOpacity  

<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. (As of v1.2)

<Boolean> visible

Visibility of the layer.
Known values: true | false
Default value: true
See also:
show   hide  
Methods Detail

hide()

Sets the visibility of the layer to "false". The layer is not removed, but it is hidden from view.
Return value: none
See also:
show   onVisibilityChange   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.
Return value: none
Input Parameters:
<Number> opacity Required Opacity value. Values range from 0.0 to 1.0, where 0.0 is 100% transparent and 1.0 has no transparency.
See also:
onOpacityChange   opacity  

show()

Sets the visibility of the layer to "true".
Return value: none
See also:
onVisibilityChange   visible   hide  

Events Detail

onError(error)

Fires when there is a problem retrieving a layer. (As of v1.3)
Arguments:
<Error> error ArcGIS Server error message returned in a JavaScript error object.

onLoad(layer)

Fires after layer properties for the layer are successfully populated. This event must be successful before the layer can be added to the map.
Arguments:
<Layer> layer The loaded layer.
Code snippets:

In Internet Explorer, due to resource caching, the onLoad event is fired as soon as the layer is constructed. Consequently you should check whether the layer's loaded property is true before registering a listener for the onLoad event:

function init() {
  //setting initial extent in constructor
  var map = new esri.Map("mapDiv", { extent: new esri.geometry.Extent(...) });

  //or use set extent method
  var map = new esri.Map("mapDiv");
  map.setExtent(new esri.geometry.Extent(...));

  //add first layer
  map.addLayer(...);
}
See also:
loaded   Map.onLoad

onOpacityChange(opacity)

Fires when the layer opacity has been changed, and returns the opacity value.
Arguments:
<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.
See also:
setOpacity  

onUpdate()

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. (As of v1.2)

onVisibilityChange(visbility)

Fires when the layer visibilty has been changed, and returns the new visibility.
Arguments:
<Boolean> visbility Determines whether the layer is visible on the map.
See also:
hide   show