diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index ab806f23f1..bb0d954bf2 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -435,6 +435,14 @@ OpenLayers.Events = OpenLayers.Class({ */ includeXY: false, + /** + * Method: clearMouseListener + * A version of that is bound to this instance so that + * it can be used with and + * . + */ + clearMouseListener: null, + /** * Constructor: OpenLayers.Events * Construct an OpenLayers.Events object. @@ -458,6 +466,11 @@ OpenLayers.Events = OpenLayers.Class({ this.eventHandler = OpenLayers.Function.bindAsEventListener( this.handleBrowserEvent, this ); + + // to be used with observe and stopObserving + this.clearMouseListener = OpenLayers.Function.bind( + this.clearMouseCache, this + ); // if eventTypes is specified, create a listeners list for each // custom application event. @@ -481,6 +494,11 @@ OpenLayers.Events = OpenLayers.Class({ destroy: function () { if (this.element) { OpenLayers.Event.stopObservingElement(this.element); + if(this.element.hasScrollEvent) { + OpenLayers.Event.stopObserving( + window, "scroll", this.clearMouseListener + ); + } } this.element = null; @@ -773,8 +791,7 @@ OpenLayers.Events = OpenLayers.Class({ if (!this.includeXY) { this.clearMouseCache(); } else if (!this.element.hasScrollEvent) { - OpenLayers.Event.observe(window, 'scroll', - OpenLayers.Function.bind(this.clearMouseCache, this)); + OpenLayers.Event.observe(window, "scroll", this.clearMouseListener); this.element.hasScrollEvent = true; }