esri-leaflet
A lightweight set of tools for working with ArcGIS services in Leaflet. :rocket:
Top Related Projects
π JavaScript library for mobile-friendly interactive maps πΊπ¦
Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
OpenLayers
Marker Clustering plugin for Leaflet
Mapbox JavaScript API, a Leaflet Plugin
Location Intelligence & Data Visualization tool
Quick Overview
Esri-leaflet is a lightweight set of tools for working with ArcGIS services in Leaflet maps. It allows developers to easily integrate Esri's mapping services and data into Leaflet-based web applications, combining the simplicity of Leaflet with the power of ArcGIS.
Pros
- Seamless integration of ArcGIS services with Leaflet maps
- Lightweight and easy to use
- Extensive documentation and examples
- Active community and regular updates
Cons
- Limited to Esri services, not as flexible for other data sources
- Some advanced ArcGIS features may not be fully supported
- Requires Leaflet knowledge, which may be a learning curve for some
Code Examples
- Adding an ArcGIS basemap:
const map = L.map('map').setView([34.0522, -118.2437], 10);
L.esri.basemapLayer('Streets').addTo(map);
- Adding a feature layer:
L.esri.featureLayer({
url: 'https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Major_Cities/FeatureServer/0'
}).addTo(map);
- Querying features:
const cities = L.esri.featureLayer({
url: 'https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Major_Cities/FeatureServer/0'
});
cities.query()
.where("POP2010 > 1000000")
.run((error, featureCollection) => {
if (error) {
console.error(error);
return;
}
console.log(featureCollection);
});
Getting Started
- Include Leaflet and Esri Leaflet in your HTML:
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>
<script src="https://unpkg.com/esri-leaflet@3.0.10/dist/esri-leaflet.js"></script>
- Create a map container in your HTML:
<div id="map" style="height: 400px;"></div>
- Initialize the map and add an ArcGIS basemap:
const map = L.map('map').setView([37.75, -122.23], 10);
L.esri.basemapLayer('Streets').addTo(map);
Competitor Comparisons
π JavaScript library for mobile-friendly interactive maps πΊπ¦
Pros of Leaflet
- Lightweight and highly customizable core library
- Large ecosystem of plugins and extensions
- Platform-agnostic, not tied to any specific mapping service
Cons of Leaflet
- Lacks built-in support for Esri services and data formats
- May require additional plugins for advanced GIS functionality
- Less optimized for Esri-specific workflows
Code Comparison
Leaflet (basic map initialization):
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Β© OpenStreetMap contributors'
}).addTo(map);
esri-leaflet (using Esri basemap):
var map = L.map('map').setView([51.505, -0.09], 13);
L.esri.basemapLayer('Streets').addTo(map);
Summary
Leaflet is a versatile, lightweight mapping library suitable for various mapping needs, while esri-leaflet extends Leaflet's functionality to work seamlessly with Esri services and data. The choice between the two depends on your specific requirements and whether you need integration with Esri's ecosystem.
Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
Pros of mapbox-gl-js
- High-performance vector rendering with WebGL
- Advanced styling capabilities and 3D terrain support
- Extensive customization options and interactivity features
Cons of mapbox-gl-js
- Steeper learning curve for developers new to WebGL
- Requires more computational resources on client-side
- Limited support for older browsers without WebGL capabilities
Code Comparison
esri-leaflet:
L.esri.basemapLayer('Streets').addTo(map);
L.esri.featureLayer({url: 'https://services.arcgis.com/....'}).addTo(map);
mapbox-gl-js:
map.addSource('my-data', {
type: 'vector',
url: 'mapbox://myusername.mapid'
});
map.addLayer({
'id': 'my-layer',
'type': 'fill',
'source': 'my-data',
'source-layer': 'my-source-layer'
});
Both libraries offer powerful mapping capabilities, but mapbox-gl-js excels in performance and advanced styling, while esri-leaflet provides easier integration with Esri services and a gentler learning curve for traditional web mapping.
OpenLayers
Pros of OpenLayers
- More comprehensive and feature-rich, offering advanced mapping capabilities
- Supports a wider range of data formats and projections
- Larger and more active community, resulting in frequent updates and extensive documentation
Cons of OpenLayers
- Steeper learning curve due to its complexity and extensive API
- Larger file size, which may impact load times for web applications
- May be overkill for simpler mapping projects that don't require advanced features
Code Comparison
esri-leaflet:
var map = L.map('map').setView([45.5, -122.5], 10);
L.esri.basemapLayer('Topographic').addTo(map);
L.esri.featureLayer({url: 'https://services.arcgis.com/....'}).addTo(map);
OpenLayers:
var map = new ol.Map({
target: 'map',
layers: [new ol.layer.Tile({source: new ol.source.OSM()})],
view: new ol.View({center: ol.proj.fromLonLat([-122.5, 45.5]), zoom: 10})
});
Both libraries offer powerful mapping capabilities, but OpenLayers provides more advanced features at the cost of increased complexity. esri-leaflet is better suited for simpler projects using Esri services, while OpenLayers offers more flexibility and support for various data sources and projections.
Marker Clustering plugin for Leaflet
Pros of Leaflet.markercluster
- Specialized for efficient clustering of large numbers of markers
- Provides smooth animations and transitions for cluster changes
- Offers more customization options for cluster appearance and behavior
Cons of Leaflet.markercluster
- Limited to marker clustering functionality only
- Requires additional setup and configuration for optimal performance
- May have a steeper learning curve for advanced customization
Code Comparison
esri-leaflet:
L.esri.featureLayer({
url: 'https://services.arcgis.com/...',
pointToLayer: function (geojson, latlng) {
return L.marker(latlng);
}
}).addTo(map);
Leaflet.markercluster:
var markers = L.markerClusterGroup();
for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var marker = L.marker(new L.LatLng(a[0], a[1]));
markers.addLayer(marker);
}
map.addLayer(markers);
Mapbox JavaScript API, a Leaflet Plugin
Pros of mapbox.js
- More extensive documentation and examples
- Better support for custom map styles and design
- Wider range of built-in controls and UI elements
Cons of mapbox.js
- Requires a Mapbox account and API key
- Less integration with ArcGIS services and data formats
- Steeper learning curve for beginners
Code Comparison
esri-leaflet:
var map = L.map('map').setView([45.528, -122.680], 13);
L.esri.basemapLayer('Streets').addTo(map);
L.esri.featureLayer({
url: 'https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Major_Cities/FeatureServer/0'
}).addTo(map);
mapbox.js:
mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [-122.680, 45.528],
zoom: 13
});
Both libraries offer powerful mapping capabilities, but esri-leaflet is more focused on integrating with ArcGIS services, while mapbox.js provides more customization options and a wider range of built-in features. The choice between them depends on specific project requirements and data sources.
Location Intelligence & Data Visualization tool
Pros of CartoDB
- More comprehensive platform with built-in data analysis and visualization tools
- Offers a cloud-based solution for easier collaboration and data management
- Provides a user-friendly interface for non-developers to create maps and visualizations
Cons of CartoDB
- Less flexible for custom integrations compared to esri-leaflet
- May have a steeper learning curve for developers used to working with raw mapping libraries
- Potentially higher costs for advanced features and large-scale usage
Code Comparison
esri-leaflet:
var map = L.map('map').setView([45.528, -122.680], 13);
L.esri.basemapLayer('Streets').addTo(map);
var featureLayer = L.esri.featureLayer({url: 'https://services.arcgis.com/....'}).addTo(map);
CartoDB:
cartodb.createVis('map', 'https://username.carto.com/api/v2/viz/vizid/viz.json', {
shareable: true,
title: true,
description: true,
search: true,
tiles_loader: true,
center_lat: 40.7,
center_lon: -73.9,
zoom: 11
});
Both libraries offer ways to create interactive maps, but CartoDB provides a higher-level API with more built-in features, while esri-leaflet offers more granular control over map elements and integrates seamlessly with other Leaflet plugins.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Esri Leaflet
Leaflet plugins for working with a handful of the most popular ArcGIS Service types. This includes Esri basemaps and feature services, as well as tiled map, dynamic map and image services.
This project is maintained with :heart: by folks on multiple teams at Esri, but we provide no guarantee of individual features, nor a traditional product lifecycle to support planning.
The goal of this project is not to replace the ArcGIS API for JavaScript but rather to provide small components for only some aspects of the ArcGIS platform for developers who prefer to build mapping applications with Leaflet.
We are proud to facilitate a project which requires participation from our diverse user community in order to thrive and we welcome contributions from those just getting their feet wet in open-source.
Support for Geocoding services and Geoprocessing services, as well as service defined rendering are available as well (via additional plugins).
If you'd like to display Esri services in any Leaflet application, we ask that you adhere to our Terms of Use and attribution requirements.
Table of Contents
Quick Start
The easiest way to get started is to load Esri Leaflet via CDN. Here is an example you can copy/paste into your own .html
file: Esri Leaflet Quick Start
Samples, Tutorials, and API Reference
Samples, tutorials, and the API reference can be found at developers.arcgis.com/esri-leaflet.
If you notice any issues or would like to propose a change to the documentation, please let us know by creating an issue in this repository.
Additional Plugins
Many folks have written plugins to customize and extend Leaflet.
http://leafletjs.com/plugins.html
You can also pick and choose additional Esri Leaflet plugins.
https://developers.arcgis.com/esri-leaflet/plugins/
Frequently Asked Questions
- What are the terms of use for ArcGIS Online services?
- What exactly is Esri Leaflet? Is it a replacement for Leaflet?
- Will Esri Leaflet replace the ArcGIS API for JavaScript?
- What is the benefit of using Esri Leaflet over using Leaflet all by itself?
- What are the goals of Esri Leaflet?
- Can I use Esri Leaflet with Leaflet Version 1.0.x?
- How do you decide what features get included in Esri Leaflet?
- I have an idea! What should I do?
- When will you support "x"?
- Can you implement feature "x"?
- I want to contribute. How can I help?
- I built something with Esri Leaflet can I show you?
- I built a reusable component (layer type, api wrapper, ui control etc...) can I contribute it to Esri Leaflet?
- Which services require authentication?
- What are some good Leaflet Plugins?
- What browsers does Esri Leaflet support?
- What versions of ArcGIS Server does Esri Leaflet support?
- Upgrading the version of Esri Leaflet used in my app broke everything!
- Does Esri Leaflet support IE 'compatibility mode'?
- I'm into TypeScript, but Esri Leaflet seems to be a vanilla JS thing. Can I find typings somewhere?
- When exactly do I need to use a paid Esri developer account to deploy to production?
Issues
If something isn't working the way you expected, please take a look at previously logged issues that resolve common problems first. Have you found a new bug? Want to request a new feature? We'd love to hear from you. Please let us know by submitting an issue.
If you're looking for help you can also find answers on Stack Overflow and GeoNet.
Going Deeper
Development Instructions
If you'd like to inspect and modify the source of Esri Leaflet, follow the instructions below to set up a local development environment.
- Fork and clone Esri Leaflet
cd
into theesri-leaflet
folder- Install the
package.json
dependencies by runningnpm install
- Run
npm start
from the command line. This will compile minified source in a brand newdist
directory, launch a tiny webserver and begin watching the raw source for changes. - Run
npm test
to make sure you haven't introduced a new 'feature' accidentally. - Make your changes and create a pull request
Dependencies
-
Esri Leaflet 1.x (available on CDN) can be used in apps alongside:
- Leaflet version 0.7.x.
-
Esri Leaflet 2.x (available on CDN) can be used in apps alongside:
- Leaflet version 1.x.
The master
branch of this repository is only compatible with Leaflet 1.x.
Versioning
For transparency into the release cycle and in striving to maintain backward compatibility, Esri Leaflet is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible.
For more information on SemVer, please visit http://semver.org/.
Contributing
Esri welcomes contributions from anyone and everyone. Please see our guidelines for contributing.
Terms
If you're using Esri content and services, you'll need to license your usage with an API key or an ArcGIS identity. Full details can be found here: Deployment guidelines.
If you display an ArcGIS Online service in any Leaflet application, we require that you include Esri attribution and recognize data providers. Using this plugin, it couldn't be easier to follow the terms. Just select your basemap and the appropriate credits will be displayed dynamically in Leaflet's own Attribution control as users pan/zoom.
L.esri.basemapLayer('Topographic').addTo(map);
Credit
L.esri.DynamicMapLayer
originally used code from AGS.Layer.Dynamic.jsL.esri.TiledMapLayer
adapts some code from arcgis-level-fixer
License
Copyright Β© 2014-2019 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
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.
Top Related Projects
π JavaScript library for mobile-friendly interactive maps πΊπ¦
Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
OpenLayers
Marker Clustering plugin for Leaflet
Mapbox JavaScript API, a Leaflet Plugin
Location Intelligence & Data Visualization tool
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot