import type { LayersMixin } from "@arcgis/core/support/LayersMixin.js";- Subclasses:
- Map, GroupLayer
- Since
- ArcGIS Maps SDK for JavaScript 4.0
Mixin for Map.
Properties
| Property | Type | Class |
|---|---|---|
| |
layers
- 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 map1map1.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 arraylet 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 collectionmap.layers.addMany([fl, gl]);
// Add layers using layers collection's push methodmap.layers.push(fl, gl);Methods
| Method | Signature | Class |
|---|---|---|
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
- Signature
-
add (layer: Layer | PromiseLike<Layer>, index?: number): void
Adds a layer 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.
- See also
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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 addmap.add(layer);
// add a layer at the end of layers collectionmap.layers.push(layer); addMany
- 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
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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 addManymap.addMany([layer, layer2]);
// add layers to layers collection using push methodmap.layers.push(layer, layer2); remove
- 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.
removeAll
- 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
- 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.
reorder
- 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.