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 :)