Skip to content

Commit 2c391fd

Browse files
author
xss
committed
initial changes for culling
1 parent 77cf4cd commit 2c391fd

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

js/tracker.js

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var clientID = "SondeHub-Tracker-" + Math.floor(Math.random() * 10000000000);
1515
var client = new Paho.Client(livedata, clientID);
1616
var clientConnected = false;
1717
var clientActive = false;
18-
var clientTopic;
18+
var clientTopic = [];
1919
var messageRate = 0;
2020
var messageRateAverage = 10;
2121

@@ -712,6 +712,29 @@ function throttle_events(event) {
712712
}
713713
}
714714

715+
function sub_to_nearby_sondes(){
716+
let bounds = map.getBounds().pad(1); // expand by one viewport
717+
for (let vehicle in vehicles){
718+
let topic = "sondes/"+vehicle;
719+
inside_bounds = map.getBounds().pad(1).contains(vehicles[vehicle].marker._latlng)
720+
if (inside_bounds){
721+
if (!clientTopic.includes(topic)){
722+
console.log("Subbing to " + topic)
723+
client.subscribe(topic);
724+
clientTopic.push(topic)
725+
}
726+
} else {
727+
if (clientTopic.includes(topic) ){
728+
console.log("unsubbing from " + topic)
729+
client.unsubscribe(topic)
730+
var topic_index = clientTopic.indexOf(topic)
731+
if (topic_index > -1) {
732+
clientTopic.splice(topic_index, 1);
733+
}
734+
}
735+
}
736+
}
737+
}
715738

716739
function clean_refresh(text, force, history_step) {
717740
force = !!force;
@@ -732,14 +755,16 @@ function clean_refresh(text, force, history_step) {
732755
}
733756

734757
try {
735-
client.unsubscribe(clientTopic);
758+
for (let topic in clientTopic){
759+
client.unsubscribe(topic);
760+
}
736761
if (wvar.query && sondePrefix.indexOf(wvar.query) == -1) {
737762
var topic = "sondes/" + wvar.query;
738763
client.subscribe(topic);
739-
clientTopic = topic;
764+
clientTopic = [topic];
740765
} else {
741-
client.subscribe("batch");
742-
clientTopic = "batch";
766+
client.subscribe("sondes-new/#");
767+
clientTopic =["sondes-new/#"];
743768
}
744769
} catch (err) {}
745770

@@ -941,6 +966,7 @@ function load() {
941966
map.on('moveend', function (e) {
942967
lhash_update();
943968
sidebar_update();
969+
sub_to_nearby_sondes();
944970
});
945971

946972
map.on('baselayerchange', function (e) {
@@ -949,6 +975,7 @@ function load() {
949975
});
950976

951977
map.on('zoomend', function() {
978+
sub_to_nearby_sondes();
952979
//do check for horizon labels
953980
if (offline.get("opt_hide_horizon")) {
954981
for (key in vehicles) {
@@ -1094,6 +1121,12 @@ function openURL(address){
10941121
function panTo(vcallsign) {
10951122
if(!vcallsign || vehicles[vcallsign] === undefined) return;
10961123

1124+
for (let serial in vehicles) {
1125+
vehicles[serial].polyline_visible = false;
1126+
set_polyline_visibility(serial,false);
1127+
}
1128+
vehicles[vcallsign].polyline_visible = true;
1129+
set_polyline_visibility(vcallsign,true);
10971130
// update lookangles
10981131
update_lookangles(vcallsign);
10991132

@@ -1782,7 +1815,6 @@ function updateVehicleInfo(vcallsign, newPosition) {
17821815
'<i class="arrow"></i></div>' +
17831816
'<div class="data">' +
17841817
'<img class="'+((vehicle.vehicle_type=="car")?'car':'')+'" src="'+image+'" />' +
1785-
'<span class="vbutton path '+((vehicle.polyline_visible) ? 'active' : '')+'" data-vcallsign="'+vcallsign+'"' + ' style="top:'+(vehicle.image_src_size[1]+55)+'px">Path</span>' +
17861818
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="shareVehicle(\'' + vcallsign + '\')" style="top:'+(vehicle.image_src_size[1]+85)+'px">Share</span>' : '') +
17871819
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="skewTdraw(\'' + vcallsign + '\')" style="top:'+(vehicle.image_src_size[1]+115)+'px">SkewT</span>' : '') +
17881820
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="openURL(\'' + grafana_dashboard_url + '\')" style="top:'+(vehicle.image_src_size[1]+145)+'px">Plots</span>' : '') +
@@ -1795,7 +1827,6 @@ function updateVehicleInfo(vcallsign, newPosition) {
17951827
'<i class="arrow"></i></div>' +
17961828
'<div class="data">' +
17971829
'<img class="'+((vehicle.vehicle_type=="car")?'car':'')+'" src="'+image+'" />' +
1798-
'<span class="vbutton path '+((vehicle.polyline_visible) ? 'active' : '')+'" data-vcallsign="'+vcallsign+'"' + ' style="top:55px">Path</span>' +
17991830
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="shareVehicle(\'' + vcallsign + '\')" style="top:85px">Share</span>' : '') +
18001831
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="skewTdraw(\'' + vcallsign + '\')" style="top:115px">SkewT</span>' : '') +
18011832
((vehicle.vehicle_type!="car") ? '<span class="sbutton" onclick="openURL(\'' + grafana_dashboard_url + '\')" style="top:145px">Plots</span>' : '') +
@@ -2206,10 +2237,10 @@ function redrawPrediction(vcallsign) {
22062237
color: balloon_colors[vehicle.color_index],
22072238
opacity: 0.5, // Was 0.4
22082239
weight: 3,
2209-
}).addTo(map);
2210-
vehicle.prediction_polyline.on('click', function (e) {
2211-
mapInfoBox_handle_prediction_path(e);
2212-
});
2240+
})//.addTo(map);
2241+
// vehicle.prediction_polyline.on('click', function (e) {
2242+
// mapInfoBox_handle_prediction_path(e);
2243+
// });
22132244
}
22142245

22152246
vehicle.prediction_polyline.path_length = path_length;
@@ -3104,13 +3135,13 @@ function addPosition(position) {
31043135
} catch (err) {}
31053136
});
31063137

3107-
polyline_visible = true;
3138+
polyline_visible = false;
31083139
polyline = [
31093140
new L.Polyline(point, {
31103141
color: balloon_colors[color_index],
31113142
opacity: 1,
31123143
weight: 3,
3113-
}).addTo(map)
3144+
})
31143145
];
31153146
}
31163147

@@ -3738,10 +3769,10 @@ function liveData() {
37383769
if (wvar.query && sondePrefix.indexOf(wvar.query) == -1) {
37393770
var topic = "sondes/" + wvar.query;
37403771
client.subscribe(topic);
3741-
clientTopic = topic;
3772+
clientTopic = [topic];
37423773
} else {
3743-
client.subscribe("batch");
3744-
clientTopic = "batch";
3774+
client.subscribe("sondes-new/#");
3775+
clientTopic = ["sondes-new/#"];
37453776
}
37463777
// Also subscribe to listener data, for listener and chase-car telemetry.
37473778
// To revert listener-via-websockets change, comment out this line,

0 commit comments

Comments
 (0)