Learn how to add a map tile layer to a map.
A map tile layer, also known as an image tile layer, displays raster imagery such as satellite photography or hillshading. You can combine map tile layers to enhance the display of a street basemap layer, position the layer on top of existing layers, or position it under existing layers. When positioned above other layers, you need to give the map tile layer a level of transparency so that users can see through it to the basemap. This combined basemap layer technique is used to enhance overall visualization.
In this tutorial, you add a Santa Monica contours map tile layer to your map.
Prerequisites
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Create a new pen
You need an access token with the correct privileges to access the resources 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
- Copy the API key access token as it will be used in the next step.
To learn about other ways to get an access token, go to Types of authentication.
- To get started, you can complete the Display a map tutorial or use the .
Get an access token
You need an access token with the correct privileges to access the resources 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
- Item access
- Note: If you are using your own custom data layer for this tutorial, you need to grant the API key credentials access to the layer item. Learn more in Item access privileges.
- Privileges
-
Copy the API key access token to your clipboard when prompted.
-
In CodePen, update the
access
variable to use your access token.Token Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }) map.setView([34.02, -118.805], 13); const accessToken = "YOUR_ACCESS_TOKEN"; const basemapEnum = "arcgis/streets"; L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken }).addTo(map);
-
Run the code to ensure the basemap is displayed in the map.
To learn about the other types of authentication available, go to Types of authentication.
Update the map
-
Center the map on
[-118.44, 34.03]
and set the zoom level to 11. This will set the map focus to Santa Monica, California.Use dark colors for code blocks const accessToken = "YOUR_ACCESS_TOKEN"; const basemapEnum = "arcgis/light-gray"; const map = L.map("map", { minZoom: 2 }).setView([34.03, -118.44], 11);
Add a map tile layer
Use the Tiled
class to access and display data from the Santa Monica contours map tile service.
-
Access the contours layer with a
Tiled
and add it to your map.Map Layer Use dark colors for code blocks L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken, }).addTo(map); const contoursLayer = L.esri.tiledMapLayer({ url:"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer/", apiKey: accessToken, }) contoursLayer.addTo(map) </script>
-
Set the opacity of the contours layer to
0.5
.Use dark colors for code blocks L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken, }).addTo(map); const contoursLayer = L.esri.tiledMapLayer({ url:"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer/", apiKey: accessToken, }) contoursLayer.addTo(map) contoursLayer.setOpacity(0.5); </script>
Reorder the layers
By default, the basemap layer is added to the same pane as the contours layer. To visually combine the contours with a basemap, you need to change the layer order so both layers are visible.
-
Create a new Leaflet pane called
esri-basemap
. Set thez
of the pane toIndex 200
to display below the contours layer. Add code so the basemap is created in the new pane.Use dark colors for code blocks const basemapPane = map.createPane('esri-basemap'); basemapPane.style.zIndex = 200; L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken, pane: basemapPane, }).addTo(map);
-
Create another pane called
contours
for the Hillshade layer. Set thez
toIndex 400
to display above the basemap. Add code so the Hillshade layer is created in the new pane.Use dark colors for code blocks const contoursPane = map.createPane('contours') contoursPane.style.zIndex = 400; const contoursLayer = L.esri.tiledMapLayer({ url:"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer/", apiKey: accessToken, pane: contoursPane }) contoursLayer.addTo(map) contoursLayer.setOpacity(0.5); </script>
Run the app
In CodePen, run your code to display the map.
Your map should display a semi-transparent contours layer on top of a basemap. You should see the contours layer combined with other layers, with labels, roads, buildings and water areas clearly visible over the top.
What's next?
Learn how to use additional ArcGIS location services in these tutorials: