Display a scene
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.
Prerequisites
You 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 pen
- Go to CodePen to create a new pen for your mapping application.
Add HTML
Define 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
view
element for the scene.Div Use dark colors for code blocks 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.
Reference the API
In the
<head>
tag, add references to the CSS file and JS library.Use dark colors for code blocks Add line. Add line. Add line.
Add 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.
Add a
<script>
tag and arequire
statement to load theMap
andScene
modules. You can also add the JavaScript code to the CodePen > JS panel instead of the HTML panel. If you do so, remove theView <script>
tag.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
Get an API key
An 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 scene
Use 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.
Use dark colors for code blocks Add line. Create a
Map
and set thebasemap
property toarcgis-topographic
and theground
property toworld-elevation
.Use dark colors for code blocks Add line. Add line. Add line. Add line.
Create a scene view
Use a Scene
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 Scene
is determined. The tilt
property refers to the number of degrees from the surface that the camera is pointed.
Create a
Scene
. Set theView container
,map
, andcamera
properties.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
Run the app
In 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: