[OpenLayers-Users] LayerSwitcher Event

Richard Greenwood richard.greenwood at gmail.com
Fri Feb 18 12:43:01 EST 2011


Answering my own question (which might not be the best answer!) I have
found that the following works:

map.events.register('changelayer', null, function(evt){
       if(evt.property === "visibility") {
          alert(evt.layer.name + " layer visibility changed to " +
evt.layer.visibility );
       }
   }
);

Regards,
Rich

On Fri, Feb 18, 2011 at 8:34 AM, Richard Greenwood
<richard.greenwood at gmail.com> wrote:
> Hello All -
>
> I am trying to implement a layer change event as Eric Lemoine
> describes below. At the end of my page initialization function I have
> placed the code:
>
> map.on({
>   "changelayer": function(e) {
>       if(e.property === "visibility") {
>           alert("visibility changed (" + e.layer.name + ")");
>       }
>   }
> });
>
> But when the page is loaded I get the error:
>  map.on is not a function
>
> Am I not registering the event correctly, or can someone see what I am
> doing worng?
>
> Thanks,
> Rich
>
>
> On Thu, Jun 10, 2010 at 4:57 AM, Eric Lemoine
> <eric.lemoine at camptocamp.com> wrote:
>> On Thu, Jun 10, 2010 at 11:59 AM, Rahn Hanno (rahn) <rahn at zhaw.ch> wrote:
>>>
>>> Hello,
>>>
>>> Today I try to realise a "trigger" for my LayerSwitcher. Something like
>>> "onLayerClick" or so.
>>>
>>> I want to start a function if I select/unselect a layer in the
>>> Layerswitcher. In my Layerswitcher I have a Layer. If I select this Layer,
>>> then I want to set the opacity from all other layers to 50%. If I unselect
>>> the Layer the opacity should change again to not transparent.
>>>
>>> I think I need a trigger function for that layer. If I select some Layer I
>>> would fire a function. I think it would be possible, but I don't know how to
>>> realise.
>>>
>>> Perhaps somebody can help me. Or is there something like this already in
>>> OpenLayers what I have not found?
>>
>> Two options:
>>
>> - register a "changelayer" listener on the map
>>
>> map.on({
>>    "changelayer": function(e) {
>>        if(e.property === "visibility") {
>>            alert("visibility changed (" + e.layer.name + ")");
>>        }
>>    }
>> });
>>
>> - register a "visibilitychanged" listener on a specific layer
>>
>> layer.on({
>>    "visibilitychanged": function() {
>>        alert"visibility changed (" + layer.name + ")");
>>    }
>> });
>>
>> Hope it helps,
>>
>> --
>> Eric Lemoine
>>
>> Camptocamp France SAS
>> Savoie Technolac, BP 352
>> 73377 Le Bourget du Lac, Cedex
>>
>> Tel : 00 33 4 79 44 44 96
>> Mail : eric.lemoine at camptocamp.com
>> http://www.camptocamp.com
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>
>
>
> --
> Richard Greenwood
> richard.greenwood at gmail.com
> www.greenwoodmap.com
>



-- 
Richard Greenwood
richard.greenwood at gmail.com
www.greenwoodmap.com


More information about the Users mailing list