Learn how to display a map.
You can display a map with Esri Leaflet by using a vector tile basemap layer from the ArcGIS Basemap Styles service. A vector tile basemap layer contains the styles, layers, font glyphs, and icons to render the layers.
In this tutorial, display a map of the world with the arcgis/outdoor
basemap style.
This application will use the basemap tiles usage model .
Prerequisites
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Create a new app
Select a type of authentication and follow the steps to create a new app.
Choose API key authentication if you:
- Want the easiest way to get started.
- Want to build public applications that access ArcGIS Location Services and secure items.
- Have an ArcGIS Location Platform or ArcGIS Online account.
Choose user authentication if you:
- Want to build private applications.
- Require application users to sign in with their own ArcGIS account and access resources their behalf.
- Have an ArcGIS Online account.
To learn more about both types of authentication, go to Authentication.
Set up authentication
Set the developer credentials
Add script references
To access vector basemap layers, you need to reference the leaflet
libraries as well as the esri-leaflet
and esri-leaflet-vector
plugins.
-
In the index.html file, add the following
<link
and> <script
references if they are missing.> Use dark colors for code blocks <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"> <title>Esri Leaflet Tutorials: Display a map</title> <!-- Load Leaflet from CDN --> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" crossorigin=""> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" crossorigin=""></script> <!-- Load Esri Leaflet from CDN --> <script src="https://unpkg.com/esri-leaflet@3.0.19/dist/esri-leaflet.js"></script> <script src="https://unpkg.com/esri-leaflet-vector@4.3.1/dist/esri-leaflet-vector.js"></script>
Create a map
Use a map
to add a map to the div
element with the basemap you specify. To find a list of basemap styles, go to Introduction to the Basemap Styles service .
-
In the
<script
tag, create a> map
with themin
set toZoom 2
.Use dark colors for code blocks const map = L.map("map", { minZoom: 2 });
-
Call the
set
method to center the map on the coordinatesView 30, -20
and to set the zoom level to3
.Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }); map.setView([30, -20], 3);
-
Create a
basemap
variable to store the basemap identifier,Enum arcgis/outdoor
.Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }); map.setView([30, -20], 3); const basemapEnum = "arcgis/outdoor";
-
Instantiate the
L.esri.
class and set theVector.vector Basemap Layer basemap
andEnum access
before adding the layer to theToken map
.Use dark colors for code blocks const basemapEnum = "arcgis/outdoor"; L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken }).addTo(map);
Run the app
Run the app.
The map should display the Outdoor basemap layer centered on the world.What's next?
Learn how to use additional location services in these tutorials: