Set time on time slider

2,826 views
Skip to first unread message

Gareth

unread,
Jul 26, 2011, 12:48:21 PM7/26/11
to google-earth-...@googlegroups.com
I have loaded up a time aware kml into my Google Earth map. The time slider appears as it is supposed to.

I am now trying to set the start time of the time slider, but having no luck. The documentation about it here is really poor:
http://code.google.com/apis/earth/documentation/time.html#creating_time_stamps_and_spans

It says you are supposed to use 'ge.createTimeStamp' and then 'ge.getTime().setTimePrimitive(timeStamp);' . But it just provides a little code snippet, not a working example. Is there a simple working example online anywhere?

Here is my code example so far:
http://chronoatlas.com/testtime.html

As you will see from the code, I am trying to get the time slider to show the year 1,000 but it keeps showing the year 20 (which is the start year of the first polyon in the kml).

I searched this forum and found some people had had some issues with the kml layer not fully loading before the time on the slider is set, I am not sure if that has anything to do with my issue but I doubt it as my example kml file is tiny.


On another note, I have no idea why the page is showing two Google Earth maps, lol. I don't think there is anything in the code that specifies to show two maps, I think that must be some sort of bug.

Brendan Kenny

unread,
Jul 28, 2011, 7:27:43 PM7/28/11
to KML Developer Support - Google Earth Plug-in
Hi Gareth,

The time slider is designed to cover the range of all the dates
currently loaded (including any historical imagery, if enabled).
Currently there is no way to manually limit the time range displayed.
If you'd like to see this added you can file a feature request, but as
a workaround you can always construct your own time control, either
from normal html elements or some concoction of overlays in the
plugin.

As for the double plugin in your example, currently you are
registering two callbacks to the init() function, one in
google.setOnLoadCallback() and one on the body tag's onload attribute.
Removing one will eliminate the problem.

Cheers,
Brendan

On Jul 26, 9:48 am, Gareth wrote:
> I have loaded up a time aware kml into my Google Earth map. The time slider
> appears as it is supposed to.
>
> I am now trying to set the start time of the time slider, but having no
> luck. The documentation about it here is really poor:http://code.google.com/apis/earth/documentation/time.html#creating_ti...
>
> It says you are supposed to use *'ge.**createTimeStamp' *and then *'ge.
> getTime().setTimePrimitive(timeStamp**);'* . But it just provides a little

Gareth

unread,
Aug 2, 2011, 4:44:54 PM8/2/11
to google-earth-...@googlegroups.com
Thanks for the reply Brendan, I am not trying to limit the time range on the slider, but simply set the current time on the slider (i.e. how far along the slider is currently slid to). Is that also not possible?

If so, does that mean that if I were to load more than 1 kml file into the map and provide checkboxes to allow the user to specify which kml to view, the date in the time slider will always get sent back to the earliest date in the newly displayed kml? Or is just when the map is initially loaded that the time slider date gets set to the lowest possible value?

Josh L

unread,
Aug 3, 2011, 12:44:32 AM8/3/11
to KML Developer Support - Google Earth Plug-in
Hi Gareth,

You can find an example of how to set the time at the code playground:
http://code.google.com/apis/ajax/playground/#time_and_historical_imagery_ui

Cheers,

-Josh

Gareth

unread,
Aug 4, 2011, 10:13:48 AM8/4/11
to google-earth-...@googlegroups.com
Thank for the reply Josh, I had previously seen that example in the code playground but i was not able to get it to do anything when I hit the button that says "Run Code" in the code playground. In the output section I just seem to get a plain Google Earth map without even a time slider showing. I am thus reluctant to try and copy and paste the code into my own web page when I can't seem to get it to even do anything in the code playground. I have tried in both mozilla firefox and internet explorer. For example the code has a section that says "//add buttons and textbox" but in the output I do not even see any buttons or texrtbox.

Brendan Kenny

unread,
Aug 5, 2011, 6:44:32 PM8/5/11
to KML Developer Support - Google Earth Plug-in
Hi Gareth,

The relevant code in that example is:

function setTime(){
var timeText = document.getElementById('inputTime').value;
var gts = ge.createTimeStamp('');
gts.getWhen().set(timeText);
ge.getTime().setTimePrimitive(gts);
}

timeText is just a string, but it needs to be a properly formatted XML
Schema time. See the KmlDateTime reference for more:

http://code.google.com/apis/earth/documentation/reference/interface_kml_date_time.html

Note that the entire dateTime string isn't required; the string can be
right truncated. For instance, if you only need to specify the year
and month, 'yyyy-mm' would be sufficient.

Cheers,
Brendan

Gareth

unread,
Aug 8, 2011, 10:36:43 AM8/8/11
to google-earth-...@googlegroups.com
Brendan,

I have taken your function and pasted it into my code, but I cannot get it to work. It is called in the page load and it can also be called by pressing the button above the map. But in neither does it adjust the time. I have tried using '2001', '2001-01' and '2001-01-01' but none of them work.

The code is in the same place as before:
http://chronoatlas.com/testtime.html

Is there anything wrong with my code? Do you have a working example where you actually got that setTime() function to work?

Thanks,

Gareth


Gareth

unread,
Aug 8, 2011, 10:56:19 AM8/8/11
to google-earth-...@googlegroups.com
I checked the error consule in Mozilla FireFox and it says "ge.createTimeStamp is not a function", so I googled that and found this forum thread:

http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/f854ed133dd020bf

The suggested solution is to create a unique identifier for the timestamp when it is created, but that did not work for me when I tried it. So the issue is still not resolved. If anyone has a working example of setting the time then I would love to see it.

Josh L

unread,
Aug 8, 2011, 2:46:46 PM8/8/11
to KML Developer Support - Google Earth Plug-in
It sounds like you might be using an old version of the plugin before
this functionality was added (plugin 5.2.1.1329 and API 1.005). Can
you confirm what plugin version you're testing with, and update to the
latest if that's the issue?

Cheers,

-Josh

On Aug 8, 7:56 am, Gareth wrote:
> I checked the error consule in Mozilla FireFox and it says
> "ge.createTimeStamp is not a function", so I googled that and found this
> forum thread:
>
> http://groups.google.com/group/google-earth-browser-plugin/browse_thr...

Gareth

unread,
Aug 8, 2011, 5:00:50 PM8/8/11
to google-earth-...@googlegroups.com
Thanks for all your help guys. I am not sure what version of the plug-in I have. In my control panel it is not listed, only Google Earth is listed and no version # is listed there. How can I find out what version of the plug-in I have?

As for the API, is that simply what number you call in the line google.load('earth', number here)? If so i have been using 1, but I just tried to change it to 1.005 but it made no difference.

Josh L

unread,
Aug 8, 2011, 5:24:01 PM8/8/11
to KML Developer Support - Google Earth Plug-in
You can go to http://code.google.com/apis/earth/ and look at the small
grey letters below the demo which will show the plugin version, or you
can use the plugin methods such as getEarthVersion() or
getApiVersion() to programmatically call it yourself.

Cheers,

-Josh

Chuck Anderson

unread,
Aug 9, 2011, 7:34:37 AM8/9/11
to KML Developer Support - Google Earth Plug-in
HI Gareth,

The set time button worked for me once the page is loaded. You might
be having a similar problem to one I had. I was trying to do a set
time when a new kml file was loaded, but it did not seem to work.
Problem was the kml load was taking too long. It would start loading,
the set time function was execute, and then the kml file would finish
loading and automatically set the time to the beginning of its time
range. I got it wokring by putting the set time function call in a
framend event listener and then removed the event listener after a
short time out in the set time function. Probably a more ellgant way
of doing it, but this worked for me.

// set time to current time
google.earth.addEventListener(ge, 'frameend', setTime);

// set time function
function setTime() {
ge.getTime().setTimePrimitive(time);
setTimeout("google.earth.removeEventListener(ge, 'frameend',
setTime)",750);
}

Cheers,
Chuck

Gareth

unread,
Aug 9, 2011, 11:07:36 AM8/9/11
to google-earth-...@googlegroups.com
A million thanks to Chuck, Josh, and Brendan for helping me out on this. After 2 weeks I finally got it to work!

It was a combination of both Josh and Chuck's final suggestions. I did need to update to the latest version of Google Earth AND I also did need to add that frame end listener thing to get it to work on the initial page load.

Here it is working properly:

http://chronoatlas.com/testtime.html

The strange thing is that now that the time is set, the time slider has zoomed in so that it only displays one year, how do I zoom back out on the time slider so that it displays the whole time period of the kml again?

On an unrelated note, it was not the Google Earth plug-in that I had to update but Google Earth itself. I do not think i even have the plug-in, if I have Google Earth on my computer does that mean that I do not need the plug-in?

Gareth

unread,
Aug 9, 2011, 12:17:55 PM8/9/11
to google-earth-...@googlegroups.com
With regards to trying to get the time slider to zoom back out programatically, I tried this:


function setExtents(){

ge.getTime().getControl().getExtents().getBegin().set('20');
ge.getTime().getControl().getExtents().getEnd().set('2005');
alert(ge.getTime().getControl().getExtents().getBegin().get());
}
But it will not set the extents on the time slider, it appears to be read only.

On another note, it seems that every other time the page is refreshed, it will be zoomed fully out on the time slider when it sets the time. In other words, the first time the page is loaded, the time slider will be zoomed in to cover 1 year, but then when I hit refresh the page reloads and the time slider is zoomed fully out after setting the time, then if I hit reload again, it zooms back in again after setting the time, and so on.

I have no idea why this is, I have even tried to call the function to set the time twice to see if on the second time it will zoom out on the time slider but it does not.

Chuck Anderson

unread,
Aug 9, 2011, 5:18:24 PM8/9/11
to KML Developer Support - Google Earth Plug-in
I noticed the same behavior on Gareth's page and also on a page of
mine that worked perfectly well about a month ago. Has there been an
update to the plugin since then? On my page a I have radio buttons
triggering a loadKML function. Whether reloading the same file, or
switching to another, every other load sets the time slider ot one
year, and the next to the proper time span.

Chuck

Brendan Kenny

unread,
Aug 11, 2011, 10:51:49 PM8/11/11
to KML Developer Support - Google Earth Plug-in
Gareth: The plugin and the Google Earth client update together (unless
you used the standalone installer), but they are separate programs. I
am not able to replicate your problem on your test page, but it's
possible you've changed your code since you posted (I don't see the
time control at all, for instance). Is it possible for you to change
it back so I can see it in action (or save a copy to a separate page)?

If you'd like to star the feature request for setting arbitrary
extents on the time control, the bug is here:
http://code.google.com/p/earth-api-samples/issues/detail?id=538

Chuck: It is possible that your system delayed updating for some
reason, but there has been no update in the last month. The release
dates and notes are here:
http://code.google.com/apis/earth/documentation/releasenotes.html

Cheers,
Brendan

Gareth

unread,
Aug 19, 2011, 3:55:56 PM8/19/11
to google-earth-...@googlegroups.com
Hi again Brendan et al,

I had to take down the old link to the example with the bug, but I have put it back here:

http://northmiamicra.org/testtimeover1000years.html

I have been playing around with it for a little bit more and have now isolated the error: it only occurs when there are more than 1,000 years of extent on the time slider.

I am still talking about the bug where on every other page refresh, the time slider is zoomed into a single year extent after setting the time.

For example, here it works without any error:

http://northmiamicra.org/testtime.html

The two pages are 100% identical, and so is the time aware KML file that is loaded, except for one tiny detail, one has a total time extent of 1001 years and the other has a total time extent of 999 years. The former reproduces the error on every other page refresh, the latter produces no error.

Any help or workaround on this would be really appreciated.



Brendan Kenny

unread,
Aug 22, 2011, 6:25:18 PM8/22/11
to KML Developer Support - Google Earth Plug-in
Hi Gareth,

Well that is definitely strange. I've tried rearranging some things
and haven't found a workaround yet, but I'll keep trying. The plugin
process itself isn't reset between refreshes, so obviously some state
is being retained, but the way that it is doing so seems especially
odd.

Would you mind opening a bug in the issue tracker? I'll link it to the
internal tracker so that anyone that wants updates can star your bug
and be CCed:

http://code.google.com/p/earth-api-samples/issues/entry?template=Bug

Thanks for your detective work!

Cheers,
Brendan

Brendan Kenny

unread,
Aug 22, 2011, 7:14:26 PM8/22/11
to KML Developer Support - Google Earth Plug-in
Just as an additional data point, this looks like it isn't a problem
with the setTimePrimitive() functionality of the API, but a bug in
Earth itself. If you add the same KML to the Earth client it will
display 1008-2009. If you delete it, then add it again, it will have
zoomed in to 1008-1009. If you delete it then add it again, it will
have zoomed out to 1008-2009, and so on.

This doesn't change the problem (and it would still be handy to have
the bug in our tracker), but it is something to be aware of when
trying to work around the issue.

Cheers,
Brendan
Reply all
Reply to author
Forward
0 new messages