From 0fa252935848b212d8e2eb50f2d9494929c7571e Mon Sep 17 00:00:00 2001 From: tuffnerdstuff Date: Fri, 2 Apr 2021 22:18:26 +0200 Subject: [PATCH] Support multiple track colors --- backend-php/dynamic.js.php | 2 +- backend-php/include/config-sample.php | 4 ++-- backend-php/include/inc.php | 2 +- frontend/main.js | 14 +++++++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend-php/dynamic.js.php b/backend-php/dynamic.js.php index 325bead..8fe60bb 100644 --- a/backend-php/dynamic.js.php +++ b/backend-php/dynamic.js.php @@ -13,7 +13,7 @@ var MAX_ZOOM = ; var MAX_POINTS = ; var VELOCITY_DELTA_TIME = ; -var TRAIL_COLOR = ; +var TRAIL_COLORS = ; var VELOCITY_UNIT = ; var OFFLINE_TIMEOUT = ; var REQUEST_TIMEOUT = ; diff --git a/backend-php/include/config-sample.php b/backend-php/include/config-sample.php index 9b9d07d..0485455 100644 --- a/backend-php/include/config-sample.php +++ b/backend-php/include/config-sample.php @@ -267,8 +267,8 @@ // Number of seconds of data that should be used to calculate velocity. "v_data_points" => 2, -// The color of the marker trails. HTML color name or #rrggbb hex color code. -"trail_color" => '#d80037', +// The colors of the marker trails. An array of HTML color names or #rrggbb hex color codes. +"trail_colors" => ['#d80037', '#3cb44b', '#ffe119', '#4363d8', '#f58231', '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', '#fabebe', '#008080', '#e6beff', '#9a6324', '#fffac8', '#800000', '#aaffc3', '#808000', '#ffd8b1', '#000075', '#808080'], // The unit of measurement of velocity. Valid are: // KILOMETERS_PER_HOUR, MILES_PER_HOUR, METERS_PER_SECOND diff --git a/backend-php/include/inc.php b/backend-php/include/inc.php index 366a7c2..2438a91 100644 --- a/backend-php/include/inc.php +++ b/backend-php/include/inc.php @@ -147,7 +147,7 @@ "max_cached_pts" => 3, "max_shown_pts" => 100, "v_data_points" => 2, - "trail_color" => '#d80037', + "trail_colors" => ['#d80037', '#3cb44b', '#ffe119', '#4363d8', '#f58231', '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', '#fabebe', '#008080', '#e6beff', '#9a6324', '#fffac8', '#800000', '#aaffc3', '#808000', '#ffd8b1', '#000075', '#808080'], "velocity_unit" => KILOMETERS_PER_HOUR, "public_url" => 'https://example.com/' diff --git a/frontend/main.js b/frontend/main.js index 3bbda17..21f70cc 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -727,7 +727,7 @@ function processUpdate(data, init) { } else { // If there is a marker, draw a line from its last location // instead and move the marker. - line = L.polyline([shares[user].marker.getLatLng(), [lat, lon]], {color: TRAIL_COLOR}).addTo(markerLayer); + line = L.polyline([shares[user].marker.getLatLng(), [lat, lon]], {color: getTrackColor(user)}).addTo(markerLayer); shares[user].marker.setLatLng([lat, lon]); } // Draw an accuracy circle if GPS accuracy was provided by the @@ -890,6 +890,18 @@ function processUpdate(data, init) { } } +var currColorIndex = 0; +// Gets a new color from TRAIL_COLORS array for each new user of the share +function getTrackColor(user) { + var trackColor = shares[user].color; + if (!trackColor) { + trackColor = TRAIL_COLORS[currColorIndex]; + shares[user].color = trackColor; + currColorIndex=(currColorIndex+1) % TRAIL_COLORS.length; + } + return trackColor; +} + // Calculates the distance between two points on a sphere using the Haversine // algorithm. function distance(from, to) {