Overview
You will learn: how to build a simple app that displays a 2D map or 3D scene.
You can build mapping applications that can display geographic data in 2D or 3D. The first step is to create a Map
that contains a basemap. You can use a basemap that is hosted inMap
is defined, it can be displayed in 2D with the MapView
or in 3D with the SceneView
. The views are responsible for displaying the map, handling user interactions, and setting the position of the map. Learn more about working with the view in the documentation.
In this tutorial, you will create a 2D map or 3D scene that displays a topographic basemap and centers on the Santa Monica Mountains in California. You will use this tutorial as the starting point for most of the other JavaScript tutorials.
Click the tabs below to see the different views.
Steps
Create an HTML page
Go to CodePen and create a new pen.
Add the main HTML content to the pen.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"> <title>ArcGIS JavaScript Tutorials: Create a JavaScript starter app</title> <style> html, body, #viewDiv { padding: 0; margin: 0; height: 100%; width: 100%; } </style> </head> <body> <div id="viewDiv"></div> </body> </html>
Add references to the CSS and API
In the
<head>
, add the references.<link rel="stylesheet" href="https://js.arcgis.com/4.14/esri/themes/light/main.css"> <script src="https://js.arcgis.com/4.14/"></script>
Create a 2D map or a 3D scene
Decide if you would like to create 2D map or a 3D scene.
In the
<head>
, add a<script>
tag and an AMDrequire
statement to load theMap
andMapView
orSceneView
modules. Create a newMap
and set the basemap property totopo-vector
. If you are creating a 3D scene, set theground
property toworld-elevation
so show elevation changes. Lastly, create the appropriate view by following one of these steps:2D map: Create a
MapView
and set the container property toviewDiv
. Set thecenter
to-118.80500,34.02700
and thezoom
property to13
.or
3D scene: Create a
SceneView
and set the container property toviewDiv
. Set theSceneView
position by creating a camera and setting the x, y, z coordinates to-118.80800, 33.96100, 2000
and thetilt
to65
. Learn more about the camera settings in the documentation.
<script> require([ "esri/Map", "esri/views/MapView" ], function(Map, MapView) { var map = new Map({ basemap: "topo-vector" }); var view = new MapView({ container: "viewDiv", map: map, center: [-118.80500, 34.02700], // longitude, latitude zoom: 13 }); }); </script>
<script> require([ "esri/Map", "esri/views/SceneView" ], function(Map, SceneView) { var map = new Map({ basemap: "topo-vector", ground: "world-elevation" // show elevation }); var view = new SceneView({ container: "viewDiv", map: map, camera: { position: { // observation point x: -118.80800, y: 33.96100, z: 25000 // altitude in meters }, tilt: 65 // perspective in degrees } }); }); </script>
Run your code to view the map.
Congratulations, you're done!
The 2D map should look like this and the 3D scene should like this.
Challenge
Explore basemaps
light-gray-vector
, dark-gray-vector
, satellite
, streets-relief-vector
, and streets-navigation-vector
.
For example:
var map = new Map({
basemap: "streets-navigation-vector"
});
Learn how to create and use your own custom basemaps in the Style a vector basemap and Display a styled vector basemap tutorials.