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 *