Struggling with progressive json loads

74 views
Skip to first unread message

João Pedro Bourbon

unread,
Feb 20, 2014, 9:06:12 AM2/20/14
to timemap-d...@googlegroups.com
Hi guys,

First off, this is an amazing tool, congrats to the devs.
Now, I'm having a bit of trouble with the progressive load example 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){
//echo $v[1]." - ".strtotime($_GET['start'])." - "; 
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 and keep up with the great work! :)

João Pedro Bourbon

unread,
Feb 25, 2014, 3:25:21 PM2/25/14
to timemap-d...@googlegroups.com
Hi guys,

Ok, so this one is solved. I just had to make sure the return didn't include the duplicates on the server side.

Now I'm facing another challenge. In the mxn.openlayers.core.js the map is initialized with a OSM map set to use meters. However, I need to use a WMS map on a EPSG:4326 projection. So I did some tinkering and now I pass an object from timemaps with specific options for map customization to the mxn. It works perfectly BUT...
although the lat/lon in the mxn marker object is in degrees, the native openlayers marker is still in meters, so it won't show in the mao.
This appears to be caused by the .toProprietary method in the marker.

Any ideas?

Thanks :)

João Pedro Bourbon

unread,
Feb 25, 2014, 4:34:31 PM2/25/14
to timemap-d...@googlegroups.com
Well, sorry for the monologue :)

I figured out how to correct the problem.
I added

pin.lonlat.lon = marker.location.lon;
pin.lonlat.lat = marker.location.lat;

to the addMarkers method on mxn.openlayers.core.js and it works like a charm now :)
I can share the changes I did to the mxn and the timemap if anyone is interested, I think it is useful to have some more control over the map initialization, including the possibility of adding layers directly from timemap, specifying a div for the layerswitcher and having a graticule and overview control.

Cheers :)
Reply all
Reply to author
Forward
0 new messages