[Geomoose-users] Diplaying Time in menu bar by Html in linksbar tag (mapbook)

Dan Little danlittle at yahoo.com
Fri Jan 8 09:22:41 EST 2010


I sure can explain that. :-)

What happens is that the Links bar is populated by simply setting the ".innerHTML" property of the DIV.  While that gives you the ability to set the HTML, the Javascript is never run because the following things never happen:
1) It doesn't trigger an onload event.
2) The inline javascript is not picked up by the interpreter at document load time, so it's not run, precisely because the document isn't "loading."

Here's what you want to do:

1) In GM 2.0.1 (which I'm assuming you're running ... or 2.0... either works):
a) Set the HTML in your Linksbar to something like:
<div id="franz-clock"></div>

b) Write the clock updating script in a file "clock.js":

function update_clock() {
    var time = new Date();
    var time_string = ...; /* place a formatting string of some sort here to format the time */
    
    var clock_div = document.getElementById('franz-clock');
    if(clock_div) {
        clock_div.innerHTML = time_string;
}

/* this will update the clock every second */
setInterval(update_clock, 1000);

c) Open up geomoose.html

After the <script ... src="compiled.js" ></script> tag add:

<script type="text/javascript" src="clock.js"></script>

d) Not having tested this code the "setInterval" command may or may not work as predicted... you'll have to test it.  If it doesn't work then you'll need to make one more modification...

Find the <body> tag and find the "onload" attribute.  This is a bunch of javascript.  At the end of it add...

onload=" ... ; setInterval(update_clock, 1000);


Now, in all honesty, this is generally a bad idea because it could break a lot when GM upgrades happen.   So, for 2.2 we invented a way for people to do exactly this kind of thing without worrying (as much) about their code being worth nothing when upgrades come down the pike.  They're called User Extensions.  For protesterity I'm going to give both the "old server link" and the "new server link" to how User Extensions will work in 2.2+.

http://www.geomoose.org/docs/user_extensions.html - link AFTER about 1/15

http://www.geomoose.org/moose/docs/user_extensions.html - link as it is NOW

In fact, if you browse SVN you can see the ColorChanger.js extension which shows an example of how to update the interface on a periodic basis using User Extensions.





>
>From: FRANZ OKYERE <franzzoa at hotmail.com>
>To: geomoose-users at lists.sourceforge.net
>Sent: Thu, January 7, 2010 2:35:49 PM
>Subject: [Geomoose-users] Diplaying Time in menu bar by Html in linksbar tag (mapbook)
>
> >
>Dear All,
>
>I need to display time information in the menu area for my applicaiton and it is not showing up. I have tried all sorts of varying javascript time codes that work. Can anyone explain why the linksbar tag can take html but will ignore my javascript code?
>
>Thanks.
>
>Franz Okyere
>
>GIS Specialist
>
>________________________________
Add other email accounts to Hotmail in 3 easy steps. Find out how.


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geomoose-users/attachments/20100108/d3d16367/attachment.html


More information about the Geomoose-users mailing list