3lips/api/map/event/radar.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-02-14 12:42:23 +00:00
function event_radar() {
2024-02-27 01:49:10 +00:00
var radar_url = window.location.origin +
'/api' + window.location.search;
fetch(radar_url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (!data["detections_localised"]) {
return;
}
removeEntitiesOlderThanAndFade("detection", 10, 0.5);
2024-02-27 01:49:10 +00:00
for (const key in data["detections_localised"]) {
if (data["detections_localised"].hasOwnProperty(key)) {
const target = data["detections_localised"][key];
const points = target["points"];
2024-02-27 02:41:18 +00:00
for (const point in points) {
2024-02-29 15:28:03 +00:00
addPoint(
points[point][0],
points[point][1],
points[point][2],
2024-03-03 06:47:38 +00:00
"detection",
2024-02-29 15:28:03 +00:00
style_point.color,
style_point.pointSize,
style_point.type,
Date.now()
);
2024-02-27 02:41:18 +00:00
}
2024-02-27 01:49:10 +00:00
}
}
})
.catch(error => {
// Handle errors during fetch
console.error('Error during fetch:', error);
})
.finally(() => {
// Schedule the next fetch after a delay (e.g., 5 seconds)
setTimeout(event_radar, 1000);
});
2024-02-29 15:28:03 +00:00
}
var style_point = {};
2024-03-03 06:47:38 +00:00
style_point.color = 'rgba(0, 255, 0, 1.0)';
style_point.pointSize = 16;
style_point.type = "detection";
2024-02-29 15:28:03 +00:00
style_point.timestamp = Date.now();