Skip to content

FeatureLayer

Class

This class allows you to load and display ArcGIS feature layers in a MapLibre map.

The FeatureLayer class provides:

  • Loading and displaying feature layers from item IDs or feature service URLs.
  • Querying of feature layer attributes.
  • Adding sources and layers to a MapLibre map.
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { FeatureLayer } from '@esri/maplibre-arcgis';

// Load a point layer from the service URL
const pointService = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0";
const trailheads = await maplibreArcGIS.FeatureLayer.fromUrl(pointService);
trailheads.addSourcesAndLayersTo(map);

// Load a polyline layer from the service URL and query
const lineService = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
const trails = await maplibreArcGIS.FeatureLayer.fromUrl(lineService, {query: {
  outFields: ['TRL_ID', 'ELEV_MIN', 'ELEV_MAX'],
  where: 'ELEV_MIN > 200'
}});
trails.addSourcesAndLayersTo(map);

// Load a polygon layer from from portal item ID
const parks = await maplibreArcGIS.FeatureLayer.fromPortalItem('f2ea5d874dad427294641d2d45097c0e');
parks.addSourcesAndLayersTo(map);
Inheritance: FeatureLayerHostedLayer

Constructors

constructor

Class Constructor
FeatureLayer(optionsIFeatureLayerOptions): FeatureLayer

Creates a new FeatureLayer instance. You must provide either an ArcGIS item ID or a feature service URL. If both are provided, the item ID will be used and the URL ignored. Query parameters are only supported when constructing with a feature layer URL.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
import { FeatureLayer } from '@esri/maplibre-arcgis';

const trails = new maplibreArcGIS.FeatureLayer({
  url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",
});
await trails.initialize();
trails.addLayerandSourcesTo(map);

Creating layers using the constructor directly is not recommended. Use FeatureLayer.fromUrl and FeatureLayer.fromPortalItem instead.

Parameters
ParameterTypeNotes
optionsIFeatureLayerOptions

Configuration options for the feature layer.

Returns 
FeatureLayer

Properties

Hide inherited properties
PropertyTypeNotes
queryIQueryOptions
token
inherited
string

An ArcGIS access token is required for accessing secure data layers. To get a token, go to the Security and Authentication Guide.

query

optional
Class Property

token

inheritedinherited
Class Property
token: string

An ArcGIS access token is required for accessing secure data layers. To get a token, go to the Security and Authentication Guide.

Inherited from HostedLayer.token

Accessors

Hide inherited accessors
AccessorReturns
layer()
inherited
Readonly<LayerSpecification>
layers()
inherited
readonlyLayerSpecification[]
source()
inherited
Readonly<SupportedSourceSpecification>
sourceId()
inherited
string
sources()
inherited
Readonly<{}>

layer

inheritedinherited
Class Accessor
layer(): Readonly<LayerSpecification>

Retrieves the layer for the hosted layer.

Returns 
Readonly<LayerSpecification>
Inherited from HostedLayer.layer

layers

inheritedinherited
Class Accessor
layers(): readonlyLayerSpecification[]

Retrieves the layers for the hosted layer.

Returns 
readonlyLayerSpecification[]
Inherited from HostedLayer.layers

source

inheritedinherited
Class Accessor
source(): Readonly<SupportedSourceSpecification>

Retrieves the source for the hosted layer.

Returns 
Readonly<SupportedSourceSpecification>
Inherited from HostedLayer.source

sourceId

inheritedinherited
Class Accessor
sourceId(): string

Retrieves the source ID for the hosted layer.

Returns 
string
Inherited from HostedLayer.sourceId

sources

inheritedinherited
Class Accessor
sources(): Readonly<{}>

Retrieves the sources for the hosted layer.

Returns 
Readonly<{}>
Inherited from HostedLayer.sources

Methods

Hide inherited methods
MethodReturnsNotes
addLayersTo(map)
inherited
HostedLayer

Add layers to a maplibre map.

addSourcesAndLayersTo(map)
inherited
HostedLayer

Convenience method that adds all associated Maplibre sources and data layers to a map.

addSourcesTo(map)
inherited
HostedLayer
copyLayer(layerId)
inherited
LayerSpecification

Returns a mutable copy of the specified layer

copySource(sourceId)
inherited
SupportedSourceSpecification

Returns a mutable copy of the specified source.

initialize()Promise<FeatureLayer>

Initializes the layer with data from ArcGIS. Called to instantiate a class.

setAttribution(sourceId, attribution)
inherited
void

Sets the data attribution of the specified source

setSourceId(oldId, newId)
inherited
void

Changes the ID of a maplibre style source, and updates all associated maplibre style layers.

fromPortalItem(itemId, options)Promise<FeatureLayer>

Creates a new FeatureLayer instance from an ArcGIS Online or ArcGIS Enterprise item ID.

fromUrl(serviceUrl, options)Promise<FeatureLayer>

Creates a new FeatureLayer instance from a feature service URL.

addLayersTo

inheritedinherited
Class Method
addLayersTo(mapMap$1): HostedLayer

Add layers to a maplibre map.

Parameters
ParameterTypeNotes
mapMap$1

A maplibre map object

Returns 
HostedLayer

addSourcesAndLayersTo

inheritedinherited
Class Method
addSourcesAndLayersTo(mapMap$1): HostedLayer

Convenience method that adds all associated Maplibre sources and data layers to a map.

Parameters
ParameterTypeNotes
mapMap$1

A MapLibre GL JS map

Returns 
HostedLayer

addSourcesTo

inheritedinherited
Class Method
addSourcesTo(mapMap$1): HostedLayer
Parameters
ParameterType
mapMap$1
Returns 
HostedLayer

copyLayer

inheritedinherited
Class Method
copyLayer(layerIdstring): LayerSpecification

Returns a mutable copy of the specified layer

Parameters
ParameterTypeNotes
layerIdstring

The ID of the maplibre style layer to copy

Returns 
LayerSpecification
Inherited from HostedLayer.copyLayer

copySource

inheritedinherited
Class Method
copySource(sourceIdstring): SupportedSourceSpecification

Returns a mutable copy of the specified source.

Parameters
ParameterTypeNotes
sourceIdstring

The ID of the maplibre style source to copy.

Returns 
SupportedSourceSpecification
Inherited from HostedLayer.copySource

initialize

Class Method
initialize(): Promise<FeatureLayer>

Initializes the layer with data from ArcGIS. Called to instantiate a class.

Returns 
Promise<FeatureLayer>

setAttribution

inheritedinherited
Class Method
setAttribution(sourceIdstring, attributionstring): void

Sets the data attribution of the specified source

Parameters
ParameterTypeNotes
sourceIdstring

The ID of the maplibre style source.

attributionstring

Custom attribution text.

Returns 
void

setSourceId

inheritedinherited
Class Method
setSourceId(oldIdstring, newIdstring): void

Changes the ID of a maplibre style source, and updates all associated maplibre style layers.

Parameters
ParameterTypeNotes
oldIdstring

The source ID to be changed.

newIdstring

The new source ID.

Returns 
void

fromPortalItem

static
Class Method
fromPortalItem(itemIdstring, optionsIFeatureLayerOptions): Promise<FeatureLayer>

Creates a new FeatureLayer instance from an ArcGIS Online or ArcGIS Enterprise item ID.

Parameters
ParameterTypeNotes
itemIdstring

A valid ArcGIS Online or ArcGIS Enterprise item ID for a hosted feature layer.

optionsIFeatureLayerOptions

Configuration options for the feature layer.

Returns 
Promise<FeatureLayer>
  • A promise that resolves to a FeatureLayer instance.
Use dark colors for code blocksCopy
1
2
3
4

// Load parks from from portal item ID
const parks = await maplibreArcGIS.FeatureLayer.fromPortalItem('f2ea5d874dad427294641d2d45097c0e');
parks.addSourcesAndLayersTo(map);

fromUrl

static
Class Method
fromUrl(serviceUrlstring, optionsIFeatureLayerOptions): Promise<FeatureLayer>

Creates a new FeatureLayer instance from a feature service URL.

Use dark colors for code blocksCopy
1
2
3
4
5

// Load trailheads from service URL
const pointService = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
const trailheads = await maplibreArcGIS.FeatureLayer.fromUrl(pointService);
trailheads.addSourcesAndLayersTo(map);
Parameters
ParameterTypeNotes
serviceUrlstring

A valid ArcGIS feature service or feature layer URL.

optionsIFeatureLayerOptions

Configuration options for the feature layer. Query parameters are only supported when constructing with a feature layer URL.

Returns 
Promise<FeatureLayer>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.