Don't duplicate radar names for entity

This commit is contained in:
30hours 2024-02-13 10:39:06 +00:00
parent d933ffecb5
commit 33ceedf6dc

View file

@ -149,6 +149,7 @@ var viewer = new Cesium.Viewer("cesiumContainer", {
// Create a point entity
const pointEntity = viewer.entities.add({
name: pointName,
position,
point: {
color: Cesium.Color.fromCssColorString(pointColor),
@ -187,7 +188,6 @@ window.addEventListener('load', function () {
style_radar.type = "radar";
style_radar.timestamp = Date.now();
radar_config_url.forEach(url => {
console.log(url);
fetch(url)
.then(response => {
if (!response.ok) {
@ -197,7 +197,7 @@ window.addEventListener('load', function () {
})
.then(data => {
// add radar rx and tx
// todo: check not duplicating points
if (!doesEntityNameExist(data.location.rx.name)) {
addPoint(
data.location.rx.latitude,
data.location.rx.longitude,
@ -208,6 +208,8 @@ window.addEventListener('load', function () {
style_radar.type,
style_radar.timestamp
);
}
if (!doesEntityNameExist(data.location.tx.name)) {
addPoint(
data.location.tx.latitude,
data.location.tx.longitude,
@ -218,6 +220,7 @@ window.addEventListener('load', function () {
style_radar.type,
style_radar.timestamp
);
}
})
.catch(error => {
// Handle errors during fetch
@ -241,3 +244,15 @@ function event_loop() {
setTimeout(event_loop, 1000);
}
function doesEntityNameExist(name) {
// loop over all entities in the viewer
viewer.entities.values.forEach((entity) => {
if (entity.name === name) {
return true;
}
});
return false;
}