Skip to content

Commit 92ff630

Browse files
committed
Direct manual control over color palette
1 parent ad99668 commit 92ff630

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ <h4>Overlays</h4>
239239
<input type="checkbox" id="opt_daylight">
240240
</div>
241241
</div>
242+
<h4>Balloon Colors</h4>
243+
<hr/>
244+
<div class="row option", id="color_selector_row">
245+
<!-- Colors populated with javascript at runtime -->
246+
</div>
242247
</div>
243248
</div>
244249
<div id="skewtbox" style="display:none;" class="flatpage">

js/tracker.js

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ var manual_pan = false;
7474

7575
var car_index = 0;
7676
var car_colors = ["blue", "red", "green", "yellow", "teal", "purple"];
77-
var balloon_colors = ["red", "blue", "lime", "magenta", "#ffb300", "#00ffff"];
77+
// MUST use 7-character, lowercase hex format. No named colors or others. Due to limits of HTML color picker.
78+
var balloon_colors = ["#ff0000", "#0000ff", "#00ff00", "#ff00ff", "#ffb300", "#00ffff"];
7879

7980
var nyan_color_index = 0;
8081
var nyan_colors = ['nyan', 'nyan-coin', 'nyan-mon', 'nyan-pirate', 'nyan-cool', 'nyan-tothemax', 'nyan-pumpkin', 'nyan-afro', 'nyan-coin', 'nyan-mummy'];
@@ -989,6 +990,18 @@ function load() {
989990
map.addLayer(nite);
990991
}
991992

993+
// Create color selector boxes in settings panel
994+
var color_row = document.getElementById("color_selector_row");
995+
for (var i = 0; i < balloon_colors.length; i++) {
996+
var input = document.createElement("input");
997+
input.type = "color";
998+
input.value = balloon_colors[i];
999+
input.id = "color" + i;
1000+
input.style = "width: 30px; height: 30px; border:none; padding:0; margin:5px";
1001+
input.onchange = recolorAllVehicles;
1002+
color_row.appendChild(input);
1003+
}
1004+
9921005
getLaunchSites();
9931006

9941007
if (!offline.get("opt_layers_launches")) {
@@ -3630,29 +3643,44 @@ function addPosition(position) {
36303643
return;
36313644
}
36323645

3633-
// When "Recolor" button is clicked in the data pane for this vehicle,
3634-
// cycle it to the next color in the sequence. Allows user to change color,
3635-
// primarily for sake of increased contrast on maps.
3646+
// When a color is changed in the settings, run recolorVehicle on all vehicles.
3647+
function recolorAllVehicles(){
3648+
// Refresh the balloon_colors array to capture all the current colors
3649+
for (var i = 0; i <= balloon_colors.length; i++) {
3650+
balloon_colors[i] = document.getElementById("color" + i).value;
3651+
}
3652+
var callsign;
3653+
for(callsign in vehicles) {
3654+
recolorVehicle(callsign);
3655+
}
3656+
}
3657+
36363658
function recolorVehicle(vcallsign) {
36373659
const vehicle = vehicles[vcallsign];
36383660

3639-
vehicle.color_index = (vehicle.color_index + 1) % balloon_colors.length;
36403661
const new_color = balloon_colors[vehicle.color_index];
36413662

36423663
// Recolor the lines on the map to the new color
3643-
vehicle.prediction_launch_polyline.setStyle({color: new_color});
3644-
vehicle.prediction_polyline.setStyle({color: new_color});
3645-
vehicle.polyline[0].setStyle({color: new_color});
3646-
3664+
if (vehicle.prediction_launch_polyline){
3665+
vehicle.prediction_launch_polyline.setStyle({color: new_color});
3666+
}
3667+
if (vehicle.prediction_polyline){
3668+
vehicle.prediction_polyline.setStyle({color: new_color});
3669+
}
3670+
if (vehicle.polyline){
3671+
vehicle.polyline[0].setStyle({color: new_color});
3672+
}
36473673
// Recolor the prediction target
3648-
const targetIcon = vehicle.prediction_target.getIcon().options.iconUrl;
3649-
const recoloredTarget = recolorSVG(targetIcon, new_color);
3650-
const newTarget = L.icon( // Create new icon which inherits properties from the existing one
3651-
Object.assign({}, vehicle.prediction_target.options.icon.options, {
3652-
iconUrl: recoloredTarget // just with a new icon
3653-
})
3654-
);
3655-
vehicle.prediction_target.setIcon(newTarget);
3674+
if (vehicle.prediction_target){
3675+
const targetIcon = vehicle.prediction_target.getIcon().options.iconUrl;
3676+
const recoloredTarget = recolorSVG(targetIcon, new_color);
3677+
const newTarget = L.icon( // Create new icon which inherits properties from the existing one
3678+
Object.assign({}, vehicle.prediction_target.options.icon.options, {
3679+
iconUrl: recoloredTarget // just with a new icon
3680+
})
3681+
);
3682+
vehicle.prediction_target.setIcon(newTarget);
3683+
}
36563684

36573685
// Recolor the balloon/parachute/whatever
36583686
const balloon = vehicle.marker.getIcon().options.iconUrl;

0 commit comments

Comments
 (0)