Esri Leaflet
Leaflet plugins for ArcGIS Services. Currently Esri Leaflet supports loading Esri basemaps and feature services, as well as tiled map, dynamic map and image services.
The goal of Esri Leaflet is not to replace the ArcGIS API for JavaScript, but rather to provide small components to allow developers to build mapping applications with Leaflet.
Currently Esri Leaflet is in development and should be thought of as a beta or preview.
Demos
We've written loads of demos showing many of the features of Esri Leaflet.
Example
Here is a quick example to get you started. Just copy/paste into your own .html
file and run.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="//cdn.jsdelivr.net/leaflet.esri/latest/esri-leaflet.js"></script>
<style>
html, body, #map {
width : 100%;
height : 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([45.528, -122.680], 13);
L.esri.basemapLayer("Gray").addTo(map);
var parks = new L.esri.FeatureLayer("http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Portland_Parks/FeatureServer/0", {
style: function () {
return { color: "#70ca49", weight: 2 };
}
}).addTo(map);
var popupTemplate = "<h3>{NAME}</h3>{ACRES} Acres<br><small>Property ID: {PROPERTYID}<small>";
parks.bindPopup(function(feature){
return L.Util.template(popupTemplate, feature.properties)
});
</script>
</body>
</html>
Documentation & Examples
A full API Reference and plenty of sample code can be found at the Esri Leaflet website.
Development Roadmap
If you are interested in contributing to Esri Leaflet or seeing what is coming up next check out the development roadmap.
Issues
Find a bug or want to request a new feature? Please let us know by submitting an issue.
Please take a look at previously logged issues that resolve common problems.
You can also post issues on GIS Stackexchange an/or the Esri Leaflet place on GeoNet.
Frequently Asked Questions
Projects Using Esri Leaflet
Feel free to add your own project to this list!
Development Instructions
In order to compile the API yourself and/or run the tests, make sure you have the Grunt CLI installed.
- Fork and clone Esri Leaflet
cd
into the esri-leaflet
folder- Install the dependencies with
npm install
- run
grunt
from the command line. This will start the web server locally at http://localhost:8001 and start watching the source files and running linting and testing commands. - Make your changes and create a pull request if you'd like to contribute
Dependencies
- Leaflet version 0.7 or higher is required but the latest version is recommended.
Versioning
For transparency into the release cycle and in striving to maintain backward compatibility, Esri Leaflet is maintained under the Semantic Versioning guidelines and will adhere to these rules whenever possible.
Releases will be numbered with the following format:
<major>.<minor>.<patch>
And constructed with the following guidelines:
- Breaking backward compatibility bumps the major while resetting minor and patch
- New additions without breaking backward compatibility bumps the minor while resetting the patch
- Bug fixes and misc changes bumps only the patch
For more information on SemVer, please visit http://semver.org/.
Contributing
Esri welcomes contributions from anyone and everyone. Please see our guidelines for contributing.
Credit
Licensing
Copyright 2015 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
A copy of the license is available in the repository's LICENSE file.
[](Esri Tags: ArcGIS Web Mapping Leaflet)
[](Esri Language: JavaScript)
[1.0.0]
This represents the stable release of Esri Leaflet compatible with Leaflet 0.7.3. All future 1.0.X releases will be compatible with Leaflet 0.7.3 and contain only bug fixes. New features will only be added in Esri Leaflet 2.0.0 which will require Leaflet 1.0.0.
As this is a major release there are a number of breaking changes.
Also see the Esri Leaflet 1.0 announcement.
Breaking Changes
L.esri.Services.FeatureLayer
has been renamed to L.esri.Services.FeatureLayerService
. It should be initialized with L.esri.Services.featureLayerService(options)
.- All layers now match services and tasks and now only accept
url
in their options. E.x. L.esri.featureLayer(url)
should now L.esri.featureLayer({url: url}})
. This does not affect L.esri.baseMapLayer
which still accepts the key
as it's first parameter. - Request callbacks across Esri Leaflet now can handle authentication errors by calling
error.authenticate(newToken)
as opposed to listening to authenticationrequired
event and calling e.target.authenticate(newToken)
. This means that your callbacks may be called multiple times, once with an authentication failure and once with an authentication success. To avoid any side affects of this you should return
as early as possible after handling errors. It is recommended you adapt techniques from http://blog.timoxley.com/post/47041269194/avoid-else-return-early to handle these cases.
L.esri.Services.service({
url: "http://logistics.arcgis.com/arcgis/rest/services/World/ServiceAreas/GPServer/GenerateServiceAreas",
token: "badtoken",
}).metadata(function (error, response) {
if (error && error.authenticate) {
// handle an authentication error, returning to stop execution of the rest of the function
error.authenticate("good token");
return;
}
if (error) {
// handle any other errors, returning to stop execution of the rest of the function
return;
}
// if you get here you are successful!
console.log(metadata);
});
Changes
[Release Candidate 8]
Breaking Changes
Changes
[Release Candidate 7]
Breaking Changes
- DynamicMapLayer will now request
json
by default to better expose the authentication process. If you are using ArcGIS Server 10.0 or have disabled CORS on your server you will need to add useCors: false
to your options.
Changes
[Release Candidate 6]
Breaking Changes
None
Changes
[Release Candidate 5]
Breaking Changes
- All
Task
and Service
constructors now accept url
as a value within options, rather than as a separate parameter. #420 - 'Layer' objects continue to expect a
url
string to be supplied as the first parameter, but afterwards, the property is now accessible via Layer.options.url instead of Layer.url
Changes
- Fixed duplicate Esri logo bug #427
- GeoJSON is now requested directly from ArcGIS Online Hosted Feature Services #418
- other FeatureLayer performance improvements #416
minZoom
, maxZoom
, #413 and cacheLayers
were added as new FeatureLayer constructor options- default fill is now specified for multipolygons #406
- dark gray basemap now utilizes our new production service #399
[Release Candidate 4]
Changes
- Fixed a bug where resetStyle would not work with MultiPolygon and MultiPolyline features #390
- Fixed a display bug when rapidly toggling L.esri.DynamicMapLayer on/off before the image completely loads #386
- Bower installation fixed #378
[Release Candidate 3]
Changes
- Removed hardcoded http call in
L.esri.Controls.Logo
#383 L.esri.TiledMapLayer
now accepts a token option for secured tiles. #384- Fixed a bug with
DynamicMapLayer
still rendering after being removed from the map. #386 - Fixed 404s on example site.
- Fixed setting sr param on
L.esri.Tasks.Find
#379 bower install esri-leaflet
now works properly.
[Release Candidate 2]
Changes
- Fixed IE 8 and 9 support that was broken in RC 1.
- Fixed sourcemaps by embedding source files inside the maps.
- Fix a bug when aborting JSONP requests
- Other small fixes for plugin support
- Added
contains
, overlaps
and intersects
to L.esri.Tasks.Query
. - Spatial methods on
L.esri.Tasks.Query
can now accept the following Leaflet types, L.Marker
, L.Polygon
, L.Polyline
, L.LatLng
, L.LatLngBounds
and L.GeoJSON
. It can also accept valid GeoJSON Point, Polyline, Polygon and GeoJSON Feature objects containing Point, Polyline, Polygon. - Most methods that accept
L.LatLng
and L.LatLngBounds
now accept the simple [lat,lng] or [[lat,lng], [lat,lng]] forms.
[Release Candidate 1]
Changes
Breaking Changes
- Task methods that accept callbacks (like
run
or bounds
) now return an instance of XMLHttpRequest
as opposed to the task or service. bindPopup
on L.esri.DynamicMapLayer
now identifies only visible features by default rather then all features.- All API requests inside of layers, tasks and services will now switch between GET and POST automatically when the request size exceeds 2000 characters. This improves IE compatibility but means that for long requests (like complex
where
clauses or long lists of IDs) you may need to setup an instance of https://github.com/Esri/resource-proxy and use the proxy
option.
Changes
[Beta 6]
Breaking Changes
L.esri.Tasks.Identify
has been renamed to L.esri.Tasks.IdentifyFeatures
. This is to reduce confusion with L.esri.Tasks.IdentifyImage
and to clearly delineate what these 2 classes do.
Changes
Misc
[Beta 5]
Breaking Changes
Oceans
no longer contains map labels, labels have been added as another key OceansLabels
.L.esri.FeatureLayer
no longer inherits from L.GeoJSON
and as a result no longer has getBounds
, bringToBack
or bringToFront
or addData
methods.- L.esri.Util.geojsonBounds has been removed. If you need to get the bounding box of a GeoJSON object please use Terraformer or
L.GeoJSON
. - Many other utility methods have been removed. If you were using methods in the
L.esri.Util
namespace please check that they exist. - Layers no longer fire a
metadata
event. They now have a metadata
method that can be used to get layer metadata. If you need to convert extents into L.LatLngBounds you can use L.esri.Util.extentToBounds
. L.esri.DynamicMapLayer
no longer inherits from L.ImageOverlay
as a result the setUrl
method no longer exists.- You can no longer pass a
cluster
object to L.esri.ClusteredFeatureLayer
, instead pass any options you want to pass to L.MarkerClusterGroup
directly to L.esri.ClusteredFeatureLayer
. - You can no long pass a string for the
layerDefs
option on L.esri.DynamicMapLayer
. Layer definitions should now be passed as an object like {'0':'STATE_NAME='Kansas' and POP2007>25000'}
- You can no longer pass a string for the
layers
option on L.esri.DynamicMapLayer
you can now only pass an array of layer ids that will be shown like [0,1,2]
. - The
createMarker
method on L.esri.ClusteredFeatureLayer
has been renamed to pointToLayer
.
Changes
- Added
OceansLabels
to L.esri.BasemapLayer
. Oceans
has switched to the new Ocean basemap with out labels.L.esri.FeatureLayer
has been refactored into several classes. L.esri.FeatureGrid
and L.esri.FeatureManager
now handle loading and querying features from the service.L.esri.ClusteredFeatureLayer
and L.esri.HeatMapFeatureLayer
now inherit from L.esri.FeatureManager
so they share many new methods and options.L.esri.FeatureLayer
, L.esri.ClusteredFeatureLayer
and L.esri.HeatMapFeatureLayer
now support time enabled service via from
, to
, timeFields
and timeFilterMode
options and setTimeRange(from, to)
and getTimeRange()
methods.L.esri.FeatureLayer
, L.esri.ClusteredFeatureLayer
and L.esri.HeatMapFeatureLayer
now support where
options and have new methods for setWhere()
and getWhere()
to perform filtering.L.esri.FeatureLayer
now supports generalizing polygon and polyline features on the service side for performance using the new simplifyFactor
option.- Don't throw errors when
L.esri.BasemapLayer
is added to maps without an attribution control. If you do not add attribution you must handle adding attribution your self to the map. - Remove rbush. Switch to tracking feature ids with the cell key system.
- Remove
L.esri.Util.geojsonBounds
as it was only being used to create bounds and envelopes for rbush. - add
bindPopup
method to L.esri.DynamicMapLayer
. - add
getTimeRange
and setTimeRange
methods L.esri.DynamicMapLayer
. - New
L.esri.Services
namespace to handle generic abstraction of interacting with ArcGIS Online and ArcGIS server services. - new
L.esri.Services.Service
base class that can be used for interacting with any service. All L.esri.Layers
classes now uses L.esri.Services.Service
internally for their API requests. This class also abstracts authentication and proxying. - new
L.esri.Services.FeatureLayer
class for interacting with the Feature Layer API. - new
L.esri.Services.MapService
class for interacting with the Map Server API. - new
L.esri.Tasks
namespace for tasks that map to individual API methods. - new
L.esri.Tasks.Query
class for interacting with the Feature Layer query API. - new
L.esri.Tasks.Identify
class for interacting with Map Servers that support identify.
[Beta 4 Patch 1]
Changes
- Patches a bug with identifying features on DynamicMapLayer
- Various updates and fixes to examples
[Beta 4]
New Demos
Changes
[Beta 3]
- Improve DynamicMapLayer panning and zooming performance. #137
- FeatureLayer and ClusteredFeatureLayer can now load features from map services. Thanks to @odoe and @jgravois.
- FeatureLayer, DynamicMapLayer and ClusteredFeatureLayer all accept a token option for accessing services that require authentication and fire a
authenticationrequired
event when they encounter a need for a token. Thanks to @aaronpk for the Oauth demos. #139 - Add DarkGray and DarkGrayLabels to BasemapLayer. #190
- An attributionControl on maps is now required when using BasemapLayer. #159