[OpenLayers-Users] Re: registering and unregistering map events
Puneet Kishor
punk.kish at gmail.com
Mon Oct 3 20:48:07 EDT 2011
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
More information about the Users
mailing list