Ticket #1402: drag.patch
| File drag.patch, 8.3 kB (added by tschaub, 10 months ago) |
|---|
-
lib/OpenLayers/Map.js
old new 1317 1317 * Parameters: 1318 1318 * dx - {Integer} 1319 1319 * dy - {Integer} 1320 * options - {Object} Only one at this time: "animate", which uses 1321 * panTo instead of setCenter. Default is true. 1320 * options - {Object} Options to configure panning: 1321 * - *animate* {Boolean} Use panTo instead of setCenter. Default is true. 1322 * - *dragging* {Boolean} Call setCenter with dragging true. Default is 1323 * false. 1322 1324 */ 1323 1325 pan: function(dx, dy, options) { 1324 1326 // this should be pushed to applyDefaults and extend 1325 1327 if (!options) { 1326 options = {animate: true} 1327 } 1328 options = {}; 1329 } 1330 OpenLayers.Util.applyDefaults(options, { 1331 animate: true, 1332 dragging: false 1333 }); 1328 1334 // getCenter 1329 1335 var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 1330 1336 1331 1337 // adjust 1332 1338 var newCenterPx = centerPx.add(dx, dy); 1333 1339 1334 // only call setCenter if there has been a change1335 if (! newCenterPx.equals(centerPx)) {1340 // only call setCenter if not dragging or there has been a change 1341 if (!options.dragging || !newCenterPx.equals(centerPx)) { 1336 1342 var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 1337 1343 if (options.animate) { 1338 1344 this.panTo(newCenterLonLat); 1339 1345 } else { 1340 this.setCenter(newCenterLonLat );1346 this.setCenter(newCenterLonLat, null, options.dragging); 1341 1347 } 1342 1348 } 1343 1349 -
lib/OpenLayers/Control/DragPan.js
old new 46 46 */ 47 47 panMap: function(xy) { 48 48 this.panned = true; 49 var deltaX = this.handler.last.x - xy.x; 50 var deltaY = this.handler.last.y - xy.y; 51 var size = this.map.getSize(); 52 var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 53 size.h / 2 + deltaY); 54 var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 55 this.map.setCenter(newCenter, null, this.handler.dragging); 49 this.map.pan( 50 this.handler.last.x - xy.x, 51 this.handler.last.y - xy.y, 52 {dragging: this.handler.dragging, animate: false} 53 ); 56 54 }, 57 55 58 56 /** -
lib/OpenLayers/Control/ModifyFeature.js
old new 297 297 * selected feature. 298 298 */ 299 299 selectFeature: function(object) { 300 this.feature = object.feature; 301 this.resetVertices(); 302 this.dragControl.activate(); 303 this.onModificationStart(this.feature); 304 this.layer.events.triggerEvent("beforefeaturemodified", 305 {feature: this.feature}); 300 var cont = this.layer.events.triggerEvent( 301 "beforefeaturemodified", {feature: this.feature} 302 ); 303 if(cont !== false) { 304 this.feature = object.feature; 305 this.resetVertices(); 306 this.dragControl.activate(); 307 this.onModificationStart(this.feature); 308 } 306 309 }, 307 310 308 311 /** -
lib/OpenLayers/Layer/Google.js
old new 75 75 * other maps, etc. 76 76 */ 77 77 sphericalMercator: false, 78 79 /** 80 * Property: dragObject 81 * {GDraggableObject} Since 2.93, Google has exposed the ability to get 82 * the maps GDraggableObject. We can now use this for smooth panning 83 */ 84 dragObject: null, 78 85 79 86 /** 80 87 * Constructor: OpenLayers.Layer.Google … … 106 113 try { 107 114 // create GMap, hide nav controls 108 115 this.mapObject = new GMap2( this.div ); 116 117 //since v 2.93 getDragObject is now available. 118 if(typeof this.mapObject.getDragObject == "function") { 119 this.dragObject = this.mapObject.getDragObject(); 120 } else { 121 this.dragPanMapObject = null; 122 } 109 123 124 110 125 // move the ToS and branding stuff up to the pane 111 126 // thanks a *mil* Erik for thinking of this 112 127 var poweredBy = this.div.lastChild; … … 123 138 termsOfUse.style.right = ""; 124 139 termsOfUse.style.bottom = ""; 125 140 126 //can we do smooth panning? (some versions don't)127 if ( !this.mapObject.G || !this.mapObject.G.qb ||128 (typeof this.mapObject.G.qb != "function") ) {129 130 this.dragPanMapObject = null;131 }132 133 141 } catch (e) { 134 // do not crash142 OpenLayers.Console.error(e); 135 143 } 136 144 137 145 }, … … 343 351 * dY - {Integer} 344 352 */ 345 353 dragPanMapObject: function(dX, dY) { 346 var newX = this.mapObject.G.left - dX; 347 var newY = this.mapObject.G.top + dY; 348 this.mapObject.G.qb(newX, newY); 354 this.dragObject.moveBy(new GSize(-dX, dY)); 349 355 }, 350 356 351 357 /** 352 358 * APIMethod: getMapObjectCenter 353 359 * -
lib/OpenLayers/Layer/EventPane.js
old new 241 241 242 242 if (dragging && this.dragPanMapObject && 243 243 this.smoothDragPan) { 244 var resolution = this.map.getResolution(); 245 var dX = (newCenter.lon - oldCenter.lon) / resolution; 246 var dY = (newCenter.lat - oldCenter.lat) / resolution; 247 this.dragPanMapObject(dX, dY); 244 var oldPx = this.map.getViewPortPxFromLonLat(oldCenter); 245 var newPx = this.map.getViewPortPxFromLonLat(newCenter); 246 this.dragPanMapObject(newPx.x-oldPx.x, oldPx.y-newPx.y); 248 247 } else { 249 248 var center = this.getMapObjectLonLatFromOLLonLat(newCenter); 250 249 var zoom = this.getMapObjectZoomFromOLZoom(newZoom); … … 281 280 var moPixel = this.getMapObjectPixelFromOLPixel(viewPortPx); 282 281 var moLonLat = this.getMapObjectLonLatFromMapObjectPixel(moPixel); 283 282 lonlat = this.getOLLonLatFromMapObjectLonLat(moLonLat); 284 var xrem = this.map.size.w % 2;285 var yrem = this.map.size.h % 2;286 if(xrem != 0 || yrem != 0) {287 // odd sized viewport288 var olPx = viewPortPx.add(xrem, yrem);289 var moPx = this.getMapObjectPixelFromOLPixel(olPx);290 var moLoc = this.getMapObjectLonLatFromMapObjectPixel(moPx);291 var olLoc = this.getOLLonLatFromMapObjectLonLat(moLoc);292 // adjust by half a pixel in odd dimension(s)293 lonlat.lon += (olLoc.lon - lonlat.lon) / 2;294 lonlat.lat += (olLoc.lat - lonlat.lat) / 2;295 }296 283 } 297 284 return lonlat; 298 285 }, -
examples/spherical-mercator.html
old new 11 11 </style> 12 12 13 13 <script src='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script> 14 <script src='http://maps.google.com/maps?file=api&v=2 .82&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>14 <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script> 15 15 <script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script> 16 16 17 17 <script src="../lib/OpenLayers.js"></script>
