Atlaslog
Atlaslog / Field Notes / deck.gl visualization
Field note · deck.gl visualization

setProps with new data leaves the layer unchanged

Quick answer

The filter handler builds a new layer and calls deck.setProps, the array in the console is shorter, but the map still shows every point in the old colour. deck.gl shallow-compares layer id and props, so a mutated array or a reused instance counts as no change.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: deck.gl
Symptom
Checklist
  1. Print ids from deck.layerManager.getLayers() to confirm the layer object is replaced.
  2. Print deck.props.layers[0].props.data.length to see whether the length actually changed.
  3. Check whether the same array was mutated with push or splice and passed back.
  4. Add onDataLoad to see whether the data is re-read at all.
Fix

Pass a fresh array (list.slice()) and a fresh layer instance from buildLayer, or keep the data and bump updateTriggers: { getFillColor: [filterVersion] } so the accessor is recomputed.

Code
function buildLayer(list) {
  return new deck.ScatterplotLayer({
    id: 'stations',
    data: list,                       // 必须是新数组
    getPosition: function (d) { return [d.lng, d.lat]; },
    getRadius: 8,
    radiusUnits: 'pixels',
    getFillColor: function (d) {
      return d.status === 'alarm' ? [220, 53, 69] : [23, 162, 184];
    },
    pickable: true
  });
}

function render(list) {
  deck.setProps({ layers: [buildLayer(list.slice())] });
}
new deck.ScatterplotLayer({
  id: 'stations',
  data: stations,
  getPosition: function (d) { return [d.lng, d.lat]; },
  getFillColor: function (d) { return d.color; },
  updateTriggers: {
    getFillColor: [filterVersion]      // 版本号变化即重算
  }
});
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). setProps with new data leaves the layer unchanged. https://www.jingweizhi.com/en/cookbook/deckgl-layer-not-refresh.html (accessed 2026-11-03).