patch for improved mousedragging. We were able to test this on my eeepc

and get a very obvious speedup in performance. This adds a configurable
'interval' to the dragpan control (and an interval to the 'drag' control,
defaulting to 0px). Patch put together by tcoulter. (Closes #1509) 


git-svn-id: http://svn.openlayers.org/trunk/openlayers@7608 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-07-30 16:27:48 +00:00
parent 7d3d615172
commit bc06972aea
3 changed files with 60 additions and 14 deletions

View File

@@ -66,6 +66,22 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
* {Function}
*/
oldOnselectstart: null,
/**
* Property: interval
* In order to increase performance, an interval (in milliseconds)
* can be set to reduce the number of drag events called. If set,
* a new drag event will not be set until the interval has passed.
* Defaults to 0, meaning no interval.
*/
interval: 0,
/**
* Property: timeoutId
* The id of the timeout used for the mousedown interval.
* This is "private", and should be left alone.
*/
timeoutId: null,
/**
* Constructor: OpenLayers.Handler.Drag
@@ -191,20 +207,29 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
* {Boolean} Let the event propagate.
*/
mousemove: function (evt) {
if (this.started) {
if(evt.xy.x != this.last.x || evt.xy.y != this.last.y) {
this.dragging = true;
this.move(evt);
this.callback("move", [evt.xy]);
if(!this.oldOnselectstart) {
this.oldOnselectstart = document.onselectstart;
document.onselectstart = function() {return false;};
}
this.last = evt.xy;
if (this.started && !this.timeoutId && (evt.xy.x != this.last.x || evt.xy.y != this.last.y)) {
if (this.interval > 0) {
this.timeoutId = setTimeout(OpenLayers.Function.bind(this.removeTimeout, this), this.interval);
}
this.dragging = true;
this.move(evt);
this.callback("move", [evt.xy]);
if(!this.oldOnselectstart) {
this.oldOnselectstart = document.onselectstart;
document.onselectstart = function() {return false;};
}
this.last = this.evt.xy;
}
return true;
},
/**
* Method: removeTimeout
* Private. Called by mousemove() to remove the drag timeout.
*/
removeTimeout: function() {
this.timeoutId = null;
},
/**
* Method: mouseup