Ticket #774: dragging.patch
| File dragging.patch, 6.2 kB (added by tschaub, 1 year ago) |
|---|
-
tests/Handler/test_Drag.html
old new 83 83 } 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: []}); 89 89 … … 141 141 map.events.triggerEvent("mousedown", testEvents.down); 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; 146 149 handler.checkModifiers = oldCheckModifiers; … … 156 159 handler.started = true; 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"); 159 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; 175 160 176 // test mouseup 161 177 handler.started = false; 162 178 map.events.triggerEvent("mouseup", {xy: {x: null, y: null}}); … … 170 186 testEvents.done = testEvents.up; 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 175 192 handler.started = false; -
lib/OpenLayers/Control/DragPan.js
old new 27 27 */ 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 33 33 /** … … 37 37 * xy - {<OpenLayers.Pixel>} Pixel of the up position 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; 46 this.map.setCenter(newCenter, null, this.handler.dragging); 50 47 }, 51 52 /**53 * Method: panMapDone54 *55 * Parameters:56 * xy - {<OpenLayers.Pixel>} Pixel of the up position57 */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.Drag67 // a safe bet for now, and saves us the extra call to clone().68 this.handler.start = xy;69 },70 48 71 49 CLASS_NAME: "OpenLayers.Control.DragPan" 72 50 }); -
lib/OpenLayers/Handler/Drag.js
old new 39 39 dragging: false, 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 /** 48 48 * Property: oldOnselectstart … … 90 90 if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { 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"; 96 96 this.callback("down", [evt.xy]); … … 112 112 */ 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 } 122 125 return true; … … 135 138 mouseup: function (evt) { 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 = ""; 140 144 this.callback("up", [evt.xy]);
