Important notes:
- This sample shows experimental functionality, please read the documentation carefully before using it in a product.
This sample demonstrates how to use deck.gl to render on top of an Esri basemap. Using the techniques described in this sample, a developer can bring any existing 2D deck.gl-based visualization into an ArcGIS Maps SDK for JavaScript application.
This sample assumes familiarity with WebGL, custom WebGL layer views, and the deck.gl visualization library.
Using deck.gl and the ArcGIS Maps SDK for JavaScript together
The ArcGIS Maps SDK for JavaScript is loaded from the js.arcgis.com
CDN by using <script
tags; deck.gl is primarily distributed through npm but CDN bundles are also available through unpkg.com
. For this sample, we need the main "deck.gl"
bundle and the two extensions "@deck.gl/geo-layers"
and "@deck.gl/arcgis"
. The first release of deck.gl that ships with support for ArcGIS is 8.1.0.
<script src="https://unpkg.com/deck.gl@8.1.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/geo-layers@8.1.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/arcgis@8.1.0/dist.min.js"></script>
<link rel="stylesheet" href="https://js.arcgis.com/4.31/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.31/"></script>
We then use require()
to load any needed "esri/*"
module; most deck.gl functionality is available on the global deck
object. The extra bits required to interface deck.gl with the ArcGIS Maps SDK for JavaScript are found in a module that must be loaded asynchronously using the methoddeck.load
.
// We use require to load "esri/*" modules
require([
"esri/Map",
"esri/views/MapView"
], (Map, MapView) => {
// Most deck.gl features are available on the global "deck" object
// The ArcGIS/deck.gl interface code is located in a separate module
// that must be loaded asynchronously
deck.loadArcGISModules().then((arcGIS) => {
// Now we can use the arcGIS module
...
Using the deck.gl layer for MapView
The loaded arc
module exposes the arc
class; this is an ArcGIS layer-like class that can be configured with a list of deck.gl layers and added to a Map
, for example:
const layer = new DeckLayer({
"deck.layers": [
new deck.GeoJsonLayer({
...
}),
new deck.ArcLayer({
...
})
]
});
const mapView = new MapView({
container: "viewDiv",
map: new Map({
basemap: "dark-gray-vector",
layers: [layer]
}),
...
});
In this sample we use a single instance of Trips
, an animated polyline layer. It is exported by the "@deck.gl/geo-layers"
module, in contrast with the majority of the other layers which are found in "@deck.gl/layers"
. To animate the Trips
we create a new instance every 50 milliseconds and set it on the Deck
.
const layer = new arcGIS.DeckLayer();
setInterval(() => {
layer.deck.layers = [
new deck.TripsLayer({
id: "trips",
data: "https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/trips/trips-v7.json",
getPath: (d) => { return d.path; },
getTimestamps: (d) => { return d.timestamps; },
getColor: (d) => { return (d.vendor === 0 ? [253, 128, 93] : [23, 184, 190]); },
opacity: 1.0,
widthMinPixels: 4,
rounded: true,
trailLength: 180,
currentTime: (performance.now() % 20000) / 10,
shadowEnabled: false
})
];
}, 50);
Known Limitations
- The spatial reference of the
Map
must be WebMercator;View - 3D deck.gl visualizations may not render properly due to depth information not being currently handled;