Fleet Parallel Playback
24 vehicles with 150 trajectory points each share one TripsLayer, colored by six palette slots keyed to vehicle index and replayed in parallel, with 1x/2x/4x speed and a 10–80 second trail slider applied live.
Business context
Fleet operations and dispatch centers use parallel playback to watch the rhythm of an entire fleet, for example shift handovers, mass returns to the yard or a section where vehicles slow together, and to judge whether a dispatch plan worked. Data comes from scheduled reports by in-vehicle terminals, archived by plate number; one vehicle produces hundreds to thousands of points per day, a hundred-vehicle fleet runs into hundreds of thousands of points, and the feed is usually downsampled or decimated before reaching the front end.
Multi-vehicle data is first aligned onto one timeline by zeroing each vehicle's first timestamp, then thinned to comparable sampling intervals so that a single high-frequency vehicle does not stretch the axis. Merging into one TripsLayer cuts draw calls from one per vehicle to one in total; getColor distinguishes vehicles by index, and under a shared clock the relative positions and formation remain readable.
In parallel playback color encodes only vehicle identity, not state: a vehicle that looks stopped may simply report at longer intervals. Because every vehicle shares one currentTime, any vehicle needing an independent clock, such as one crossing time zones or with a large data gap, will drift out of place in a single layer and has to be split out or have its timestamps rewritten.
How it works
24 trajectories of 150 points each with 1-second timestamp spacing span 149 seconds; getColor takes the vehicle index modulo 6 into the PALETTE colors, and all of it goes into one TripsLayer with id fleet-trips. Each frame changes only currentTime and trailLength while the path and color arrays keep their references, so no geometry is rebuilt on the GPU side.
One layer per vehicle would mean 24 draw calls against 1 when shared; the cost is that all trajectories must share a timeline, so any vehicle needing an independent clock forces a layer split or rewritten timestamps. The speed buttons only scale how fast currentTime advances — at 1x one real second advances 6 seconds of simulated time — and the trail slider moves trailLength between 10 and 80; neither triggers data recomputation.
| Configuration | What it does |
|---|---|
| getColor | Picks one of six colors by vehicle index |
| currentTime | Shared timeline, advanced every frame |
| trailLength | 10–80 seconds, changed live by the slider |
| widthMinPixels | Fixed minimum pixel width so paths persist at distance |
Note. For multi-vehicle playback, merge into a single TripsLayer and distinguish vehicles with getColor; split layers only when an independent timeline is required, and estimate the draw-call cost before splitting.
Source
<!--
示例:车队并行回放
要点:24 条轨迹共用一条 TripsLayer 与一条时间轴,颜色按车辆编号区分,速度与拖尾实时可调
依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>车队并行回放</title>
<style>
html,body{height:100%;margin:0;background:#0d1117}
body{display:flex;flex-direction:column;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
.bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
display:flex;gap:10px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
.bar b{color:#58a6ff;font-weight:600}
.bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:5px;cursor:pointer;
border:1px solid #303845;background:#1d2531;color:#c8d2e0}
.bar button:hover{background:#253040}
.bar button.on{background:#2c4a7a;border-color:#4f8ad6;color:#dfe9ff}
.bar .sep{width:1px;height:18px;background:#2a313c;margin:0 4px}
.bar input[type=range]{width:150px;accent-color:#4f9ef8}
#cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
<span>车辆 <b>24</b></span>
<span class="sep"></span>
<span>速度</span>
<button data-speed="1" class="on">1x</button>
<button data-speed="2">2x</button>
<button data-speed="4">4x</button>
<span class="sep"></span>
<span>拖尾 <b id="tv">35</b> s</span>
<input id="tl" type="range" min="10" max="80" step="5" value="35">
<span class="sep"></span>
<span>当前 <b id="ct">0.0</b> s</span>
</div>
<canvas id="cv"></canvas>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
'use strict';
if (typeof deck === 'undefined') {
document.body.innerHTML =
'<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
return;
}
var PALETTE = [
[64, 154, 255], [86, 214, 168], [246, 186, 78],
[240, 104, 72], [176, 132, 255], [64, 206, 226]
];
var trips = [];
for (var v = 0; v < 24; v++) {
var path = [];
var ts = [];
var lng = 116.34 + Math.random() * 0.14;
var lat = 39.84 + Math.random() * 0.14;
var head = Math.random() * Math.PI * 2;
for (var s = 0; s < 150; s++) {
head += (Math.random() - 0.5) * 0.42;
lng += Math.cos(head) * 0.0012;
lat += Math.sin(head) * 0.0009;
lng = Math.max(116.30, Math.min(116.52, lng));
lat = Math.max(39.81, Math.min(40.01, lat));
path.push([lng, lat]);
ts.push(s);
}
trips.push({
path: path,
timestamps: ts,
color: PALETTE[v % PALETTE.length]
});
}
var current = 0;
var trailLength = 35;
var speed = 1;
function fleetLayer() {
return new deck.TripsLayer({
id: 'fleet-trips',
data: trips,
getPath: function (d) { return d.path; },
getTimestamps: function (d) { return d.timestamps; },
getColor: function (d) { return d.color; },
currentTime: current,
trailLength: trailLength,
fadeTrail: true,
widthMinPixels: 2,
opacity: 0.9,
capRounded: true,
jointRounded: true
});
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: 116.41,
latitude: 39.91,
zoom: 10.4,
pitch: 50,
bearing: -18,
maxPitch: 70
},
controller: true,
layers: [fleetLayer()]
});
var speedButtons = document.querySelectorAll('[data-speed]');
for (var b = 0; b < speedButtons.length; b++) {
speedButtons[b].addEventListener('click', function (e) {
speed = Number(e.currentTarget.getAttribute('data-speed'));
for (var k = 0; k < speedButtons.length; k++) {
speedButtons[k].classList.toggle('on', speedButtons[k] === e.currentTarget);
}
});
}
document.getElementById('tl').addEventListener('input', function () {
trailLength = Number(this.value);
document.getElementById('tv').textContent = trailLength;
deckgl.setProps({ layers: [fleetLayer()] });
});
var last = performance.now();
function frame(now) {
var dt = (now - last) / 1000;
last = now;
current += dt * 6 * speed;
if (current > 150) current = 0;
document.getElementById('ct').textContent = current.toFixed(1) + ' s';
deckgl.setProps({ layers: [fleetLayer()] });
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
window.__deck = deckgl;
})();
</script>
</body>
</html>