gets prediction CSV from server via ajax

pull/73/head
jonsowman 2010-05-27 23:51:57 +01:00
rodzic d99da9a417
commit c698d54235
3 zmienionych plików z 36 dodań i 10 usunięć

20
ajax.php 100644
Wyświetl plik

@ -0,0 +1,20 @@
<?php
$action = $_GET['action'];
switch($action) {
case "getCSV":
$uuid = $_GET['uuid'];
$fh = fopen("preds/".$uuid."/flight_path.csv", "r");
$data = array();
while (!feof($fh)) {
$line = trim(fgets($fh));
array_push($data, $line);
}
$returned = json_encode($data);
echo $returned;
break;
}
?>

Wyświetl plik

@ -159,10 +159,18 @@ function predSub() {
appendDebug("Downloading GRIB data for tile, this could take some time..."); appendDebug("Downloading GRIB data for tile, this could take some time...");
} }
function handlePred() { function handlePred(pred_uuid) {
appendDebug("Prediction running with uuid: " + running_uuid); appendDebug("Prediction running with uuid: " + running_uuid);
appendDebug("Prediction done for uuid: " + running_uuid); appendDebug("Prediction done for uuid: " + running_uuid);
// now go get the prediction data from the server // now go get the prediction data from the server
getCSV(pred_uuid);
}
function getCSV(pred_uuid) {
$.get("ajax.php", { "action":"getCSV", "uuid":pred_uuid }, function(data) {
//alert(data.length);
parseCSV(data);
}, 'json');
} }
function appendDebug(appendage) { function appendDebug(appendage) {
@ -187,13 +195,12 @@ function initialize() {
mapTypeId: google.maps.MapTypeId.ROADMAP mapTypeId: google.maps.MapTypeId.ROADMAP
}; };
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
parseCSV("new.csv"); // debug remove //parseCSV("new.csv"); // debug remove
if ( form_submitted ) handlePred(); if ( form_submitted ) handlePred(running_uuid);
} }
function parseCSV(csv_name) { function parseCSV(lines) {
$.get(csv_name, null, function(data, textStatus) { alert(lines[0]);
var lines = data.split('\n');
var path = []; var path = [];
var max_height = -10; //just any -ve number var max_height = -10; //just any -ve number
var max_point = null; var max_point = null;
@ -259,7 +266,7 @@ function parseCSV(csv_name) {
strokeColor: '#000000', strokeColor: '#000000',
strokeWeight: 3, strokeWeight: 3,
strokeOpacity: 0.75 strokeOpacity: 0.75
}); });
path_polyline.setMap(map); path_polyline.setMap(map);
@ -270,7 +277,6 @@ function parseCSV(csv_name) {
title: 'Balloon burst (max. altitude: ' + max_height + 'm)', title: 'Balloon burst (max. altitude: ' + max_height + 'm)',
}); });
});
} }
</script> </script>

Wyświetl plik

@ -1,2 +1,2 @@
2010052712 2010052718
1274961600 1274983200