3hstack commited on
Commit
aaa5f52
·
verified ·
1 Parent(s): 34dd717

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -73
app.py CHANGED
@@ -367,7 +367,7 @@ PAGE = r'''<!DOCTYPE html>
367
  #scrub{flex:1;min-width:160px;-webkit-appearance:none;appearance:none;height:5px;border-radius:3px;background:#2b3342;outline:0;cursor:pointer}
368
  #scrub::-webkit-slider-thumb{-webkit-appearance:none;width:15px;height:15px;border-radius:50%;background:var(--acc);cursor:pointer;border:2px solid #0f1115}
369
  #scrub::-moz-range-thumb{width:15px;height:15px;border-radius:50%;background:var(--acc);border:2px solid #0f1115;cursor:pointer}
370
- #pp{width:42px;padding:9px 0;text-align:center}
371
  select{background:#252a35;color:var(--txt);border:1px solid var(--line);border-radius:7px;padding:8px;font-size:12px;cursor:pointer}
372
  .hud{position:absolute;top:12px;left:12px;z-index:900;background:#0f1115f2;border:1px solid var(--line);border-radius:9px;padding:10px 13px;min-width:200px;display:none}
373
  .hud.on{display:block}
@@ -385,8 +385,6 @@ PAGE = r'''<!DOCTYPE html>
385
  .truck{filter:drop-shadow(0 2px 5px rgba(0,0,0,.7))}
386
  .arrow{pointer-events:none}
387
  #map.routed .leaflet-tile-pane{filter:brightness(.72) saturate(.85)}
388
- .flow{stroke-dasharray:14 12;animation:flow .9s linear infinite}
389
- @keyframes flow{to{stroke-dashoffset:-26}}
390
  .pin{font:700 10px sans-serif;color:#fff;text-align:center;line-height:1;text-shadow:0 1px 3px #000;white-space:nowrap}
391
  .pin svg{display:block;margin:0 auto}
392
  </style>
@@ -435,7 +433,7 @@ PAGE = r'''<!DOCTYPE html>
435
  </div>
436
  <div class="legend" id="legend"></div>
437
  <div id="play">
438
- <button id="pp">&#9654;</button>
439
  <button id="restart" class="sec">&#8634;</button>
440
  <input type="range" id="scrub" min="0" max="1000" value="0">
441
  <select id="speed">
@@ -581,10 +579,11 @@ solveBtn.onclick = async () => {
581
  };
582
  // ================= route data =================
583
  let PATH=[], TOTAL_M=0, DRIVE_MIN=0, STEPS=[];
584
- let flowCasing=null, flowLine=null, deadLayer=null, startPin=null, endPin=null;
585
 
586
- const ROUTE_COLOR = '#22d3ee'; // one bright colour for the whole delivering route
587
- const DEAD_COLOR = '#ff4d5e';
 
588
 
589
  function bearing(a, b){
590
  const r = Math.PI/180;
@@ -595,8 +594,7 @@ function bearing(a, b){
595
 
596
  function render(d){
597
  stop();
598
- [flowCasing, flowLine, deadLayer, arrowLayer, trailLine, truck, startPin, endPin]
599
- .forEach(l => l && map.removeLayer(l));
600
 
601
  const feats = d.geojson.features;
602
  PATH = []; TOTAL_M = 0;
@@ -610,37 +608,20 @@ function render(d){
610
  });
611
  DRIVE_MIN = d.stats.drive_min; STEPS = d.directions;
612
 
613
- // continuous centre-line of the whole route, in drive order
614
- const line = [PATH[0].a];
615
- PATH.forEach(s => line.push(s.b));
616
-
617
- // dark casing, then one bright animated line whose dashes FLOW the drive direction
618
- flowCasing = L.polyline(line, {pane:'routePane', color:'#05070c', weight:9,
619
- opacity:.6, lineCap:'round', lineJoin:'round'}).addTo(map);
620
- flowLine = L.polyline(line, {pane:'routePane', color:ROUTE_COLOR, weight:5,
621
- opacity:.95, lineCap:'round', lineJoin:'round',
622
- className:'flow'}).addTo(map);
623
-
624
- // deadhead (repeat) passes drawn on top, red + dashed, so they read as "no delivery"
625
- deadLayer = L.layerGroup([], {pane:'routePane'});
626
- PATH.forEach(s => {
627
- if (!s.deadhead) return;
628
- L.polyline([s.a, s.b], {pane:'routePane', color:DEAD_COLOR, weight:4.5,
629
- opacity:.95, dashArray:'2,8', lineCap:'round'})
630
- .bindTooltip('#' + s.order + ' ' + s.name + ' — deadhead (no delivery)').addTo(deadLayer);
631
- });
632
- deadLayer.addTo(map);
633
-
634
- buildArrows();
635
 
636
- // driven-so-far trail (grows as the truck moves)
637
- trailLine = L.polyline([], {pane:'routePane', color:'#ffffff', weight:9,
638
- opacity:.9, lineCap:'round', lineJoin:'round'}).addTo(map);
639
 
640
- // single START/END pin -- the route is a closed loop, so both are the same spot
641
- startPin = L.marker(PATH[0].a, {zIndexOffset:1100,
642
- icon: pinIcon('START / END', '#22c55e')}).addTo(map);
643
 
 
644
  truck = L.marker(PATH[0].a, {icon: truckIcon(0), zIndexOffset:1200, interactive:false}).addTo(map);
645
 
646
  const bb = L.latLngBounds([]); line.forEach(p => bb.extend(p));
@@ -650,22 +631,23 @@ function render(d){
650
  document.getElementById('play').classList.add('on');
651
  document.getElementById('hud').classList.add('on');
652
  renderStats(d.stats);
 
653
  seek(0);
654
  }
655
 
656
- // periodic arrowheads along the route, all one colour, pointing the drive direction
657
  function buildArrows(){
658
  if (arrowLayer) map.removeLayer(arrowLayer);
659
  arrowLayer = L.layerGroup();
660
- const stride = Math.max(1, Math.ceil(PATH.length / 90)); // fewer, cleaner
661
  PATH.forEach((s, i) => {
662
  if (i % stride) return;
663
- if (s.len < 25) return;
664
  const mid = L.latLng((s.a.lat+s.b.lat)/2, (s.a.lng+s.b.lng)/2);
665
- L.marker(mid, {interactive:false, icon: L.divIcon({className:'', iconSize:[18,18], iconAnchor:[9,9],
666
  html:'<div class="arrow" style="transform:rotate(' + bearing(s.a, s.b) + 'deg)">' +
667
- '<svg width="18" height="18" viewBox="0 0 18 18">' +
668
- '<path d="M9 1.5 L14 13 L9 10.2 L4 13 Z" fill="#eafcff" stroke="#05070c" stroke-width="1.2"/>' +
669
  '</svg></div>'})}).addTo(arrowLayer);
670
  });
671
  if (document.getElementById('arrowsOn').checked) arrowLayer.addTo(map);
@@ -676,7 +658,7 @@ document.getElementById('arrowsOn').onchange = e => {
676
  };
677
 
678
  function pinIcon(label, color){
679
- return L.divIcon({className:'', iconSize:[54,34], iconAnchor:[27,32], html:
680
  '<div class="pin"><svg width="26" height="30" viewBox="0 0 26 30">' +
681
  '<path d="M13 29 C13 29 24 17 24 11 A11 11 0 1 0 2 11 C2 17 13 29 13 29 Z" ' +
682
  'fill="' + color + '" stroke="#05070c" stroke-width="1.5"/>' +
@@ -685,16 +667,16 @@ function pinIcon(label, color){
685
  }
686
 
687
  function truckIcon(deg){
688
- return L.divIcon({className:'', iconSize:[32,32], iconAnchor:[16,16],
689
  html:'<div class="truck" style="transform:rotate(' + deg + 'deg)">' +
690
- '<svg width="32" height="32" viewBox="0 0 32 32">' +
691
- '<circle cx="16" cy="16" r="14" fill="#05070c" opacity=".6"/>' +
692
- '<g transform="translate(16,16)">' +
693
- '<rect x="-6.5" y="-8.5" width="13" height="17" rx="2.5" fill="#ffffff"/>' +
694
- '<rect x="-6.5" y="-8.5" width="13" height="6" rx="2" fill="#0891b2"/>' +
695
- '<rect x="-8" y="-2" width="3" height="6" rx="1" fill="#1b2130"/>' +
696
- '<rect x="5" y="-2" width="3" height="6" rx="1" fill="#1b2130"/>' +
697
- '<path d="M0 -13 L4.5 -8.5 L-4.5 -8.5 Z" fill="#22c55e"/>' +
698
  '</g></svg></div>'});
699
  }
700
 
@@ -702,32 +684,39 @@ function buildLegend(){
702
  const el = document.getElementById('legend');
703
  el.innerHTML =
704
  '<div class="ttl">Route</div>' +
705
- '<div class="lg"><span class="sw" style="background:' + ROUTE_COLOR + '"></span>drive this way (arrows + flow)</div>' +
706
- '<div class="lg"><span class="sw" style="background:#ffffff"></span>already driven</div>' +
707
- '<div class="lg"><span class="sw" style="background:' + DEAD_COLOR + '"></span>deadhead (repeat, no delivery)</div>' +
708
- '<div class="lg" style="margin-top:5px"><span class="sw" style="background:#22c55e"></span>start / end (loop)</div>';
709
  el.style.display = 'block';
710
  }
711
 
712
- // ================= animation =================
713
- let pos=0, playing=false, raf=null, last=0;
714
  const pp=document.getElementById('pp'), scrub=document.getElementById('scrub'),
715
  speedSel=document.getElementById('speed'), followCk=document.getElementById('follow');
716
  pp.onclick = () => playing ? stop() : play();
717
  document.getElementById('restart').onclick = () => { seek(0); play(); };
718
  scrub.oninput = () => { stop(); seek(TOTAL_M * (scrub.value/1000)); };
719
 
 
 
 
 
 
 
720
  function play(){
721
  if (!PATH.length) return;
722
- if (pos >= TOTAL_M - 0.5) pos = 0;
723
- playing = true; pp.innerHTML = '&#10073;&#10073;';
724
  last = performance.now(); raf = requestAnimationFrame(tick);
725
  }
726
- function stop(){ playing = false; pp.innerHTML = '&#9654;'; if (raf) cancelAnimationFrame(raf); raf = null; }
 
727
  function tick(now){
728
  if (!playing) return;
729
  const dt = Math.min((now - last)/1000, 0.1); last = now;
730
- pos += (TOTAL_M / 90) * parseFloat(speedSel.value) * dt;
731
  if (pos >= TOTAL_M) { seek(TOTAL_M); stop(); return; }
732
  seek(pos); raf = requestAnimationFrame(tick);
733
  }
@@ -735,6 +724,8 @@ function tick(now){
735
  function seek(m){
736
  if (!PATH.length) return;
737
  pos = Math.max(0, Math.min(m, TOTAL_M));
 
 
738
  let lo=0, hi=PATH.length-1, i=0;
739
  while (lo <= hi){ const mid=(lo+hi)>>1, s=PATH[mid];
740
  if (pos < s.cum) hi = mid-1; else if (pos > s.cum+s.len) lo = mid+1; else { i=mid; break; }
@@ -742,11 +733,26 @@ function seek(m){
742
  const s = PATH[i];
743
  const f = s.len ? Math.max(0, Math.min((pos-s.cum)/s.len, 1)) : 0;
744
  const here = L.latLng(s.a.lat+(s.b.lat-s.a.lat)*f, s.a.lng+(s.b.lng-s.a.lng)*f);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
745
  truck.setLatLng(here); truck.setIcon(truckIcon(bearing(s.a, s.b)));
746
- const tr = []; for (let k=0;k<i;k++) tr.push(PATH[k].a); tr.push(s.a, here);
747
- trailLine.setLatLngs(tr);
748
- if (followCk.checked && playing && !map.getBounds().pad(-0.18).contains(here))
749
- map.panTo(here, {animate:true, duration:.4});
 
750
  scrub.value = Math.round((pos/TOTAL_M)*1000);
751
  updateHud(s);
752
  }
@@ -754,15 +760,15 @@ function seek(m){
754
  function updateHud(s){
755
  const pct = pos/TOTAL_M;
756
  const leg = document.getElementById('hudLeg');
757
- leg.textContent = Math.round(pct*100) + '% done';
758
- leg.style.background = s.deadhead ? DEAD_COLOR : ROUTE_COLOR;
759
  document.getElementById('hudStreet').innerHTML =
760
- (s.deadhead ? '<span style="color:' + DEAD_COLOR + '">&#8631; </span>' : '') + s.name;
761
  document.getElementById('hudMeta').textContent =
762
  (pos/1609.344).toFixed(2) + ' / ' + (TOTAL_M/1609.344).toFixed(2) + ' mi · ~' +
763
  Math.round(DRIVE_MIN*pct) + ' min in';
764
  document.getElementById('hudBar').style.width = (pct*100) + '%';
765
- document.getElementById('hudBar').style.background = ROUTE_COLOR;
766
  let acc=0, idx=0;
767
  for (let k=0;k<STEPS.length;k++){ acc += STEPS[k].mi*1609.344; idx=k; if (pos <= acc) break; }
768
  document.querySelectorAll('#out .street.now').forEach(r => r.classList.remove('now'));
@@ -788,9 +794,9 @@ function renderStats(s){
788
  ' intersection(s) were unreachable from the main network and left out.</div>';
789
  h += '<div class="hd" style="margin-top:8px">Turn-by-turn (in drive order)</div>';
790
  STEPS.forEach(x => {
791
- const col = x.deadhead ? DEAD_COLOR : ROUTE_COLOR;
792
  h += '<div class="street" data-step="' + x.step + '" style="border-left-color:' + col + '">' +
793
- '<span>' + x.step + '. ' + (x.deadhead ? '<i style="color:' + DEAD_COLOR + '">(deadhead)</i> ' : '') +
794
  x.name + '</span><b>' + x.mi.toFixed(2) + '</b></div>';
795
  });
796
  document.getElementById('out').innerHTML = h;
 
367
  #scrub{flex:1;min-width:160px;-webkit-appearance:none;appearance:none;height:5px;border-radius:3px;background:#2b3342;outline:0;cursor:pointer}
368
  #scrub::-webkit-slider-thumb{-webkit-appearance:none;width:15px;height:15px;border-radius:50%;background:var(--acc);cursor:pointer;border:2px solid #0f1115}
369
  #scrub::-moz-range-thumb{width:15px;height:15px;border-radius:50%;background:var(--acc);border:2px solid #0f1115;cursor:pointer}
370
+ #pp{min-width:82px;padding:9px 12px;text-align:center;background:#22c55e;color:#05130a}
371
  select{background:#252a35;color:var(--txt);border:1px solid var(--line);border-radius:7px;padding:8px;font-size:12px;cursor:pointer}
372
  .hud{position:absolute;top:12px;left:12px;z-index:900;background:#0f1115f2;border:1px solid var(--line);border-radius:9px;padding:10px 13px;min-width:200px;display:none}
373
  .hud.on{display:block}
 
385
  .truck{filter:drop-shadow(0 2px 5px rgba(0,0,0,.7))}
386
  .arrow{pointer-events:none}
387
  #map.routed .leaflet-tile-pane{filter:brightness(.72) saturate(.85)}
 
 
388
  .pin{font:700 10px sans-serif;color:#fff;text-align:center;line-height:1;text-shadow:0 1px 3px #000;white-space:nowrap}
389
  .pin svg{display:block;margin:0 auto}
390
  </style>
 
433
  </div>
434
  <div class="legend" id="legend"></div>
435
  <div id="play">
436
+ <button id="pp">&#9654; Play</button>
437
  <button id="restart" class="sec">&#8634;</button>
438
  <input type="range" id="scrub" min="0" max="1000" value="0">
439
  <select id="speed">
 
579
  };
580
  // ================= route data =================
581
  let PATH=[], TOTAL_M=0, DRIVE_MIN=0, STEPS=[];
582
+ let baseLayer=null, doneLayer=null, partialLine=null, truck=null, startPin=null;
583
 
584
+ const C_TODO = '#ffd21e'; // untraveled = yellow
585
+ const C_DONE = '#22c55e'; // traveled = green
586
+ const C_DEAD = '#ef4444'; // traveled deadhead (repeat) = red
587
 
588
  function bearing(a, b){
589
  const r = Math.PI/180;
 
594
 
595
  function render(d){
596
  stop();
597
+ [baseLayer, doneLayer, partialLine, arrowLayer, truck, startPin].forEach(l => l && map.removeLayer(l));
 
598
 
599
  const feats = d.geojson.features;
600
  PATH = []; TOTAL_M = 0;
 
608
  });
609
  DRIVE_MIN = d.stats.drive_min; STEPS = d.directions;
610
 
611
+ // whole route drawn YELLOW (not yet driven), with a dark casing under it
612
+ const line = [PATH[0].a]; PATH.forEach(s => line.push(s.b));
613
+ baseLayer = L.layerGroup([
614
+ L.polyline(line, {pane:'routePane', color:'#05070c', weight:9, opacity:.6, lineCap:'round', lineJoin:'round'}),
615
+ L.polyline(line, {pane:'routePane', color:C_TODO, weight:5, opacity:.95, lineCap:'round', lineJoin:'round'})
616
+ ]).addTo(map);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
 
618
+ // layer that fills in GREEN/RED behind the truck as it drives
619
+ doneLayer = L.layerGroup([], {pane:'routePane'}).addTo(map);
620
+ partialLine = L.polyline([], {pane:'routePane', color:C_DONE, weight:6, opacity:1, lineCap:'round'}).addTo(map);
621
 
622
+ buildArrows();
 
 
623
 
624
+ startPin = L.marker(PATH[0].a, {zIndexOffset:1100, icon: pinIcon('START / END', '#3b82f6')}).addTo(map);
625
  truck = L.marker(PATH[0].a, {icon: truckIcon(0), zIndexOffset:1200, interactive:false}).addTo(map);
626
 
627
  const bb = L.latLngBounds([]); line.forEach(p => bb.extend(p));
 
631
  document.getElementById('play').classList.add('on');
632
  document.getElementById('hud').classList.add('on');
633
  renderStats(d.stats);
634
+ resetTravel();
635
  seek(0);
636
  }
637
 
638
+ // small dark arrowheads so you can read direction on the yellow line
639
  function buildArrows(){
640
  if (arrowLayer) map.removeLayer(arrowLayer);
641
  arrowLayer = L.layerGroup();
642
+ const stride = Math.max(1, Math.ceil(PATH.length / 80));
643
  PATH.forEach((s, i) => {
644
  if (i % stride) return;
645
+ if (s.len < 28) return;
646
  const mid = L.latLng((s.a.lat+s.b.lat)/2, (s.a.lng+s.b.lng)/2);
647
+ L.marker(mid, {interactive:false, pane:'routePane', icon: L.divIcon({className:'', iconSize:[16,16], iconAnchor:[8,8],
648
  html:'<div class="arrow" style="transform:rotate(' + bearing(s.a, s.b) + 'deg)">' +
649
+ '<svg width="16" height="16" viewBox="0 0 16 16">' +
650
+ '<path d="M8 2 L12 12 L8 9.6 L4 12 Z" fill="#111" stroke="#fff" stroke-width="1"/>' +
651
  '</svg></div>'})}).addTo(arrowLayer);
652
  });
653
  if (document.getElementById('arrowsOn').checked) arrowLayer.addTo(map);
 
658
  };
659
 
660
  function pinIcon(label, color){
661
+ return L.divIcon({className:'', iconSize:[70,34], iconAnchor:[35,32], html:
662
  '<div class="pin"><svg width="26" height="30" viewBox="0 0 26 30">' +
663
  '<path d="M13 29 C13 29 24 17 24 11 A11 11 0 1 0 2 11 C2 17 13 29 13 29 Z" ' +
664
  'fill="' + color + '" stroke="#05070c" stroke-width="1.5"/>' +
 
667
  }
668
 
669
  function truckIcon(deg){
670
+ return L.divIcon({className:'', iconSize:[34,34], iconAnchor:[17,17],
671
  html:'<div class="truck" style="transform:rotate(' + deg + 'deg)">' +
672
+ '<svg width="34" height="34" viewBox="0 0 34 34">' +
673
+ '<circle cx="17" cy="17" r="15" fill="#05070c" opacity=".6"/>' +
674
+ '<g transform="translate(17,17)">' +
675
+ '<rect x="-7" y="-9" width="14" height="18" rx="2.5" fill="#ffffff"/>' +
676
+ '<rect x="-7" y="-9" width="14" height="6.5" rx="2" fill="#16a34a"/>' +
677
+ '<rect x="-8.5" y="-2" width="3" height="6.5" rx="1" fill="#1b2130"/>' +
678
+ '<rect x="5.5" y="-2" width="3" height="6.5" rx="1" fill="#1b2130"/>' +
679
+ '<path d="M0 -14 L5 -9 L-5 -9 Z" fill="#ffd21e"/>' +
680
  '</g></svg></div>'});
681
  }
682
 
 
684
  const el = document.getElementById('legend');
685
  el.innerHTML =
686
  '<div class="ttl">Route</div>' +
687
+ '<div class="lg"><span class="sw" style="background:' + C_TODO + '"></span>not driven yet</div>' +
688
+ '<div class="lg"><span class="sw" style="background:' + C_DONE + '"></span>driven</div>' +
689
+ '<div class="lg"><span class="sw" style="background:' + C_DEAD + '"></span>driven deadhead (repeat)</div>' +
690
+ '<div class="lg" style="margin-top:5px"><span class="sw" style="background:#3b82f6"></span>start / end (loop)</div>';
691
  el.style.display = 'block';
692
  }
693
 
694
+ // ================= animation (a video of the truck driving the route) =================
695
+ let pos=0, playing=false, raf=null, last=0, drawnUpto=0;
696
  const pp=document.getElementById('pp'), scrub=document.getElementById('scrub'),
697
  speedSel=document.getElementById('speed'), followCk=document.getElementById('follow');
698
  pp.onclick = () => playing ? stop() : play();
699
  document.getElementById('restart').onclick = () => { seek(0); play(); };
700
  scrub.oninput = () => { stop(); seek(TOTAL_M * (scrub.value/1000)); };
701
 
702
+ // clear the green/red overlay (used on (re)start and when scrubbing backward)
703
+ function resetTravel(){
704
+ if (doneLayer) doneLayer.clearLayers();
705
+ drawnUpto = 0;
706
+ }
707
+
708
  function play(){
709
  if (!PATH.length) return;
710
+ if (pos >= TOTAL_M - 0.5) { pos = 0; resetTravel(); }
711
+ playing = true; pp.innerHTML = '&#10073;&#10073; Pause';
712
  last = performance.now(); raf = requestAnimationFrame(tick);
713
  }
714
+ function stop(){ playing = false; pp.innerHTML = '&#9654; Play'; if (raf) cancelAnimationFrame(raf); raf = null; }
715
+
716
  function tick(now){
717
  if (!playing) return;
718
  const dt = Math.min((now - last)/1000, 0.1); last = now;
719
+ pos += (TOTAL_M / 75) * parseFloat(speedSel.value) * dt; // 1x = whole route in ~75s
720
  if (pos >= TOTAL_M) { seek(TOTAL_M); stop(); return; }
721
  seek(pos); raf = requestAnimationFrame(tick);
722
  }
 
724
  function seek(m){
725
  if (!PATH.length) return;
726
  pos = Math.max(0, Math.min(m, TOTAL_M));
727
+
728
+ // find current segment i and fraction f
729
  let lo=0, hi=PATH.length-1, i=0;
730
  while (lo <= hi){ const mid=(lo+hi)>>1, s=PATH[mid];
731
  if (pos < s.cum) hi = mid-1; else if (pos > s.cum+s.len) lo = mid+1; else { i=mid; break; }
 
733
  const s = PATH[i];
734
  const f = s.len ? Math.max(0, Math.min((pos-s.cum)/s.len, 1)) : 0;
735
  const here = L.latLng(s.a.lat+(s.b.lat-s.a.lat)*f, s.a.lng+(s.b.lng-s.a.lng)*f);
736
+
737
+ // scrubbed backward past what we've painted -> repaint from scratch
738
+ if (i < drawnUpto) resetTravel();
739
+ // paint every segment the truck has fully passed (green, or red if it's a deadhead)
740
+ while (drawnUpto < i){
741
+ const p = PATH[drawnUpto];
742
+ L.polyline([p.a, p.b], {pane:'routePane', color: p.deadhead ? C_DEAD : C_DONE,
743
+ weight:6, opacity:1, lineCap:'round'}).addTo(doneLayer);
744
+ drawnUpto++;
745
+ }
746
+ // the segment the truck is on: paint the part already covered
747
+ partialLine.setLatLngs([s.a, here]);
748
+ partialLine.setStyle({color: s.deadhead ? C_DEAD : C_DONE});
749
+
750
  truck.setLatLng(here); truck.setIcon(truckIcon(bearing(s.a, s.b)));
751
+
752
+ // camera follows the truck like a chase cam
753
+ if (followCk.checked && playing && !map.getBounds().pad(-0.28).contains(here))
754
+ map.panTo(here, {animate:true, duration:.5});
755
+
756
  scrub.value = Math.round((pos/TOTAL_M)*1000);
757
  updateHud(s);
758
  }
 
760
  function updateHud(s){
761
  const pct = pos/TOTAL_M;
762
  const leg = document.getElementById('hudLeg');
763
+ leg.textContent = Math.round(pct*100) + '% driven';
764
+ leg.style.background = s.deadhead ? C_DEAD : C_DONE;
765
  document.getElementById('hudStreet').innerHTML =
766
+ (s.deadhead ? '<span style="color:' + C_DEAD + '">&#8631; </span>' : '') + s.name;
767
  document.getElementById('hudMeta').textContent =
768
  (pos/1609.344).toFixed(2) + ' / ' + (TOTAL_M/1609.344).toFixed(2) + ' mi · ~' +
769
  Math.round(DRIVE_MIN*pct) + ' min in';
770
  document.getElementById('hudBar').style.width = (pct*100) + '%';
771
+ document.getElementById('hudBar').style.background = C_DONE;
772
  let acc=0, idx=0;
773
  for (let k=0;k<STEPS.length;k++){ acc += STEPS[k].mi*1609.344; idx=k; if (pos <= acc) break; }
774
  document.querySelectorAll('#out .street.now').forEach(r => r.classList.remove('now'));
 
794
  ' intersection(s) were unreachable from the main network and left out.</div>';
795
  h += '<div class="hd" style="margin-top:8px">Turn-by-turn (in drive order)</div>';
796
  STEPS.forEach(x => {
797
+ const col = x.deadhead ? C_DEAD : C_DONE;
798
  h += '<div class="street" data-step="' + x.step + '" style="border-left-color:' + col + '">' +
799
+ '<span>' + x.step + '. ' + (x.deadhead ? '<i style="color:' + C_DEAD + '">(deadhead)</i> ' : '') +
800
  x.name + '</span><b>' + x.mi.toFixed(2) + '</b></div>';
801
  });
802
  document.getElementById('out').innerHTML = h;