Learn how to create and display a scene with a basemap layer and elevation .
A scene contains layers of geographic data that are displayed in 3D. Scenes allow you to display real-world visualizations of landscapes, objects, buildings, and other 3D objects. You display a scene using a scene view to display a basemap layer and data layers, and also to control the center location , tilt, and angle of the view.
In this tutorial, you create and display a scene of the Santa Monica Mountains in California using the topographic basemap layer and the world elevation layer . The scene and code will be used as the starting point for other 3D tutorials.
PrerequisitesYou need a free ArcGIS developer account to access your dashboard and API keys . The API key must be scoped to access the services used in this tutorial.
Steps Create a new penGo to CodePen to create a new pen for your mapping application. Add HTMLDefine an HTML page to create a scene that is the full width and height of the browser window.
In CodePen > HTML , add HTML and CSS to create a page with a viewDiv
element for the scene.
More info The HTML will create a scene that is the full width and height of the page. The viewDiv
is the element displays the scene and its CSS resets any browser settings so it can consume the full width and height of the browser.
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
< html >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "initial-scale=1, maximum-scale=1, user-scalable=no" >
< title > ArcGIS API for JavaScript Tutorials: Display a scene </ title >
< style >
html , body , #viewDiv {
padding : 0 ;
margin : 0 ;
height : 100% ;
width : 100% ;
}
</ style >
< link rel = "stylesheet" href = "https://js.arcgis.com/4.18/esri/themes/light/main.css" >
< script src = "https://js.arcgis.com/4.18/" > </ script >
< script >
require ([
"esri/config" ,
"esri/Map" ,
"esri/views/SceneView"
], function ( esriConfig,Map, SceneView ) {
esriConfig.apiKey = "YOUR-API-KEY" ;
const map = new Map ({
basemap : "arcgis-topographic" , //Basemap layer service
ground: "world-elevation" , //Elevation service
});
const view = new SceneView({
container : "viewDiv" ,
map : map,
camera : {
position : {
x : -118.808 , //Longitude
y: 33.961 , //Latitude
z: 2000 //Meters
},
tilt : 75
}
});
});
</ script >
</ head >
< body >
< div id = "viewDiv" > </ div >
</ body >
</ html >
Reference the APIIn the <head>
tag, add references to the CSS file and JS library.
Add line. Add line. Add line.
< html >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "initial-scale=1, maximum-scale=1, user-scalable=no" >
< title > ArcGIS API for JavaScript Tutorials: Display a scene </ title >
< style >
html , body , #viewDiv {
padding : 0 ;
margin : 0 ;
height : 100% ;
width : 100% ;
}
</ style >
< link rel = "stylesheet" href = "https://js.arcgis.com/4.18/esri/themes/light/main.css" >
< script src = "https://js.arcgis.com/4.18/" > </ script >
< script >
require ([
"esri/config" ,
"esri/Map" ,
"esri/views/SceneView"
], function ( esriConfig,Map, SceneView ) {
esriConfig.apiKey = "YOUR-API-KEY" ;
const map = new Map ({
basemap : "arcgis-topographic" , //Basemap layer service
ground: "world-elevation" , //Elevation service
});
const view = new SceneView({
container : "viewDiv" ,
map : map,
camera : {
position : {
x : -118.808 , //Longitude
y: 33.961 , //Latitude
z: 2000 //Meters
},
tilt : 75
}
});
});
</ script >
</ head >
< body >
< div id = "viewDiv" > </ div >
</ body >
</ html >
Add modulesThe ArcGIS JS API contains AMD modules. Reference the Map
and SceneView
modules in the require
statement.
Add a <script>
tag and an AMD require
statement to load the Map
and SceneView
modules.
More info You can also add the JavaScript code to the CodePen > JS panel instead of the HTML panel. If you do so, remove the <script>
tag.
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
< html >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "initial-scale=1, maximum-scale=1, user-scalable=no" >
< title > ArcGIS API for JavaScript Tutorials: Display a scene </ title >
< style >
html , body , #viewDiv {
padding : 0 ;
margin : 0 ;
height : 100% ;
width : 100% ;
}
</ style >
< link rel = "stylesheet" href = "https://js.arcgis.com/4.18/esri/themes/light/main.css" >
< script src = "https://js.arcgis.com/4.18/" > </ script >
< script >
require ([
"esri/config" ,
"esri/Map" ,
"esri/views/SceneView"
], function ( esriConfig,Map, SceneView ) {
esriConfig.apiKey = "YOUR-API-KEY" ;
const map = new Map ({
basemap : "arcgis-topographic" , //Basemap layer service
ground: "world-elevation" , //Elevation service
});
const view = new SceneView({
container : "viewDiv" ,
map : map,
camera : {
position : {
x : -118.808 , //Longitude
y: 33.961 , //Latitude
z: 2000 //Meters
},
tilt : 75
}
});
});
</ script >
</ head >
< body >
< div id = "viewDiv" > </ div >
</ body >
</ html >
Get an API keyAn API key is required to access ArcGIS services .
Go to your developer dashboard to get an API key . Copy the key as it will be used in the next step. Create a sceneUse a Map
to define the basemap layer and elevation surface. Scenes use the information in the elevation layer to determine the ground
(surface) height that will be rendered on the map.
Go back to CodePen .
At the beginning of the main function, set your API key.
Show more lines
Add line.
< html >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "initial-scale=1, maximum-scale=1, user-scalable=no" >
< title > ArcGIS API for JavaScript Tutorials: Display a scene </ title >
< style >
html , body , #viewDiv {
padding : 0 ;
margin : 0 ;
height : 100% ;
width : 100% ;
}
</ style >
< link rel = "stylesheet" href = "https://js.arcgis.com/4.18/esri/themes/light/main.css" >
< script src = "https://js.arcgis.com/4.18/" > </ script >
< script >
require ([
"esri/config" ,
"esri/Map" ,
"esri/views/SceneView"
], function ( esriConfig,Map, SceneView ) {
esriConfig.apiKey = "YOUR-API-KEY" ;
const map = new Map ({
basemap : "arcgis-topographic" , //Basemap layer service
ground: "world-elevation" , //Elevation service
});
const view = new SceneView({
container : "viewDiv" ,
map : map,
camera : {
position : {
x : -118.808 , //Longitude
y: 33.961 , //Latitude
z: 2000 //Meters
},
tilt : 75
}
});
});
</ script >
</ head >
< body >
< div id = "viewDiv" > </ div >
</ body >
</ html >
Show more lines
Create a Map
and set the basemap
property to arcgis-topographic
and the ground
property to world-elevation
.
Show more lines
Add line. Add line. Add line. Add line.
< html >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "initial-scale=1, maximum-scale=1, user-scalable=no" >
< title > ArcGIS API for JavaScript Tutorials: Display a scene </ title >
< style >
html , body , #viewDiv {
padding : 0 ;
margin : 0 ;
height : 100% ;
width : 100% ;
}
</ style >
< link rel = "stylesheet" href = "https://js.arcgis.com/4.18/esri/themes/light/main.css" >
< script src = "https://js.arcgis.com/4.18/" > </ script >
< script >
require ([
"esri/config" ,
"esri/Map" ,
"esri/views/SceneView"
], function ( esriConfig,Map, SceneView ) {
esriConfig.apiKey = "YOUR-API-KEY" ;
const map = new Map ({
basemap : "arcgis-topographic" , //Basemap layer service
ground: "world-elevation" , //Elevation service
});
const view = new SceneView({
container : "viewDiv" ,
map : map,
camera : {
position : {
x : -118.808 , //Longitude
y: 33.961 , //Latitude
z: 2000 //Meters
},
tilt : 75
}
});
});
</ script >
</ head >
< body >
< div id = "viewDiv" > </ div >
</ body >
</ html >
Show more lines
Create a scene viewUse a SceneView
class to set the map
and layers to draw, as well as to define the camera position. The camera
is the point from which the visible extent of the SceneView
is determined. The tilt
property refers to the number of degrees from the surface that the camera is pointed.
Create a SceneView
. Set the container
, map
, and camera
properties.
Show more lines
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
< html >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "initial-scale=1, maximum-scale=1, user-scalable=no" >
< title > ArcGIS API for JavaScript Tutorials: Display a scene </ title >
< style >
html , body , #viewDiv {
padding : 0 ;
margin : 0 ;
height : 100% ;
width : 100% ;
}
</ style >
< link rel = "stylesheet" href = "https://js.arcgis.com/4.18/esri/themes/light/main.css" >
< script src = "https://js.arcgis.com/4.18/" > </ script >
< script >
require ([
"esri/config" ,
"esri/Map" ,
"esri/views/SceneView"
], function ( esriConfig,Map, SceneView ) {
esriConfig.apiKey = "YOUR-API-KEY" ;
const map = new Map ({
basemap : "arcgis-topographic" , //Basemap layer service
ground: "world-elevation" , //Elevation service
});
const view = new SceneView({
container : "viewDiv" ,
map : map,
camera : {
position : {
x : -118.808 , //Longitude
y: 33.961 , //Latitude
z: 2000 //Meters
},
tilt : 75
}
});
});
</ script >
</ head >
< body >
< div id = "viewDiv" > </ div >
</ body >
</ html >
Show more lines
Run the appIn CodePen , run your code to display the map.
The scene view should display the topographic basemap layer and elevation layer for an area of the Santa Monica Mountains in California.
What's next?Learn how to use additional API features and
ArcGIS services in these tutorials: