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.
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);
Constructors
constructor
Class ConstructorFeatureLayer(options: IFeatureLayerOptions): 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.
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
Parameter | Type | Notes |
---|---|---|
options | IFeatureLayerOptions | Configuration options for the feature layer. |
Returns
FeatureLayer
Properties
Property | Type | Notes |
---|---|---|
query | IQueryOptions | |
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
query: IQueryOptions
token
token: string
An ArcGIS access token is required for accessing secure data layers. To get a token, go to the Security and Authentication Guide.
Accessors
Accessor | Returns |
---|---|
layer() inherited | Readonly<LayerSpecification> |
layers() inherited | readonlyLayerSpecification[] |
source() inherited | Readonly<SupportedSourceSpecification> |
sourceId() inherited | string |
sources() inherited | Readonly<{}> |
layer
layer(): Readonly<LayerSpecification>
Retrieves the layer for the hosted layer.
Returns
Readonly<LayerSpecification>
layers
layers(): readonlyLayerSpecification[]
Retrieves the layers for the hosted layer.
Returns
readonlyLayerSpecification[]
source
source(): Readonly<SupportedSourceSpecification>
Retrieves the source for the hosted layer.
Returns
Readonly<SupportedSourceSpecification>
sourceId
sourceId(): string
Retrieves the source ID for the hosted layer.
Returns
string
sources
sources(): Readonly<{}>
Retrieves the sources for the hosted layer.
Returns
Readonly<{}>
Methods
Method | Returns | Notes |
---|---|---|
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
addLayersTo(map: Map$1): HostedLayer
Add layers to a maplibre map.
Parameters
Parameter | Type | Notes |
---|---|---|
map | Map$1 | A maplibre map object |
Returns
HostedLayer
addSourcesAndLayersTo
addSourcesAndLayersTo(map: Map$1): HostedLayer
Convenience method that adds all associated Maplibre sources and data layers to a map.
Parameters
Parameter | Type | Notes |
---|---|---|
map | Map$1 |
Returns
HostedLayer
addSourcesTo
addSourcesTo(map: Map$1): HostedLayer
Parameters
Parameter | Type |
---|---|
map | Map$1 |
Returns
HostedLayer
copyLayer
copyLayer(layerId: string): LayerSpecification
Returns a mutable copy of the specified layer
Parameters
Parameter | Type | Notes |
---|---|---|
layer | string | The ID of the maplibre style layer to copy |
Returns
LayerSpecification
copySource
copySource(sourceId: string): SupportedSourceSpecification
Returns a mutable copy of the specified source.
Parameters
Parameter | Type | Notes |
---|---|---|
source | string | The ID of the maplibre style source to copy. |
Returns
SupportedSourceSpecification
initialize
Class Methodinitialize(): Promise<FeatureLayer>
Initializes the layer with data from ArcGIS. Called to instantiate a class.
Returns
Promise<FeatureLayer>
setAttribution
setAttribution(sourceId: string, attribution: string): void
Sets the data attribution of the specified source
Parameters
Parameter | Type | Notes |
---|---|---|
source | string | The ID of the maplibre style source. |
attribution | string | Custom attribution text. |
Returns
void
setSourceId
setSourceId(oldId: string, newId: string): void
Changes the ID of a maplibre style source, and updates all associated maplibre style layers.
Parameters
Parameter | Type | Notes |
---|---|---|
old | string | The source ID to be changed. |
new | string | The new source ID. |
Returns
void
fromPortalItem
fromPortalItem(itemId: string, options: IFeatureLayerOptions): Promise<FeatureLayer>
Creates a new FeatureLayer instance from an ArcGIS Online or ArcGIS Enterprise item ID.
Parameters
Parameter | Type | Notes |
---|---|---|
item | string | A valid ArcGIS Online or ArcGIS Enterprise item ID for a hosted feature layer. |
options | IFeatureLayerOptions | Configuration options for the feature layer. |
Returns
Promise<FeatureLayer>
- A promise that resolves to a FeatureLayer instance.
// Load parks from from portal item ID
const parks = await maplibreArcGIS.FeatureLayer.fromPortalItem('f2ea5d874dad427294641d2d45097c0e');
parks.addSourcesAndLayersTo(map);
fromUrl
fromUrl(serviceUrl: string, options: IFeatureLayerOptions): Promise<FeatureLayer>
Creates a new FeatureLayer instance from a feature service URL.
// 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
Parameter | Type | Notes |
---|---|---|
service | string | A valid ArcGIS feature service or feature layer URL. |
options | IFeatureLayerOptions | Configuration options for the feature layer. Query parameters are only supported when constructing with a feature layer URL. |
Returns
Promise<FeatureLayer>