Atlaslog / Field Notes / deck.gl visualization
Field note · deck.gl visualization
Swapped lat/lng order sends every point to the Antarctic
Quick answer
The accessor returns [d.lat, d.lng] while deck.gl expects [lng, lat], so 39.9 becomes a longitude and 116.4 an out-of-range latitude. Mixing 2- and 3-element points in getPath also breaks the buffer length check.
Symptom
- Beijing stations render near the Antarctic coast or along a straight line at the equator.
- Error: deck.gl: attribute positions: length 2400 is not divisible by size 3.
- A PathLayer on the same records draws nothing while the scatterplot still shows points.
Checklist
- Print data[0] with its raw field names and values.
- Call deck.pickObject at the intended location to see whether the data or the projection is wrong.
- Check that getPath and getPolygon arrays have a uniform arity.
- Verify each returned position against a known landmark.
Fix
Normalize fields to { lng, lat } before creating the layer and always return [d.lng, d.lat]; declare positionFormat: 'XY' for 2D paths and pad missing z with 0 for 'XYZ'.
Code
Error: deck.gl: attribute positions: length 2400 is not divisible by size 3
at Attribute.updateBuffer (attribute.js:512)console.log(data[0]);
// { lng: 116.391, lat: 39.907, z: null }
var p = [data[0].lat, data[0].lng];
console.log('错误写法得到的坐标', p); // [39.907, 116.391]
Watch out
- Patching the accessor with a per-record conditional hides the field mismatch and still leaves some features misplaced.
- Adding z to only some points keeps the total length indivisible and the buffer still fails.
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Atlaslog (2026). Swapped lat/lng order sends every point to the Antarctic. https://www.jingweizhi.com/en/cookbook/deckgl-coord-dimension.html (accessed 2026-11-03).