Learn how to display a map
You can display a map with Esri Leaflet by using a vector tile basemap layer
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
A public application is an application that allows anonymous access without requiring users to sign in with an ArcGIS account. It supports API key or app authentication. that access ArcGIS Location ServicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. and secure itemsAn item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. . - 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
An ArcGIS account is an identity with a user type and set of privileges that can access specific ArcGIS products, tools, APIs, services, and resources. The main account types that can be used for development are an ArcGIS Location Platform account, ArcGIS Online account, and ArcGIS Enterprise account. ArcGIS Location Platform and ArcGIS Online accounts are also associated with a subscription. 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
<linkand> <scriptreferences 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.2/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
<scripttag, create a> mapwith theminset toZoom 2.Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }); -
Call the
setmethod to center the map on the coordinatesView 30, -20and 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
basemapvariable 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 basemapandEnum accessbefore 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 layerWhat's next?
Learn how to use additional location services in these tutorials:



