예제 #1
0
파일: vg_tracks.php 프로젝트: vicb/VisuGps
function buildJsonTrack($track)
{
    if (isset($track['kmlUrl'])) {
        return ['kmlUrl' => $track['kmlUrl']];
    }
    if (isset($track['error'])) {
        return ['error' => $track['error']];
    }
    $track['nbPt'] = $nbPts = count($track['lat']);
    // Generate the time in second
    for ($i = 0; $i < count($track['time']['hour']); $i++) {
        $track['timeSec'][$i] = $track['time']['hour'][$i] * 3600 + $track['time']['min'][$i] * 60 + $track['time']['sec'][$i];
    }
    // Generate CHART_NBLBL labels
    for ($i = 0, $idx = 0, $step = ($nbPts - 1) / (CHART_NBLBL - 1); $i < CHART_NBLBL; $i++, $idx += $step) {
        $jsTrack['time']['label'][$i] = sprintf("%02dh%02d", $track['time']['hour'][$idx], $track['time']['min'][$idx]);
    }
    // Change the number of points to CHART_NBPTS
    for ($i = 0, $idx = 0, $step = ($nbPts - 1) / (CHART_NBPTS - 1); $i < CHART_NBPTS; $i++, $idx += $step) {
        $jsTrack['elev'][$i] = $track['elev'][$idx];
        $jsTrack['time']['hour'][$i] = sprintf("%02d", $track['time']['hour'][$idx]);
        $jsTrack['time']['min'][$i] = sprintf("%02d", $track['time']['min'][$idx]);
        $jsTrack['time']['sec'][$i] = sprintf("%02d", $track['time']['sec'][$idx]);
    }
    $jsTrack['lat'] = array();
    foreach ($track['lat'] as $lat) {
        $jsTrack['lat'][] = round($lat, 5);
    }
    $jsTrack['lon'] = array();
    foreach ($track['lon'] as $lon) {
        $jsTrack['lon'][] = round($lon, 5);
    }
    $jsTrack['elevGnd'] = GetElevGnd($track, CHART_NBPTS);
    $jsTrack['speed'] = GetSpeed($track, CHART_NBPTS);
    $jsTrack['vario'] = GetVario($track, CHART_NBPTS);
    $jsTrack['nbTrackPt'] = $track['nbPt'];
    $jsTrack['nbChartPt'] = CHART_NBPTS;
    $jsTrack['nbChartLbl'] = CHART_NBLBL;
    $jsTrack['date'] = $track['date'];
    $jsTrack['pilot'] = $track['pilot'];
    return $jsTrack;
}
예제 #2
0
function MakeTrack($url)
{
    $file = implode('', file($url));
    $track['date'] = array('day' => 0, 'month' => 0, 'year' => 0);
    $track['pilot'] = '';
    $nbPts = ParseIgc($file, $track);
    if ($nbPts < 5) {
        $nbPts = ParseGpx($file, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseTrk($file, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseNmea($file, $track);
    }
    if ($nbPts < 5) {
        $nbPts = ParseOzi($file, $track);
    }
    if ($nbPts < 5) {
        if (IsKml($file)) {
            $jsTrack['kmlUrl'] = $url;
        } else {
            $jsTrack['error'] = 'Unsupported track format!';
        }
    } else {
        // Generate the time in second
        for ($i = 0; $i < count($track['time']['hour']); $i++) {
            $track['timeSec'][$i] = $track['time']['hour'][$i] * 3600 + $track['time']['min'][$i] * 60 + $track['time']['sec'][$i];
        }
        // Generate CHART_NBLBL labels
        for ($i = 0, $idx = 0, $step = ($nbPts - 1) / (CHART_NBLBL - 1); $i < CHART_NBLBL; $i++, $idx += $step) {
            $jsTrack['time']['label'][$i] = $track['time']['hour'][$idx] . "h" . $track['time']['min'][$idx];
        }
        // Change the number of points to CHART_NBPTS
        for ($i = 0, $idx = 0, $step = ($nbPts - 1) / (CHART_NBPTS - 1); $i < CHART_NBPTS; $i++, $idx += $step) {
            $jsTrack['elev'][$i] = $track['elev'][$idx];
            $jsTrack['time']['hour'][$i] = $track['time']['hour'][$idx];
            $jsTrack['time']['min'][$i] = $track['time']['min'][$idx];
            $jsTrack['time']['sec'][$i] = $track['time']['sec'][$idx];
        }
        $jsTrack['lat'] = $track['lat'];
        $jsTrack['lon'] = $track['lon'];
        $jsTrack['elevGnd'] = GetElevGnd($track, CHART_NBPTS);
        $jsTrack['speed'] = GetSpeed($track, CHART_NBPTS);
        $jsTrack['vario'] = GetVario($track, CHART_NBPTS);
        $jsTrack['nbTrackPt'] = $track['nbPt'];
        $jsTrack['nbChartPt'] = CHART_NBPTS;
        $jsTrack['nbChartLbl'] = CHART_NBLBL;
        $jsTrack['date'] = $track['date'];
        $jsTrack['pilot'] = $track['pilot'];
    }
    //print_r($jsTrack);
    $data = json::encode($jsTrack);
    //print_r($data );
    // if (!isset($jsTrack['error']) && !isset($jsTrack['kmlUrl'])) {
    //    $cache->set($data, $url);
    // }
    return $data;
}