Learn how to add multiple basemap layers from different services to your map.
This tutorial shows how to display two basemap layers from different services in your application. You will use the World Imagery map tile service satellite imagery basemap to provide the underlying visual and geographic context for the map. To provide additional context, you will use the arcgis/imagery/labels
style from the static basemap tiles service to display place labels for the world. The combination of the two layers will result in a basemap that provides additional context for the mapping application.
Prerequisites
An ArcGIS Location Platform 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's viewpoint
-
Change the map's center to
[-91.2996, 37.1174]
and zoom level to4
. This will focus the map on the United States of America.Use dark colors for code blocks const map = new maplibregl.Map({ container: "map", zoom: 4, center: [-91.2996, 37.1174] // USA (x, y) });
Add basemap layer 1
Create a tile source and tile layer to access and display basemap layer from the World Imagery map tile service.
-
Define a
tile
to load raster tiles from the World Imagery map tile service.Source Use dark colors for code blocks const tileSource = { imagery: { type: "raster", tiles: [`https://ibasemaps-api.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}?token=${accessToken}`], } };
-
Add the data attribution for the map tile layer source.
- Go to the World Imagery 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 const tileSource = { imagery: { type: "raster", tiles: [`https://ibasemaps-api.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}?token=${accessToken}`], attribution: "Esri, Maxar, Earthstar Geographics, and the GIS User Community" } };
-
Define a
tile
that references theLayer tile
.Source Use dark colors for code blocks const tileSource = { imagery: { type: "raster", tiles: [`https://ibasemaps-api.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}?token=${accessToken}`], attribution: "Esri, Maxar, Earthstar Geographics, and the GIS User Community" } }; const tileLayer = { id: "imagery-raster", type: "raster", source: "imagery" };
Add basemap layer 2
In this step, you add another basemap layer from the static basemap tiles service to provide place labels.
-
Replace
basemap
toEnum arcgis/imagery/labels
andbase
to the static basemap tiles service endpoint.Url Use dark colors for code blocks const basemapEnum = "arcgis/imagery/labels"; const baseUrl = `https://static-map-tiles-api.arcgis.com/arcgis/rest/services/static-basemap-tiles-service/v1`;
-
Create a
static
using the static basemap tiles service.Basemap Tile Source Use dark colors for code blocks const basemapEnum = "arcgis/imagery/labels"; const baseUrl = `https://static-map-tiles-api.arcgis.com/arcgis/rest/services/static-basemap-tiles-service/v1`; const staticBasemapTileSource = { "raster-tiles": { type: "raster", tiles: [`${baseUrl}/${basemapEnum}/static/tile/{z}/{y}/{x}?token=${accessToken}`], tileSize: 512, attribution: "Powered by <a href='https://www.esri.com/en-us/home' target='_blank'>Esri</a> | Sources: Esri, TomTom, Garmin, FAO, NOAA, USGS, © OpenStreetMap contributors, and the GIS User Community" } };
-
Add a
static
that references the basemap source.Basemap Tile Layer Use dark colors for code blocks const basemapEnum = "arcgis/imagery/labels"; const baseUrl = `https://static-map-tiles-api.arcgis.com/arcgis/rest/services/static-basemap-tiles-service/v1`; const staticBasemapTileSource = { "raster-tiles": { type: "raster", tiles: [`${baseUrl}/${basemapEnum}/static/tile/{z}/{y}/{x}?token=${accessToken}`], tileSize: 512, attribution: "Powered by <a href='https://www.esri.com/en-us/home' target='_blank'>Esri</a> | Sources: Esri, TomTom, Garmin, FAO, NOAA, USGS, © OpenStreetMap contributors, and the GIS User Community" } }; const staticBasemapTileLayer = { id: "static-basemap-tiles", type: "raster", source: "raster-tiles", minzoom: 0, maxzoom: 22 };
-
Add both sources and both layers to the map. Make sure that
tile
is added first, followed byLayer static
, so the static basemap tile layer appears on top of the map tile layer.Basemap Tile Layer Use dark colors for code blocks const map = new maplibregl.Map({ container: "map", style: { version: 8, sources: { ...tileSource, ...staticBasemapTileSource }, layers: [tileLayer, staticBasemapTileLayer] }, zoom: 4, center: [-91.2996, 37.1174] // USA (x, y) });
Run the app
Run the app.
The map should display basemap layers from the World Imagery map tile service and the static basemap tiles service.What's next?
Learn how to use additional ArcGIS location services in these tutorials: