Learn how to display attributes of 3D objects in a pop-up
A pop-up
In this tutorial, you customize the interactive pop-up created by CesiumJS for the San Francisco Buildings 3D object layer. When a building is clicked, a pop-up is displayed containing the name of the building and its object ID.
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
-
Update the camera position to
-122.43305, 37.77655, 500to focus on San Francisco, California.Use dark colors for code blocks Copy viewer.camera.setView({ destination: Cesium.Cartesian3.fromDegrees(-122.43305, 37.77655, 500), orientation: { heading: Cesium.Math.toRadians(60), pitch: Cesium.Math.toRadians(-15.0) } });
Add a terrain provider
To ensure that your 3D objects sit properly on top of the terrain, you need to use a geoid
-
Initialize a terrain provider called
geoidthat references the Earth Gravitational Model EGM2008. This provider will allow for geoid conversion between the gravity-based 3D object layer and the ellipsoidal-based Cesium World Terrain.Service Use dark colors for code blocks const geoidService = await Cesium.ArcGISTiledElevationTerrainProvider.fromUrl("https://tiles.arcgis.com/tiles/GVgbJbqm8hXASVYi/arcgis/rest/services/EGM2008/ImageServer"); viewer.creditDisplay.addStaticCredit(new Cesium.Credit("National Geospatial-Intelligence Agency (NGA)", false)); -
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 EGM2008 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 geoidService = await Cesium.ArcGISTiledElevationTerrainProvider.fromUrl("https://tiles.arcgis.com/tiles/GVgbJbqm8hXASVYi/arcgis/rest/services/EGM2008/ImageServer"); viewer.creditDisplay.addStaticCredit(new Cesium.Credit("National Geospatial-Intelligence Agency (NGA)", false));
- Go to the EGM2008 item
Add 3D objects
-
Reference the service URL of the San Francisco 3D Objects scene layer
A scene layer is a data layer is used to access and display 3D data from a scene service. .Use dark colors for code blocks const i3sLayer = "https://tiles.arcgis.com/tiles/z2tnIkrLQ2BRzr6P/arcgis/rest/services/SanFrancisco_Bldgs/SceneServer"; -
Create an
I3by calling theS Data Provider frommethod. Pass theUrl geoidyou created and add it to the viewer.Service Use dark colors for code blocks const i3sLayer = "https://tiles.arcgis.com/tiles/z2tnIkrLQ2BRzr6P/arcgis/rest/services/SanFrancisco_Bldgs/SceneServer"; const i3sProvider = await Cesium.I3SDataProvider.fromUrl(i3sLayer, { geoidTiledTerrainProvider: geoidService, token: accessToken }); viewer.scene.primitives.add(i3sProvider); -
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 scene layer source.- Go to the San Francisco 3D Objects 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 i3sLayer = "https://tiles.arcgis.com/tiles/z2tnIkrLQ2BRzr6P/arcgis/rest/services/SanFrancisco_Bldgs/SceneServer"; const i3sProvider = await Cesium.I3SDataProvider.fromUrl(i3sLayer, { geoidTiledTerrainProvider: geoidService, token: accessToken }); viewer.scene.primitives.add(i3sProvider); // Attribution text retrieved from https://www.arcgis.com/home/item.html?id=d3344ba99c3f4efaa909ccfbcc052ed5 viewer.creditDisplay.addStaticCredit(new Cesium.Credit("Precision Light Works (PLW)", false));
- Go to the San Francisco 3D Objects item
Get feature attributes
-
Create a click handler to detect user clicks on the viewer. Get the clicked feature using
viewer.scene.pick(), and get the position of the click usingviewer.scene.pick.Position() Use dark colors for code blocks // An entity object which will hold info about the currently selected feature for infobox display const selectedEntity = new Cesium.Entity(); // Show metadata in the InfoBox. viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) { // Pick a new feature const pickedFeature = viewer.scene.pick(movement.position); if (!Cesium.defined(pickedFeature)) { return; } const pickedPosition = viewer.scene.pickPosition(movement.position); }, Cesium.ScreenSpaceEventType.LEFT_CLICK); -
Create a helper function
isthat checks if a property is aName Property namefield. You will use this helper function when displaying information of a clicked feature in a popup.Use dark colors for code blocks function isNameProperty(propertyName) { const name = propertyName.toLowerCase(); if ( name.localeCompare("name") === 0 || name.localeCompare("objname") === 0 ) { return true; } return false; } -
Inside the click handler, use
I3to load the properties of the closest I3S node. Get the exact geometry that was clicked usingS Node.load Fields() I3.S Geometry.get Closest Point Index On Triangle Use dark colors for code blocks // An entity object which will hold info about the currently selected feature for infobox display const selectedEntity = new Cesium.Entity(); // Show metadata in the InfoBox. viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) { // Pick a new feature const pickedFeature = viewer.scene.pick(movement.position); if (!Cesium.defined(pickedFeature)) { return; } const pickedPosition = viewer.scene.pickPosition(movement.position); if ( Cesium.defined(pickedFeature.content) && Cesium.defined(pickedFeature.content.tile.i3sNode) ) { const i3sNode = pickedFeature.content.tile.i3sNode; i3sNode.loadFields().then(function () { const geometry = i3sNode.geometryData[0]; if (pickedPosition) { const location = geometry.getClosestPointIndexOnTriangle( pickedPosition.x, pickedPosition.y, pickedPosition.z ); let description = "No attributes"; let name; if (!Cesium.defined(name)) { name = "unknown"; } selectedEntity.name = name; selectedEntity.description = description; viewer.selectedEntity = selectedEntity; } }); } }, Cesium.ScreenSpaceEventType.LEFT_CLICK); -
Access the properties of the clicked geometry. Display them in an
Info.Box Use dark colors for code blocks if ( Cesium.defined(pickedFeature.content) && Cesium.defined(pickedFeature.content.tile.i3sNode) ) { const i3sNode = pickedFeature.content.tile.i3sNode; i3sNode.loadFields().then(function () { const geometry = i3sNode.geometryData[0]; if (pickedPosition) { const location = geometry.getClosestPointIndexOnTriangle( pickedPosition.x, pickedPosition.y, pickedPosition.z ); let description = "No attributes"; let name; if (location.index !== -1 && geometry.customAttributes.featureIndex) { const featureIndex = geometry.customAttributes.featureIndex[location.index]; if (Object.keys(i3sNode.fields).length > 0) { description = "<table class=\"cesium-infoBox-defaultTable\"><tbody>"; for (const fieldName in i3sNode.fields) { if (Object.hasOwn(i3sNode.fields, fieldName)) { const field = i3sNode.fields[fieldName]; description += `<tr><th>${field.name}</th><td>`; description += `${field.values[featureIndex]}</td></tr>`; console.log( `${field.name}: ${field.values[featureIndex]}` ); if ( !Cesium.defined(name) && isNameProperty(field.name) ) { name = field.values[featureIndex]; } } } description += "</tbody></table>"; } } if (!Cesium.defined(name)) { name = "unknown"; } selectedEntity.name = name; selectedEntity.description = description; viewer.selectedEntity = selectedEntity; } }); }
Run the app
Run the app.
When you click on a feature, a popup should appear displaying the attribute information of the selected feature.What's next?
Learn how to use additional location services in these tutorials:


