Learn how to create and display a map with a basemap layer.
A map contains layers of geographic data. Maps include a basemap layer and, optionally, one or more data layers. You can display a specific area of a map by setting the location and zoom level.
This tutorial shows you how to create and display a map of the Santa Monica Mountains in California using the topographic basemap layer.
The map and code in this tutorial will be used as the starting point for other 2D tutorials.
Prerequisites
Steps
Create a new pen
- Go to CodePen to create a new pen for your mapping application.
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 both the opening and closing tag.
Add basic HTML
Define a basic HTML page.
- In CodePen > HTML, add HTML to create a basic page.
Use dark colors for code blocks <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" /> <title>ArcGIS Maps SDK for JavaScript Tutorials: Display a map</title> </head> <body> </body> </html>
Add CSS
- In CodePen > HTML, add CSS to set the map to use the full width and height of the browser.
Use dark colors for code blocks <style> html, body { height: 100%; margin: 0; } </style>
Get an access token
You need an access token with the correct privileges to access the location services used in this tutorial.
- Go to the Create an API key tutorial and create an API key with the following privilege(s):
 - Privileges
- Location services > Basemaps
 
 
- Privileges
- In CodePen, set esrito your access token.Config.api Key Use dark colors for code blocks <!-- The esriConfig variable must be defined before adding the other esri libraries --> <script> var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN", }; </script>
To learn about other ways to get an access token, go to Types of authentication.
Add references
- In the <head, add the> <scripttags for the Map Components and the Calcite Design System.> Use dark colors for code blocks <!-- Load Calcite components from CDN --> <script type="module" src="https://js.arcgis.com/calcite-components/3.3.3/calcite.esm.js"></script> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script src="https://js.arcgis.com/4.34/"></script> <!-- Load Map components from CDN--> <script type="module" src="https://js.arcgis.com/4.34/map-components/"></script>
Add a map
Use the Map component to set the basemap layer, location and zoom level.
- 
In the <bodytag, add the> <arcgis-mapcomponent and specify the> basemap,centerandzoomattributes.Use dark colors for code blocks <body> <arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"> </arcgis-map> </body>
- 
In the <arcgis-mapcomponent, add an> <arcgis-zoomcomponent, which enables users to zoom in and out without a mouse wheel.> Use dark colors for code blocks <arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"> <arcgis-zoom slot="top-left"></arcgis-zoom> </arcgis-map>
Run the app
In CodePen, run your code to display the map.
The map should display the topographic basemap layer for an area of the Santa Monica Mountains in California.
What's next?
Learn how to use additional SDK features and ArcGIS services in these tutorials: