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

View File

@@ -33,10 +33,16 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
/**
* Property: feature
* {<OpenLayers.Feature.Vector>} The last feature that was handled.
* {<OpenLayers.Feature.Vector>} The feature currently being handled.
*/
feature: null,
/**
* Property: lastFeature
* {<OpenLayers.Feature.Vector>} The last feature that was handled.
*/
lastFeature: null,
/**
* Property: down
* {<OpenLayers.Pixel>} 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;