Example #1
0
function make_kml($mid)
{
    $map = map_get_single($mid);
    if ($map === false) {
        return array(false, "no such map");
    }
    // 把地圖拿出來換成 kml
    $gpx = str_replace(".tag.png", ".gpx", $map['filename']);
    // test kml happyman add test path
    $cachefile = sprintf("/srv/www/htdocs/map/gpxtmp/test/%06d/%d/%s", $map['uid'], $map['mid'], basename(str_replace(".gpx", ".kml", $gpx)));
    if (file_exists($gpx)) {
        if (0 && file_exists($cachefile) && filemtime($cachefile) >= filemtime($gpx)) {
            return array(true, $cachefile);
        }
        @mkdir(dirname($cachefile), 0755, true);
        //$cmds_args[10]  = "-x nuketypes,tracks,routes -x simplify,count=10 -x position,distance=20k";
        //	$cmds_args[11]  = "-x nuketypes,tracks,routes -x position,distance=10k";
        //	$cmds_args[12]  = "-x nuketypes,tracks,routes -x position,distance=5k";
        //$cmds_args[13]  = "-x nuketypes,tracks,routes -x position,distance=2k";
        //$cmds_args[14]  = "-x nuketypes,tracks,routes -x position,distance=1k";
        //$cmds_args[15]  = "-x nuketypes,tracks,routes -x position,distance=500m";
        //$cmds_args[16]  = "-x nuketypes,tracks,routes -x position,distance=200m";
        //$cmds_args[17]  = "-x nuketypes,tracks,routes -x position,distance=100m";
        //$cmds_args[18]  = "-x nuketypes,tracks,routes -x position,distance=1m";
        $cmd = sprintf("gpsbabel -i gpx -f %s -x nuketypes,points -o kml,lines=1,points=0,line_color=%s,line_width=3 -F %s", $gpx, pick_color($mid), $cachefile);
        exec($cmd);
        return array(true, $cachefile);
    } else {
        return array(false, "no gpx");
    }
}
Example #2
0
/**
 * [tilestache_clean 新增/刪除 mid 的時候 hook
 * @param  [type] $mid [description]
 * @return [type]      [description]
 */
function tilestache_clean($mid)
{
    $row = map_get_single($mid);
    //print_r($row);
    echo "clean " . $row['title'] . "\n";
    if ($row == null) {
        return array(false, "no such map");
    }
    $tl = proj_67toge(array($row['locX'], $row['locY']));
    $br = proj_67toge(array($row['locX'] + $row['shiftX'] * 1000, $row['locY'] - $row['shiftY'] * 1000));
    //$cmd = sprintf("ssh 172.31.39.193 'tilestache-clean.py -c ~wwwrun/etc/tilestache.cfg -l twmap_gpx -b %f %f %f %f 10 11 12 13 14 15 16 17 18 2>&1'",$tl[1],$tl[0],$br[1],$br[0]);
    $cmd = sprintf("tilestache-clean.py -c ~www-data/etc/tilestache.cfg -l twmap_gpx -b %f %f %f %f 10 11 12 13 14 15 16 17 18 2>&1", $tl[1], $tl[0], $br[1], $br[0]);
    error_log("tilestache_clean: " . $cmd);
    /*
      利用 tilestache-clean 的 output 來砍另一層 cache 
    
      10164 of 10192... twmap_gpx/18/219563/112348.png
      10165 of 10192... twmap_gpx/18/219564/112348.png
      10166 of 10192... twmap_gpx/18/219565/112348.png
      10167 of 10192... twmap_gpx/18/219566/112348.png
      10168 of 10192... twmap_gpx/18/219567/112348.png
      10169 of 10192... twmap_gpx/18/219568/112348.png
      10170 of 10192... twmap_gpx/18/219569/112348.png
      10171 of 10192... twmap_gpx/18/219570/112348.png
      10172 of 10192... twmap_gpx/18/219571/112348.png
      10173 of 10192... twmap_gpx/18/219572/112348.png
      10174 of 10192... twmap_gpx/18/219573/112348.png
      10175 of 10192... twmap_gpx/18/219574/112348.png
    */
    exec($cmd, $out, $ret);
    if ($ret == 0) {
        foreach ($out as $line) {
            list($a, $png) = preg_split("/\\.\\.\\./", $line);
            $clean[] = trim($png);
        }
        return array(true, $clean);
    } else {
        return array(false, implode("\n", $out));
    }
}
Example #3
0
            $inp['starty'] = $svg->bound_twd67['tl'][1] / 1000;
            $inp['shiftx'] = ($svg->bound_twd67['br'][0] - $svg->bound_twd67['tl'][0]) / 1000;
            $inp['shifty'] = ($svg->bound_twd67['tl'][1] - $svg->bound_twd67['br'][1]) / 1000;
            $inp['ph'] = $svg->bound_twd67['ph'];
            unset($svg);
        }
    } else {
        $msgarr = array(1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini", 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3 => "The uploaded file was only partially uploaded", 4 => "No file was uploaded", 6 => "Missing a temporary folder", 7 => 'Failed to write file to disk.', 8 => 'A PHP extension stopped the file upload.');
        error_out("上傳失敗" . $msgarr[$_FILES['gpxfile']['error']]);
    }
    // end of if
    // 2.1. 處理上傳檔案
} else {
    if ($inp['gps'] == 2) {
        // a. 從 mid 確認 expire 是不是 1, 然後檔案存不存在
        $row = map_get_single($inp['gpxmid']);
        if ($row['flag'] == 1 && $row['gpx'] == 1 && $row['uid'] == $_SESSION['uid']) {
            $tmp_gpx = str_replace(".tag.png", ".gpx", $row['filename']);
            if (!file_exists($tmp_gpx)) {
                error_out("gpx 檔案已經消失");
            }
        } else {
            error_out("gpx 資訊有誤");
        }
        $inp['startx'] = $row['locX'] / 1000;
        $inp['starty'] = $row['locY'] / 1000;
        $inp['shiftx'] = $row['shiftX'];
        $inp['shifty'] = $row['shiftY'];
        if (strstr($tmp_gpx, "p.gpx")) {
            $inp['ph'] = 1;
        } else {
Example #4
0
<?php

// 1. 檢查是不是在 2013/9/6 - 2013/10/18 之間產生的地圖
// 如果是就重新產生,不然就直接 redirect
//
session_start();
require_once "config.inc.php";
$mid = $_GET['mid'];
$map = map_get_single($mid);
if ($map == null) {
    echo "<h1>無此 map" . print_r($_GET, true) . "</h1>";
    exit(0);
}
$kmzfile = str_replace(".png", ".kmz", $map['filename']);
$mtime = filemtime($kmzfile);
// 這一段時間有 bug
$start = strtotime("2013-9-6");
$end = strtotime("2013-10-18 23:00");
if ($mtime > $start && $mtime < $end) {
    unlink($kmzfile);
    error_log("remake...kmz");
    require_once "lib/garmin.inc.php";
    $kmz = new garminKMZ(3, 3, $map['filename'], strstr($map['filename'], 'v3p') ? 1 : 0);
    $kmz->doit();
}
$kmzname = basename($kmzfile);
$size = filesize($kmzfile);
header("Content-type: application/vnd.google-earth.kmz");
header("Content-Disposition: filename=\"{$kmzname}\"");
header("Content-Length: {$size}");
readfile($kmzfile);
Example #5
0
// $Id: backend_del.php 282 2012-05-17 08:49:51Z happyman $
// 1. check login
session_start();
if (empty($_SESSION['loggedin'])) {
    header("Location: login.php");
    exit(0);
}
require_once "config.inc.php";
// 2. check _POST
$_inp = $_POST;
if (!isset($_inp['mid'])) {
    error_out(print_r($_POST, true) . " requires mid");
}
// 3. 檢查 user 是否能刪除此檔
$map = map_get_single($_inp['mid']);
if ($map == null) {
    error_out("no such map" . $_inp['mid']);
}
if ($map['uid'] != $_SESSION['uid']) {
    error_out("you are not the owner");
}
// 3.1 正在搬移資料結構, 或重新整理
$block_msg = map_blocked($out_root, $_SESSION['uid']);
if ($block_msg != null) {
    error_out($block_msg);
}
// 4. 真的刪除/回收
if ($_inp['op'] && $_inp['op'] == 'recycle') {
    $ok = map_expire($_inp['mid']);
} else {