Learn how to add a map tile layer to a map
A map tile layer, also known as an image tile layer
In this tutorial, you add a Santa Monica contours map tile layer, which is a 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
A public application is an application that allows anonymous access without requiring users to sign in with an ArcGIS account. It supports API key or app authentication. that access ArcGIS Location ServicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. and secure itemsAn item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. . - 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
An ArcGIS account is an identity with a user type and set of privileges that can access specific ArcGIS products, tools, APIs, services, and resources. The main account types that can be used for development are an ArcGIS Location Platform account, ArcGIS Online account, and ArcGIS Enterprise account. ArcGIS Location Platform and ArcGIS Online accounts are also associated with a subscription. 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
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 Copy 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
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
Data attribution is the requirement to display the names of data source providers in all applications when accessing ArcGIS content, layers, or services. for the map tile layer source.- Go to the Santa Monica contours item
An item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. . - 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);
- Go to the Santa Monica contours item
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: