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.
NoteFor more information about maps and layers, visit Maps, scenes, and layers in the Mapping and location services guide.
Prerequisites ArcGIS Accounts:You need an ArcGIS Location Platform or ArcGIS Online account.
Steps Create a new penThe <!doctype html></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.
Define a basic HTML page.
Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<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>
Expand
Use dark colors for code blocks1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<style>
html,
body {
height: 100%;
margin: 0;
}
</style>
You need an access token with the correct privileges to access the location services used in this tutorial.
esriConfig.apiKey
to your access token.
Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
<!-- 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<head>
, add the <script>
and <link>
tags for the Map Components and the Calcite Design System.
Expand
Use dark colors for code blocks1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!-- Load Calcite components from CDN -->
<script type="module" src="https://js.arcgis.com/calcite-components/3.2.1/calcite.esm.js"></script>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<link rel="stylesheet" href="https://js.arcgis.com/4.33/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.33/"></script>
<!-- Load Map components from CDN-->
<script type="module" src="https://js.arcgis.com/4.33/map-components/"></script>
Use the Map
component to set the basemap layer, location and zoom level.
In the <body>
tag, add the <arcgis-map>
component and specify the basemap
, center
and zoom
attributes.
Expand
Use dark colors for code blocks1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<body>
<arcgis-map basemap="arcgis/topographic" center="-118.805, 34.027" zoom="13">
</arcgis-map>
</body>
In the <arcgis-map>
component, add an <arcgis-zoom>
component, which enables users to zoom in and out without a mouse wheel.
Expand
Use dark colors for code blocks1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<arcgis-map basemap="arcgis/topographic" center="-118.805, 34.027" zoom="13">
<arcgis-zoom position="top-left"></arcgis-zoom>
</arcgis-map>
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 API features and ArcGIS services in these tutorials:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4