Changeset 3891
- Timestamp:
- 08/10/07 23:32:41 (1 year ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Control/DragPan.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Handler/Drag.js (modified) (4 diffs)
- trunk/openlayers/tests/Handler/test_Drag.html (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Control/DragPan.js
r3787 r3891 28 28 draw: function() { 29 29 this.handler = new OpenLayers.Handler.Drag( this, 30 {"move": this.panMap, "up": this.panMap Done} );30 {"move": this.panMap, "up": this.panMap} ); 31 31 }, 32 32 … … 38 38 */ 39 39 panMap: function (xy) { 40 var deltaX = this.handler. start.x - xy.x;41 var deltaY = this.handler. start.y - xy.y;40 var deltaX = this.handler.last.x - xy.x; 41 var deltaY = this.handler.last.y - xy.y; 42 42 var size = this.map.getSize(); 43 43 var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 44 44 size.h / 2 + deltaY); 45 45 var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 46 this.map.setCenter(newCenter, null, true); 47 // this assumes xy won't be changed inside Handler.Drag 48 // a safe bet for now, and saves us the extra call to clone(). 49 this.handler.start = xy; 50 }, 51 52 /** 53 * Method: panMapDone 54 * 55 * Parameters: 56 * xy - {<OpenLayers.Pixel>} Pixel of the up position 57 */ 58 panMapDone: function (xy) { 59 var deltaX = this.handler.start.x - xy.x; 60 var deltaY = this.handler.start.y - xy.y; 61 var size = this.map.getSize(); 62 var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 63 size.h / 2 + deltaY); 64 var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 65 this.map.setCenter(newCenter, null, false); 66 // this assumes xy won't be changed inside Handler.Drag 67 // a safe bet for now, and saves us the extra call to clone(). 68 this.handler.start = xy; 46 this.map.setCenter(newCenter, null, this.handler.dragging); 69 47 }, 70 48 trunk/openlayers/lib/OpenLayers/Handler/Drag.js
r3787 r3891 40 40 41 41 /** 42 * Property: start42 * Property: last 43 43 * {<OpenLayers.Pixel>} 44 44 */ 45 start: null,45 last: null, 46 46 47 47 /** … … 91 91 this.started = true; 92 92 this.dragging = false; 93 this. start = evt.xy.clone();93 this.last = evt.xy; 94 94 // TBD replace with CSS classes 95 95 this.map.div.style.cursor = "move"; … … 113 113 mousemove: function (evt) { 114 114 if (this.started) { 115 this.dragging = true; 116 this.callback("move", [evt.xy]); 117 if(!this.oldOnselectstart) { 118 this.oldOnselectstart = document.onselectstart; 119 document.onselectstart = function() {return false;} 115 if(evt.xy.x != this.last.x || evt.xy.y != this.last.y) { 116 this.dragging = true; 117 this.callback("move", [evt.xy]); 118 if(!this.oldOnselectstart) { 119 this.oldOnselectstart = document.onselectstart; 120 document.onselectstart = function() {return false;} 121 } 122 this.last = evt.xy; 120 123 } 121 124 } … … 136 139 if (this.started) { 137 140 this.started = false; 141 this.dragging = false; 138 142 // TBD replace with CSS classes 139 143 this.map.div.style.cursor = ""; trunk/openlayers/tests/Handler/test_Drag.html
r3870 r3891 84 84 85 85 function test_Handler_Drag_callbacks(t) { 86 t.plan(2 5);86 t.plan(28); 87 87 88 88 var map = new OpenLayers.Map('map', {controls: []}); … … 142 142 t.ok(handler.started, "mousedown sets the started flag to true"); 143 143 t.ok(!handler.dragging, "mouse down sets the dragging flag to false"); 144 t.ok(handler.last.x == testEvents.down.xy.x && 145 handler.last.y == testEvents.down.xy.y, 146 "mouse down sets handler.last correctly"); 144 147 OpenLayers.Event.isLeftClick = oldIsLeftClick; 145 148 OpenLayers.Event.stop = oldStop; … … 157 160 map.events.triggerEvent("mousemove", testEvents.move); 158 161 t.ok(handler.dragging, "mousemove sets the dragging flag to true"); 162 t.ok(handler.last.x == testEvents.move.xy.x && 163 handler.last.y == testEvents.move.xy.y, 164 "mouse move sets handler.last correctly"); 165 166 // a second move with the same evt.xy should not trigger move callback 167 // if it does, the test page will complain about a bad plan number 168 var oldMove = handler.callbacks.move; 169 handler.callbacks.move = function() { 170 t.ok(false, 171 "a second move with the same evt.xy should not trigger a move callback"); 172 } 173 map.events.triggerEvent("mousemove", testEvents.move); 174 handler.callbacks.move = oldMove; 159 175 160 176 // test mouseup … … 171 187 map.events.triggerEvent("mouseup", testEvents.up); 172 188 t.ok(!this.started, "mouseup sets the started flag to false"); 189 t.ok(!this.dragging, "mouseup sets the dragging flag to false"); 173 190 174 191 // test mouseout
