Learn how to change the basemap layer in a map .
The basemap styles service provides a number of basemap layer styles such as topography, streets, and imagery that you can use in maps.
In this tutorial, you use the layers
control to toggle between a number of different basemap layers .
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 To get started, either complete the Display a map tutorial or use this pen . Set the 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 dashboard to get an API key. The API key must be scoped to access the services used in this tutorial.
In CodePen , update api Key
to use your key.
Use dark colors for code blocks
Change line
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const map = L.map( "map" , {
minZoom : 2
})
map.setView([ 34.02 , - 118.805 ], 13 );
const apiKey = "YOUR_API_KEY" ;
const basemapEnum = "ArcGIS:Streets" ;
L.esri.Vector.vectorBasemapLayer(basemapEnum, {
apiKey : apiKey
}).addTo(map);
Remove basemap references Remove the basemap Enum
and vector Basemap Layer
references contained in the starter code .
Expand
Use dark colors for code blocks
Remove line Remove line Remove line Remove line
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const map = L.map( "map" , {
minZoom : 2
})
map.setView([ 34.02 , - 118.805 ], 13 );
const apiKey = "YOUR_API_KEY" ;
const basemapEnum = "ArcGIS:Streets" ;
L.esri.Vector.vectorBasemapLayer(basemapEnum, {
apiKey : apiKey
}).addTo(map);
Add the basemap styles Reference the additional basemap styles you would like to use in your application. For a complete list of default styles, go to the basemap styles service page in the Mapping APIs and location services guide.
Create a basemap Layers
object that contains the labels for each basemap layer enumeration. Reference the vector Basemap Layer
class and set the api Key
for each enumeration.
Expand
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.
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const apiKey = "YOUR_API_KEY" ;
const basemapLayers = {
Streets : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Streets" , { apiKey : apiKey }).addTo(map),
Navigation : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Navigation" , { apiKey : apiKey }),
Topographic : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Topographic" , { apiKey : apiKey }),
"Light Gray" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:LightGray" , { apiKey : apiKey }),
"Dark gray" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:DarkGray" , { apiKey : apiKey }),
"Streets Relief" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:StreetsRelief" , { apiKey : apiKey }),
Imagery : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Imagery" , { apiKey : apiKey }),
ChartedTerritory : L.esri.Vector.vectorBasemapLayer( "ArcGIS:ChartedTerritory" , { apiKey : apiKey }),
ColoredPencil : L.esri.Vector.vectorBasemapLayer( "ArcGIS:ColoredPencil" , { apiKey : apiKey }),
Nova : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Nova" , { apiKey : apiKey }),
Midcentury : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Midcentury" , { apiKey : apiKey }),
OSM : L.esri.Vector.vectorBasemapLayer( "OSM:Standard" , { apiKey : apiKey }),
"OSM:Streets" : L.esri.Vector.vectorBasemapLayer( "OSM:Streets" , { apiKey : apiKey })
};
Append add T o
to the ArcGIS: Streets
entry so that it is the default style when the application loads.
Expand
Use dark colors for code blocks
Change line
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const apiKey = "YOUR_API_KEY" ;
const basemapLayers = {
Streets : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Streets" , { apiKey : apiKey }).addTo(map),
Navigation : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Navigation" , { apiKey : apiKey }),
Topographic : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Topographic" , { apiKey : apiKey }),
"Light Gray" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:LightGray" , { apiKey : apiKey }),
"Dark gray" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:DarkGray" , { apiKey : apiKey }),
"Streets Relief" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:StreetsRelief" , { apiKey : apiKey }),
Imagery : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Imagery" , { apiKey : apiKey }),
ChartedTerritory : L.esri.Vector.vectorBasemapLayer( "ArcGIS:ChartedTerritory" , { apiKey : apiKey }),
ColoredPencil : L.esri.Vector.vectorBasemapLayer( "ArcGIS:ColoredPencil" , { apiKey : apiKey }),
Nova : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Nova" , { apiKey : apiKey }),
Midcentury : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Midcentury" , { apiKey : apiKey }),
OSM : L.esri.Vector.vectorBasemapLayer( "OSM:Standard" , { apiKey : apiKey }),
"OSM:Streets" : L.esri.Vector.vectorBasemapLayer( "OSM:Streets" , { apiKey : apiKey })
};
Create a Layers
control that references basemap Layers
and add it to your map.
Expand
Use dark colors for code blocks
Add line.
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const basemapLayers = {
Streets : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Streets" , { apiKey : apiKey }).addTo(map),
Navigation : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Navigation" , { apiKey : apiKey }),
Topographic : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Topographic" , { apiKey : apiKey }),
"Light Gray" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:LightGray" , { apiKey : apiKey }),
"Dark gray" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:DarkGray" , { apiKey : apiKey }),
"Streets Relief" : L.esri.Vector.vectorBasemapLayer( "ArcGIS:StreetsRelief" , { apiKey : apiKey }),
Imagery : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Imagery" , { apiKey : apiKey }),
ChartedTerritory : L.esri.Vector.vectorBasemapLayer( "ArcGIS:ChartedTerritory" , { apiKey : apiKey }),
ColoredPencil : L.esri.Vector.vectorBasemapLayer( "ArcGIS:ColoredPencil" , { apiKey : apiKey }),
Nova : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Nova" , { apiKey : apiKey }),
Midcentury : L.esri.Vector.vectorBasemapLayer( "ArcGIS:Midcentury" , { apiKey : apiKey }),
OSM : L.esri.Vector.vectorBasemapLayer( "OSM:Standard" , { apiKey : apiKey }),
"OSM:Streets" : L.esri.Vector.vectorBasemapLayer( "OSM:Streets" , { apiKey : apiKey })
};
L.control.layers(basemapLayers, null , { collapsed : false }).addTo(map);
Run the app In CodePen , run your code to display the map.
Use the layers control in the top right to select and explore different basemap layer styles.
What's next? Learn how to use additional ArcGIS location services in these tutorials: