From afa7b9c2bbb5833a376e41bc0d0bca3ed63a982b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 9 Jul 2010 21:52:04 +0000 Subject: [PATCH] Making it so the Google layer is not visible if used as an overlay with visibility false. Container is offset to allow proper calculation of size. r=ahocevar (closes #2730) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10480 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/all-overlays-google.html | 29 +++++++++++++++++++++++++++++ examples/all-overlays-google.js | 19 +++++++++++++++++++ lib/OpenLayers/Layer/Google/v3.js | 8 ++++---- tests/Layer/Google/v3.html | 28 +++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 examples/all-overlays-google.html create mode 100644 examples/all-overlays-google.js diff --git a/examples/all-overlays-google.html b/examples/all-overlays-google.html new file mode 100644 index 0000000000..cc3e2da038 --- /dev/null +++ b/examples/all-overlays-google.html @@ -0,0 +1,29 @@ + + + + OpenLayers All Overlays with Google and OSM + + + + + + + + +

All Overlays with Google and OSM

+

+ Using the Google and OSM layers as overlays. +

+
+
+

+ Using the allOverlays property on the map, the first layer added + must initially be visible. This example demonstrates the use of + a Google layer and an OSM layer treated as overlays. +

+ See the + all-overlays-google.js source to see how this is done. +

+
+ + diff --git a/examples/all-overlays-google.js b/examples/all-overlays-google.js new file mode 100644 index 0000000000..f26d3fc80e --- /dev/null +++ b/examples/all-overlays-google.js @@ -0,0 +1,19 @@ +var map; + +function init() { + + map = new OpenLayers.Map({ + div: "map", + allOverlays: true + }); + + var osm = new OpenLayers.Layer.OSM(); + var gmap = new OpenLayers.Layer.Google("Google Streets", {visibility: false}); + + // note that first layer must be visible + map.addLayers([osm, gmap]); + + map.addControl(new OpenLayers.Control.LayerSwitcher()); + map.zoomToMaxExtent(); + +} diff --git a/lib/OpenLayers/Layer/Google/v3.js b/lib/OpenLayers/Layer/Google/v3.js index 97a59b37cf..0be53f2879 100644 --- a/lib/OpenLayers/Layer/Google/v3.js +++ b/lib/OpenLayers/Layer/Google/v3.js @@ -102,8 +102,8 @@ OpenLayers.Layer.Google.v3 = { OpenLayers.Function.bind(this.repositionMapElements, this) ); } - this.mapObject = mapObject; + this.setGMapVisibility(this.visibility); }, /** @@ -146,7 +146,7 @@ OpenLayers.Layer.Google.v3 = { poweredBy.className = "olLayerGooglePoweredBy olLayerGoogleV3 gmnoprint"; poweredBy.style.display = ""; cache.poweredBy = poweredBy; - + this.setGMapVisibility(true); }, @@ -183,7 +183,7 @@ OpenLayers.Layer.Google.v3 = { var container = this.mapObject.getDiv(); if (visible === true) { this.mapObject.setMapTypeId(this.type); - container.style.display = ""; + container.style.left = ""; if (cache.termsOfUse && cache.termsOfUse.style) { cache.termsOfUse.style.left = ""; cache.termsOfUse.style.display = ""; @@ -195,7 +195,7 @@ OpenLayers.Layer.Google.v3 = { delete cache.displayed; } if (!cache.displayed) { - container.style.display = "none"; + container.style.left = "-9999px"; if (cache.termsOfUse && cache.termsOfUse.style) { cache.termsOfUse.style.display = "none"; // move ToU far to the left in addition to setting diff --git a/tests/Layer/Google/v3.html b/tests/Layer/Google/v3.html index e29c74aef0..30a2c7a429 100644 --- a/tests/Layer/Google/v3.html +++ b/tests/Layer/Google/v3.html @@ -226,7 +226,7 @@ gmap.repositionMapElements = function() { ++called; original.apply(gmap, arguments); - } + } gmap.setVisibility(true); t.delay_call(2, function() { @@ -235,6 +235,32 @@ }); } + function test_allOverlays_invisible(t) { + + t.plan(1); + + var map = new OpenLayers.Map('map', {allOverlays: true}); + + var osm = new OpenLayers.Layer.OSM(); + var gmap = new OpenLayers.Layer.Google("Google Streets", {visibility: false}); + + // keep track of last argument to setGMapVisibility + var visible; + var original = gmap.setGMapVisibility; + gmap.setGMapVisibility = function(vis) { + visible = vis; + original.apply(gmap, arguments); + } + + map.addLayers([osm, gmap]); + map.zoomToMaxExtent(); + + t.ok(visible === false, "setGMapVisibility last called with false"); + + map.destroy(); + + } +