From 10bc8f5726c017a118d91ba5cc91450975e2530f Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 10 Mar 2009 18:07:53 +0000 Subject: [PATCH] "Switching between google layers after map resize", after map size change, as is used by mapfish and others, the google map can get confused as to its size and not resize correctly. This patch changes that so that the check happens on moveTo, so we know if the map has resized. The checkResize is a cheap call in the default case. r=me, patch by gregers, (Closes #1797) git-svn-id: http://svn.openlayers.org/trunk/openlayers@8990 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google.js | 40 +++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index ba17861ae7..566d23cb2d 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -190,13 +190,25 @@ OpenLayers.Layer.Google = OpenLayers.Class( * evt - {Event} */ onMapResize: function() { + this.windowResized = true; if(this.visibility) { - this.mapObject.checkResize(); - } else { - this.windowResized = true; + 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; + } + }, + /** * Method: display * Hide or show the layer @@ -206,10 +218,22 @@ OpenLayers.Layer.Google = OpenLayers.Class( */ display: function(display) { OpenLayers.Layer.EventPane.prototype.display.apply(this, arguments); - if(this.div.style.display == "block" && this.windowResized) { - this.mapObject.checkResize(); - this.windowResized = false; - } + this.checkResize(); + }, + + /** + * 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(); }, /**