Take care not to handle features without a layer. These are typically destroyed features - but could be some other sort of miscreants. Thanks for the report igrcic. r=crschmidt (closes #1806).

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8581 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-01-05 04:46:34 +00:00
parent 20907c7fa5
commit 850d69a02f
2 changed files with 131 additions and 14 deletions

View File

@@ -218,18 +218,32 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
* {Boolean} The event occurred over a relevant feature.
*/
handle: function(evt) {
if(this.feature && !this.feature.layer) {
// feature has been destroyed
this.feature = null;
}
var type = evt.type;
var handled = false;
var previouslyIn = !!(this.feature); // previously in a feature
var click = (type == "click" || type == "dblclick");
this.feature = this.layer.getFeatureFromEvent(evt);
if(this.feature && this.feature.layer) {
if(this.feature && !this.feature.layer) {
// feature has been destroyed
this.feature = null;
}
if(this.lastFeature && !this.lastFeature.layer) {
// last feature has been destroyed
this.lastFeature = null;
}
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]);
if(this.lastFeature) {
this.triggerCallback(type, 'out', [this.lastFeature]);
}
this.triggerCallback(type, 'in', [this.feature]);
} else if(!previouslyIn || click) {
// in feature for the first time
@@ -239,7 +253,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
handled = true;
} else {
// not in to a feature
if(previouslyIn && inNew || (click && this.lastFeature)) {
if(this.lastFeature && (previouslyIn && inNew || click)) {
// out of last feature for the first time
this.triggerCallback(type, 'out', [this.lastFeature]);
}
@@ -251,8 +265,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
this.feature = null;
}
} else {
if(this.lastFeature && this.lastFeature.layer &&
(previouslyIn || click)) {
if(this.lastFeature && (previouslyIn || click)) {
this.triggerCallback(type, 'out', [this.lastFeature]);
}
}