On Jan 11, 2008 10:21 PM, Attila Csipa <[EMAIL PROTECTED]> wrote:
> Yes, I outdid myself with the parentheses, sorry about that. The code:
>
> var drag = new OpenLayers.Control.DragFeature(pointlayer,{
> onStart: function(feature, pixel)
> {
> storeGeometry(feature.geometry);
> },
> onComplete: function(feature, pixel)
> {
> processNewGeometry(feature.geometry);
> }
> });
>
> drag.dragHandler.stopDown = false;
> map.addControl(drag);
> drag.activate();
> map.events.register("click", map, function(e) {
> var lonlat = map.getLonLatFromViewPortPx(e.xy);
> alert("You clicked near " + lonlat.lat + " N, " +
> + lonlat.lon + " E");
> });
>
> What I want to do is to preserve 'click' functionality even if the click
> happened over a draggable feature. pointlayer is a GML layer containing
> features with point geometries. What happens in the svn version is that in
> pointlayer.events, Events.js on line 627, after Handler.Drag returns
> continueChain = true due to the stopDown property, but on the call to the
> next listener (a Handler.Feature), continueChain = false and thus it doesn't
> fall through to other elements. I'm still familiarizing myself with OL
> structures, so my assessment might be wrong of course...
Setting the drag handler's stopDown property to false won't help you
because the event you want to get "click" not "mousedown". Anyhow the
feature handler (also used in the drag feature control) stops the
propagation of clicks that occur on features. That's what kills you
here.
Currently, there's no way to prevent the feature handler from stopping
the propagation of clicks occuring on features. I think this deserves
a ticket and a patch. In the meantime, you can try the patch attached
to this email. The patch adds the property stopHandledClick to the
feature handler. By default, stopHandledClick is set to true. By
making it false, clicks occuring on features will propagate.
So apply the patch and replace
drag.dragHandler.stopDown = false;
with
drag.featureHandler.stopHandledClick = false;
Hope this helps,
PS: if you'd like to quickly see this patch included in the trunk,
feel free to open a ticket in the trac, complement my patch with
tests, and attach the patch to the ticket. That'd be a good first code
contribution to OpenLayers ;-)
Thanks,
--
Eric
Index: lib/OpenLayers/Handler/Feature.js
===================================================================
--- lib/OpenLayers/Handler/Feature.js (revision 5728)
+++ lib/OpenLayers/Handler/Feature.js (working copy)
@@ -72,8 +72,35 @@
* @type Array(String)
*/
geometryTypes: null,
-
+
/**
+ * Property: stopHandledClick
+ * {Boolean} If stopHandledClick 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 stopHandledClick. Defaults to true.
+ */
+ stopHandledClick: true,
+
+ /**
+ * Property: stopHandledDown
+ * {Boolean} If stopHandledDown 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 stopHandledDown. Defaults to true.
+ */
+ stopHandledDown: true,
+
+ /**
+ * Property: stopHandledUp
+ * {Boolean} If stopHandledUp 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 stopHandledUp. Defaults to true.
+ */
+ stopHandledUp: true,
+
+ /**
* Property: layerIndex
* {Int}
*/
@@ -106,7 +133,7 @@
*/
mousedown: function(evt) {
this.down = evt.xy;
- return !this.handle(evt);
+ return this.handle(evt) ? !this.stopHandledDown: true;
},
/**
@@ -119,7 +146,7 @@
*/
mouseup: function(evt) {
this.up = evt.xy;
- return !this.handle(evt);
+ return this.handle(evt) ? !this.stopHandledUp : true;
},
/**
@@ -134,7 +161,7 @@
* {Boolean}
*/
click: function(evt) {
- return !this.handle(evt);
+ return this.handle(evt) ? !this.stopHandledClick : true;
},
/**
@@ -195,7 +222,7 @@
*/
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);
@@ -211,7 +238,7 @@
// in feature for the first time
this.triggerCallback(type, 'in', [this.feature]);
}
- stopEvtPropag = true;
+ handled = true;
} else {
// not in to a feature
if(previouslyIn && inNew || (click && this.lastFeature)) {
@@ -225,7 +252,7 @@
this.triggerCallback(type, 'out', [this.lastFeature]);
}
}
- return stopEvtPropag;
+ return handled;
},
/**
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users