Overview
You will learn: how to build an app to load and display a 3D web scene from ArcGIS Online.
Applications can load and display 3D
In this tutorial, you will build an app that loads and displays a pre-configured web scene stored in
Explore the web scene layer styles and pop-ups in the scene below.
Steps
Create a starter app
Open the JavaScript Starter App on CodePen.
In CodePen, click Fork and save the pen as
ArcGIS API for JavaScript Tutorials: Display a web scene.
Preview the web scene
Go to the LA Trails and Parks Scene to view the scene in the Scene Viewer. Make note of the ID at the end of the URL.
Display the web scene in your app
In the
requirestatement, remove theMapand add a reference to theWebScenemodule.require([ "esri/WebScene", "esri/views/SceneView" ], function(WebScene, SceneView) {At the beginning of the code in the main
function, remove the code to create aMapandSceneViewand replace it with code to create a newWebSceneand a newSceneView. Set theportalItemID to579f97b2f3b94d4a8e48a5f140a6639b. Update the code in theSceneViewto set thewebsceneto themapproperty and comment the code to change thecameraposition. The web scene provides the positioning information.//*** ADD ***// var webscene = new WebScene({ portalItem: { id: "579f97b2f3b94d4a8e48a5f140a6639b" } });var view = new SceneView({ container: "viewDiv", //*** UPDATE ***// map: webscene //camera: { // position: { // x: -118.808, // y: 33.961, // z: 2000 // meters // }, // tilt: 75 //} });Run your code to view the web scene. Be sure to click on the layers and zoom around!
Congratulations, you're done!
Your app should look something like this.
Challenge
Add a legend
To make your mapping app more meaningful, try adding a Legend widget to the top-right area of the view DefaultUI. Visit the documentation to learn more about widgets and how to position them in the view.
require([
"esri/WebScene",
"esri/views/SceneView",
//*** ADD ***//
"esri/widgets/Legend"
], function(WebScene, SceneView, Legend) {
...
//*** ADD ***//
var legend = new Legend({
view: view
});
view.ui.add(legend, "top-right");
Explore other web scenes
ArcGIS Online contains thousands of public web maps and scenes that can be loaded by applications. Go to