diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 483c53930d..79388df452 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -148,6 +148,12 @@ OpenLayers.Layer.prototype = { Object.extend(this, this.options); }, + /** + * + */ + onMapResize: function() { + //this function can be implemented by subclasses + }, /** * @param {OpenLayers.Bounds} bound diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 922b069a9d..3aaeefd480 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -147,6 +147,13 @@ OpenLayers.Layer.Google.prototype = } }, + /** + * @param {Event} evt + */ + onMapResize: function() { + this.gmap.checkResize(); + }, + /** If we can't load the GMap, then display an error message to the * user and tell them where to go for help. * diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 4aea80fff5..349dba9879 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -148,7 +148,7 @@ OpenLayers.Map.prototype = { Event.observe(window, 'resize', this.updateSize.bindAsEventListener(this)); } - + //set the default options this.setOptions(options); @@ -470,14 +470,18 @@ OpenLayers.Map.prototype = { if (oldSize == null) this.size = oldSize = newSize; if (!newSize.equals(oldSize)) { - // move the layer container so that the map is still centered - var dx = (newSize.w - oldSize.w) / 2, - dy = (newSize.h - oldSize.h) / 2; - var lcStyle = this.layerContainerDiv.style; - lcStyle.left = (parseInt(lcStyle.left) + dx) + "px"; - lcStyle.top = (parseInt(lcStyle.top ) + dy) + "px"; - // reset the map center - this.layerContainerOrigin = this.center.clone(); + + //notify layers of mapresize + for(var i=0; i < this.layers.length; i++) { + this.layers[i].onMapResize(); + } + + var center = new OpenLayers.Pixel(newSize.w /2, newSize.h / 2); + + var zoom = this.getZoom(); + this.zoom = null; + this.setCenter(center, zoom); + // store the new size this.size = newSize; // the div might have moved on the page, also