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 hillshade map tile layer to your map and display it beneath a semitransparent basemap layer.
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 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.
- To get started, either complete the Display a map tutorial or .
Set the API key
-
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
to use your key.Key Use dark colors for code blocks 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 a map tile layer
Use the Tiled
class to access and display data from the World Hillshade map tile service.
-
Access the hillshade layer with a
Tiled
and add it to your map.M a p Layer Use dark colors for code blocks L.esri.Vector.vectorBasemapLayer(basemapEnum, { apiKey: apiKey, }).addTo(map); L.esri.tiledMapLayer({ url:"https://server.arcgisonline.com/arcgis/rest/services/Elevation/World_Hillshade/MapServer", apiKey: apiKey, }).addTo(map); </script>
Reposition and style the basemap
By default, the basemap layer is added to the same pane as the hillshade layer. To visuallly combine hillshading with a basemap, you need to change the layer order and opacity of the basemap so both layers are visible.
-
Create a new Leaflet pane called
esri-basemap
. Set thez
of the pane toIndex 300
to display above the hillshade 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 = 300; L.esri.Vector.vectorBasemapLayer(basemapEnum, { apiKey: apiKey, pane: basemapPane, }).addTo(map);
-
Reduce the opacity of everything in the basemap layer except for water and buildings. This will make the hillshade layer visible on land.
Use dark colors for code blocks L.esri.Vector.vectorBasemapLayer(basemapEnum, { apiKey: apiKey, pane: basemapPane, style: function (style) { for (const [i, layer] of style.layers.entries()) { if (layer.type === 'fill' && !layer.id.match(/(Water|Marine|Bathymetry|Building)/)) { style.layers[i].paint['fill-opacity'] = 0.5; } } return style } }).addTo(map);
Run the app
In CodePen, run your code to display the map.
Your map should display a hillshade layer underneath a semi-transparent basemap. You should see the hillshade 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: