Ticket #1125: OpenLayersSmoothDrag.patch
| File OpenLayersSmoothDrag.patch, 3.3 kB (added by haakeyar, 1 year ago) |
|---|
-
tests/Control/test_DragPan.html
old new 32 32 map.events.triggerEvent('mousedown', {'type':'mousedown', 'xy':new OpenLayers.Pixel(0,0), 'which':1}); 33 33 map.events.triggerEvent('mousemove', {'type':'mousemove', 'xy':new OpenLayers.Pixel(5,5), 'which':1}); 34 34 map.events.triggerEvent('mouseup', {'type':'mouseup', 'xy':new OpenLayers.Pixel(5,5), 'which':1}); 35 36 t.eq(map.getCenter().lat, res * 5, "Lat is " + (res * 5) + " after drag"); 37 t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag"); 35 t.delay_call(0.2, function() 36 { 37 t.eq(map.getCenter().lat, res * 5, "Lat is " + (res * 5) + " after drag"); 38 t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag"); 39 }); 38 40 } 39 41 function test_Control_DragPan_click(t) { 40 42 t.plan(1); -
lib/OpenLayers/Control/DragPan.js
old new 27 27 panned: false, 28 28 29 29 /** 30 * Property: deltaX 31 * {Integer} The number of x pixels that has been moved since the last update of the map 32 */ 33 deltaX: 0, 34 35 /** 36 * Property: deltaX 37 * {Integer} The number of y pixels that has been moved since the last update of the map 38 */ 39 deltaY: 0, 40 41 /** 42 * Property: updateMapTimeout 43 * {Integer} The identifier for the timeout that will update the map. 44 */ 45 updateMapTimeout: null, 46 47 /** 30 48 * Method: draw 31 49 * Creates a Drag handler, using <OpenLayers.Control.PanMap.panMap> and 32 50 * <OpenLayers.Control.PanMap.panMapDone> as callbacks. … … 44 62 */ 45 63 panMap: function(xy) { 46 64 this.panned = true; 47 var deltaX = this.handler.last.x - xy.x; 48 var deltaY = this.handler.last.y - xy.y; 65 this.deltaX += this.handler.last.x - xy.x; 66 this.deltaY += this.handler.last.y - xy.y; 67 if(this.updateMapTimeout == null) // If there is already a timeout waiting to update the map, do nothing. If there isn't, create one. 68 { 69 this.updateMapTimeout = setTimeout(OpenLayers.Function.bind(this.updateMap, this), 10); // Wait 10 ms and update the map. 70 } 71 }, 72 73 /** 74 * Method: updateMap 75 * Update the map to the new position set by panMap. 76 * Called automatically from panMap in a timeout. 77 * 78 * @private 79 */ 80 updateMap: function() 81 { 49 82 var size = this.map.getSize(); 50 var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 51 size.h / 2 + deltaY); 83 var newXY = new OpenLayers.Pixel(size.w / 2 + this.deltaX, 84 size.h / 2 + this.deltaY); 85 86 // Clean up, so that a new timeout will be created on the next move event 87 this.updateMapTimeout = null; 88 this.deltaX = 0; 89 this.deltaY = 0; 90 52 91 var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 53 92 this.map.setCenter(newCenter, null, this.handler.dragging); 54 93 },
