From 0e53fa10bfd323f785b07751033fe7f8dd04eb77 Mon Sep 17 00:00:00 2001 From: euzuro Date: Tue, 20 Nov 2007 22:21:54 +0000 Subject: [PATCH] patch for smoother dragging of google layer. For now this remains a wierd (and admirable) hack... restricted to the use of v2.82 of the google api... but hot damn. it does work. hopefully the good folks at google might help us out and open this up as part of the API. Dinosaur egg kudos to cr5 for finding this and taking the time to plug it in. Thanks to tschaub for the quick review. (Closes #816) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5224 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/draggingGoogle.html | 62 +++++++++++++++++++++++++++++++ lib/OpenLayers/Layer/EventPane.js | 12 +++++- lib/OpenLayers/Layer/Google.js | 20 ++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100755 examples/draggingGoogle.html diff --git a/examples/draggingGoogle.html b/examples/draggingGoogle.html new file mode 100755 index 0000000000..c4721721f9 --- /dev/null +++ b/examples/draggingGoogle.html @@ -0,0 +1,62 @@ + + + + + + + + + + +

OpenLayers With Responsive Google Dragging

+

Uses Google Maps v2.82

+
+ + diff --git a/lib/OpenLayers/Layer/EventPane.js b/lib/OpenLayers/Layer/EventPane.js index 3c8a75cd07..02464556d6 100644 --- a/lib/OpenLayers/Layer/EventPane.js +++ b/lib/OpenLayers/Layer/EventPane.js @@ -225,8 +225,16 @@ OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, { !(newZoom == oldZoom) ) { var center = this.getMapObjectLonLatFromOLLonLat(newCenter); - var zoom = this.getMapObjectZoomFromOLZoom(newZoom); - this.setMapObjectCenter(center, zoom); + + if (dragging && this.dragPanMapObject) { + var res = this.map.resolution; //readability + var dX = (newCenter.lon - oldCenter.lon) / res; + var dY = (newCenter.lat - oldCenter.lat) / res; + this.dragPanMapObject(dX, dY); + } else { + var zoom = this.getMapObjectZoomFromOLZoom(newZoom); + this.setMapObjectCenter(center, zoom, dragging); + } } } } diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 9d247cb401..92e652ed2b 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -119,6 +119,13 @@ 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 } @@ -334,6 +341,19 @@ OpenLayers.Layer.Google = OpenLayers.Class( this.mapObject.setCenter(center, zoom); }, + /** + * APIMethod: dragPanMapObject + * + * Parameters: + * dX - {Integer} + * 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); + }, + /** * APIMethod: getMapObjectCenter *