diff --git a/lib/OpenLayers/Handler/Feature.js b/lib/OpenLayers/Handler/Feature.js index 02d47c75a1..7f2158cc5a 100644 --- a/lib/OpenLayers/Handler/Feature.js +++ b/lib/OpenLayers/Handler/Feature.js @@ -33,10 +33,16 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { /** * Property: feature - * {} The last feature that was handled. + * {} The feature currently being handled. */ feature: null, + /** + * Property: lastFeature + * {} The last feature that was handled. + */ + lastFeature: null, + /** * Property: down * {} The location of the last mousedown. @@ -133,8 +139,8 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { /** * Method: mousemove - * Handle mouse moves. Call the "over" callback if move over a feature, - * or the "out" callback if move outside any feature. + * Handle mouse moves. Call the "over" callback if moving in to a feature, + * or the "out" callback if moving out of a feature. * * Parameters: * evt - {Event} @@ -190,33 +196,35 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { handle: function(evt) { var type = evt.type; var stopEvtPropag = false; - var lastFeature = this.feature; - var feature = this.layer.getFeatureFromEvent(evt); - if(feature) { - if(this.geometryTypeMatches(feature)) { - if(lastFeature && (lastFeature != feature)) { - // out of last feature - this.triggerCallback(type, 'out', [lastFeature]); + var previouslyIn = !!(this.feature); // previously in a feature + var click = (type == "click" || type == "dblclick"); + this.feature = this.layer.getFeatureFromEvent(evt); + if(this.feature) { + var inNew = (this.feature != this.lastFeature); + if(this.geometryTypeMatches(this.feature)) { + // in to a feature + if(previouslyIn && inNew) { + // out of last feature and in to another + this.triggerCallback(type, 'out', [this.lastFeature]); + this.triggerCallback(type, 'in', [this.feature]); + } else if(!previouslyIn || click) { + // in feature for the first time + this.triggerCallback(type, 'in', [this.feature]); } - this.triggerCallback(type, 'in', [feature]); - lastFeature = feature; stopEvtPropag = true; } else { - if(lastFeature && (lastFeature != feature)) { - // out of last feature - this.triggerCallback(type, 'out', [lastFeature]); - lastFeature = feature; + // not in to a feature + if(previouslyIn && inNew || (click && this.lastFeature)) { + // out of last feature for the first time + this.triggerCallback(type, 'out', [this.lastFeature]); } } + this.lastFeature = this.feature; } else { - if(lastFeature) { - this.triggerCallback(type, 'out', [lastFeature]); - lastFeature = null; + if(previouslyIn || (click && this.lastFeature)) { + this.triggerCallback(type, 'out', [this.lastFeature]); } } - if(lastFeature) { - this.feature = lastFeature; - } return stopEvtPropag; }, @@ -277,6 +285,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { this.layer.div.style.zIndex = this.layerIndex; } this.feature = null; + this.lastFeature = null; this.down = null; this.up = null; deactivated = true;