Changeset 3902
- Timestamp:
- 08/14/07 11:27:59 (1 year ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Control/DragPan.js (modified) (4 diffs)
- trunk/openlayers/tests/Control/test_DragPan.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Control/DragPan.js
r3891 r3902 22 22 23 23 /** 24 * Property: panned 25 * {Boolean} The map moved. 26 */ 27 panned: false, 28 29 /** 24 30 * Method: draw 25 31 * Creates a Drag handler, using <OpenLayers.Control.PanMap.panMap> and … … 27 33 */ 28 34 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}); 31 37 }, 32 38 … … 35 41 * 36 42 * Parameters: 37 * xy - {<OpenLayers.Pixel>} Pixel of the upposition43 * xy - {<OpenLayers.Pixel>} Pixel of the mouse position 38 44 */ 39 panMap: function (xy) { 45 panMap: function(xy) { 46 this.panned = true; 40 47 var deltaX = this.handler.last.x - xy.x; 41 48 var deltaY = this.handler.last.y - xy.y; … … 43 50 var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 44 51 size.h / 2 + deltaY); 45 var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 52 var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 46 53 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 } 47 69 }, 48 70 trunk/openlayers/tests/Control/test_DragPan.html
r3888 r3902 3 3 <script src="../../lib/OpenLayers.js"></script> 4 4 <script type="text/javascript"><!-- 5 var map ;5 var map, control, layer; 6 6 7 7 function init_map() { … … 37 37 t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag"); 38 38 } 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 } 39 74 40 75 // -->
