Making feature handler call over and out callbacks just once per mouseover and mouseout (of a feature). r=elemoine (closes #1226)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5555 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-12-21 08:48:08 +00:00
parent 33e313b059
commit 86116ddd73
+31 -22
View File
@@ -33,10 +33,16 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
/** /**
* Property: feature * Property: feature
* {<OpenLayers.Feature.Vector>} The last feature that was handled. * {<OpenLayers.Feature.Vector>} The feature currently being handled.
*/ */
feature: null, feature: null,
/**
* Property: lastFeature
* {<OpenLayers.Feature.Vector>} The last feature that was handled.
*/
lastFeature: null,
/** /**
* Property: down * Property: down
* {<OpenLayers.Pixel>} The location of the last mousedown. * {<OpenLayers.Pixel>} The location of the last mousedown.
@@ -133,8 +139,8 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
/** /**
* Method: mousemove * Method: mousemove
* Handle mouse moves. Call the "over" callback if move over a feature, * Handle mouse moves. Call the "over" callback if moving in to a feature,
* or the "out" callback if move outside any feature. * or the "out" callback if moving out of a feature.
* *
* Parameters: * Parameters:
* evt - {Event} * evt - {Event}
@@ -190,33 +196,35 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
handle: function(evt) { handle: function(evt) {
var type = evt.type; var type = evt.type;
var stopEvtPropag = false; var stopEvtPropag = false;
var lastFeature = this.feature; var previouslyIn = !!(this.feature); // previously in a feature
var feature = this.layer.getFeatureFromEvent(evt); var click = (type == "click" || type == "dblclick");
if(feature) { this.feature = this.layer.getFeatureFromEvent(evt);
if(this.geometryTypeMatches(feature)) { if(this.feature) {
if(lastFeature && (lastFeature != feature)) { var inNew = (this.feature != this.lastFeature);
// out of last feature if(this.geometryTypeMatches(this.feature)) {
this.triggerCallback(type, 'out', [lastFeature]); // 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; stopEvtPropag = true;
} else { } else {
if(lastFeature && (lastFeature != feature)) { // not in to a feature
// out of last feature if(previouslyIn && inNew || (click && this.lastFeature)) {
this.triggerCallback(type, 'out', [lastFeature]); // out of last feature for the first time
lastFeature = feature; this.triggerCallback(type, 'out', [this.lastFeature]);
} }
} }
this.lastFeature = this.feature;
} else { } else {
if(lastFeature) { if(previouslyIn || (click && this.lastFeature)) {
this.triggerCallback(type, 'out', [lastFeature]); this.triggerCallback(type, 'out', [this.lastFeature]);
lastFeature = null;
} }
} }
if(lastFeature) {
this.feature = lastFeature;
}
return stopEvtPropag; return stopEvtPropag;
}, },
@@ -277,6 +285,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
this.layer.div.style.zIndex = this.layerIndex; this.layer.div.style.zIndex = this.layerIndex;
} }
this.feature = null; this.feature = null;
this.lastFeature = null;
this.down = null; this.down = null;
this.up = null; this.up = null;
deactivated = true; deactivated = true;