Checking accuracy circle !== null when setting color

This commit is contained in:
tuffnerdstuff 2021-04-01 14:55:08 +02:00
parent 9d637c5b58
commit 02ccb4fcd2

View file

@ -732,8 +732,8 @@ function processUpdate(data, init) {
}
// Draw an accuracy circle if GPS accuracy was provided by the
// client.
if (shares[user].circle == null) {
shares[user].circle = L.circle([lat, lon], {radius: acc != null ? acc : 0, fillColor: iconColor, fillOpacity: 0.25, color: iconColor, opacity: 0.5, interactive: false}).addTo(circleLayer);
if (acc !== null && shares[user].circle == null) {
shares[user].circle = L.circle([lat, lon], {radius: acc, fillColor: iconColor, fillOpacity: 0.25, color: iconColor, opacity: 0.5, interactive: false}).addTo(circleLayer);
} else if (shares[user].circle !== null) {
shares[user].circle.setLatLng([lat, lon]);
if (acc !== null) shares[user].circle.setRadius(acc);
@ -856,19 +856,13 @@ function processUpdate(data, init) {
}
eLastSeen.textContent = unit.split("{{time}}").join(time);
}
shares[user].circle.setStyle({
fillColor: STATE_DEAD_COLOR,
color: STATE_DEAD_COLOR
})
setAccuracyCircleColor(shares[user].circle, STATE_DEAD_COLOR);
} else {
eArrow.className = eArrow.className.split("dead").join(shares[user].state);
if (eLabel !== null) eLabel.className = shares[user].state;
var iconColor = STATE_LIVE_COLOR;
if (shares[user].state == "rough") iconColor = STATE_ROUGH_COLOR;
shares[user].circle.setStyle({
fillColor: iconColor,
color: iconColor
});
setAccuracyCircleColor(shares[user].circle, iconColor);
}
}
}
@ -890,6 +884,15 @@ function processUpdate(data, init) {
}
}
function setAccuracyCircleColor(circle, color) {
if( circle ) {
circle.setStyle({
fillColor: color,
color: color
});
}
}
// Calculates the distance between two points on a sphere using the Haversine
// algorithm.
function distance(from, to) {