[OpenLayers-Users] Re: registering and unregistering map events

Janis Elmeris janis.elmeris at intelligentsystems.lv
Tue Oct 4 06:07:19 EDT 2011


You are creating a new function each time you register a listener. 
Create the function beforehand and pass it everywhere. It could be that 
the unregistering requires to pass the active handler itself, not 
another function that just acts the same, but is not the same function 
instance.

Janis


On 2011.10.04. 3:48, Puneet Kishor wrote:
> Seems like the problem I am encountering is that I am unable to "unregister" a "click" event from the map. Is there a way to ascertain if an event has been "unregister"ed successfully? (that is, besides, of course, discovering that it is still firing).
>
>
> On Oct 3, 2011, at 6:44 PM, Puneet Kishor wrote:
>
>> I would welcome suggestions to solve the following. I want to "enable" the "activation" of a functionality at a certain zoom level, and after the functionality is completed, I want the "deactivate" the functionality, but still keep it enable-able (huh!). See below for a better description of the problem --
>>
>>
>>     // add a "zoomend" event so…
>>     map.events.register("zoomend", map, function() {
>>
>>         // when the map is zoomed in at the correct level,
>>         if (map.getZoom()>  3) {
>>
>>             // a button is activated so that when the button is clicked…
>>             $("#button").bind("click", function() {
>>
>>                 // the button is turned "on"
>>                 ..
>>
>>                 // the map begins listening for clicks to do
>>                 // cool functionality
>>                 map.events.register("click", map, function(e) {
>>                     coolFunctionality(e);
>>                 })
>>             });
>>
>>         }
>>
>>         // but when the map zoom is not at the correct level,
>>         else {
>>
>>             // map is no longer listening to clicks
>>             map.events.unregister("click", map, function(e) {
>>                 coolFunctionality(e);
>>             })
>>
>>             // and the button is turned "off" and deactivated
>>             $("#button").unbind("click", function() {});
>>
>>         }
>>     });
>>
>> In another part of the script
>>
>>     "coolFunctionality": function (e) {
>>
>>         // do cool functionality,
>>         ..
>>
>>         // turn the button "off" (but it can still be clicked)
>>         ..
>>
>>         // and turn off the map listener so it may not be fired accidentally
>>         map.events.unregister("click", map, function(e) {
>>             coolFunctionality(e);
>>         })
>>     }
>>
>> So, the problem is, when I am in `coolFunctionality()` and `unregister` the event, I am still in the zoom level range where the event is `register`ed. Hmmmm... what to do?
>>
>> --
>> Puneet Kishor
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20111004/5b0861bb/attachment.html


More information about the Users mailing list