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
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Get the starter app
Select a type of authentication and follow the steps to create a new app.
Choose API key authentication if you:
- Want the easiest way to get started.
- Want to build public applications that access ArcGIS Location Services and secure items.
- Have an ArcGIS Location Platform or ArcGIS Online account.
Choose user authentication if you:
- Want to build private applications.
- Require application users to sign in with their own ArcGIS account and access resources their behalf.
- Have an ArcGIS Online account.
To learn more about both types of authentication, go to Authentication.
Set up authentication
Set developer credentials
Use the API key or OAuth developer credentials so your application can access ArcGIS 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: 11 }) );
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
olmsload handler, create anXYZsource 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
Tilelayer using theXYZsource, 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 Acknowledgments section and copy its value.
- Paste the copied value to the
attributionsproperty.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 location services in these tutorials: