Atlaslog
Atlaslog / deck.gl / Tutorial / Picking and interaction
deck.gl · Tutorial

Picking and interaction

Quick answer

This tutorial explains that deck.gl picking encodes each primitive as a color in an off-screen pass, which is why pickable defaults to false. It enables onClick and onHover, reads info.object, info.index, info.layer and info.coordinate, and configures autoHighlight, highlightColor and pickingRadius. It also describes how overlapping layers resolve top-down and when the Deck-level handler fires. Readers can build dependable hover and click behavior.

Last verified 2026-11-03 · deck.gl 9.0 · Cite this page
Key points
Example
var stationsLayer = new deck.ScatterplotLayer({
  id: 'stations',
  data: stations,
  getPosition: function (d) { return [d.lng, d.lat]; },
  getRadius: function (d) { return d.flow > 800 ? 10 : 6; },
  getFillColor: [40, 140, 255, 200],
  pickable: true,
  autoHighlight: true,
  highlightColor: [255, 200, 0, 220],
  onClick: function (info) {
    console.log('点击', info.object.name, '索引', info.index);
  },
  onHover: function (info) {
    document.body.style.cursor = info.object ? 'pointer' : 'default';
  }
});

new deck.Deck({
  container: 'map',
  initialViewState: {
    longitude: 116.397,
    latitude: 39.908,
    zoom: 11,
    pitch: 0
  },
  controller: true,
  pickingRadius: 6,
  layers: [stationsLayer]
});
var layers = [
  new deck.GeoJsonLayer({
    id: 'parcels',
    data: parcels,
    filled: true,
    pickable: true,
    onClick: function (info) { console.log('地块', info.object.properties.id); }
  }),
  new deck.ScatterplotLayer({
    id: 'stations',
    data: stations,
    getPosition: function (d) { return [d.lng, d.lat]; },
    getRadius: 7,
    pickable: true
  })
];
var deckgl = new deck.Deck({
  container: 'map',
  initialViewState: { longitude: 116.397, latitude: 39.908, zoom: 11 },
  controller: true,
  layers: layers,
  onClick: function (info, event) {
    if (!info.object) console.log('空白处', info.coordinate);
  }
});
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Picking and interaction. https://www.jingweizhi.com/en/deckgl/tutorials/picking.html (accessed 2026-11-03).