Learn how to add a map tile layer to a map.
A map tile layer, also known as an image tile layer, displays raster images 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, which is a basemap layer composed of jpeg images, on top of a street basemap layer.
Prerequisites
An ArcGIS Location Platform or ArcGIS Online account.
Steps
Get the starter app
Select a type of authentication below and follow the steps to create a new application.
Set up authentication
Create developer credentials in your portal for the type of authentication you selected.
Set developer credentials
Use the API key or OAuth developer credentials so your application can access location services.
Update the map
-
Center the map on
[-118.44, 34.03]
. This will set the map focus to Santa Monica, California.Use dark colors for code blocks map.setView( new ol.View({ center: ol.proj.fromLonLat([-118.44, 34.03]), zoom: 12 }) );
Create a tile layer
To load the contour tiles, you will create an XYZ
source, using an XYZ URL. This is a URL with {x}
, {y}
and {z}
elements which the source substitutes with numbers when requesting each tile. The source can be displayed using a Tile
layer with the source
property. Set the opacity
to 0.3 so that the basemap can be seen through the contours layer.
The URL for the Santa Monica contours map tile service is:
https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer/tile/{z}/{y}/{x}
-
Inside
olms
load handler, create anXYZ
source using the XYZ url for the contours layer.Use dark colors for code blocks const basemapId = "arcgis/light-gray"; const basemapURL = `https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/${basemapId}?token=${accessToken}`; olms.apply(map, basemapURL) .then(function (map) { const contoursURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer/tile/{z}/{y}/{x}"; const contoursSource = new ol.source.XYZ({ url: contoursURL, // Attribution text retrieved from https://arcgis.com/home/item.html?id=5fd812155876416997c1a03e841e8821 attributions: ['| City of Santa Monica GIS Data'] });
-
Create a
Tile
layer using theXYZ
source, with 0.3 opacity. Add it to the map usingmap.add
.Layer Use dark colors for code blocks .then(function (map) { const contoursURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer/tile/{z}/{y}/{x}"; const contoursSource = new ol.source.XYZ({ url: contoursURL, }); const tileLayer = new ol.layer.Tile({ source: contoursSource, opacity: 0.3 }); map.addLayer(tileLayer);
-
Add the data attribution for the map tile layer source.
- Go to the Santa Monica contours item.
- Scroll down to the Credits (Attribution) section and copy its value.
- Create an
attribution
property and paste the attribution value from the item.Use dark colors for code blocks .then(function (map) { const contoursURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer/tile/{z}/{y}/{x}"; const contoursSource = new ol.source.XYZ({ url: contoursURL, // Attribution text retrieved from https://arcgis.com/home/item.html?id=5fd812155876416997c1a03e841e8821 attributions: ['| City of Santa Monica GIS Data'] }); const tileLayer = new ol.layer.Tile({ source: contoursSource, opacity: 0.3 }); map.addLayer(tileLayer);
Run the app
Run the app.
Your map should display a semi-transparent contours layer overlaid over a basemap.
What's next?
Learn how to use additional ArcGIS location services in these tutorials: