turn layer labels on and off dynamically

LITTLE Nelson nelson.little at TENIX.COM
Tue May 29 22:57:14 PDT 2007


Thank you both for your help. I was able to use setLabelrequires method
to turn on/off the display of the label. For the record
setLabelrequires("0") turned them off, setLabelrequires("1") turned them
on.

Cheers,
Nelson

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Stephen Woodbridge
Sent: Wednesday, 30 May 2007 12:56 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] turn layer labels on and off
dynamically

Gregor Mosheh wrote:
>> I am using the Java MapScript for my application and I would like to
>> present the option for the user to decide whether or not to show
labels
>> for a given layer. Is there any way to turn the label for a layer on
or
>> off dynamically? I didn't see anything obvious in the MapScript API.
> 
> Speaking from the world of PHP/Mapscript, with hopes that it's 
> applicable to your situation... Our solution is to set the label color

> to something invalid, to suppress the rendering of labels, e.g.:
> 
>    $class = $layer->getClassNyName('roads');
>    if (!$labels) {
>       $class->label->color->setRGB(-1,-1,-1);
>    }
> 
> 
> 

Ooops, that does not quite work the way you are expecting it to. color 
-1 -1 -1 means transparent. so you are rendering the labels but they are

just transparent. Since you are rendering the labels, it takes cpu time 
and it might bump other labels out of the cache. I don't think you 
really want to do this.

A better solution might be to set the LABELMINSCALE or LABELMAXSCALE to 
a value that would force the labels off, then reset the value to its 
normal value to turn them back on based on the zoom scale.

You might also be able to use LABELREQUIRES "0" | "1" to turn on/off
labels.

Both of these are LAYER attributes.

I have not played with either of these, but you should be able to get 
one of them to work.

-Steve W.

Disclaimer :
The contents of this e-mail including any attachments are intended only
for the person or entity to which this e-mail is addressed.  If you are not,
or believe you may not be, the intended recipient, please advise the sender
immediately by return e-mail, delete this e-mail and destroy any copies.
Tenix does not warrant nor guarantee that this email communication is free
from errors, virus, interception or interference.



More information about the MapServer-users mailing list