From ec33ea6ad111921cfa06668ff8ec9c4ce6aa6a32 Mon Sep 17 00:00:00 2001 From: "M. Eren Akbiyik" Date: Thu, 19 Oct 2023 00:31:23 +0200 Subject: [PATCH] feat: color spline segments per speed --- src/App.tsx | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 16a179c..c61fa43 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -293,19 +293,28 @@ function MapContent({ data.cts > cleanMarkerVals[1].cts && data.cts < cleanMarkerVals[cleanMarkerVals.length - 2].cts, ) - .map((data): L.LatLngExpression => [data.lat, data.lng]); + .map((data): L.LatLngTuple => [data.lat, data.lng]); + + const Polylines = splinePositions.slice(0, -3).map((_, index) => { + // color according to the speed. Green for slow and red for fast. 0=green, 1e-9=red + const diff = + (splinePositions[index + 3][0] - splinePositions[index][0]) ** 2 + + (splinePositions[index + 3][1] - splinePositions[index][1]) ** 2; + const color = Math.min(1, diff / 3 / 2e-10); + return ( + + ); + }); return ( <> {splineData && cleanMarkerVals.length > 1 && ( <> {/* render the spline for all points except the first and last two */} - {cleanMarkerVals.length > 3 && ( - - )} + {cleanMarkerVals.length > 3 && Polylines} {/* render a line for the first/last two points */} { - // subsample every 4th point - if (idx % 4 !== 0 || idx === gpsStreamSamples.length - 1) { + // subsample every 8th point + if (idx % 8 !== 0 || idx === gpsStreamSamples.length - 1) { acc.push({ lat: sample.value[0], lng: sample.value[1], @@ -774,7 +783,7 @@ function App() { url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" attribution='© OpenStreetMap contributors' maxNativeZoom={19} - maxZoom={23} + maxZoom={24} /> {...originalMarkers}