From b98dba227e156725e0f1411666dab5e337c8b677 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 30 Apr 2009 21:52:08 +0000 Subject: [PATCH] Fix GMap initialization sequence when resizing previously invisible layers. r=tschaub (pullup #1797) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9333 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google.js | 48 ++++++++++++---------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index c6bdf4f81a..48d516cb89 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -212,22 +212,24 @@ OpenLayers.Layer.Google = OpenLayers.Class( * evt - {Event} */ onMapResize: function() { - this.windowResized = true; if(this.visibility) { - this.checkResize(); - } - }, - - /** - * APIMethod: checkResize - * Check if the map has been resized, and if the Google Maps object is ready for checkResize. - * If the mapObject.getSize() equals the layer div's offset size, or if mapObject.getCenter() - * is null, the mapObject.checkResize() will fail. - */ - checkResize: function() { - if (this.windowResized && this.div.style.display != "none" && this.mapObject.getCenter()) { this.mapObject.checkResize(); - this.windowResized = false; + } else { + // workaround for resizing of invisible layers where + // GMap2.checkResize() does not work. We need to load all tiles + // for the old div size, then checkResize(), and then call + // layer.moveTo() to trigger GMap.setCenter() (which will finish + // the GMap initialization). + if(!this._resized) { + var layer = this; + var handle = GEvent.addListener(this.mapObject, "tilesloaded", function() { + GEvent.removeListener(handle); + delete layer._resized; + layer.mapObject.checkResize(); + layer.moveTo(layer.map.getCenter(), layer.map.getZoom()); + }) + } + this._resized = true; } }, @@ -240,7 +242,6 @@ OpenLayers.Layer.Google = OpenLayers.Class( */ display: function(display) { OpenLayers.Layer.EventPane.prototype.display.apply(this, arguments); - this.checkResize(); this.termsOfUse.style.display = this.div.style.display; this.poweredBy.style.display = this.div.style.display; }, @@ -263,22 +264,7 @@ OpenLayers.Layer.Google = OpenLayers.Class( } OpenLayers.Layer.EventPane.prototype.removeMap.apply(this, arguments); }, - - /** - * Method: moveTo - * Handle calls to move the layer. - * - * Parameters: - * bound - {} - * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to - * do some init work in that case. - * dragging - {Boolean} - */ - moveTo:function(bounds, zoomChanged, dragging) { - OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); - this.checkResize(); - }, - + /** * APIMethod: getZoomForExtent *