A web scene is a scene that is stored as an item in ArcGIS Online. A web scene item contains all of the configuration settings for the scene (in JSON format) such as extent, basemap, data layers, and styles. Applications can access and display the web scene using its item ID.
In this tutorial, you will access and display a pre-configured web scene stored in ArcGIS Online.
Prerequisites
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or .
Get an access token
You need an access token with the correct privileges to access the location services used in this tutorial.
- Go to the Create an API key tutorial and create an API key with the following privilege(s):
- Privileges
- Location services > Basemaps
- Privileges
- In CodePen, set
esri
to your API key..Config.api Key Use dark colors for code blocks esriConfig.apiKey = "YOUR_ACCESS_TOKEN"; const map = new Map({ basemap: "arcgis/topographic" // basemap styles service });
To learn about other ways to get an access token, go to Types of authentication.
Add modules
-
In the
require
statement, delete theMap
andMap
modules. Add theView Web
,Scene Scene
, andView Legend
modules.The ArcGIS Maps SDK for JavaScript is available as AMD modules and ES modules, but this tutorial is based on AMD. The AMD
require
function uses references to determine which modules will be loaded – for example, you can specify"esri/
for loading the Map module. After the modules are loaded, they are passed as parameters (e.g.Map" Map
) to the callback function where they can be used in your application. It is important to keep the module references and callback parameters in the same order. To learn more about the API's different modules visit the Overview Guide page.Use dark colors for code blocks "esri/config", "esri/Map", "esri/MapView", "esri/WebScene", "esri/views/SceneView", "esri/widgets/Legend" ], function(esriConfig, WebScene, SceneView, Legend) {
Load the web scene
You can use the portal item ID to create a Web
. The web scene will be passed to the view.
-
Delete the code that creates the
Map
and theMap
.View Use dark colors for code blocks esriConfig.apiKey = "YOUR_ACCESS_TOKEN"; const map = new Map ({ basemap: "arcgis/topographic" }); const view = new MapView({ map: map, center: [-118.805, 34.027], // Longitude, latitude zoom: 13, // Zoom level container: "viewDiv" // Div element });
-
Create a
Web
. Load the web scene using its portal item ID.Scene Use dark colors for code blocks esriConfig.apiKey = "YOUR_ACCESS_TOKEN"; const webscene = new WebScene({ portalItem: { id: "579f97b2f3b94d4a8e48a5f140a6639b" } });
Create a scene view
-
Create a
Scene
and set theView container
andmap
properties.Use dark colors for code blocks const webscene = new WebScene({ portalItem: { id: "579f97b2f3b94d4a8e48a5f140a6639b" } }); const view = new SceneView({ container: "viewDiv", map: webscene });
-
At the top-right, click Run to verify that the web map has been successfully loaded and displays.
Add widgets
Use the Legend
widget to add more context to the application. The Legend
widget displays labels and symbols for layers visible in the view.
- Create a
Legend
to display feature information. Add thelegend
to thetop-right
of theview
.Use dark colors for code blocks const view = new SceneView({ container: "viewDiv", map: webscene }); const legend = new Legend ({ view:view }); view.ui.add(legend, "top-right");
Run the app
In CodePen, run your code to display the map.
What's next?
Learn how to use additional API features and ArcGIS services in these tutorials: