Display a map
Learn how to use Esri Leaflet and the basemap styles service to display a map.
You can display a map with Esri Leaflet by using a vector tile basemap layer from the basemap styles service. A vector tile basemap layer contains the styles, layers, font glyphs, and icons to render the layers.
In this tutorial, you display a map of the Santa Monica Mountains using the streets basemap layer from the Basemap styles service.
This code is used as the starting point for the other Esri Leaflet tutorials.
Prerequisites
You need an ArcGIS Developer or ArcGIS Online account to access the developer dashboard and create an API key.
Steps
Create a new pen
- Go to CodePen to create a new pen for your application.
Add HTML
Define an HTML page to create a map that is the full width and height of the browser window.
In CodePen > HTML, add HTML and CSS to create a page with a div element called
map
.Use the HTML to create a page with a map. Use the
map
div to display the map. Use the CSS to make the map full width and height.The
<!DOCTYPE html>
tag is not required in CodePen. If you are using a different editor or running the page on a local server, be sure to add this tag to the top of your HTML page.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
Add script references
To access vector basemap layers, you reference both the esri-leaflet
and the esri-leaflet-vector
plugins in addition to theleaflet
libraries.
Add
<script>
and<link>
tags to reference the libraries.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line.
Get an API key
To access location services, you need an API key or OAuth 2.0 access token. To learn how to create and scope your key, visit the Create an API key tutorial.
- Go to your developer dashboard to get an API key.
- Copy the key as it will be used in the next step.
Create a map
Use a map
to add a map to the div
element with the basemap you specify. To find the list of default basemap styles, go to Basemap styles service in the Mapping APIs and location services guide.
Add
<script>
elements in the HTML<body>
. Create amap
with themin
set toZoom 2
.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Call the
set
method to center the map on the coordinatesView 34.02, -118.805
and to set the zoom level to13
.Use dark colors for code blocks Add line. Create an
api
variable to store your API key. ReplaceKey YOUR_
with the API key you previously copied from the developer dashboard.API_ KEY Use dark colors for code blocks Add line. Create a
basemap
variable to store the basemap identifier,Enum ArcGIS:
.Streets Use dark colors for code blocks Add line. Instantiate the
vector
class and set theBasemap Layer basemap
andEnum api
before adding the layer to theKey map
.Use dark colors for code blocks Add line. Add line. Add line.
Run the app
In CodePen, run your code to display the map. The map should display a street basemap layer centered on Point Dume in California.
What's next?
Learn how to use additional ArcGIS location services in these tutorials:

Change the basemap style
Switch a basemap style in a map.

Change the place label language
Switch the language of place labels on a basemap.

Display a custom basemap style
Add a styled vector basemap layer to a map.

Search for an address
Find an address or place using a search box and the geocoding service.

Find a route and directions
Find a route and directions with the route service.