SelectFeature should allow panning the map when over features, without activating click method at the end of drag, r=tschaub (closes #1824)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9194 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -56,13 +56,13 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
||||
up: null,
|
||||
|
||||
/**
|
||||
* Property: clickoutTolerance
|
||||
* {Number} The number of pixels the mouse can move during a click that
|
||||
* still constitutes a click out. When dragging the map, clicks should
|
||||
* not trigger the clickout property unless this tolerance is reached.
|
||||
* Default is 4.
|
||||
* Property: clickTolerance
|
||||
* {Number} The number of pixels the mouse can move between mousedown
|
||||
* and mouseup for the event to still be considered a click.
|
||||
* Dragging the map should not trigger the click and clickout callbacks
|
||||
* unless the map is moved by less than this tolerance. Defaults to 4.
|
||||
*/
|
||||
clickoutTolerance: 4,
|
||||
clickTolerance: 4,
|
||||
|
||||
/**
|
||||
* Property: geometryTypes
|
||||
@@ -275,7 +275,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
||||
/**
|
||||
* Method: triggerCallback
|
||||
* Call the callback keyed in the event map with the supplied arguments.
|
||||
* For click out, the <clickoutTolerance> is checked first.
|
||||
* For click and clickout, the <clickTolerance> is checked first.
|
||||
*
|
||||
* Parameters:
|
||||
* type - {String}
|
||||
@@ -283,13 +283,13 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
||||
triggerCallback: function(type, mode, args) {
|
||||
var key = this.EVENTMAP[type][mode];
|
||||
if(key) {
|
||||
if(type == 'click' && mode == 'out' && this.up && this.down) {
|
||||
// for clickout, only trigger callback if tolerance is met
|
||||
if(type == 'click' && this.up && this.down) {
|
||||
// for click/clickout, only trigger callback if tolerance is met
|
||||
var dpx = Math.sqrt(
|
||||
Math.pow(this.up.x - this.down.x, 2) +
|
||||
Math.pow(this.up.y - this.down.y, 2)
|
||||
);
|
||||
if(dpx <= this.clickoutTolerance) {
|
||||
if(dpx <= this.clickTolerance) {
|
||||
this.callback(key, args);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -417,8 +417,63 @@
|
||||
}
|
||||
|
||||
handler.destroy();
|
||||
|
||||
}
|
||||
|
||||
function test_click_tolerance(t) {
|
||||
t.plan(3);
|
||||
|
||||
var map, control, layer, feature, evtPx;
|
||||
var clicks, callbacks, handler;
|
||||
|
||||
map = new OpenLayers.Map('map', {controls: []});
|
||||
control = new OpenLayers.Control();
|
||||
map.addControl(control);
|
||||
layer = new OpenLayers.Layer();
|
||||
map.addLayer(layer);
|
||||
|
||||
feature = new OpenLayers.Feature.Vector();
|
||||
feature.layer = layer;
|
||||
|
||||
evtPx = {
|
||||
xy: new OpenLayers.Pixel(Math.random(), Math.random()),
|
||||
type: "click"
|
||||
};
|
||||
|
||||
// override the layer's getFeatureFromEvent func so that it always
|
||||
// returns newFeature
|
||||
layer.getFeatureFromEvent = function(evt) { return feature; };
|
||||
|
||||
callbacks = {
|
||||
click: function() {
|
||||
clicks++;
|
||||
}
|
||||
};
|
||||
|
||||
handler = new OpenLayers.Handler.Feature(
|
||||
control, layer, callbacks, {clickTolerance: 4});
|
||||
handler.activate();
|
||||
handler.down = {x: 0, y: 0};
|
||||
|
||||
// distance between down and up is 1, which is
|
||||
// lower than clickTolerance so "click" should trigger
|
||||
handler.up = {x: 1, y: 0};
|
||||
clicks = 0;
|
||||
map.events.triggerEvent("click", evtPx);
|
||||
t.eq(clicks, 1, "click callback triggers when tolerance is not reached (lower than)");
|
||||
|
||||
// distance between down and up is 4, which is
|
||||
// equal to clickTolerance so "click" should trigger
|
||||
handler.up = {x: 0, y: 4};
|
||||
clicks = 0;
|
||||
map.events.triggerEvent("click", evtPx);
|
||||
t.eq(clicks, 1, "click callback triggers when tolerance is not reached (equal to)");
|
||||
|
||||
// distance between down and up is 5, which is
|
||||
// greater than clickTolerance so "click" should not trigger
|
||||
handler.up = {x: 5, y: 0};
|
||||
clicks = 0;
|
||||
map.events.triggerEvent("click", evtPx);
|
||||
t.eq(clicks, 0, "click callback does not trigger when tolerance is reached");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user