Description
Samples
Search for
samples that use this class.
Class hierarchy
esri.layers.Layer
Subclasses
DynamicMapServiceLayer GraphicsLayer TiledMapServiceLayer Properties
| 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
| hide() |
none
|
Sets the visibility of the layer to "false". The layer is not removed, but it is hidden from view. |
| setOpacity() |
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. |
| setVisibility(isVisible) |
none
|
Sets the visibility of the layer. When true, the layer is visible. |
| show() |
none
|
Sets the visibility of the layer to "true". |
Events
| 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.
Deprecated at v2.0. Use onUpdateStart and onUpdateEnd instead. |
| onUpdateEnd(error)
|
Fires when a layer has finished updating its content. It is the responsibility of the subclass to determine when this event is fired. |
| onUpdateStart()
|
Fires when a layer begins to update its content. It is the responsibility of the subclass to determine when this event is fired. |
| onVisibilityChange(visbility)
|
Fires when the layer visibilty has been changed, and returns the new visibility. |
Properties Detail
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);
}
}
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
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
Visibility of the layer.
Known values: true | false
Default value: true
Methods Detail
Sets the visibility of the layer to "false". The layer is not removed, but it is hidden from view.
Return value: 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.
Return value: none
Code snippets:
layer.setOpacity(0.5);
Sets the visibility of the layer. When true, the layer is visible.
Return value: none
Input Parameters:
|
<Boolean> isVisible |
Required |
Set the visibility of the layer. |
Sets the visibility of the layer to "true".
Return value: none
Events Detail
Fires when there is a problem retrieving a layer. (As of v1.3)
Arguments:
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(...);
}
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.
|
Fires when a layer has finished updating its content. It is the responsibility of the subclass to determine when this event is fired.
Arguments:
|
<Error> error
|
Optional argument. The error object is available when an error occurs during the update.
|
Code snippets:
dojo.connect(layer, "onUpdateEnd", layerUpdateCompleted);
function layerUpdateCompleted(error) {
if (error) {
console.log("Update completed with error: ", error);
}
else {
console.log("Update completed");
}
}
Fires when a layer begins to update its content. It is the responsibility of the subclass to determine when this event is fired.
Code snippets:
dojo.connect(layer, "onUpdateStart", layerUpdateStarted);
function layerUpdateStarted() {
console.log("Update started...");
}
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.
|