dongzhiman2162 2014-02-20 14:44
浏览 47

时间图时间轴中的重复元素(渐进式加载)

I'm having a bit of trouble with the progressive load example in Timemap (https://github.com/datadesk/timemap/blob/master/examples/progressive.html) which I'm using as a base for a project. So I have a data file with more than 6k lines, so I figured I didn't want to go through all of the file every time a request as made to the server, so I created an index file mapping the lines where each year begin, so I could quickly jump to the appropriate beginning and ending lines on the big file.

Here is the service file:

<?php
// get timestamps
$start = strtotime($_GET['start']);
$end = strtotime($_GET['end']);
$cb = $_GET['callback'];


//index file
$ifile = "../indexfile.txt";
if(file_exists($ifile)){
    $ihandler = fopen($ifile, "r");
}
$index = array();
while (($line = fgetcsv($ihandler, 50, " ")) !== FALSE) {
    if ($line[0] != "1"){
        $index[] = array($line[0],strtotime($line[3]."-".$line[1]."-".$line[2]));
    }
}
$startline = 0;
$endline = 0;
$flag = true;
foreach($index as $k => $v){
    if($flag == true){
        if($v[1] >= strtotime($_GET['start'])){
            $startline = $v[0];
            $flag = false;
        }
    }
    if($v[1] >= strtotime($_GET['end'])){
        $endline = $v[0];
        break;
    }
}

//load file
$file = "../file.txt";
if(file_exists($file)){
    $handler = file($file);
} 

// start data
echo "$cb([";

for($i=$startline-1;$i<=$endline-1;$i++){
    $line = explode("\t", $handler[$i]);

    if(strlen($line[2]) == 1){$line[2] = "0".$line[2];}
    if(strlen($line[3]) == 1){$line[3] = "0".$line[3];}
    if($i>$startline-1){echo ',';}

    echo '{';
    echo 'title:"'.rtrim($line[6]).'",';
    echo 'start:"'.$line[4].'-'.$line[2].'-'.$line[3].'T12:00:00-0100",';
    echo 'point:{lat:'.$line[1].',lon:'.$line[0].'},';
    echo 'options:{theme:"theme_'.iconsize(rtrim($line[6])).'",infoHtml:"<div>'.$line[5].' - '.rtrim($line[6]).' Lorem ipsum... bla bla bla...</div>"}';
    echo '}';
}
        // end data
echo "])";

//function to calculate the size of the icon in percentage of the maximum size
function iconsize($size){
    $min = 169;
    $max = 577214;

    $isize = ceil(($size/$max)*10);

    return $isize;
}
?>

The index file has a pair line/year; The file proper is a tabbed set of values such as lon/lat, month, day, year, date and value The timemap uses openlayers instead of google maps like the original, other than that it's similar.

Now the problem: I have some duplicate data appearing on the timeline (not the map), but the json responses are absolutely correct. If I decrease the interval for the requests the duplication (or triplication or *plication) inscreases, and if I increase the interval it decreases. My theory is that timemap saves the load results in the same array but doesn't check for repeated that in subsequent responses from the server. Is this the case? And how can I correct this?

Thanks :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 组策略中的计算机配置策略无法下发
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)