mirror of
https://github.com/30hours/3lips.git
synced 2024-11-18 12:33:58 +00:00
Don't duplicate radar names for entity
This commit is contained in:
parent
d933ffecb5
commit
33ceedf6dc
1 changed files with 37 additions and 22 deletions
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue