OpenLayers OpenLayers

Changeset 7608

Show
Ignore:
Timestamp:
07/30/08 12:27:48 (4 months ago)
Author:
crschmidt
Message:

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)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Control/DragPan.js

    r6833 r7608  
    3030     
    3131    /** 
     32     * Property: interval 
     33     * The number of milliseconds that should ellapse before 
     34     * panning the map again. Set this to increase dragging performance. 
     35     * Defaults to 25 milliseconds. 
     36     */ 
     37    interval: 25,  
     38     
     39    /** 
    3240     * Method: draw 
    3341     * Creates a Drag handler, using <panMap> and 
     
    3543     */     
    3644    draw: function() { 
    37         this.handler = new OpenLayers.Handler.Drag(this, 
    38                             {"move": this.panMap, "done": this.panMapDone}); 
     45        this.handler = new OpenLayers.Handler.Drag(this, { 
     46                "move": this.panMap, 
     47                "done": this.panMapDone 
     48            }, { 
     49                interval: this.interval 
     50            } 
     51        ); 
    3952    }, 
    4053 
  • trunk/openlayers/lib/OpenLayers/Control/Navigation.js

    r6462 r7608  
    3131    dragPan: null, 
    3232 
     33    /** 
     34     * APIProprety: dragPanOptions 
     35     * Options passed to the DragPan control. 
     36     */ 
     37    dragPanOptions: null, 
     38 
    3339    /**  
    3440     * Property: zoomBox 
     
    4248     */ 
    4349    zoomWheelEnabled: true,  
    44  
     50     
    4551    /** 
    4652     * Constructor: OpenLayers.Control.Navigation 
     
    111117                                          'stopDouble': true 
    112118                                        }); 
    113         this.dragPan = new OpenLayers.Control.DragPan({map: this.map}); 
     119        this.dragPan = new OpenLayers.Control.DragPan( 
     120            OpenLayers.Util.extend({map: this.map}, this.dragPanOptions) 
     121        ); 
    114122        this.zoomBox = new OpenLayers.Control.ZoomBox( 
    115123                    {map: this.map, keyMask: OpenLayers.Handler.MOD_SHIFT}); 
  • trunk/openlayers/lib/OpenLayers/Handler/Drag.js

    r5911 r7608  
    6767     */ 
    6868    oldOnselectstart: null, 
     69     
     70    /** 
     71     * Property: interval 
     72     * In order to increase performance, an interval (in milliseconds) 
     73     * can be set to reduce the number of drag events called. If set,  
     74     * a new drag event will not be set until the interval has passed.  
     75     * Defaults to 0, meaning no interval.  
     76     */ 
     77    interval: 0, 
     78     
     79    /** 
     80     * Property: timeoutId 
     81     * The id of the timeout used for the mousedown interval. 
     82     * This is "private", and should be left alone. 
     83     */ 
     84    timeoutId: null, 
    6985 
    7086    /** 
     
    192208     */ 
    193209    mousemove: function (evt) { 
    194         if (this.started) { 
    195             if(evt.xy.x != this.last.x || evt.xy.y != this.last.y) { 
    196                 this.dragging = true; 
    197                 this.move(evt); 
    198                 this.callback("move", [evt.xy]); 
    199                 if(!this.oldOnselectstart) { 
    200                     this.oldOnselectstart = document.onselectstart; 
    201                     document.onselectstart = function() {return false;}; 
    202                 } 
    203                 this.last = evt.xy; 
    204             } 
     210        if (this.started && !this.timeoutId && (evt.xy.x != this.last.x || evt.xy.y != this.last.y)) { 
     211            if (this.interval > 0) { 
     212                this.timeoutId = setTimeout(OpenLayers.Function.bind(this.removeTimeout, this), this.interval); 
     213            } 
     214            this.dragging = true; 
     215            this.move(evt); 
     216            this.callback("move", [evt.xy]); 
     217            if(!this.oldOnselectstart) { 
     218                this.oldOnselectstart = document.onselectstart; 
     219                document.onselectstart = function() {return false;}; 
     220            } 
     221            this.last = this.evt.xy; 
    205222        } 
    206223        return true; 
     224    }, 
     225     
     226    /** 
     227     * Method: removeTimeout 
     228     * Private. Called by mousemove() to remove the drag timeout. 
     229     */ 
     230    removeTimeout: function() { 
     231        this.timeoutId = null; 
    207232    }, 
    208233