Extends L.Layer
L.esri.FeatureLayer
is used to visualize, style, query and edit vector geographic data hosted using ArcGIS Online, Location Platform, and Enterprise portals. Copyright text from the service is added to map attribution automatically.
Feature Layers reference an individual data source in either a parent Map Service or Feature Service that can contain multiple layers. You can see a sample Map Service URL below:
Use dark colors for code blocks Copy
1
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer
This particular service includes two different data sources. The URL for the 'Hurricane Tracks' feature layer will end in a number (representing its position among the other layers).
Use dark colors for code blocks Copy
1
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/1
Feature Layer URLs always end in a number (ex: /FeatureServer/{LAYER_ID}
or /MapServer/{LAYER_ID}
).
You can use your portal to create a new feature service based on a CSV, Shapefile, GeoJSON, or other data types. To learn more, go to Publish hosted feature layers.
L.esri.FeatureLayer
divides the current map extent into a grid of individual cells and uses them to fire queries to fetch nearby features. This technique is comparable to MODE_ONDEMAND in the ArcGIS API for JavaScript.
If you want your FeatureLayer
to display the symbology defined in the map or feature service, you need to use the Esri Leaflet Renderers plugin.
L.esri.featureLayer(<Object> options)
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(<GeoJSON Feature> feature, <LatLng> latlng)
Function
Function that will be used for creating layers for GeoJSON points. If the option is not specified, simple markers will be created). For point layers, custom panes should be passed through pointToLayer sample here . style(<GeoJSON Feature> feature, <ILayer> layer)
Function
Function that will be used to get style options for vector layers created for GeoJSON features. onEachFeature(<GeoJSON Feature> feature, <ILayer> layer)
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 syntax can be found here. maxZoom
Number
Closest zoom level the layer will be displayed on the map. sample: maxZoom:19
minZoom
Number
Furthest zoom level the layer will be displayed on the map. sample: minZoom:3
cacheLayers
Boolean
Will remove layers from the internal cache when they are removed from the map. fields
Array
An array of fieldnames to pull from the service. Includes all fields by default. You should always specify 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. Requires the Feature Layer to be time enabled. to
Date
When paired with from
defines the time range of features to display. Requires 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
'server'
(default) or 'client'
Determines where features are filtered by time. By default features will be filtered by the server. If set to 'client'
all features are requested and filtered by the app before display. simplifyFactor
Number
How much to simplify polygons and polylines. A higher value gives better performance, a lower value gives a 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. apikey
String
If you pass an api key in your options it will be included in all requests to the service. 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. renderer
L.svg()
or L.canvas()
The vector renderer to use to draw the service. Usually L.svg()
is preferable but setting to L.canvas()
can have performance benefits for large polygon layers. isModern
Boolean
Set this to false
if your own service supports GeoJSON as an output format but you'd like to ask for Geoservices JSON instead. ignoreRenderer
Boolean
When utilizing esri-leaflet-renderers '2.0.2' or above, this option makes it possible to override the symbology defined by the service itself. fetchAllFeatures
Boolean
When true, the Feature Layer will make multiple requests to get all the data if the query exceeds the transfer limit (paging size). This should be used when working with large numbers of features. Default: false. 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.FeatureLayer
also fires all L.esri.FeatureLayerService
events.
In addition to the events above, L.esri.FeatureLayer
also fires the following Mouse Events click
, dblclick
, mouseover
, mouseout
, mousemove
, and contextmenu
and the following Popup Events popupopen
and popupclose
.
setStyle(<PathOptions> style)
setStyle(<Function> style)
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
featureLayer.setStyle({
color: 'white'
})
featureLayer.setStyle(function(feature){
return {
weight: feature.properties.pixelWidth
};
})
setFeatureStyle(<String or Integer> id, <Function or Path Optionsa>> [object Object])
this
Changes the style on a specfic feature. resetStyle(<String or Integer> undefined)
this
Given the ID of a feature, reset that feature to the original style. eachFeature(<Function> fn, <Object> context)
this
Calls the passed function against every feature. The function will be passed the layer that represents the feature.
fl.on('load', iterateFeatures);
function iterateFeatures () {
fl.eachFeature(function(layer) {
console.log(layer.feature);
});
}
eachActiveFeature(<Function> fn, <Object> context)
this
Calls the passed function against every feature that is currently being displayed.
getFeature(<String or Integer> undefined id)
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(<String> where, <Function> callback, <Object> context)
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(<Date> from, <Date> to
, <Function> callback, <Object> context)
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(<String> token)
this
Authenticates this service with a new token and runs any pending requests that required a token. query()
this
Returns a new
L.esri.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.
featureLayer.query()
.within(latlngbounds)
.where("Direction = 'WEST'")
.run(function(error, featureCollection){
console.log(featureCollection);
});
metadata(<Function> callback, <Object> context)
this
Requests metadata about this Feature Layer. Callback will be called with error
and metadata
.
featureLayer.metadata(function(error, metadata){
console.log(metadata);
});
addFeature(<GeoJSON Feature> feature, <Function> callback, <Object> context)
this
Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful.
Create
capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities.updateFeature(<GeoJSON Feature> feature, <Function> callback, <Object> context)
this
Update the provided feature on the Feature Layer. This also updates the feature on the map.
Update
capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.deleteFeature(<String or Integer> id, <Function> callback, <Object> context)
this
Remove the feature with the provided id from the feature layer. This will also remove the feature from the map if it exists.
Delete
capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.deleteFeatures(<Array of String or Integers> ids, <Function> callback, <Object> context)
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.
Delete
capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.redraw(<String or Integer> id)
this
Redraws a feature with the provided id from the feature layer.
refresh()
this
Redraws all features from the feature layer that exist on the map.
ExampleExpand
Use dark colors for code blocks Copy1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var trailheads = L.esri
.featureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_Styled/FeatureServer/0"
});
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4