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
You need an ArcGIS Developer or ArcGIS Online account to access the dashboard and create an API key.
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or .
Set the API key
To access ArcGIS services, you need an API key.
- Go to your dashboard to get an API key.
- In CodePen, set the
api
to your key, so it can be used to access basemap layer and location services.Key
esriConfig.apiKey = "YOUR_API_KEY";
const map = new Map({
basemap: "arcgis/topographic" // basemap styles service
});
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/Map"
for loading the Map module. After the modules are loaded, they are passed as parameters (e.g.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. For more information on the different types of modules, visit the Introduction to Tooling guide topic.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_API_KEY"; 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_API_KEY"; const webscene = new WebScene({ portalItem: { id: "579f97b2f3b94d4a8e48a5f140a6639b" } });
Create a scene view
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.
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: