Updating/refreshing Timeline Data

309 views
Skip to first unread message

Paul Duggan

unread,
Oct 6, 2009, 10:25:54 AM10/6/09
to SIMILE Widgets
Hi,

First off, I'd just like to say how great Timeline is, really enjoying
working with it.
I have a a fairly simple question (I hope) about changing the data
source.

I've gone through the getting started tutorial here:
http://code.google.com/p/simile-widgets/wiki/Timeline_GettingStarted
I'd now like to add a Javascript function to change the data source.
E.g. load a new XML file and refresh the Timeline.

I've searched a lot and found references to paint(), and update() but
I can't work out how to use them.

Here is the simple sort of code I'm trying:

function updateData(filename) {
Timeline.loadJSON(filename, function(json, url) {eventSource.loadJSON
(json, url); });
tl.layout();
}

I'm sure someone can tell me what I'm doing wrong fairly quickly.

Many Thanks,

Michael Nosal

unread,
Oct 6, 2009, 11:12:11 AM10/6/09
to simile-...@googlegroups.com
The code below is the right direction.

A couple of things:
* This code will add events to your eventSource, not replace the
existing events. You'd need to call eventSource.clear() if you want to
blow away the old events.
* You said "load a new XML file" but the code below is for json.
change 'json' to 'xml' and you're good (unless you really are loading
json).
* You need to have a valid reference for eventSource in the inner
anonymous function. Try:

function updateData(filename) {
var eventSource = tl.getBand(0).getEventSource();
Timeline.loadJSON(filename,
function(json, url) {eventSource.loadJSON(json,url); });
tl.layout();
}

Use the index of whichever band you want to load the data into in the
call to getBand.
If your bands have different event sources, then you'd need to
call .loadJSON on each one separately.

--Mike Nosal

Paul Duggan

unread,
Oct 6, 2009, 11:47:10 AM10/6/09
to SIMILE Widgets
Thank you very much. That works perfectly!
It wasn't clear to me that you had to call getBand() in order to get
to the event source.

Thanks again,
Reply all
Reply to author
Forward
0 new messages