[Chameleon] HTML Legend with Javascript

Jacob Delfos jacob.delfos at maunsell.com
Sun Oct 3 02:17:11 EDT 2004


Robin,

I'm no expert, but as far as I know it's not possible to pass javascript 
or DHTML values into the page loaded next (e.g. after submit). I think 
the best way around it is to create a hidden form variable for the state 
of each folder (values "closed", "open") and then use a function called 
using the body's "onLoad" to re-set the status of each folder to what 
its form variable says it should be. It is possible because form 
variables will find their way into the newly loaded page. The other 
(perhaps more logical but more difficult) way is to use frames. You will 
have a hard time getting your legend frame to communicate with the 
mapframe, though. But it should be faster once it works. I think someone 
did something like this with an iframe once.

regards,

Jacob


-----Original Message-----
From: chameleon-bounces at lists.maptools.org
To: pspencer at dmsolutions.ca; Paul Spencer
Cc: chameleon at lists.maptools.org
Sent: 2/10/2004 1:46 AM
Subject: Re: [Chameleon] HTML Legend with Javascript

Paul,

I have made all the changes you indicated but I still have the refresh
problem.  The
code creates an expanding/collapsing legend but with any zoom/update
etc, all folders
go back to the starting state of closed.

Am I missing something?  Should my legend still have all divisions with
style="display:'none'"? or should I be checking for something?

Robin


Quoting Paul Spencer <pagameba at magma.ca>:

 > Warning: This message has had one or more attachments removed
 > Warning: (jsExpander.js).
 > Warning: Please read the "VirusWarning.txt" attachment(s) for more
information.
 >
 > Robin,
 >
 > this gets a little more complicated ... I've extracted the code into a

 > separate js and css file (attached).
 >
 > You can remove the cExpander related javascript and <style> sections
in
 > your application template and add the following:
 >
 > <script language="JavaScript" src="jsExpander.js"></script>
 > <link href="jsExpander.css" rel="stylesheet" type="text/css">
 >
 > Your legend template is slightly modified, in the group section add:
 >
 > //this is the existing line
 > oGroup = new cExpander( CWCDHTML_GetLayer( '[leg_group_name]', true
));
 > //this is the new line
 > goExpanderManager.add( oGroup );
 >
 > in your application template, you will also need to add:
 >
 > <input type="hidden" name="ExpanderStatus"
value="[$ExpanderStatus|$]">
 >
 > and right after the legend template widget you will need to add:
 >
 >    <cwc2 type="LegendTemplate" visible="true" embedded="true"
 > template="fancy_legend.html" popupstyleresource="TextButtons"
 > popupwidth="500" popupheight="400" status="false" menubar="false"/>
 >
 > <script language="JavaScript" type="text/javascript">
 > goExpanderManager.formElement = document.forms[0].ExpanderStatus;
 > goExpanderManager.initialize();
 > </script>
 >
 > Cheers,
 >
 > Paul
 >
 > Robin Brown wrote:
 > > Paul,
 > >
 > > Nope, not working:)  I quickly gave up as I would need too many
variables to get
 > > everything running smoothly and as you suggested, this would cause
problems in the
 > > future.  I am now using the code you so kindly provided.  I am
having trouble with
 > the
 > > refresh problem.  Is it possible to change the legend template file
from the
 > chameleon
 > > template where I have the script?  I tried to check the value of
 > > this.element.style.display in my legend template and use this value
but I get an
 > error.
 > >  I think it is because on the initial render, these values would not
be set yet?
 > I'm
 > > not entirely sure it is even possible to do this.  Sorry to be
asking so many
 > > questions.  I am new to all of this and have been struggling with
the legend for
 > the
 > > last 2+ weeks.  Also, is it ok for me to put this up on the wiki
after I get it
 > > functioning properly?  It is really your code but if you don't mind,
I would like
 > to do
 > > anything I can to help new users as there is not much out there on
creating
 > dynamic
 > > legends.  Thanks again for all your help.
 > >
 > > Robin
 > >
 > >
 > > Quoting Paul Spencer <pagameba at magma.ca>:
 > >
 > >
 > >>let me know if you get it working ... I did try a solution that used

 > >>metadata in the map file but I generally avoid that as changes to
the
 > >>map file can break things if you are not very careful about keeping
all
 > >>the metadata synchronized etc.
 > >>
 > >>Robin Brown wrote:
 > >>
 > >>>Paul,
 > >>>
 > >>>Wow, thanks.  This looks very complicated.  I would not have been
able to do this
 > >>
 > >>on my
 > >>
 > >>>own!  I think though that I am going to try something else first:)
I was looking
 > >>
 > >>at
 > >>
 > >>>the wiki for HTML legends and I saw that you can set wms variables
and check them
 > >>
 > >>in
 > >>
 > >>>the legend template.  I thought for each layer I can specify if it
has classes or
 > >>
 > >>not.
 > >>
 > >>>If it does, I will start a new division and end that division in
the
 > >>
 > >>[leg_class_html]
 > >>
 > >>>section.  If the layer doesn't have classes, I won't bother
starting a new
 > >>
 > >>division.
 > >>
 > >>>That way I don't have to worry about closing for those that had no
classes.  Does
 > >>
 > >>this
 > >>
 > >>>make sense?  I think it will be something like this:
 > >>>
 > >>>
 > >>
 > >>--
 > >>  -----------------------------------------------------------------
 > >>|Paul Spencer                           pspencer at dmsolutions.ca   |
 > >>|-----------------------------------------------------------------|
 > >>|Applications & Software Development                              |
 > >>|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
 > >>  -----------------------------------------------------------------
 > >>
 > >>
 > >
 > >
 > >
 >
 > --
 >   -----------------------------------------------------------------
 > |Paul Spencer                           pspencer at dmsolutions.ca   |
 > |-----------------------------------------------------------------|
 > |Applications & Software Development                              |
 > |DM Solutions Group Inc                 http://www.dmsolutions.ca/|
 >   -----------------------------------------------------------------
 >


-- 
NB Aquatic Data Warehouse
Canadian Rivers Institute
University of New Brunswick
Hugh John Fleming Forestry Complex
Sir James Dunn Wildlife Research Center
Room 263
1350 Regent Street
Fredericton, NB
E3C 2G6

Phone:    (506) 458-7557
Email:     rbrown at unb.ca
_______________________________________________
Chameleon mailing list
Chameleon at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/chameleon



More information about the Chameleon mailing list