OpenLayers OpenLayers

Changeset 3902

Show
Ignore:
Timestamp:
08/14/07 11:27:59 (1 year ago)
Author:
tschaub
Message:

#774 - dragPan only calls setCenter if the map moves - thanks for the discussion and careful review Eric!

Files:

Legend:

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

    r3891 r3902  
    2222     
    2323    /** 
     24     * Property: panned 
     25     * {Boolean} The map moved. 
     26     */ 
     27    panned: false, 
     28     
     29    /** 
    2430     * Method: draw 
    2531     * Creates a Drag handler, using <OpenLayers.Control.PanMap.panMap> and 
     
    2733     */     
    2834    draw: function() { 
    29         this.handler = new OpenLayers.Handler.Drag( this, 
    30                             {"move": this.panMap, "up": this.panMap} ); 
     35        this.handler = new OpenLayers.Handler.Drag(this, 
     36                            {"move": this.panMap, "done": this.panMapDone}); 
    3137    }, 
    3238 
     
    3541    * 
    3642    * Parameters: 
    37     * xy - {<OpenLayers.Pixel>} Pixel of the up position 
     43    * xy - {<OpenLayers.Pixel>} Pixel of the mouse position 
    3844    */ 
    39     panMap: function (xy) { 
     45    panMap: function(xy) { 
     46        this.panned = true; 
    4047        var deltaX = this.handler.last.x - xy.x; 
    4148        var deltaY = this.handler.last.y - xy.y; 
     
    4350        var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 
    4451                                         size.h / 2 + deltaY); 
    45         var newCenter = this.map.getLonLatFromViewPortPx( newXY );  
     52        var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 
    4653        this.map.setCenter(newCenter, null, this.handler.dragging); 
     54    }, 
     55     
     56    /** 
     57     * Method: panMapDone 
     58     * Finish the panning operation.  Only call setCenter (through <panMap>) 
     59     *     if the map has actually been moved. 
     60     * 
     61     * Parameters: 
     62     * xy - {<OpenLayers.Pixel>} Pixel of the mouse position 
     63     */ 
     64    panMapDone: function(xy) { 
     65        if(this.panned) { 
     66            this.panMap(xy); 
     67            this.panned = false; 
     68        } 
    4769    }, 
    4870 
  • trunk/openlayers/tests/Control/test_DragPan.html

    r3888 r3902  
    33  <script src="../../lib/OpenLayers.js"></script> 
    44  <script type="text/javascript"><!-- 
    5     var map;  
     5    var map, control, layer;  
    66 
    77    function init_map() { 
     
    3737        t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag"); 
    3838    } 
     39    function test_Control_DragPan_click(t) { 
     40        t.plan(1); 
     41        var control = new OpenLayers.Control.DragPan(); 
     42        var map = new OpenLayers.Map("map", {controls:[control]}); 
     43        var layer = new OpenLayers.Layer.WMS("OpenLayers WMS",  
     44                                        "http://labs.metacarta.com/wms/vmap0", 
     45                                        {layers: 'basic'}); 
     46        map.addLayer(layer);  
     47        map.zoomToMaxExtent(); 
     48        map.zoomIn(); 
     49        control.activate(); 
     50        map.setCenter = function() { 
     51            t.ok(false, "map.setCenter should not be called here"); 
     52        }; 
     53        var xy = new OpenLayers.Pixel(0, 0); 
     54        var down = { 
     55            'type': 'mousedown', 
     56            'xy': xy, 
     57            'which': 1 
     58        }; 
     59        var move = { 
     60            'type': 'mousemove', 
     61            'xy': xy, 
     62            'which': 1 
     63        }; 
     64        var up = { 
     65            'type': 'mouseup', 
     66            'xy': xy, 
     67            'which': 1 
     68        }; 
     69        map.events.triggerEvent('mousedown', down); 
     70        map.events.triggerEvent('mousemove', move); 
     71        map.events.triggerEvent('mouseup', up); 
     72        t.ok(true, "clicking without moving the mouse does not call setCenter"); 
     73    } 
    3974     
    4075  // -->