[Chameleon] Layers not turned 'on' when coming into scale basedview

Ken Sanderson ken at rockies.ca
Thu Sep 23 16:08:40 EDT 2004


Given the Mapserver limitations outlined by Paul, I did a kludge work
around to get the legend working the way I wanted it too. Just in case
anyone else is interested or finds this thread in the future I thought I
would post my work around. Sorry in advance if there are formating
problems with the code portions of the email, also if anyone has
recommendations to stream line it further, feel free to comment

As the scale dependant layers will be 'on' from the start if you use
opt_flag=15 with the HTML legend, I figured a good solution was to just
use that, and hide the layers from the legend client side (ie
javascript) rather then setting it to opt_flag=14.

1) I needed the scale accessible via javascript, so I added a hidden
input that holds current map scale. In this case what I did was add the
following to the GetHTMLHiddenVariables function in
LegendTemplate.widget.php file.

        $this->moMapObject->oMap->setExtent(
             $this->moMapObject->oMap->extent->minx,
             $this->moMapObject->oMap->extent->miny,
             $this->moMapObject->oMap->extent->maxx,
             $this->moMapObject->oMap->extent->maxy);
        $szLegScale = round($this->moMapObject->oMap->scale);
        $szVariable = "LEGEND_SCALE";
        $szValue = " <INPUT TYPE=\"HIDDEN\" NAME=\"$szVariable\"
VALUE=\"$szLegScale\">\n";
        $aReturn[$szVariable] = $szValue;

This is probably not the best way to do this, as in the future you will
need to change this file after every new version of Chameleon that you
install. Still trying to decide how I want to add it, likely as just a
stand alone widget so I don't have to worry about upgrading.

2) I also needed to be able to see the minscale and maxscale information
from the legend template so I added metadata values, min_scale and
max_scale with the appropriate values. With my template they are both
required, but I only check for one (max_scale) as I wanted to keep the
size of the template down as much as possible. Further you only need
them for the layers you want to control via scale, no need to add them
to the other layers.

3) Lastly I changed my legend template to more javascript based so that
I could control which layers are to be displayed. Keep in mind that you
cannot simply ignore the scale dependant layers when they are not
visible, ie just don't write them to the legend, or you will encounter
the same problem you get with opt_flag=14, so I have added them as a
hidden input instead of checkbox. Here is my legend template file:

[leg_layer_html order=ascending opt_flag=15]
  <tr bgcolor="#ffffff">
    <td align="center" width=20>
    <script language="javascript">
      [if name=max_scale oper=isset]
        if(([metadata
name=max_scale]>=document.forms[0].LEGEND_SCALE.value) && ([metadata
name=min_scale]<=document.forms[0].LEGEND_SCALE.value)){        
          document.write("<input type=\"checkbox\"
name=\"legendlayername[]\" value=\"[leg_layer_name]\"");
          document.write("[if name=layer_status oper=eq
value=1]CHECKED[/if]");
          document.write("[if name=layer_status oper=eq
value=2]CHECKED[/if]>");
          [if name=display_class oper=isnull]
            document.write("<td><img src=\"[leg_icon width=20
height=18]\" width=\"20\" height=\"20\"></td>");
          [/if]
          [if name=display_class oper=isset]
            document.write("<td>&nbsp;</td>");
          [/if]
          [if name=wms_name oper=isnull]
            document.write("<td><a href=\"#\"
onclick=\"javascript:LegendTemplateLayerInfo('[leg_layer_name]');\"><spa
n class=\"label\">[leg_layer_name]</span></a></td></tr>");
          [/if]
          [if name=wms_name oper=isset]
            document.write("<td><a href=\"#\"
onclick=\"javascript:LegendTemplateLayerInfo('[leg_layer_name]');\"><spa
n class=\"label\">[metadata name=WMS_TITLE]</span></a></td></tr>");
          [/if]
        } else {
          document.write("<input type=\"hidden\"
name=\"legendlayername[]\" value=\"[leg_layer_name]\"");
        }
      [/if]
      [if name=max_scale oper=isnull]
          document.write("<input type=\"checkbox\"
name=\"legendlayername[]\" value=\"[leg_layer_name]\"");
          document.write("[if name=layer_status oper=eq
value=1]CHECKED[/if]");
          document.write("[if name=layer_status oper=eq
value=2]CHECKED[/if]>");
          [if name=display_class oper=isnull]
            document.write("<td><img src=\"[leg_icon width=20
height=18]\" width=\"20\" height=\"20\"></td>");
          [/if]
          [if name=display_class oper=isset]
            document.write("<td>&nbsp;</td>");
          [/if]
          [if name=wms_name oper=isnull]
            document.write("<td><a href=\"#\"
onclick=\"javascript:LegendTemplateLayerInfo('[leg_layer_name]');\"><spa
n class=\"label\">[leg_layer_name]</span></a></td></tr>");
          [/if]
          [if name=wms_name oper=isset]
            document.write("<td><a href=\"#\"
onclick=\"javascript:LegendTemplateLayerInfo('[leg_layer_name]');\"><spa
n class=\"label\">[metadata name=WMS_TITLE]</span></a></td></tr>");
          [/if]
      [/if]
    </script>       
    </td>
[/leg_layer_html]
[leg_class_html]
    [if name=display_class oper=isset]
      <tr>
      <td colspan="2">&nbsp;</td>
      <td><img src="[leg_icon width=20 height=18]" width="20"
height="20"></td>
      <td><span class="label">[leg_class_name]</span></td>
      </tr>
    [/if]
[/leg_class_html]








More information about the Chameleon mailing list