Skip to content

Commit 96e9bf4

Browse files
added infobox to prediction burst/land/path
1 parent 62f2a29 commit 96e9bf4

File tree

1 file changed

+67
-28
lines changed

1 file changed

+67
-28
lines changed

js/tracker.js

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ function stringToDateUTC(text) {
502502
return new Date(text.replace(" ","T") + "Z");
503503
}
504504

505-
function formatDate(date) {
505+
function formatDate(date,utc) {
506506
var a,b,c,d,e,f,g,z;
507507

508508
a = date.getFullYear();
@@ -512,7 +512,12 @@ function formatDate(date) {
512512
f = twoZeroPad(date.getMinutes());
513513
g = twoZeroPad(date.getSeconds());
514514

515-
return a+'-'+b+'-'+c+' '+e+':'+f+':'+g;
515+
if(typeof utc != "undefined") {
516+
z = date.getTimezoneOffset() / -60;
517+
return a+'-'+b+'-'+c+' '+e+':'+f+':'+g+" UTC"+((z<0)?"-":"+")+z;
518+
} else {
519+
return a+'-'+b+'-'+c+' '+e+':'+f+':'+g;
520+
}
516521
}
517522

518523
function updateVehicleInfo(index, newPosition) {
@@ -672,24 +677,6 @@ function updateVehicleInfo(index, newPosition) {
672677
return true;
673678
}
674679

675-
function addMarker(icon, latlng) {
676-
var marker = new google.maps.Marker({
677-
position: latlng,
678-
optimized: false,
679-
zIndex: Z_SHADOW,
680-
icon: {
681-
url: icon,
682-
scaledSize: new google.maps.Size(20,20),
683-
size: new google.maps.Size(20,20),
684-
anchor: new google.maps.Point(10, 10)
685-
},
686-
map: map,
687-
clickable: false
688-
});
689-
690-
return marker;
691-
}
692-
693680
function removePrediction(vehicle_index) {
694681
if(vehicles[vehicle_index].prediction_polyline) {
695682
vehicles[vehicle_index].prediction_polyline.setMap(null);
@@ -715,14 +702,18 @@ function redrawPrediction(vehicle_index) {
715702
var max_alt = -99999;
716703
var latlng_burst = null;
717704
var burst_index = 0;
705+
var path_length = 0;
706+
718707
for(var i = 0, ii = data.length; i < ii; i++) {
719708
latlng = new google.maps.LatLng(data[i].lat, data[i].lon);
720709
line.push(latlng);
710+
721711
if(parseFloat(data[i].alt) > max_alt) {
722712
max_alt = parseFloat(data[i].alt);
723713
latlng_burst = latlng;
724714
burst_index = i;
725715
}
716+
if(i > 1) path_length += google.maps.geometry.spherical.computeDistanceBetween(line[i-1], line[i]);
726717
}
727718

728719
if(typeof vehicle.prediction_polyline !== 'undefined') {
@@ -735,9 +726,11 @@ function redrawPrediction(vehicle_index) {
735726
strokeColor: balloon_colors[vehicle.color_index],
736727
strokeOpacity: 0.4,
737728
strokeWeight: 3,
738-
clickable: false,
729+
clickable: true,
739730
draggable: false,
740731
});
732+
vehicle.prediction_polyline.path_length = path_length;
733+
google.maps.event.addListener(vehicle.prediction_polyline, 'click', mapInfoBox_handle_path);
741734
}
742735
var image_src;
743736
if(vehicle_names[vehicle_index] != "wb8elk2") { // WhiteStar
@@ -746,8 +739,22 @@ function redrawPrediction(vehicle_index) {
746739
vehicle.prediction_target.setPosition(latlng);
747740
} else {
748741
image_src = host_url + markers_url + "target-" + balloon_colors_name[vehicle.color_index] + ".png";
749-
vehicle.prediction_target = addMarker(image_src, latlng);
742+
vehicle.prediction_target = new google.maps.Marker({
743+
position: latlng,
744+
optimized: false,
745+
zIndex: Z_SHADOW,
746+
icon: {
747+
url: image_src,
748+
scaledSize: new google.maps.Size(20,20),
749+
size: new google.maps.Size(20,20),
750+
anchor: new google.maps.Point(10, 10)
751+
},
752+
map: map,
753+
clickable: true
754+
});
755+
google.maps.event.addListener(vehicle.prediction_target, 'click', mapInfoBox_handle_prediction);
750756
}
757+
vehicle.prediction_target.pdata = data[data.length-1];
751758
} else {
752759
if(vehicle.prediction_target) vehicle.prediction_target = null;
753760
}
@@ -757,8 +764,22 @@ function redrawPrediction(vehicle_index) {
757764
vehicle.prediction_burst.setPosition(latlng_burst);
758765
} else {
759766
image_src = host_url + markers_url + "balloon-pop.png";
760-
vehicle.prediction_burst = addMarker(image_src, latlng_burst);
767+
vehicle.prediction_burst = new google.maps.Marker({
768+
position: latlng_burst,
769+
optimized: false,
770+
zIndex: Z_SHADOW,
771+
icon: {
772+
url: image_src,
773+
scaledSize: new google.maps.Size(20,20),
774+
size: new google.maps.Size(20,20),
775+
anchor: new google.maps.Point(10, 10)
776+
},
777+
map: map,
778+
clickable: true
779+
});
780+
google.maps.event.addListener(vehicle.prediction_burst, 'click', mapInfoBox_handle_prediction);
761781
}
782+
vehicle.prediction_burst.pdata = data[burst_index];
762783
} else {
763784
if(vehicle.prediction_burst) vehicle.prediction_burst = null;
764785
}
@@ -836,15 +857,33 @@ function drawAltitudeProfile(c1, c2, alt_list, alt_max) {
836857
var mapInfoBox = new google.maps.InfoWindow();
837858

838859
var mapInfoBox_handle_path = function(event) {
839-
var value = "";
860+
var value = ("path_length" in this) ? this.path_length : this.vehicle.path_length;
861+
862+
if(offline.get('opt_imperial')) {
863+
value = Math.round(value*0.000621371192) + " miles";
864+
} else {
865+
value = Math.round(value/10)/100 + " km";
866+
}
867+
868+
mapInfoBox.setContent("<span>Length: " + value + "</span>");
869+
mapInfoBox.setPosition(event.latLng);
870+
mapInfoBox.open(map);
871+
}
872+
var mapInfoBox_handle_prediction = function(event) {
873+
var data = this.pdata;
874+
var altitude;
840875

841876
if(offline.get('opt_imperial')) {
842-
value = Math.round(this.vehicle.path_length*0.000621371192) + "miles";
877+
altitude = Math.round(alt*3.2808399) + " feet";
843878
} else {
844-
value = Math.round(this.vehicle.path_length/10)/100 + "km";
879+
altitude = Math.round(data.alt) + " m";
845880
}
846881

847-
mapInfoBox.setContent("Length: " + value);
882+
mapInfoBox.setContent("<span>" + formatDate(new Date(parseInt(data.time) * 1000), true) + "</span><br/><br/>"
883+
+ "<span>Altitude: " + altitude + "</span><br/>"
884+
+ "<span>Latitude: " + data.lat + "</span><br/>"
885+
+ "<span>Longtitude: " + data.lon + "</span>"
886+
);
848887
mapInfoBox.setPosition(event.latLng);
849888
mapInfoBox.open(map);
850889
}
@@ -858,7 +897,7 @@ var mapInfoBox_handle_horizons = function(event, obj, title) {
858897
}
859898

860899

861-
mapInfoBox.setContent(title + "<br/>r = "+ value);
900+
mapInfoBox.setContent("<span>" + title + "</span><br/><span>r = "+ value + "</span>");
862901
mapInfoBox.setPosition(event.latLng);
863902
mapInfoBox.open(map);
864903
}

0 commit comments

Comments
 (0)