Skip to content

Commit 88fd4a0

Browse files
author
xss
committed
add more culling demo stuff
1 parent 2c391fd commit 88fd4a0

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

js/tracker.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -714,22 +714,33 @@ function throttle_events(event) {
714714

715715
function sub_to_nearby_sondes(){
716716
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);
717+
let zoomed_out = map.getZoom() <= 7;
718+
if (zoomed_out){
719+
// If we are fairly zooomed out - only give the slow feed
720+
for(let i = 1; i<clientTopic.length; i++){ // skip first slow topic
721+
console.log("zoomed fully out. unsubbing from " + clientTopic[i])
722+
client.unsubscribe(clientTopic[i]);
723+
}
724+
clientTopic = [clientTopic[0]]
725+
} else {
726+
// If zoomed in then we sub to specific sondes
727+
for (let vehicle in vehicles){
728+
let topic = "sondes/"+vehicle;
729+
inside_bounds = map.getBounds().pad(1).contains(vehicles[vehicle].marker._latlng)
730+
if (inside_bounds){
731+
if (!clientTopic.includes(topic)){
732+
console.log("Subbing to " + topic)
733+
client.subscribe(topic);
734+
clientTopic.push(topic)
735+
}
736+
} else {
737+
if (clientTopic.includes(topic) ){
738+
console.log("unsubbing from " + topic)
739+
client.unsubscribe(topic)
740+
var topic_index = clientTopic.indexOf(topic)
741+
if (topic_index > -1) {
742+
clientTopic.splice(topic_index, 1);
743+
}
733744
}
734745
}
735746
}

0 commit comments

Comments
 (0)