Learn how to customize the CesiumJS base layer picker to display ArcGIS data provider options.
ArcGIS provides base layers for both imagery and terrain that you can use in your CesiumJS applications. You can use map tiles from the ArcGIS Basemap Styles serviceImagery.
In this tutorial, you customize the Base widget to display the different ArcGIS base layers available for imagery and terrain.
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
Get a Cesium ion access token
All Cesium applications must use an access token provided through Cesium ion. This token allows you to access assets such as Cesium World Terrain in your application.
-
Go to your Cesium ion dashboard to generate an access token. Copy the key to your clipboard.
-
Create a
cesiumvariable and replaceAccess Token YOURwith the access token you copied from the Cesium ion dashboard._CESIUM _ACCESS _TOKEN Use dark colors for code blocks <script> /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URI", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; Cesium.ArcGisMapService.defaultAccessToken = accessToken; const cesiumAccessToken = "YOUR_CESIUM_ACCESS_TOKEN"; </script> -
Configure
Cesium.with the Cesium access token to validate the application.Ion.default Access Token Use dark colors for code blocks <script> /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URI", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; Cesium.ArcGisMapService.defaultAccessToken = accessToken; const cesiumAccessToken = "YOUR_CESIUM_ACCESS_TOKEN"; Cesium.Ion.defaultAccessToken = cesiumAccessToken; </script>
Update the camera position
-
Change the camera position to
-122.4106, 37.7908, 200000to focus on San Francisco.Use dark colors for code blocks Copy viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(-122.4106, 37.7908, 200000) });
Add a terrain provider
To create accurate and realistic terrain in your CesiumJS scene, you need to use a geoid
-
Initialize a terrain provider called
arcthat references the Terrain 3D. This terrain will provide global elevation surface for your basemap layer.Gis Terrain Use dark colors for code blocks const arcGisTerrain = new Cesium.ProviderViewModel({ name: "ArcGIS World Terrain", iconUrl: "https://www.arcgis.com/sharing/rest/content/items/58a541efc59545e6b7137f961d7de883/info/thumbnail/thumbnail1585609861151.png", creationFunction: () => { return Cesium.ArcGISTiledElevationTerrainProvider.fromUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"); } }); viewModel.terrainProviderViewModels = [arcGisTerrain]; -
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 elevation layer source.- Go to the Terrain 3D 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
creditproperty.Use dark colors for code blocks const arcGisTerrain = new Cesium.ProviderViewModel({ name: "ArcGIS World Terrain", iconUrl: "https://www.arcgis.com/sharing/rest/content/items/58a541efc59545e6b7137f961d7de883/info/thumbnail/thumbnail1585609861151.png", creationFunction: () => { return Cesium.ArcGISTiledElevationTerrainProvider.fromUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"); } }); viewModel.terrainProviderViewModels = [arcGisTerrain]; // Attribution text retrieved from https://www.arcgis.com/home/item.html?id=7029fb60158543ad845c7e1527af11e4 viewer.creditDisplay.addStaticCredit(new Cesium.Credit("Sources: Maxar, Airbus DS, USGS, NGA, NASA, CGIAR, GEBCO, N Robinson, NCEAS, NLS, OS, NMA, Geodatastyrelsen and the GIS User Community", false));
- Go to the Terrain 3D item
Change the imagery providers
CesiumJS includes a base by default that includes imagery layers from multiple providers. Customize this widget to include additional offerings from ArcGIS.
-
Inside
viewer, set thebaseproperty toLayer Picker true.Use dark colors for code blocks const viewer = new Cesium.Viewer("cesiumContainer", { baseLayer: Cesium.ImageryLayer.fromProviderAsync(arcGisImagery), terrain: Cesium.Terrain.fromWorldTerrain(), baseLayerPicker: true, timeline: false, animation: false, geocoder: false }); -
Access the
baseto manage the available base layer options.Layer Picker.view Model Use dark colors for code blocks const viewModel = viewer.baseLayerPicker.viewModel; -
Define a set of base layers you want to include in your base layer picker, e.g.
ArcGI,S World Imagery ArcGI, andS World Hillshade Esri World Ocean.Use dark colors for code blocks const imageryProviderNames = ["ArcGIS World Imagery", "ArcGIS World Hillshade", "Esri World Ocean"]; -
The
viewcontains all available basemaps by default. Use a for loop to filter and select only the desired basemaps.Model.imagery Provider View Models Use dark colors for code blocks const imageryProviderNames = ["ArcGIS World Imagery", "ArcGIS World Hillshade", "Esri World Ocean"]; const imageryProviders = []; for (imageryProvider of viewModel.imageryProviderViewModels) { if (imageryProviderNames.includes(imageryProvider.name)) { imageryProviders.push(imageryProvider); } } -
Replace the
viewwith the filtered list.Model.imagery Provider View Models Use dark colors for code blocks const imageryProviderNames = ["ArcGIS World Imagery", "ArcGIS World Hillshade", "Esri World Ocean"]; const imageryProviders = []; for (imageryProvider of viewModel.imageryProviderViewModels) { if (imageryProviderNames.includes(imageryProvider.name)) { imageryProviders.push(imageryProvider); } } viewModel.imageryProviderViewModels = imageryProviders;
Run the app
Run the app.
Open the base layer picker and ensure that only the specified basemaps are available for selection.What's next?
Learn how to use additional location services in these tutorials:


