From a02c0ea8b7f6923a2ec1ec7ab6d43137ed0889a8 Mon Sep 17 00:00:00 2001 From: euzuro Date: Fri, 30 Jun 2006 01:04:10 +0000 Subject: [PATCH] you wanted viewportpx from latlon? well, you got it mister. using a small and but ingenious hack by the astute dr. steven erle, we are able to fix the last remaining (famous last words) kink in the google layer. seems like it should be all a-o-k now. Changed the getLonLatFromViewPortPx() to use the Container as well. Case closed. git-svn-id: http://svn.openlayers.org/trunk/openlayers@834 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google.js | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index e4a3bc623f..9ea219534b 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -172,7 +172,7 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { */ getLonLatFromViewPortPx: function (viewPortPx) { var gPoint = this.getGPointFromOLPixel(viewPortPx); - var gLatLng = this.gmap.fromDivPixelToLatLng(gPoint) + var gLatLng = this.gmap.fromContainerPixelToLatLng(gPoint) return this.getOLLonLatFromGLatLng(gLatLng); }, @@ -187,11 +187,40 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { */ getViewPortPxFromLonLat: function (lonlat) { var gLatLng = this.getGLatLngFromOLLonLat(lonlat); - var gPoint = this.gmap.fromLatLngToDivPixel(gLatLng) - + + // note we use special hacked function here, + // because GMaps doesnt give it to us + var gPoint = this.fromLatLngToContainerPixel(gLatLng); + return this.getOLPixelFromGPoint(gPoint); }, + /** Hacked function because GMAPS does not give us + * a fromLatLngToContainerPixel. Cheers sde for the + * firstChild.firstChild find. + * + * @param {GLatLng} gLatLng + * + * @returns A GPoint specifying gLatLng translated into "Container" + * coordinates + * @type GPoint + */ + fromLatLngToContainerPixel: function(gLatLng) { + + // first we translate into "DivPixel" + var gPoint = this.gmap.fromLatLngToDivPixel(gLatLng); + + // locate the sliding "Div" div + var div = this.div.firstChild.firstChild; + + // adjust by the offset of "Div" and voila! + gPoint.x += div.offsetLeft; + gPoint.y += div.offsetTop; + + return gPoint; + }, + + /** * @param {OpenLayers.Bounds} bounds *