diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index e5134ed777..9150f917a7 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -217,7 +217,7 @@ OpenLayers.Layer.Google = OpenLayers.Class( delete layer._resized; layer.mapObject.checkResize(); layer.moveTo(layer.map.getCenter(), layer.map.getZoom()); - }) + }); } this._resized = true; } @@ -257,6 +257,7 @@ OpenLayers.Layer.Google = OpenLayers.Class( if (visible === true) { this.mapObject.setMapType(this.type); container.style.display = ""; + this.termsOfUse.style.left = ""; this.termsOfUse.style.display = ""; this.poweredBy.style.display = ""; cache.displayed = this.id; @@ -267,6 +268,12 @@ OpenLayers.Layer.Google = OpenLayers.Class( if (!cache.displayed) { container.style.display = "none"; this.termsOfUse.style.display = "none"; + // move ToU far to the left in addition to setting display + // to "none", because at the end of the GMap2 load + // sequence, display: none will be unset and ToU would be + // visible after loading a map with a google layer that is + // initially hidden. + this.termsOfUse.style.left = "-9999px"; this.poweredBy.style.display = "none"; } } diff --git a/tests/Layer/Google.html b/tests/Layer/Google.html index 4948133ffe..3dbae82bfc 100644 --- a/tests/Layer/Google.html +++ b/tests/Layer/Google.html @@ -209,6 +209,27 @@ } } + function test_Layer_Google_setGMapVisibility(t) { + if(validkey) { + t.plan(3); + var map = new OpenLayers.Map('map'); + var gmap = new OpenLayers.Layer.Google("Google Streets"); + var dummy = new OpenLayers.Layer("Dummy", {isBaseLayer: true}); + map.addLayers([dummy, gmap]); + map.zoomToMaxExtent(); + + t.delay_call(2, function() { + t.eq(map.baseLayer.name, "Dummy", "Dummy layer is the base layer"); + t.ok(gmap.termsOfUse.style.display == "none" || gmap.termsOfUse.style.left == "-9999px", "termsOfUse is not visible"); + t.eq(gmap.poweredBy.style.display, "none", "poweredBy is not visible"); + }); + } else { + t.plan(0); + t.debug_print("Google tests can't be run from " + + window.location.host); + } + } +