[Chameleon] HTML Legend with Javascript

Paul Spencer pagameba at magma.ca
Fri Oct 1 10:02:55 EDT 2004


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/|
  -----------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jsExpander.css
Type: text/css
Size: 527 bytes
Desc: not available
Url : http://lists.maptools.org/pipermail/chameleon/attachments/20041001/71b33935/jsExpander-0001.css
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jsExpander.js
Type: application/x-javascript
Size: 4299 bytes
Desc: not available
Url : http://lists.maptools.org/pipermail/chameleon/attachments/20041001/71b33935/jsExpander-0001.js
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/chameleon/attachments/20041001/71b33935/fancy_legend-0001.html


More information about the Chameleon mailing list