Note: Support for 3D on mobile devices may vary, view the system requirements for more information.
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 API 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 API for JavaScript together
The ArcGIS API 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.18/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.18/"></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 API for JavaScript are found in a module that must be loaded asynchronously using the method deck.loadArcGISModules()
.
// We use require to load "esri/*" modules
require([
"esri/Map",
"esri/views/MapView"
], function(Map, MapView) {
// Most deck.gl features are available on the global "deck" object
const GeoJsonLayer = deck.GeoJsonLayer;
const ArcLayer = deck.ArcLayer;
const TripsLayer = deck.TripsLayer;
// The ArcGIS/deck.gl interface code is located in a separate module
// that must be loaded asynchronously
deck.loadArcGISModules().then(function(arcGIS) {
// Now we can use the arcGIS module
...
Using the deck.gl layer for MapView
The loaded arcGIS
module exposes the arcGIS.DeckLayer
class; this is an ArcGIS layer-like class that can be configured with a list of deck.gl layers and added to a MapView
.
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 TripsLayer
, 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 TripsLayer
we create a new instance every 50 milliseconds and set it on the DeckLayer
.
const layer = new arcGIS.DeckLayer();
setInterval(function () {
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: function (d) { return d.path; },
getTimestamps: function (d) { return d.timestamps; },
getColor: function (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
MapView
must be WebMercator; - 3D deck.gl visualizations may not render properly due to depth information not being currently handled;