L.esri.Layers.FeatureLayer
L.esri.Layers.FeatureLayer
is used to visualize and query vector geographic data hosted in both ArcGIS Online and published using ArcGIS Server.
Feature Layers are provided by Feature Services which can contain multiple layers. Feature Layers expose vector geographic information as a web service that can be visualized, styled, queried and edited.
Here is a sample Feature Service URL
http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Neighborhoods_pdx/
This particular service contains only one Feature Layer. Here is the Feature Layer URL
http://services.arcgis.com/rOo16HdIMeOBI4Mb/ArcGIS/rest/services/Neighborhoods_pdx/FeatureServer/0
Note that the Feature Layer URL ends in /FeatureServer/{LAYER_ID}
.
You can create a new empty feature service with a single layer on the ArcGIS for Developers website or you can use ArcGIS Online to create a Feature Service from a CSV or Shapefile.
Constructor
Constructor | Description |
---|---|
L.esri.featureLayer( |
You must pass a url to a Feature Layer in your options |
Options
Option | Type | Description |
---|---|---|
url |
String |
Required The URL to the Feature Layer. |
pointToLayer( |
Function |
Function that will be used for creating layers for GeoJSON points (if not specified, simple markers will be created). |
style( |
Function |
Function that will be used to get style options for vector layers created for GeoJSON features. |
onEachFeature( |
Function |
Provides an opportunity to introspect individual GeoJSON features in the layer. |
where |
String |
An optional expression to filter features server side. String values should be denoted using single quotes ie: where: "FIELDNAME = 'field value'"; More information about valid SQL can be found here. |
minZoom |
Integer |
Minimum zoom level of the map that features will display. example: minZoom:0 |
maxZoom |
Integer |
Maximum zoom level of the map that features will display. example: maxZoom:19 |
cacheLayers |
Boolean |
Will remove layers from the internal cache when they are removed from the map. |
fields |
Array |
An array of metadata names to pull from the service. Includes all fields by default. You should always specifcy the name of the unique id for the service. Usually either 'FID' or 'OBJECTID' . |
from |
Date |
When paired with to defines the time range of features to display. Required the Feature Layer to be time enabled. |
to |
Date |
When paired with from defines the time range of features to display. Required the Feature Layer to be time enabled. |
timeField |
false |
The name of the field to lookup the time of the feature. Can be an object like {start:'startTime', end:'endTime'} or a string like 'created' . |
timeFilterMode |
'client' or 'server' |
Determines where features are filtered by time. By default features will be filtered by the server. If set to 'client' all features are loaded and filtered on the client before display. |
simplifyFactor |
Integer |
How much to simplify polygons and polylines. More means better performance, and less means more accurate representation. |
precision |
Integer |
How many digits of precision to request from the server. Wikipedia has a great reference of digit precision to meters. |
token |
String |
If you pass a token in your options it will be included in all requests to the service. |
proxy |
String |
URL of an ArcGIS API for JavaScript proxies or ArcGIS Resource Proxies to use for proxying POST requests. |
useCors |
Boolean |
If this service should use CORS when making GET requests. |
Events
Event | Type | Description |
---|---|---|
loading |
<LoadingEvent > |
Fires when new features start loading. |
load |
<LoadEvent > |
Fires when all features in the current bounds of the map have loaded. |
createfeature |
<CreateFeatureEvent > |
Fired when a feature from the Feature Layer is loaded for the first time. |
removefeature |
<RemoveFeatureEvent > |
Fired when a feature on the layer is removed from the map. |
addfeature |
<AddFeatureEvent > |
Fired when a previously removed feature is added back to the map. |
L.esri.Layers.FeatureLayer
also fires all L.esri.Services.FeatureLayer
events.
In addition to the events above, L.esri.Layers.FeatureLayer
also fires the following Mouse Events click
, dblclick
, mouseover
, mouseout
, mousemove
, and contextmenu
and the following the Popup Events popupopen
and popupclose
Methods
Method | Returns | Description |
---|---|---|
setStyle( setStyle( |
this |
Sets the given path options to each layer that has a setStyle method. Can also be a Function that will receive a feature argument and should return Path Options
|
setFeatureStyle( |
this |
Changes the style on a specfic feature. |
resetStyle( |
this |
Given the ID of a feature, reset that feature to the original style. |
bindPopup( |
this |
Defines a function that will return HTML to be bound to a popup on each feature.
|
unbindPopup() |
this |
Removed a popup previously bound with bindPopup . |
eachFeature( |
this |
Calls the passed function against every feature. The function will be passed the layer that represents the feature.
|
getFeature( |
Layer |
Given the id of a Feature return the layer on the map that represents it. This will usually be a Leaflet vector layer like Polyline or Polygon, or a Leaflet Marker. |
getWhere() |
String |
Returns the current where setting |
setWhere( |
this |
Sets the new where option and refreshes the layer to reflect the new where filter. Accepts an optional callback and function context. |
getTimeRange() |
Array |
Returns the current time range as an array like [from, to] |
setTimeRange( |
this |
Sets the current time filter applied to features. An optional callback is run upon completion if timeFilterMode is set to 'server' . Also accepts function context as the last argument. |
authenticate( |
this |
Authenticates this service with a new token and runs any pending requests that required a token. |
query() |
this |
Returns a new L.esri.services.Query object that can be used to query this layer. Your callback function will be passed a GeoJSON FeatureCollection with the results or an error.
|
metadata( |
this |
Requests metadata about this Feature Layer. Callback will be called with error and metadata .
|
addFeature( |
this |
Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful.
|
updateFeature( |
this |
Update the provided feature on the Feature Layer. This also updates the feature on the map.
|
deleteFeature( |
this |
Remove the feature with the provided id from the feature layer. This will also remove the feature from the map if it exists.
|
deleteFeatures( |
this |
Removes an array of features with the provided ids from the feature layer. This will also remove the features from the map if they exist.
|
Example
var map = L.map('map').setView([45.53,-122.64], 14);
L.esri.basemapLayer("Streets").addTo(map);
var busStops = L.esri.featureLayer('http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/stops/FeatureServer/0/').addTo(map);
Esri Leaflet is a project from the Esri PDX R&D Center and the Esri Community