Turning on and off labels

Stuart Eve stuarteve at LPARCHAEOLOGY.COM
Wed Jan 25 09:42:14 EST 2006


Right, just incase this is useful for anyone - I have managed to do a 
bit of a hacky solution to turning the labels off:

I set the 'labelrequires' option of the layers to evaluate true if I 
wanted the label to be drawn and false if I didn't.

Thus:

     $layerObj = $map->getLayerByName($name);
     $layerObj->set("labelrequires", "1 == 1");

turns the label on for layer $name.

and....

     $layerObj = $map->getLayerByName($name);
     $layerObj->set("labelrequires", "1 == 2");

Turns it off.

It feels a bit of a hack, so if anyone has anything more elegant I'd be 
happy to hear it.

Stu


> Thanks Norbert, thats certainly an option (which I hadn't thought of!) 
> and I may do that - I was just hoping that I would be able to find a 
> way to do with Mapscript (so I don't have to have such a huge mapfile!)
>
> Stu
>
>
>> Hi,
>>
>> I'm not sure if this is what you want but you can make a layer for 
>> the data and a separate one for the labels then you can turn them on 
>> or off.
>>
>> Regards,
>>
>> Norbert 
>
>
>
>
>
> Stuart Eve wrote:
>
>> Hi all,
>>
>> I am trying to use Mapscript to turn off labels 'on-demand'. I have 
>> my label information set up in my mapfile - but this means that they 
>> are always drawn. I want to retain that information in the mapfile 
>> (rather than recreating the whole thing with Mapscript), so was 
>> wondering if there was a way to tell Mapserver if they should be 
>> drawn or not (without turning the whole layer off!). I have tried 
>> using a 'STATUS OFF' within the label tags, but that doesn't work (of 
>> course!).
>>
>> Any ideas?
>>
>> Stu
>>
>
> -- 
> Stuart Eve
> L - P : Archaeology
> stuarteve at lparchaeology.com
>

-- 
Stuart Eve
L - P : Archaeology
stuarteve at lparchaeology.com 



More information about the mapserver-users mailing list