diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 27ac91a69b..e59a49862b 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -2,31 +2,8 @@ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full * text of the license. */ -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 @@ -65,7 +42,7 @@ OpenLayers.Layer.Google.prototype = if (this.maxExtent == null) { this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90); } - + this.addContainerPxFunction(); this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1; }, @@ -431,8 +408,34 @@ OpenLayers.Layer.Google.prototype = } return gLatLngBounds; }, - - + + addContainerPxFunction: function() { + if (typeof GMap2 != "undefined" && !GMap2.fromLatLngToContainerPixel) { + + /** 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; + }; + } + }, /** @final @type String */ CLASS_NAME: "OpenLayers.Layer.Google" });