[OpenLayers-Users] How to stop registering events

Eric Lemoine eric.lemoine at camptocamp.com
Thu Oct 29 09:14:12 EDT 2009


On Thu, Oct 29, 2009 at 1:00 PM, Max Stephan <x.zam at gmx.net> wrote:
>
> Hi list,
>
> I´m using layer.events.register('loadend',map,zoomToFeature); in my
> application. The scenario is the following:
> In a list the user clicks on an icon that represents a polygon-Feature and
> has an ID. After that I´m querying my Geoserver for the feature with this ID
> and get the response back. From this I can calculate the bounds of this
> geometry and zoom to it.
> Now I want to select this layer because most of the features are surrounded
> by other features to show the user which one he selected in the list. For
> this to happen I have to wait till the layer is loaded (it contains all the
> features of the same featureclass that I´m querying from the Geoserver).
> Then I´m selecting the feature via selectControl.select(//FeatureObject//);.
> The problem is: The script keeps on registering the loadend event and for
> that reason always reactivates the queried feature (for example when I click
> on another feature).
> So, what I need is a way to deactivate the registering after the first
> registration of the event. I tried
> layer.events.unregister('loadend',map,zoomToFeature); but that´s not
> working.

Hi

it should work. I just did the following in the FireBug console:

>>> var cb = function() {}; scope = {};
>>> var e = new OpenLayers.Events({}, null, ["eventtype"]);
>>> e.register("eventtype", scope, cb);
>>> e.listeners["eventtype"].length == 1
>>> e.unregister("eventtype", scope, cb);
>>> e.listeners["eventtype"].length == 0

Cheers,

-- 
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



More information about the Users mailing list