Files
tar1090/html/planeObject.js

1240 lines
35 KiB
JavaScript
Raw Normal View History

2019-07-26 15:21:08 +02:00
"use strict";
function PlaneObject(icao) {
// Info about the plane
this.icao = icao;
this.icaorange = findICAORange(icao);
this.flight = null;
this.squawk = null;
this.selected = false;
this.category = null;
2019-10-17 22:09:33 +02:00
this.dataSource = "other";
this.trCache = [];
2019-07-26 15:21:08 +02:00
// Basic location information
this.altitude = null;
this.alt_baro = null;
this.alt_geom = null;
this.altitudeTime = 0;
2019-07-26 15:21:08 +02:00
this.speed = null;
this.gs = null;
this.ias = null;
this.tas = null;
this.track = null;
this.track_rate = null;
this.mag_heading = null;
this.true_heading = null;
this.mach = null;
this.roll = null;
this.nav_altitude = null;
this.nav_heading = null;
this.nav_modes = null;
this.nav_qnh = null;
this.rc = null;
this.rotation = 0;
2019-07-26 15:21:08 +02:00
this.nac_p = null;
this.nac_v = null;
this.nic_baro = null;
this.sil_type = null;
this.sil = null;
this.baro_rate = null;
this.geom_rate = null;
this.vert_rate = null;
this.version = null;
this.prev_position = null;
2019-08-06 21:49:57 +02:00
this.prev_time = null;
2019-07-28 23:59:46 +02:00
this.prev_track = null;
2019-07-26 15:21:08 +02:00
this.position = null;
this.sitedist = null;
this.too_fast = 0;
2019-07-26 15:21:08 +02:00
// Data packet numbers
2019-10-13 13:42:23 +02:00
this.messages = 0;
2019-07-26 15:21:08 +02:00
this.rssi = null;
2019-10-13 13:42:23 +02:00
this.msgs1090 = 0;
this.msgs978 = 0;
this.messageRate = 0;
this.messageRateOld = 0;
2019-07-26 15:21:08 +02:00
// Track history as a series of line segments
this.elastic_feature = null;
this.track_linesegs = [];
this.history_size = 0;
// Track (direction) at the time we last appended to the track history
this.tail_track = null;
2019-08-07 10:42:40 +02:00
this.tail_true = null;
2019-07-28 23:59:46 +02:00
// Timestamp of the most recent point appended to the track history
this.tail_update = null;
2019-07-26 15:21:08 +02:00
// When was this last updated (receiver timestamp)
2019-08-05 08:37:26 +02:00
this.last_message_time = 0;
2019-08-06 21:49:57 +02:00
this.position_time = 0;
2019-07-26 15:21:08 +02:00
// When was this last updated (seconds before last update)
this.seen = null;
this.seen_pos = null;
// Display info
this.visible = true;
this.marker = null;
this.markerStyle = null;
this.markerIcon = null;
this.markerStyleKey = null;
this.markerSvgKey = null;
this.baseScale = 1;
2019-07-26 15:21:08 +02:00
this.filter = {};
// start from a computed registration, let the DB override it
// if it has something else.
this.registration = registration_from_hexid(this.icao);
2019-08-18 13:26:51 +02:00
this.icaoType = null;
2019-07-26 15:21:08 +02:00
this.typeDescription = null;
this.wtc = null;
this.trail_features = new ol.Collection();
this.layer = new ol.layer.Vector({
name: this.icao,
isTrail: true,
source: new ol.source.Vector({
features: this.trail_features,
2019-08-24 20:32:42 +02:00
}),
2019-08-29 08:28:50 +02:00
renderOrder: null,
});
trailGroup.push(this.layer);
2019-07-26 15:21:08 +02:00
// request metadata
getAircraftData(this.icao).done(function(data) {
if ("r" in data) {
this.registration = data.r;
}
if ("t" in data) {
2019-08-18 13:26:51 +02:00
this.icaoType = data.t;
this.icaoTypeCache = this.icaoType;
2019-07-26 15:21:08 +02:00
}
if ("desc" in data) {
this.typeDescription = data.desc;
}
if (data.vType != null) {
this.vType = data.vType;
}
2019-07-26 15:21:08 +02:00
if ("wtc" in data) {
this.wtc = data.wtc;
}
if (this.selected) {
refreshSelected();
}
2019-08-03 17:28:43 +02:00
data = null;
2019-07-26 15:21:08 +02:00
}.bind(this));
}
const estimateStyle = new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#808080',
width: 1.2
})
});
const nullStyle = new ol.style.Style({});
2019-10-28 10:43:07 +01:00
const badDot = new ol.style.Style({
image: new ol.style.Circle({
2019-10-13 12:30:02 +02:00
radius: 3.5,
fill: new ol.style.Fill({
color: '#FF0000',
})
}),
});
2019-10-28 10:43:07 +01:00
const badDotMlat = new ol.style.Style({
image: new ol.style.Circle({
radius: 3.5,
fill: new ol.style.Fill({
color: '#FFA500',
})
}),
});
PlaneObject.prototype.logSel = function(loggable) {
2019-10-15 17:04:36 +02:00
if (debugTracks && this.selected && !SelectedAllPlanes)
console.log(loggable);
return;
}
2019-07-26 15:21:08 +02:00
PlaneObject.prototype.isFiltered = function() {
2019-10-27 08:41:05 +01:00
if (onlySelected && !this.selected) {
return true;
}
if (onlyMLAT && this.dataSource != "mlat" && this.dataSource != "other") {
return true;
}
if (onlyADSB && this.dataSource != "adsb" && this.dataSource != "uat") {
return true;
}
if (filterTISB && this.dataSource == "tisb") {
2019-10-12 06:46:57 +02:00
return true;
}
if (!filterTracks && this.altFiltered(this.altitude))
return true;
2019-07-26 15:21:08 +02:00
// filter out ground vehicles
if (typeof this.filter.groundVehicles !== 'undefined' && this.filter.groundVehicles === 'filtered') {
if (typeof this.category === 'string' && this.category.startsWith('C')) {
return true;
}
}
// filter out blocked MLAT flights
if (typeof this.filter.blockedMLAT !== 'undefined' && this.filter.blockedMLAT === 'filtered') {
if (typeof this.icao === 'string' && this.icao.startsWith('~')) {
return true;
}
}
return false;
}
PlaneObject.prototype.altFiltered = function(altitude) {
if (this.filter.minAltitude == null || this.filter.maxAltitude == null)
return false;
if (altitude == null) {
return true;
}
const planeAltitude = altitude === "ground" ? 0 : altitude;
if (planeAltitude < this.filter.minAltitude || planeAltitude > this.filter.maxAltitude) {
return true;
}
return false;
}
2019-08-06 21:49:57 +02:00
PlaneObject.prototype.updateTail = function() {
this.tail_update = this.prev_time;
this.tail_track = this.prev_track;
2019-08-07 10:42:40 +02:00
this.tail_true = this.prev_true;
2019-08-06 21:49:57 +02:00
this.tail_position = this.prev_position;
2019-08-07 10:42:40 +02:00
return this.updateTrackPrev();
2019-08-06 21:49:57 +02:00
}
2019-08-07 10:42:40 +02:00
2019-08-06 21:49:57 +02:00
PlaneObject.prototype.updateTrackPrev = function() {
this.prev_position = this.position;
this.prev_time = this.position_time;
this.prev_track = this.track;
2019-08-07 10:42:40 +02:00
this.prev_true = this.true_head;
2019-08-28 19:53:58 +02:00
this.prev_alt = this.altitude;
this.prev_alt_rounded = this.alt_rounded;
2019-08-28 19:53:58 +02:00
this.prev_speed = this.speed;
2019-08-07 10:42:40 +02:00
2019-08-06 21:49:57 +02:00
return true;
}
2019-07-26 15:21:08 +02:00
// Appends data to the running track so we can get a visual tail on the plane
// Only useful for a long running browser session.
2019-10-13 13:42:23 +02:00
PlaneObject.prototype.updateTrack = function(now, last) {
2019-07-28 23:59:46 +02:00
if (this.position == null)
2019-07-26 15:21:08 +02:00
return false;
if (this.prev_position && this.position[0] == this.prev_position[0] && this.position[1] == this.prev_position[1])
2019-07-26 15:21:08 +02:00
return false;
if (this.bad_position && this.position[0] == this.bad_position[0] && this.position[1] == this.bad_position[1])
return false;
2019-07-26 15:21:08 +02:00
var projHere = ol.proj.fromLonLat(this.position);
2019-07-30 15:01:56 +02:00
var on_ground = (this.altitude === "ground");
2019-07-26 15:21:08 +02:00
if (this.track_linesegs.length == 0) {
// Brand new track
//console.log(this.icao + " new track");
var newseg = { fixed: new ol.geom.LineString([projHere]),
feature: null,
estimated: false,
2019-07-30 15:01:56 +02:00
ground: on_ground,
2019-08-20 14:30:26 +02:00
altitude: this.alt_rounded,
2019-08-28 19:53:58 +02:00
alt_real: this.altitude,
speed: this.speed,
2019-07-26 15:21:08 +02:00
};
this.track_linesegs.push(newseg);
this.history_size ++;
2019-08-06 21:49:57 +02:00
this.prev_position = this.position;
return this.updateTail();
2019-07-26 15:21:08 +02:00
}
2019-08-06 21:49:57 +02:00
var projPrev = ol.proj.fromLonLat(this.prev_position);
2019-07-26 15:21:08 +02:00
var lastseg = this.track_linesegs[this.track_linesegs.length - 1];
2019-10-13 06:41:32 +02:00
var distance = ol.sphere.getDistance(this.position, this.prev_position);
var derivedMach = (distance/(this.position_time - this.prev_time + 0.4))/343;
2019-10-13 06:41:32 +02:00
var filterSpeed = on_ground ? positionFilterSpeed/10 : positionFilterSpeed;
filterSpeed = (this.speed != null && this.prev_speed != null) ? (positionFilterGsFactor*(Math.max(this.speed, this.prev_speed)+10+(this.dataSource == "mlat")*100)/666) : filterSpeed;
2019-10-13 12:30:02 +02:00
// ignore the position if the object moves faster than positionFilterSpeed (default Mach 3.5)
// or faster than twice the transmitted groundspeed
2019-10-13 06:41:32 +02:00
if (positionFilter && derivedMach > filterSpeed && this.too_fast < 1) {
this.bad_position = this.position;
this.too_fast++;
if (debugPosFilter) {
2019-10-28 10:43:07 +01:00
console.log(this.icao + " / " + this.name + " ("+ this.dataSource + "): Implausible position filtered: " + this.bad_position[0] + ", " + this.bad_position[1] + " (kts/Mach " + (derivedMach*666).toFixed(0) + " > " + (filterSpeed*666).toFixed(0) + " / " + derivedMach.toFixed(2) + " > " + filterSpeed.toFixed(2) + ") (" + (this.position_time - this.prev_time + 0.2).toFixed(1) + "s)");
}
2019-10-13 12:30:02 +02:00
this.position = this.prev_position;
this.position_time = this.prev_time;
2019-10-13 06:41:32 +02:00
if (debugPosFilter) {
this.drawRedDot(this.bad_position);
}
return false;
} else {
2019-10-27 10:51:38 +01:00
this.too_fast = Math.max(-5, this.too_fast-0.8);
}
if (positionFilter && this.dataSource == "mlat" && on_ground) {
this.bad_position = this.position;
2019-08-07 10:42:40 +02:00
return true;
}
2019-07-26 15:21:08 +02:00
// Determine if track data are intermittent/stale
// Time difference between two position updates should not be much
// greater than the difference between data inputs
2019-10-13 13:42:23 +02:00
var time_difference = (this.position_time - this.prev_time) - (now - last);
2019-07-26 15:21:08 +02:00
2019-09-22 11:32:53 +02:00
var stale_timeout = lastseg.estimated ? 5 : 10;
2019-07-26 15:21:08 +02:00
// MLAT data are given some more leeway
if (this.dataSource == "mlat")
stale_timeout = 15;
// On the ground you can't go that quick
if (on_ground)
stale_timeout = 30;
2019-07-26 15:21:08 +02:00
var est_track = (time_difference > stale_timeout);
// Also check if the position was already stale when it was exported by dump1090
// Makes stale check more accurate for example for 30s spaced history points
2019-10-13 13:42:23 +02:00
est_track = est_track || ((now - this.position_time) > stale_timeout);
2019-07-26 15:21:08 +02:00
if (est_track) {
if (!lastseg.estimated) {
// >5s gap in data, create a new estimated segment
//console.log(this.icao + " switching to estimated");
lastseg.fixed.appendCoordinate(projPrev);
this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev]),
2019-07-26 15:21:08 +02:00
feature: null,
altitude: 0,
estimated: true });
this.history_size += 2;
} else {
// Keep appending to the existing dashed line; keep every point
lastseg.fixed.appendCoordinate(projPrev);
2019-07-26 15:21:08 +02:00
this.history_size++;
}
2019-08-06 21:49:57 +02:00
return this.updateTail();
2019-07-26 15:21:08 +02:00
}
if (lastseg.estimated) {
// We are back to good data (we got two points close in time), switch back to
// solid lines.
lastseg.fixed.appendCoordinate(projPrev);
2019-08-03 17:28:43 +02:00
this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev]),
2019-07-26 15:21:08 +02:00
feature: null,
estimated: false,
2019-07-30 15:01:56 +02:00
ground: on_ground,
altitude: this.prev_alt_rounded,
2019-08-28 19:53:58 +02:00
alt_real: this.prev_alt,
speed: this.prev_speed,
2019-08-20 14:30:26 +02:00
});
this.history_size += 2;
2019-08-06 21:49:57 +02:00
return this.updateTail();
2019-07-26 15:21:08 +02:00
}
var track_change = this.track != null ? Math.abs(this.tail_track - this.track) : NaN;
track_change = track_change < 180 ? track_change : Math.abs(track_change - 360);
var true_change = this.trueheading != null ? Math.abs(this.tail_true - this.true_heading) : NaN;
true_change = true_change < 180 ? true_change : Math.abs(true_change - 360);
2019-08-07 10:42:40 +02:00
if (!isNaN(true_change)) {
track_change = isNaN(track_change) ? true_change : Math.max(track_change, true_change);
}
2019-10-21 10:03:14 +02:00
2019-08-20 14:30:26 +02:00
var alt_change = Math.abs(this.alt_rounded - lastseg.altitude);
2019-08-06 21:49:57 +02:00
var since_update = this.prev_time - this.tail_update;
2019-10-21 10:03:14 +02:00
var distance_traveled = ol.sphere.getDistance(this.tail_position, this.prev_position);
if (
this.prev_alt_rounded !== lastseg.altitude
2019-08-20 14:30:26 +02:00
//lastseg.ground != on_ground
//|| (!on_ground && isNaN(alt_change))
//|| (alt_change > 700)
//|| (alt_change > 375 && this.alt_rounded < 9000)
//|| (alt_change > 150 && this.alt_rounded < 5500)
) {
2019-07-26 15:21:08 +02:00
// Create a new segment as the ground state or the altitude changed.
// The new state is only drawn after the state has changed
2019-07-30 15:03:43 +02:00
// and we then get a new position.
2019-07-26 15:21:08 +02:00
2019-10-21 10:03:14 +02:00
this.logSel("sec_elapsed: " + since_update.toFixed(1) + " alt_change: "+ alt_change.toFixed(0) + " derived_speed(kts/Mach): " + (distance_traveled/since_update*1.94384).toFixed(0) + " / " + (distance_traveled/since_update/343).toFixed(1));
lastseg.fixed.appendCoordinate(projPrev);
this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev]),
2019-07-26 15:21:08 +02:00
feature: null,
estimated: false,
altitude: this.prev_alt_rounded,
2019-08-28 19:53:58 +02:00
alt_real: this.prev_alt,
speed: this.prev_speed,
2019-08-20 14:30:26 +02:00
ground: on_ground,
});
2019-08-06 21:49:57 +02:00
2019-07-26 15:21:08 +02:00
this.history_size += 2;
2019-08-06 21:49:57 +02:00
return this.updateTail();
2019-07-26 15:21:08 +02:00
}
2019-10-13 17:38:12 +02:00
2019-07-26 15:21:08 +02:00
// Add current position to the existing track.
// We only retain some points depending on time elapsed and track change
2019-08-07 10:42:40 +02:00
var turn_density = 6.5;
2019-08-04 17:08:39 +02:00
if (
2019-09-22 18:27:37 +02:00
since_update > 86 ||
(!on_ground && since_update > (100/turn_density)/track_change) ||
2019-08-06 21:49:57 +02:00
(!on_ground && isNaN(track_change) && since_update > 8) ||
2019-08-07 10:42:40 +02:00
(on_ground && since_update > (500/turn_density)/track_change && distance_traveled > 8) ||
2019-08-16 09:59:06 +02:00
(on_ground && distance_traveled > 40 && since_update > 4) ||
2019-08-04 17:08:39 +02:00
debugAll
) {
2019-08-06 21:49:57 +02:00
lastseg.fixed.appendCoordinate(projPrev);
2019-07-26 15:21:08 +02:00
this.history_size ++;
2019-08-06 21:49:57 +02:00
2019-10-21 10:03:14 +02:00
this.logSel("sec_elapsed: " + since_update.toFixed(1) + " " + (on_ground ? "ground" : "air") + " dist:" + distance_traveled.toFixed(0) + " track_change: "+ track_change.toFixed(1) + " derived_speed(kts/Mach): " + (distance_traveled/since_update*1.94384).toFixed(0) + " / " + (distance_traveled/since_update/343).toFixed(1));
2019-08-06 21:49:57 +02:00
return this.updateTail();
2019-07-26 15:21:08 +02:00
}
2019-08-06 21:49:57 +02:00
return this.updateTrackPrev();
2019-07-26 15:21:08 +02:00
};
// This is to remove the line from the screen if we deselect the plane
PlaneObject.prototype.clearLines = function() {
2019-08-05 20:27:56 +02:00
if (this.layer.getVisible())
this.layer.setVisible(false);
2019-07-26 15:21:08 +02:00
};
PlaneObject.prototype.getDataSourceNumber = function() {
// MLAT
2019-08-03 20:26:12 +02:00
if (this.dataSource == "mlat") {
return 3;
}
2019-08-03 20:26:12 +02:00
if (this.dataSource == "uat")
return 2; // UAT
// Not MLAT, but position reported - ADSB or variants
if (this.dataSource == "tisb")
return 4; // TIS-B
if (this.dataSource == "adsb")
return 1;
// Otherwise Mode S
return 5;
// TODO: add support for Mode A/C
};
2019-07-26 15:21:08 +02:00
PlaneObject.prototype.getDataSource = function() {
// MLAT
2019-08-03 20:26:12 +02:00
if (this.dataSource == "mlat") {
2019-07-26 15:21:08 +02:00
return 'mlat';
}
2019-08-03 20:26:12 +02:00
if (this.dataSource == "uat")
return 'uat';
2019-07-26 15:21:08 +02:00
2019-08-04 23:33:25 +02:00
if (this.addrtype) {
2019-07-26 15:21:08 +02:00
return this.addrtype;
}
2019-08-04 23:33:25 +02:00
if (this.dataSource == "adsb")
return "adsb_icao";
2019-07-26 15:21:08 +02:00
// Otherwise Mode S
return 'mode_s';
// TODO: add support for Mode A/C
};
PlaneObject.prototype.getMarkerColor = function() {
// Emergency squawks override everything else
if (this.squawk in SpecialSquawks)
return SpecialSquawks[this.squawk].markerColor;
var h, s, l;
2019-08-20 14:30:26 +02:00
var colorArr = this.getAltitudeColor(this.alt_rounded);
2019-07-26 15:21:08 +02:00
h = colorArr[0];
s = colorArr[1];
l = colorArr[2];
// If we have not seen a recent position update, change color
2019-08-20 06:14:17 +02:00
if (this.seen_pos > 15) {
2019-07-26 15:21:08 +02:00
h += ColorByAlt.stale.h;
s += ColorByAlt.stale.s;
l += ColorByAlt.stale.l;
}
2019-08-20 14:30:26 +02:00
if (this.alt_rounded == "ground") {
2019-08-20 06:14:17 +02:00
l += 15;
}
2019-07-26 15:21:08 +02:00
// If this marker is selected, change color
2019-10-27 08:41:05 +01:00
if (this.selected && !SelectedAllPlanes && !onlySelected){
2019-07-26 15:21:08 +02:00
h += ColorByAlt.selected.h;
s += ColorByAlt.selected.s;
l += ColorByAlt.selected.l;
}
// If this marker is a mlat position, change color
2019-08-03 20:26:12 +02:00
if (this.dataSource == "mlat") {
2019-07-26 15:21:08 +02:00
h += ColorByAlt.mlat.h;
s += ColorByAlt.mlat.s;
l += ColorByAlt.mlat.l;
}
if (h < 0) {
h = (h % 360) + 360;
} else if (h >= 360) {
h = h % 360;
}
if (s < 5) s = 5;
else if (s > 95) s = 95;
if (l < 5) l = 5;
else if (l > 95) l = 95;
2019-08-19 20:02:05 +02:00
return 'hsl(' + h.toFixed(0) + ',' + s.toFixed(0) + '%,' + l.toFixed(0) + '%)'
2019-07-26 15:21:08 +02:00
}
PlaneObject.prototype.getAltitudeColor = function(altitude) {
if (typeof altitude === 'undefined') {
2019-08-20 14:30:26 +02:00
altitude = this.alt_rounded;
2019-07-26 15:21:08 +02:00
}
return altitudeColor(altitude);
}
function altitudeColor(altitude) {
var h, s, l;
2019-07-26 15:21:08 +02:00
if (altitude == null) {
2019-07-26 15:21:08 +02:00
h = ColorByAlt.unknown.h;
s = ColorByAlt.unknown.s;
l = ColorByAlt.unknown.l;
2019-07-30 14:45:51 +02:00
} else if (altitude === "ground") {
2019-07-26 15:21:08 +02:00
h = ColorByAlt.ground.h;
s = ColorByAlt.ground.s;
l = ColorByAlt.ground.l;
} else {
s = ColorByAlt.air.s;
// find the pair of points the current altitude lies between,
// and interpolate the hue between those points
var hpoints = ColorByAlt.air.h;
h = hpoints[0].val;
for (var i = hpoints.length-1; i >= 0; --i) {
if (altitude > hpoints[i].alt) {
if (i == hpoints.length-1) {
h = hpoints[i].val;
} else {
h = hpoints[i].val + (hpoints[i+1].val - hpoints[i].val) * (altitude - hpoints[i].alt) / (hpoints[i+1].alt - hpoints[i].alt)
}
break;
}
}
var lpoints = ColorByAlt.air.l;
lpoints = lpoints.length ? lpoints : [{h:0, val:lpoints}];
l = lpoints[0].val;
for (var i = lpoints.length-1; i >= 0; --i) {
if (h > lpoints[i].h) {
if (i == lpoints.length-1) {
l = lpoints[i].val;
} else {
l = lpoints[i].val + (lpoints[i+1].val - lpoints[i].val) * (h - lpoints[i].h) / (lpoints[i+1].h - lpoints[i].h)
}
break;
}
}
2019-07-26 15:21:08 +02:00
}
if (h < 0) {
h = (h % 360) + 360;
} else if (h >= 360) {
h = h % 360;
}
if (s < 5) s = 5;
else if (s > 95) s = 95;
if (l < 5) l = 5;
else if (l > 95) l = 95;
return [h, s, l];
}
PlaneObject.prototype.updateIcon = function() {
var col = this.getMarkerColor();
//var opacity = 1.0;
2019-08-03 20:26:12 +02:00
var outline = (this.dataSource == "mlat" ? OutlineMlatColor : OutlineADSBColor);
2019-10-27 08:41:05 +01:00
var add_stroke = (this.selected && !SelectedAllPlanes && !onlySelected) ? (' stroke="'+outline+'" stroke-width="1px"') : '';
2019-08-20 14:30:26 +02:00
var baseMarkerKey = (this.category ? this.category : "A0") + "_"
+ this.typeDescription + "_" + this.wtc + "_" + this.icaoType;
2019-08-17 20:10:14 +02:00
if (!this.baseMarker || this.baseMarkerKey != baseMarkerKey) {
2019-08-05 20:27:56 +02:00
this.baseMarkerKey = baseMarkerKey;
2019-08-18 13:26:51 +02:00
this.baseMarker = getBaseMarker(this.category, this.icaoType, this.typeDescription, this.wtc);
2019-08-20 19:38:31 +02:00
this.shape = this.baseMarker[0];
2019-08-24 10:44:20 +02:00
this.baseScale = this.baseMarker[1];
2019-08-20 19:38:31 +02:00
this.baseMarker = shapes[this.shape]
2019-08-24 10:44:20 +02:00
if (!this.baseMarker)
console.log(baseMarkerKey);
2019-08-05 20:27:56 +02:00
}
2019-07-26 15:21:08 +02:00
2019-08-22 16:58:25 +02:00
this.scale = scaleFactor * this.baseScale;
var svgKey = col + '!' + outline + '!' + this.shape + '!' + add_stroke;
var labelText = null;
2019-10-27 08:41:05 +01:00
if ( ( (enableLabels && !multiSelect) || (enableLabels && multiSelect && this.selected)) && (
2019-08-24 10:44:20 +02:00
(ZoomLvl >= labelZoom && this.altitude != "ground")
|| (ZoomLvl >= labelZoomGround-2 && this.speed > 18)
|| ZoomLvl >= labelZoomGround
2019-08-29 15:45:12 +02:00
|| (this.selected && !SelectedAllPlanes)
2019-08-24 10:44:20 +02:00
)) {
2019-08-28 20:42:47 +02:00
if (extendedLabels) {
2019-08-31 10:54:13 +02:00
if (this.altitude && (!this.onGround || (this.speed && this.speed > 15) || (this.selected && !SelectedAllPlanes))) {
2019-08-29 11:12:03 +02:00
labelText = Number(this.speed).toFixed(0).toString().padStart(4, NBSP)+ " "
+ this.altitude.toString().padStart(5, NBSP) + " \n " + this.name + " ";
2019-08-29 15:45:12 +02:00
} else {
labelText = " " + this.name + " ";
}
2019-08-28 20:42:47 +02:00
} else {
2019-08-29 11:12:03 +02:00
labelText = " " + this.name + " ";
2019-08-28 20:42:47 +02:00
}
2019-08-22 16:58:25 +02:00
}
var styleKey = svgKey + '!' + labelText + '!' + this.scale;
2019-07-26 15:21:08 +02:00
2019-08-20 14:30:26 +02:00
if (this.markerStyle == null || this.markerIcon == null || (this.markerSvgKey != svgKey)) {
2019-07-26 15:21:08 +02:00
//console.log(this.icao + " new icon and style " + this.markerSvgKey + " -> " + svgKey);
this.markerSvgKey = svgKey;
this.rotationCache = this.rotation;
2019-08-25 01:46:57 +02:00
if (iconCache[svgKey] == undefined) {
var svgURI = svgPathToURI(this.baseMarker.svg, outline, col, add_stroke);
2019-08-25 01:46:57 +02:00
addToIconCache.push([svgKey, null, svgURI]);
this.markerIcon = new ol.style.Icon({
2019-08-22 16:58:25 +02:00
scale: this.scale,
imgSize: this.baseMarker.size,
2019-08-24 14:03:12 +02:00
src: svgURI,
rotation: (this.baseMarker.noRotate ? 0 : this.rotation * Math.PI / 180.0),
2019-08-22 16:58:25 +02:00
rotateWithView: (this.baseMarker.noRotate ? false : true),
});
} else {
this.markerIcon = new ol.style.Icon({
2019-08-22 16:58:25 +02:00
scale: this.scale,
imgSize: this.baseMarker.size,
img: iconCache[svgKey],
rotation: (this.baseMarker.noRotate ? 0 : this.rotation * Math.PI / 180.0),
2019-08-22 16:58:25 +02:00
rotateWithView: (this.baseMarker.noRotate ? false : true),
});
2019-08-20 14:30:26 +02:00
}
2019-08-20 16:39:30 +02:00
//iconCache[svgKey] = undefined; // disable caching for testing
2019-08-22 16:58:25 +02:00
}
if (this.styleKey != styleKey) {
this.styleKey = styleKey;
if (labelText) {
this.markerStyle = new ol.style.Style({
image: this.markerIcon,
text: new ol.style.Text({
text: labelText ,
fill: new ol.style.Fill({color: 'white' }),
backgroundFill: new ol.style.Stroke({color: 'rgba(0,0,0,0.4'}),
textAlign: 'left',
textBaseline: "top",
font: 'bold 12px tahoma',
2019-08-22 17:34:41 +02:00
offsetX: (this.baseMarker.size[0]*0.5*0.74*this.scale),
offsetY: (this.baseMarker.size[0]*0.5*0.74*this.scale),
2019-08-22 16:58:25 +02:00
}),
zIndex: this.zIndex,
});
} else {
this.markerStyle = new ol.style.Style({
image: this.markerIcon,
zIndex: this.zIndex,
});
}
2019-08-22 16:58:25 +02:00
this.marker.setStyle(this.markerStyle);
}
/*
if (this.opacityCache != opacity) {
this.opacityCache = opacity;
2019-07-26 15:21:08 +02:00
this.markerIcon.setOpacity(opacity);
}
*/
2019-08-22 16:58:25 +02:00
if (this.rotationCache == null || Math.abs(this.rotationCache - this.rotation) > 0.15) {
this.rotationCache = this.rotation;
this.markerIcon.setRotation(this.baseMarker.noRotate ? 0 : this.rotation * Math.PI / 180.0);
}
if (this.scaleCache != this.scale) {
this.scaleCache = this.scale;
this.markerIcon.setScale(this.scale);
}
2019-07-26 15:21:08 +02:00
return true;
};
// Update our data
2019-10-13 13:42:23 +02:00
PlaneObject.prototype.updateData = function(now, last, data, init) {
2019-07-28 23:59:46 +02:00
// get location data first, return early if only those are needed.
var isArray = Array.isArray(data);
// [.hex, .alt_baro, .gs, .track, .lat, .lon, .seen_pos, mlat/tisb/.type , .flight]
2019-10-28 20:12:11 +01:00
// 0 1 2 3 4 5 6 7 8
// this format is only valid for chunk loading the history
2019-10-28 20:12:11 +01:00
const alt_baro = isArray? data[1] : data.alt_baro;
const gs = isArray? data[2] : data.gs;
const track = isArray? data[3] : data.track;
const lat = isArray? data[4] : data.lat;
const lon = isArray? data[5] : data.lon;
var seen = isArray? data[6] : data.seen;
2019-10-28 20:12:11 +01:00
const seen_pos = isArray? data[6] : data.seen_pos;
2019-10-29 18:56:48 +01:00
seen = (seen == null) ? 5 : seen;
var mlat = isArray? (data[7] == "mlat") : (data.mlat != null && data.mlat.indexOf("lat") >= 0);
const type = isArray? data[7] : data.type;
2019-10-28 20:12:11 +01:00
const flight = isArray? data[8] : data.flight;
2019-10-13 13:42:23 +02:00
this.last_message_time = now - seen;
if (noMLAT && mlat)
return;
2019-08-24 10:44:20 +02:00
// remember last known position even if stale
2019-10-13 06:41:32 +02:00
// and some other magic to avoid mlat positions when a current ads-b position is available
if (lat != null && this.dataSource != "mlat" && mlat && this.position != null && now - this.position_time < mlatTimeout) {
2019-10-13 06:41:32 +02:00
mlat = false;
// don't use MLAT for mlatTimeout (default 30) seconds after getting an ADS-B position
// console.log(this.icao + ': mlat position ignored');
if (debug && this.prev_position) {
this.drawRedDot([lon, lat]);
}
2019-10-13 13:42:23 +02:00
} else if (lat != null && seen_pos < (now - this.position_time + 2)) {
this.position = [lon, lat];
2019-10-13 13:42:23 +02:00
this.position_time = now - seen_pos;
2019-08-05 08:37:26 +02:00
}
// remember last known altitude even if stale
var altitude = null;
if (alt_baro != null) {
altitude = alt_baro;
this.alt_baro = alt_baro;
} else if (data.altitude != null) {
altitude = data.altitude;
this.alt_baro = data.altitude;
} else {
this.alt_baro = null;
if (data.alt_geom != null) {
altitude = data.alt_geom;
}
2019-08-20 14:30:26 +02:00
}
// Filter anything greater than 10000 fpm
if (this.altitude == null || altitude == "ground" || this.altitude == "ground") {
this.altitude = altitude;
} else if (altitude != null && this.altitude != altitude
&& (Math.abs(altitude - this.altitude) / (now - this.altitudeTime) < 160)) {
this.altitude = altitude;
}
2019-10-29 10:07:30 +01:00
if (altitude != null && seen < 5)
this.altitudeTime = now;
2019-08-20 14:30:26 +02:00
2019-08-24 14:03:12 +02:00
this.alt_rounded = calcAltitudeRounded(this.altitude);
2019-08-22 16:58:25 +02:00
if (this.altitude == "ground") {
this.onGround = true;
this.zIndex = -10000;
} else {
this.onGround = false;
this.zIndex = this.alt_rounded;
}
2019-08-28 20:42:47 +02:00
// needed for track labels
this.speed = gs;
2019-08-28 20:42:47 +02:00
// don't expire the track, even display outdated track
if (track != null) {
this.track = track;
this.rotation = track;
}
2019-10-28 20:12:11 +01:00
// don't expire callsigns
if (flight != null) {
this.flight = flight;
this.name = flight;
2019-10-28 20:12:11 +01:00
}
2019-08-03 20:26:12 +02:00
2019-10-13 06:41:32 +02:00
if (mlat)
2019-09-18 22:31:46 +02:00
this.dataSource = "mlat";
else if (type && type.substring(0,4) == "tisb")
2019-10-13 06:41:32 +02:00
this.dataSource = "tisb";
else if (!displayUATasADSB && this.receiver == "uat")
this.dataSource = "uat";
else if (lat != null && type == null)
2019-10-13 06:41:32 +02:00
this.dataSource = "adsb";
else if (type == "adsb_icao" || type == "adsb_other")
2019-10-13 06:41:32 +02:00
this.dataSource = "adsb";
else if (type && type.substring(0,4) == "adsr")
2019-10-13 06:41:32 +02:00
this.dataSource = "adsb";
else if (type == "adsb_icao_nt")
2019-10-13 06:41:32 +02:00
this.dataSource = "other";
2019-10-30 16:51:58 +01:00
if (init || isArray)
return;
2019-07-28 23:59:46 +02:00
2019-07-26 15:21:08 +02:00
// Update all of our data
2019-10-13 13:42:23 +02:00
if (this.receiver == "1090") {
const messageRate = (data.messages - this.msgs1090)/(now - last);
this.messageRate = (messageRate + this.messageRateOld)/2;
this.messageRateOld = messageRate;
2019-10-13 13:42:23 +02:00
this.msgs1090 = data.messages;
} else {
const messageRate = (data.messages - this.msgs978)/(now - last);
this.messageRate = (messageRate + this.messageRateOld)/2;
this.messageRateOld = messageRate;
2019-10-13 13:42:23 +02:00
this.msgs978 = data.messages;
}
2019-10-30 16:51:58 +01:00
this.messages = data.messages ? data.messages : 0;
2019-10-13 13:42:23 +02:00
this.rssi = data.rssi;
2019-07-26 15:21:08 +02:00
if (data.gs != null)
this.gs = data.gs;
else if (data.speed != null)
this.gs = data.speed;
else
this.gs = null;
if (data.baro_rate != null)
this.baro_rate = data.baro_rate;
else if (data.vert_rate != null)
this.baro_rate = data.vert_rate;
else
this.baro_rate = null;
2019-07-26 15:21:08 +02:00
// simple fields
2019-07-28 23:59:46 +02:00
this.alt_geom = data.alt_geom;
this.ias = data.ias;
this.tas = data.tas;
this.track_rate = data.track_rate;
this.mag_heading = data.mag_heading;
this.mach = data.mach;
this.roll = data.roll;
this.nav_altitude = data.nav_altitude;
this.nav_heading = data.nav_heading;
this.nav_modes = data.nav_modes;
this.nac_p = data.nac_p;
this.nac_v = data.nac_v;
this.nic_baro = data.nic_baro;
this.sil_type = data.sil_type;
this.sil = data.sil;
this.nav_qnh = data.nav_qnh;
this.geom_rate = data.geom_rate;
this.rc = data.rc;
this.squawk = data.squawk;
2019-07-26 15:21:08 +02:00
// fields with more complex behaviour
2019-09-22 09:47:34 +02:00
if (data.version != null) {
this.version = data.version;
}
if (data.category != null) {
this.category = data.category;
}
if (data.true_heading != null)
2019-07-26 15:21:08 +02:00
this.true_heading = data.true_heading;
else
this.true_heading = null;
2019-07-26 15:21:08 +02:00
if (data.type != null)
2019-08-03 20:26:12 +02:00
this.addrtype = data.type;
else
this.addrtype = null;
2019-07-26 15:21:08 +02:00
2019-10-13 06:41:32 +02:00
if (this.position && SitePosition) {
2019-07-28 23:59:46 +02:00
//var WGS84 = new ol.Sphere(6378137);
//this.sitedist = WGS84.haversineDistance(SitePosition, this.position);
this.sitedist = ol.sphere.getDistance(SitePosition, this.position);
2019-07-26 15:21:08 +02:00
}
// Pick a selected altitude
if (data.nav_altitude_fms != null) {
2019-07-26 15:21:08 +02:00
this.nav_altitude = data.nav_altitude_fms;
} else if (data.nav_altitude_mcp != null){
2019-07-26 15:21:08 +02:00
this.nav_altitude = data.nav_altitude_mcp;
} else {
this.nav_altitude = null;
}
// Pick vertical rate from either baro or geom rate
// geometric rate is generally more reliable (smoothed etc)
if (data.geom_rate != null ) {
2019-07-26 15:21:08 +02:00
this.vert_rate = data.geom_rate;
} else if (data.baro_rate != null) {
2019-07-26 15:21:08 +02:00
this.vert_rate = data.baro_rate;
} else if (data.vert_rate != null) {
// legacy from mut v 1.15
this.vert_rate = data.vert_rate;
2019-07-26 15:21:08 +02:00
} else {
this.vert_rate = null;
}
if (this.flight && this.flight.trim()) {
2019-08-22 16:58:25 +02:00
this.name = this.flight;
} else if (this.registration) {
this.name = '_' + this.registration;
2019-08-22 16:58:25 +02:00
} else {
this.name = '_' + this.icao.toUpperCase();
2019-08-22 16:58:25 +02:00
}
this.name = this.name.trim();
if (this.altitude == "ground" && this.true_heading != null) {
this.rotation = this.true_heading;
} else if (this.track != null) {
this.rotation = this.track;
} else if (this.true_heading != null) {
2019-08-22 16:58:25 +02:00
this.rotation = this.true_heading;
} else if (this.mag_heading != null) {
2019-08-22 16:58:25 +02:00
this.rotation = this.mag_heading;
} else if (
this.position && this.prev_position
2019-08-22 16:58:25 +02:00
&& this.position[0] != this.prev_position[0]
&& this.position[1] != this.prev_position[1]
&& ol.sphere.getDistance(this.position, this.prev_position) > 50
2019-08-22 16:58:25 +02:00
) {
this.rotation = bearingFromLonLat(this.prev_position, this.position);
}
2019-07-26 15:21:08 +02:00
};
2019-10-13 13:42:23 +02:00
PlaneObject.prototype.updateTick = function(now, last, init) {
2019-07-26 15:21:08 +02:00
// recompute seen and seen_pos
2019-10-13 13:42:23 +02:00
this.seen = now - this.last_message_time;
this.seen_pos = now - this.position_time;
2019-07-26 15:21:08 +02:00
// If no packet in over 58 seconds, clear the plane.
2019-07-30 19:59:17 +02:00
// Only clear the plane if it's not selected individually
2019-10-28 10:43:07 +01:00
if (
(this.seen > 58 || this.position == null || this.seen_pos > 60)
&& (!this.selected || SelectedAllPlanes || multiSelect)
&& (!noVanish || this.position == null)
) {
2019-07-26 15:21:08 +02:00
if (this.visible) {
//console.log("hiding " + this.icao);
this.clearMarker();
this.clearLines();
2019-07-26 15:21:08 +02:00
this.visible = false;
if (SelectedPlane == this.icao)
selectPlaneByHex(null,false);
}
} else {
this.visible = true;
2019-10-13 13:42:23 +02:00
if (init || this.updateTrack(now, last)) {
this.updateLines();
this.updateMarker(true);
} else {
this.updateMarker(false); // didn't move
2019-07-26 15:21:08 +02:00
}
}
};
PlaneObject.prototype.clearMarker = function() {
2019-08-25 01:46:57 +02:00
if (this.marker && this.marker.visible) {
//PlaneIconFeatures.remove(this.marker);
this.marker.setStyle(emptyStyle);
this.marker.visible = false;
2019-07-26 15:21:08 +02:00
}
};
// Update our marker on the map
PlaneObject.prototype.updateMarker = function(moved) {
if (!this.visible || this.position == null || this.isFiltered()) {
this.clearMarker();
return;
}
2019-08-20 14:30:26 +02:00
if (!this.marker) {
2019-07-26 15:21:08 +02:00
this.marker = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
this.marker.hex = this.icao;
PlaneIconFeatures.push(this.marker);
2019-08-20 14:30:26 +02:00
} else if (moved) {
this.marker.setGeometry(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
2019-07-26 15:21:08 +02:00
}
2019-08-25 01:46:57 +02:00
2019-08-20 14:30:26 +02:00
this.updateIcon();
2019-08-25 01:46:57 +02:00
if (!this.marker.visible) {
this.marker.visible = true;
this.marker.setStyle(this.markerStyle);
}
2019-07-26 15:21:08 +02:00
};
// return the styling of the lines based on altitude
PlaneObject.prototype.altitudeLines = function(altitude) {
var colorArr = this.getAltitudeColor(altitude);
2019-10-16 08:06:01 +02:00
//var color = 'hsl(' + colorArr[0].toFixed(0) + ', ' + colorArr[1].toFixed(0) + '%, ' + colorArr[2].toFixed(0) + '%)';
var color = hslToRgb(colorArr[0], colorArr[1], colorArr[2]);
2019-10-29 13:06:50 +01:00
const lineKey = color + '_' + debugTracks + '_' + noVanish;
if (lineStyleCache[lineKey])
return lineStyleCache[lineKey];
2019-10-15 17:04:36 +02:00
if (!debugTracks) {
2019-10-29 13:06:50 +01:00
lineStyleCache[lineKey] = new ol.style.Style({
stroke: new ol.style.Stroke({
color: color,
width: (2-(noVanish*0.8)),
})
});
2019-08-04 14:28:01 +02:00
} else {
2019-10-29 13:06:50 +01:00
lineStyleCache[lineKey] = [
new ol.style.Style({
image: new ol.style.Circle({
radius: 2,
fill: new ol.style.Fill({
color: color
})
}),
geometry: function(feature) {
return new ol.geom.MultiPoint(feature.getGeometry().getCoordinates());
}
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: color,
2019-08-04 10:02:47 +02:00
width: 2
})
})
];
2019-08-04 14:28:01 +02:00
}
2019-10-29 13:06:50 +01:00
return lineStyleCache[lineKey];
2019-07-26 15:21:08 +02:00
}
// Update our planes tail line,
PlaneObject.prototype.updateLines = function() {
if (!this.selected)
return;
if (this.track_linesegs.length == 0)
return;
2019-08-05 20:27:56 +02:00
// create the new elastic band feature
var lastseg = this.track_linesegs[this.track_linesegs.length - 1];
var lastfixed = lastseg.fixed.getCoordinateAt(1.0);
var geom = new ol.geom.LineString([lastfixed, ol.proj.fromLonLat(this.position)]);
this.elastic_feature = new ol.Feature(geom);
if (filterTracks && this.altFiltered(lastseg.altitude)) {
this.elastic_feature.setStyle(nullStyle);
} else if (lastseg.estimated) {
this.elastic_feature.setStyle(noVanish ? nullStyle : estimateStyle);
2019-08-05 20:27:56 +02:00
} else {
this.elastic_feature.setStyle(this.altitudeLines(lastseg.altitude));
}
// elastic feature is always at index 0 for each aircraft
this.trail_features.setAt(0, this.elastic_feature);
// create any missing fixed line features
2019-08-05 20:27:56 +02:00
for (var i = this.track_linesegs.length-1; i >= 0; i--) {
var seg = this.track_linesegs[i];
if (seg.feature && (!trackLabels || seg.label))
break;
if (filterTracks && this.altFiltered(seg.altitude)) {
} else if (!seg.feature) {
seg.feature = new ol.Feature(seg.fixed);
if (seg.estimated) {
seg.feature.setStyle(noVanish ? nullStyle : estimateStyle);
} else {
seg.feature.setStyle(this.altitudeLines(seg.altitude));
}
seg.feature.hex = this.icao;
this.trail_features.push(seg.feature);
}
if (filterTracks && this.altFiltered(seg.altitude)) {
} else if (trackLabels && !seg.label && seg.alt_real != null) {
2019-08-28 19:53:58 +02:00
seg.label = new ol.Feature(new ol.geom.Point(seg.fixed.getFirstCoordinate()));
2019-08-29 11:12:03 +02:00
const text = seg.alt_real == "ground" ? "" :
(Number(seg.speed).toFixed(0).toString().padStart(6, NBSP) + " \n" + seg.alt_real.toString().padStart(6, NBSP)) + " ";
2019-08-28 19:53:58 +02:00
seg.label.setStyle(
new ol.style.Style({
text: new ol.style.Text({
text: text,
2019-08-28 19:53:58 +02:00
fill: new ol.style.Fill({color: 'white' }),
backgroundFill: new ol.style.Stroke({color: 'rgba(0,0,0,0.4'}),
textAlign: 'left',
textBaseline: "top",
font: 'bold 12px tahoma',
offsetX: 5,
offsetY: 5,
}),
})
);
seg.label.hex = this.icao;
2019-08-28 19:53:58 +02:00
this.trail_features.push(seg.label);
}
}
2019-07-26 15:21:08 +02:00
2019-08-06 09:04:39 +02:00
// after making sure everything is drawn, also show the layer
if (!this.layer.getVisible())
this.layer.setVisible(true);
2019-07-26 15:21:08 +02:00
};
PlaneObject.prototype.remakeTrail = function() {
this.trail_features.clear();
for (var i in this.track_linesegs) {
2019-08-28 19:53:58 +02:00
this.track_linesegs[i].feature = undefined;
this.track_linesegs[i].label = undefined;
}
this.elastic_feature = null;
trailGroup.remove(this.layer);
this.trail_features = new ol.Collection();
this.layer = new ol.layer.Vector({
name: this.icao,
isTrail: true,
source: new ol.source.Vector({
features: this.trail_features,
2019-08-29 08:28:50 +02:00
}),
renderOrder: null,
});
trailGroup.push(this.layer);
this.updateLines();
}
2019-07-26 15:21:08 +02:00
PlaneObject.prototype.destroy = function() {
this.clearLines();
this.clearMarker();
this.visible = false;
2019-08-25 01:46:57 +02:00
if (this.marker) {
PlaneIconFeatures.remove(this.marker);
}
trailGroup.remove(this.layer);
this.trail_features.clear();
2019-08-03 18:06:35 +02:00
if (this.tr) {
this.tr.removeEventListener('click', this.clickListener);
this.tr.removeEventListener('dblclick', this.dblclickListener);
if (this.tr.parentNode)
this.tr.parentNode.removeChild(this.tr);
2019-08-03 18:06:35 +02:00
this.tr = null;
}
2019-08-04 22:51:30 +02:00
if (this.icao == SelectedPlane)
SelectedPlane = null;
2019-08-22 17:34:41 +02:00
for (var key in Object.keys(this)) {
delete this[key];
}
2019-07-26 15:21:08 +02:00
};
2019-08-24 14:03:12 +02:00
function calcAltitudeRounded(altitude) {
if (altitude == "ground") {
return altitude;
} else if (altitude > 10000) {
return (altitude/1000).toFixed(0)*1000;
} else {
return (altitude/500).toFixed(0)*500;
}
}
2019-10-13 06:41:32 +02:00
PlaneObject.prototype.drawRedDot = function(bad_position) {
if (debugJump && loadFinished && SelectedPlane != this) {
2019-10-13 06:41:32 +02:00
OLMap.getView().setCenter(ol.proj.fromLonLat(bad_position));
selectPlaneByHex(this.icao, false);
}
var badFeat = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(bad_position)));
badFeat.setStyle(this.dataSource == "mlat" ? badDotMlat : badDot);
this.trail_features.push(badFeat);
var geom = new ol.geom.LineString([ol.proj.fromLonLat(this.prev_position), ol.proj.fromLonLat(bad_position)]);
var lineFeat = new ol.Feature(geom);
lineFeat.setStyle(this.altitudeLines(this.dataSource == "mlat" ? 0 : 60000));
this.trail_features.push(lineFeat);
2019-10-13 06:41:32 +02:00
}
2019-10-16 08:06:01 +02:00
/**
* Converts an HSL color value to RGB. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes h, s, and l are contained in the set [0, 1] and
* returns r, g, and b in the set [0, 255].
*
* @param {number} h The hue
* @param {number} s The saturation
* @param {number} l The lightness
* @return {Array} The RGB representation
*/
function hslToRgb(h, s, l){
var r, g, b;
h /= 360;
s *= 0.01;
l *= 0.01;
if(s == 0){
r = g = b = l; // achromatic
}else{
var hue2rgb = function hue2rgb(p, q, t){
if(t < 0) t += 1;
if(t > 1) t -= 1;
if(t < 1/6) return p + (q - p) * 6 * t;
if(t < 1/2) return q;
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
return 'rgb(' + Math.round(r * 255) + ', ' + Math.round(g * 255) + ', ' + Math.round(b * 255) + ')';
}