Hello -
Some cut-and-pasting from a recent email on a similar question (I should probably make this a wiki page sometime soon):
The idea here is a JSONP model:
http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/
This won't work unless your JSON is being generated by a script (e.g. in PHP) rather than a static file. The idea is that you specify a function name in the URL parameters, then repeat that in the script - so if the url is
http://www.example.com/mydata.php?callback=SPAMthe script would return
SPAM(...some data...);
so that the function SPAM() gets called. Timemap.js will generate the function name automatically - the first time you load data, it'll be TimeMap.loaders.jsonp._0, then ._1, etc - so all you need to supply as a url is "
http://www.example.com/mydata.php?callback=" - but then you're responsible for writing the script so that it takes the "callback" parameter and puts it into the output, e.g. (in PHP):
$func = $_GET['callback'];
echo $func . '(' . $myjsonstring . ');';
To load data from a separate JSON file, without messing with any JSONP issues, there are two ways: the easy way and the harder way. The harder way is to use the json_string loader, which requires the development version of timemap.js (version 1.5, not yet released - I should be releasing it soon, but it's likely to be another week or two - to get it now, you'll need to get it using a subversion program:
http://code.google.com/p/timemap/source/checkout). You can see the loading syntax here:
http://code.google.com/p/timemap/source/browse/trunk/tests/loadTests.js#160and what the file might look like here:
http://code.google.com/p/timemap/source/browse/trunk/tests/data/data_string.jsBut if you don't need to pass any parameters to the JSON file (that is, if you are always going to want the same set of data), then you can do it the easy way, which is just to declare it in a global variable in a separate file:
var myItems = [{...item 1...}, etc]
Then, when you call TimeMap.init(), just use the "basic" loader and load your variable:
datasets: [
{
title: "Test Dataset",
id: "test",
data: {
type: "basic",
value: myItems
}
}
]
I hope that helps.
-Nick