From 39536e788ad1bfb73e1a878f7b1aa7ce7263e491 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Mon, 21 Aug 2006 19:34:15 +0000 Subject: [PATCH] If Google fails to load before OpenLayers, occasionally dragging is not possible with Google, because GMap2 would be undefined when the Google class is included. So, we put this in a wrapper function, and call it when you init the layer instead. git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1321 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google.js | 59 ++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 28 deletions(-) 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" });