diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 023b8011f2..065801b00f 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -1,8 +1,36 @@ /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full * text of the license. */ + // @require: OpenLayers/Layer.js + +if (typeof GMap2 != "undefined") { + + /** Hack-on function because GMAPS does not give it to us + * + * @param {GLatLng} gLatLng + * + * @returns A GPoint specifying gLatLng translated into "Container" coords + * @type GPoint + */ + GMap2.prototype.fromLatLngToContainerPixel = function(gLatLng) { + + // first we translate into "DivPixel" + var gPoint = this.fromLatLngToDivPixel(gLatLng); + + // locate the sliding "Div" div + // it seems like "b" is the main div + var div = this.b.firstChild.firstChild; + + // adjust by the offset of "Div" and voila! + gPoint.x += div.offsetLeft; + gPoint.y += div.offsetTop; + + return gPoint; + }; +} + /** * @class */ @@ -188,40 +216,14 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { if (this.gmap != null) { var gLatLng = this.getGLatLngFromOLLonLat(lonlat); - // note we use special hacked function here, - // because GMaps doesnt give it to us - var gPoint = this.fromLatLngToContainerPixel(gLatLng); + // note we use special hacked function here + var gPoint = this.gmap.fromLatLngToContainerPixel(gLatLng); viewPortPx = this.getOLPixelFromGPoint(gPoint); } return viewPortPx; }, - /** 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