Smooth GDragging at last. Thanks to overstdr for digging up the getDragObject method. With v2.93 and later we no longer get flickers on panning. Non-API smooth dragging is no longer supported. r=crschmidt,me (closes #1402)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6492 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-03-11 18:32:17 +00:00
parent 008c820e2b
commit d12fd7c04c
6 changed files with 47 additions and 45 deletions

View File

@@ -241,10 +241,9 @@ OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, {
if (dragging && this.dragPanMapObject &&
this.smoothDragPan) {
var resolution = this.map.getResolution();
var dX = (newCenter.lon - oldCenter.lon) / resolution;
var dY = (newCenter.lat - oldCenter.lat) / resolution;
this.dragPanMapObject(dX, dY);
var oldPx = this.map.getViewPortPxFromLonLat(oldCenter);
var newPx = this.map.getViewPortPxFromLonLat(newCenter);
this.dragPanMapObject(newPx.x-oldPx.x, oldPx.y-newPx.y);
} else {
var center = this.getMapObjectLonLatFromOLLonLat(newCenter);
var zoom = this.getMapObjectZoomFromOLZoom(newZoom);
@@ -281,18 +280,6 @@ OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, {
var moPixel = this.getMapObjectPixelFromOLPixel(viewPortPx);
var moLonLat = this.getMapObjectLonLatFromMapObjectPixel(moPixel);
lonlat = this.getOLLonLatFromMapObjectLonLat(moLonLat);
var xrem = this.map.size.w % 2;
var yrem = this.map.size.h % 2;
if(xrem != 0 || yrem != 0) {
// odd sized viewport
var olPx = viewPortPx.add(xrem, yrem);
var moPx = this.getMapObjectPixelFromOLPixel(olPx);
var moLoc = this.getMapObjectLonLatFromMapObjectPixel(moPx);
var olLoc = this.getOLLonLatFromMapObjectLonLat(moLoc);
// adjust by half a pixel in odd dimension(s)
lonlat.lon += (olLoc.lon - lonlat.lon) / 2;
lonlat.lat += (olLoc.lat - lonlat.lat) / 2;
}
}
return lonlat;
},

View File

@@ -75,6 +75,13 @@ OpenLayers.Layer.Google = OpenLayers.Class(
* other maps, etc.
*/
sphericalMercator: false,
/**
* Property: dragObject
* {GDraggableObject} Since 2.93, Google has exposed the ability to get
* the maps GDraggableObject. We can now use this for smooth panning
*/
dragObject: null,
/**
* Constructor: OpenLayers.Layer.Google
@@ -106,6 +113,14 @@ OpenLayers.Layer.Google = OpenLayers.Class(
try {
// create GMap, hide nav controls
this.mapObject = new GMap2( this.div );
//since v 2.93 getDragObject is now available.
if(typeof this.mapObject.getDragObject == "function") {
this.dragObject = this.mapObject.getDragObject();
} else {
this.dragPanMapObject = null;
}
// move the ToS and branding stuff up to the pane
// thanks a *mil* Erik for thinking of this
@@ -123,15 +138,8 @@ OpenLayers.Layer.Google = OpenLayers.Class(
termsOfUse.style.right = "";
termsOfUse.style.bottom = "";
//can we do smooth panning? (some versions don't)
if ( !this.mapObject.G || !this.mapObject.G.qb ||
(typeof this.mapObject.G.qb != "function") ) {
this.dragPanMapObject = null;
}
} catch (e) {
// do not crash
OpenLayers.Console.error(e);
}
},
@@ -343,11 +351,9 @@ OpenLayers.Layer.Google = OpenLayers.Class(
* dY - {Integer}
*/
dragPanMapObject: function(dX, dY) {
var newX = this.mapObject.G.left - dX;
var newY = this.mapObject.G.top + dY;
this.mapObject.G.qb(newX, newY);
this.dragObject.moveBy(new GSize(-dX, dY));
},
/**
* APIMethod: getMapObjectCenter
*