Add properties stopClick, stopDown, and stopUp to the feature handler. If

stopClick is true, clicks handled by the feature handler don't propagate to
other click listeners; otherwise handled clicks do propagate. The same kind of
rule applies to stopDown and stopUp. These properties default to true. Thanks
to Attila Csipa for expressing the need for this feature and cooking up the
first patch. r=tschaub. (closes #1266)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5976 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2008-02-03 17:35:39 +00:00
parent f9950ec389
commit cf87ffc26c
2 changed files with 76 additions and 8 deletions

View File

@@ -72,7 +72,34 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
* @type Array(String)
*/
geometryTypes: null,
/**
* Property: stopClick
* {Boolean} If stopClick is set to true, handled clicks do not
* propagate to other click listeners. Otherwise, handled clicks
* do propagate. Unhandled clicks always propagate, whatever the
* value of stopClick. Defaults to true.
*/
stopClick: true,
/**
* Property: stopDown
* {Boolean} If stopDown is set to true, handled mousedowns do not
* propagate to other mousedown listeners. Otherwise, handled
* mousedowns do propagate. Unhandled mousedowns always propagate,
* whatever the value of stopDown. Defaults to true.
*/
stopDown: true,
/**
* Property: stopUp
* {Boolean} If stopUp is set to true, handled mouseups do not
* propagate to other mouseup listeners. Otherwise, handled mouseups
* do propagate. Unhandled mouseups always propagate, whatever the
* value of stopUp. Defaults to true.
*/
stopUp: true,
/**
* Property: layerIndex
* {Int}
@@ -106,7 +133,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
*/
mousedown: function(evt) {
this.down = evt.xy;
return !this.handle(evt);
return this.handle(evt) ? !this.stopDown : true;
},
/**
@@ -119,7 +146,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
*/
mouseup: function(evt) {
this.up = evt.xy;
return !this.handle(evt);
return this.handle(evt) ? !this.stopUp : true;
},
/**
@@ -134,7 +161,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
* {Boolean}
*/
click: function(evt) {
return !this.handle(evt);
return this.handle(evt) ? !this.stopClick : true;
},
/**
@@ -191,11 +218,11 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
* evt - {Event}
*
* Returns:
* {Boolean} Stop event propagation.
* {Boolean} The event occurred over a relevant feature.
*/
handle: function(evt) {
var type = evt.type;
var stopEvtPropag = false;
var handled = false;
var previouslyIn = !!(this.feature); // previously in a feature
var click = (type == "click" || type == "dblclick");
this.feature = this.layer.getFeatureFromEvent(evt);
@@ -212,7 +239,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
this.triggerCallback(type, 'in', [this.feature]);
}
this.lastFeature = this.feature;
stopEvtPropag = true;
handled = true;
} else {
// not in to a feature
if(previouslyIn && inNew || (click && this.lastFeature)) {
@@ -225,7 +252,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
this.triggerCallback(type, 'out', [this.lastFeature]);
}
}
return stopEvtPropag;
return handled;
},
/**