diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 6f9d3e16f1..6e85fbaa42 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -274,6 +274,10 @@ OpenLayers.Layer.Google = OpenLayers.Class( if (poweredBy && poweredBy.parentNode) { poweredBy.parentNode.removeChild(poweredBy); } + if (this.mapObject && window.google && google.maps && + google.maps.event && google.maps.event.clearListeners) { + google.maps.event.clearListeners(this.mapObject, 'tilesloaded'); + } } }, diff --git a/lib/OpenLayers/Layer/Google/v3.js b/lib/OpenLayers/Layer/Google/v3.js index 10c3e856c5..067b7a08fc 100644 --- a/lib/OpenLayers/Layer/Google/v3.js +++ b/lib/OpenLayers/Layer/Google/v3.js @@ -53,10 +53,9 @@ OpenLayers.Layer.Google.v3 = { /** * Method: loadMapObject - * Load the GMap and register appropriate event listeners. If we can't - * load GMap2, then display a warning message. + * Load the GMap and register appropriate event listeners. */ - loadMapObject:function() { + loadMapObject: function() { if (!this.type) { this.type = google.maps.MapTypeId.ROADMAP; } @@ -92,7 +91,6 @@ OpenLayers.Layer.Google.v3 = { googleControl.style.width = '100%'; googleControl.style.height = '100%'; mapObject.controls[google.maps.ControlPosition.TOP_LEFT].push(googleControl); - this.map.div.appendChild(container); // cache elements for use by any other google layers added to // this same map @@ -141,13 +139,24 @@ OpenLayers.Layer.Google.v3 = { } var container = this.mapObject.getDiv(); if (visible === true) { - container.style.display = ''; - cache.googleControl.appendChild(map.viewPortDiv); - google.maps.event.trigger(this.mapObject, 'resize'); + if (container.parentNode !== map.div) { + if (!cache.rendered) { + var me = this; + google.maps.event.addListenerOnce(this.mapObject, 'tilesloaded', function() { + cache.rendered = true; + me.setGMapVisibility(me.getVisibility()); + me.moveTo(me.map.getCenter()); + }); + } else { + map.div.appendChild(container); + cache.googleControl.appendChild(map.viewPortDiv); + google.maps.event.trigger(this.mapObject, 'resize'); + } + } this.mapObject.setMapTypeId(type); - } else { + } else if (cache.googleControl.hasChildNodes()) { map.div.appendChild(map.viewPortDiv); - container.style.display = 'none'; + map.div.removeChild(container); } } },