The
The SDK also integrates with Esri’s Calcite Design System for a consistent and accessible user experience. Calcite provides a complete UI toolkit, including a rich library of web components, icons, color schemes, and design patterns.
The best way to start with the JavaScript Maps SDK depends on your goals and requirements:
- Build with vanilla JavaScript and HTML app without installing local packages — see Create an app with the ArcGIS CDN
- Create a project from a template — see Create an app with npm.
Prerequisites
To use the ArcGIS Maps SDK for JavaScript to access
If you do not have an account, select one of the options below:
Access tokens
See the Create an API key tutorial for more information.
Create an app with the ArcGIS CDN
This section covers manual setup. If you prefer a starter project, use the CDN template.
The JavaScript Maps SDK can be integrated into a vanilla JavaScript and HTML application using the ArcGIS CDN. This approach leverages optimized cloud caching, removes local build requirements, and makes it easier to stay up to date with the latest SDK versions.
Setup
To get started, include the ArcGIS CDN <script> in the <head> section of a basic HTML file.
This is the main entry point for adding the core API library, all component packages, and the CSS to your application. The CDN is available in MAJOR.MINOR format, and patch-specific versions are available in MAJOR.MINOR.PATCH format. See the Release Notes for the latest patch version.
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script>Configure CSS
Add custom CSS so that components will be visible in your application. This needs to be the last item in the <head> section, after importing the ArcGIS libraries from the CDN:
<style> html, body { height: 100%; margin: 0; }</style>Choose a light or dark theme through Calcite modes.
Create a layout
Add the 2D Map component, or 3D Scene component, to the <body> of your HTML and assign it an optional item-id if using a WebMap or WebScene from ArcGIS Online or ArcGIS Enterprise portal. Use the Map or Scene’s slots to position other components, like Zoom, within the map or scene.
<!-- There is no need to programmatically set the basemap, extent or zoom --><!-- All this information comes from the WebMap --><arcgis-map item-id="02b37471d5d84cacbebcccd785460e94"> <arcgis-zoom slot="top-left"></arcgis-zoom></arcgis-map>Alternatively, you can set the basemap, center and zoom attributes manually on the Map or Scene components if you’re not using a WebMap or WebScene.
Add core API modules
You can set properties, watch for changes, and add custom JavaScript logic using the core API in a <script> tag at the bottom but within the <body> of your HTML.
Ensure the script is marked as <script type="module">.
Modules from the core API can be loaded via the global $arcgis.import() method. The method accepts a module path or an array of module paths, and returns a promise that resolves with the requested modules.
You can find the module identifier at the top of each API reference page. See Graphic for reference.
The code below will wait for the map’s View to be ready. Once the View is ready, more functionality can be added.
<script type="module"> const Graphic = await $arcgis.import("@arcgis/core/Graphic.js"); const viewElement = document.querySelector("arcgis-map"); // Wait for the view to be ready before adding additional functionality await viewElement.viewOnReady();
// ...
// Create a graphic and add the geometry and symbol to it const pointGraphic = new Graphic({ geometry: point, // A point geometry symbol: markerSymbol, // A symbol for drawing the point }); viewElement.graphics.add(pointGraphic);</script>Create an app with npm
When working with local builds, you can install the JavaScript Maps SDK manually, use the @arcgis/create CLI tool, or visit the Esri/jsapi-resources GitHub repository to download application templates. The repository contains a variety of templates for quickly scaffolding your first application. These templates demonstrate working with the SDK’s core API, components, OAuth, and Calcite.
Manually install
To use Map components in your project, install the @arcgis/map-components package and its dependencies:
npm install @arcgis/map-components @arcgis/core @esri/calcite-componentsyarn add @arcgis/map-components @arcgis/core @esri/calcite-componentspnpm install @arcgis/map-components @arcgis/core @esri/calcite-componentsFor additional configuration information on framework and tooling setup, see the following guide topics:
Use @arcgis/create
The @arcgis/create CLI tool can be used with either npm init or npx. Before you start, make sure you are using the latest long-term support (LTS) version of Node.js and npm.
Run npm init @arcgis or npx @arcgis/create to quickly scaffold a new mapping application.
When using npx, you can also pass CLI options to skip all interactive prompts:
# CLI options:# -n, --name <name> Name of the project# -t, --template <template> Template to use
# Vite app template with SDK integrationnpx @arcgis/create -n my-arcgis-app -t viteOther templates include:
# React app template with SDK integrationnpx @arcgis/create -n my-arcgis-app -t react# Angular app template with SDK integrationnpx @arcgis/create -n my-arcgis-app -t angular# Vue app template with SDK integrationnpx @arcgis/create -n my-arcgis-app -t vue# Webpack app template with SDK integrationnpx @arcgis/create -n my-arcgis-app -t webpack# Vanilla JavaScript setup using the ArcGIS CDNnpx @arcgis/create -n my-arcgis-app -t cdn# The SDK's core API only, no UI componentsnpx @arcgis/create -n my-arcgis-app -t nodeAdditional information
Please refer to these additional links for further information: