Skip to content
Types
import type { LayersMixin } from "@arcgis/core/support/LayersMixin.js";
Subclasses:
Map, GroupLayer
Since
ArcGIS Maps SDK for JavaScript 4.0

Mixin for Map.

Properties

PropertyTypeClass

layers

autocast Property
Type
Collection<Layer>

A collection of operational layers. This property contains the operational layers, such as FeatureLayers, WebTileLayers and GraphicsLayers that may be queried, assigned different renderers, analyzed, etc. It does not include basemaps.

A Layer is a collection of one or more features, or graphics, that represent real-world phenomena. Each feature contains a Symbol and geographic data that allows it to be rendered on the map as a graphic with spatial context. Features within the layer may also contain data attributes that provide additional information that may be viewed in popup windows and used for rendering the layer.

Layers may be added in the constructor, with the add() or addMany() methods, or directly to the layers collection using Collection.add() or Collection.addMany().

In 3D, for layers that are rendered on the terrain, the order of the layers also depends on the type of layer. Tiled layers (BaseTileLayer, ImageryTileLayer, OpenStreetMapLayer, TileLayer, VectorTileLayer, WCSLayer, WebTileLayer and WMTSLayer) are always drawn first in the same order as specified in the layer collection. Dynamic layers (MapImageLayer, ImageryLayer, WMSLayer, and feature based layers with elevation mode on-the-ground) are rendered on top using the order from the layer collection.

A Layer may only be added to one parent. Adding the same layer to multiple Maps or GroupLayers is not possible. If you attempt to do so, the layer will automatically be removed from its current parent and placed in the new parent.

let layer = new GraphicsLayer();
// The layer belongs to map1
map1.layers.add(layer);
// The layer now belongs to map2
// and implicitly does: map1.layers.remove(layer)
map2.layers.add(layer);

To access tables from feature layers, use the tables property in either Map.tables or WebMap.tables classes.

Example
// Add layers in the constructor of Map using an array
let fl = new FeatureLayer(url);
let gl = new GraphicsLayer();
let map = new Map({
layers: [fl, gl]
});
// Add layers using add()
map.addMany([fl, gl]);
// Add layers using layers collection
map.layers.addMany([fl, gl]);
// Add layers using layers collection's push method
map.layers.push(fl, gl);

Methods

MethodSignatureClass
add
add(layer: Layer | PromiseLike<Layer>, index?: number): void
addMany(layers: Layer[], index?: number): void
findLayerById(layerId: string): Layer | null | undefined
remove(layer: Layer): Layer | null | undefined
removeAll(): Layer[]
removeMany(layers: Layer[]): Layer[]
reorder(layer: Layer, index?: number): Layer | null | undefined

add

Method
Signature
add (layer: Layer | PromiseLike<Layer>, index?: number): void
Parameters
ParameterTypeDescriptionRequired
layer
Layer | PromiseLike<Layer>

Layer or a promise that resolves to a layer to add to the layers collection.

index

A layer can be added at a specified index in the layers collection. If no index is specified or the index specified is greater than the current number of layers, the layer is automatically appended to the list of layers in the layers collection and the index is normalized.

Returns
void
Example
// add() and push methods can be used
// to add a layer to layers collection
// add a layer to layers collection using add
map.add(layer);
// add a layer at the end of layers collection
map.layers.push(layer);

addMany

Method
Signature
addMany (layers: Layer[], index?: number): void

Adds a layer or an array of layers to the layers collection. The Collection.@before-changes, Collection.@before-add, Collection.@after-add, Collection.@after-changes and Collection.@change events will be emitted when this method is called.

The Collection.push() method on the layers collection also can be used to add a layer or layers.

See also
Parameters
ParameterTypeDescriptionRequired
layers
Layer[]

Layer(s) to be added to the layers collection.

index

A layer can be added at a specified index in the layers collection. If no index is specified or the index specified is greater than the current number of layers, the layer is automatically appended to the list of layers in the layers collection and the index is normalized.

Returns
void
Example
// addMany and push methods can be used
// to add layers to layers collection
// add an array of layers to layers collection using addMany
map.addMany([layer, layer2]);
// add layers to layers collection using push method
map.layers.push(layer, layer2);

findLayerById

Method
Signature
findLayerById (layerId: string): Layer | null | undefined

Returns a layer based on the given layer ID.

Parameters
ParameterTypeDescriptionRequired
layerId

The ID assigned to the layer.

Returns
Layer | null | undefined

Returns the requested layer object.

remove

Method
Signature
remove (layer: Layer): Layer | null | undefined

Removes the specified layer from the layers collection. The Collection.@before-changes, Collection.@before-remove, Collection.@after-remove, Collection.@after-changes and Collection.@change events will be emitted when this method is called.

Parameters
ParameterTypeDescriptionRequired
layer

Layer to remove from the layers collection.

Returns
Layer | null | undefined

Returns the layer removed from the layers collection.

removeAll

Method
Signature
removeAll (): Layer[]

Removes all layers. The Collection.@before-changes, Collection.@before-remove, Collection.@after-remove, Collection.@after-changes and Collection.@change events will be emitted when this method is called.

Returns
Layer[]

Returns the layers removed from the layers collection.

removeMany

Method
Signature
removeMany (layers: Layer[]): Layer[]

Removes the specified layers. The Collection.@before-changes, Collection.@before-remove, Collection.@after-remove, Collection.@after-changes and Collection.@change events will be emitted when this method is called.

Parameters
ParameterTypeDescriptionRequired
layers
Layer[]

Array of layers to remove from the layers collection.

Returns
Layer[]

Returns the layers removed from the layers collection.

reorder

Method
Signature
reorder (layer: Layer, index?: number): Layer | null | undefined

Changes the layer order. The first layer added is always the base layer, even if its order is changed. The Collection.@change event will be emitted when this method is called.

In 3D, for layers that are rendered on the terrain, the order of the layers also depends on the type of layer. Tiled layers (BaseTileLayer, ImageryTileLayer, OpenStreetMapLayer, TileLayer, VectorTileLayer, WCSLayer, WebTileLayer and WMTSLayer) are always drawn first in the same order as specified in the layer collection. Dynamic layers (MapImageLayer, ImageryLayer, WMSLayer, and feature based layers with elevation mode on-the-ground) are rendered on top using the order from the layer collection.

Parameters
ParameterTypeDescriptionRequired
layer

The layer to be moved.

index

The index location for placing the layer. The bottom-most layer has an index of 0.

Returns
Layer | null | undefined

Returns the layer that was moved.