Add a raster tile layer
Learn how to add a raster tile layer to a map.
A raster tile layer, also known as an image tile layer, displays imagery such as satellite photography or hillshading. You can combine raster 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 raster 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 raster tile layer, which is a basemap layer composed of JPEG images, on top of a street 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 get started, either complete the Display a map tutorial or .
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
to use your key.Key Use dark colors for code blocks Change line
Add a load event handler
To add layers to the map, you need to use the load
event to ensure the map is fully loaded.
Add an event handler for the
load
event.Use dark colors for code blocks Add line. Add line. Add line. Add line.
Add a raster source
You need to define a source for the raster tiles. This tells the Map
how to access the data for the layer, but does not display it.
Inside the load event handler, add a raster source with id
hillshade
.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line.
Add a raster layer
To display the raster tiles, add a layer of type raster
.
Add a raster layer with id
hillshade-raster
, connected to thehillshade
source.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. At the top right, click Run. You should see the hillshade layer only.
Adjust the basemap
By default, the hillshade layer is added on top of all the basemap layers. To visually combine hillshading with roads and park layers, you need to make two changes.
Move the hillshade layer below every layer except the background layer. You do this by passing the id of the next layer as an extra argument to
map.add
.Layer Reduce the opacity of most fill layers so the hillshade layer can be seen through them. In the
ArcGIS:
basemap, this includes several layers whose ids begin withStreets Water area
,Marine area
,Bathymetry
orBuilding
. You can usemap.get
to get the current style, and itsStyle layers
property to access all layers. Usemap.set
to change thePaint Property fill-opacity
for each layer.In the load handler, find the id of the first non-background layer. Modify your
add
call to insert the raster layer before that layer.Layer Use dark colors for code blocks Add line. Add line. Add line. Add line. Set 50%
fill-opacity
for every fill layer except water and building layers.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line.
Run the app
In CodePen, run your code to display the map.
Your map should display a semi-transparent hillshade layer overlaid over a 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: