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
This commit is contained in:
29
examples/all-overlays-google.html
Normal file
29
examples/all-overlays-google.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>OpenLayers All Overlays with Google and OSM</title>
|
||||||
|
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="../theme/default/google.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="style.css" type="text/css">
|
||||||
|
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
|
||||||
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
|
<script src="all-overlays-google.js"></script>
|
||||||
|
</head>
|
||||||
|
<body onload="init()">
|
||||||
|
<h1 id="title">All Overlays with Google and OSM</h1>
|
||||||
|
<p id="shortdesc">
|
||||||
|
Using the Google and OSM layers as overlays.
|
||||||
|
</p>
|
||||||
|
<div id="map" class="smallmap"></div>
|
||||||
|
<div id="docs">
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p><p>
|
||||||
|
See the <a href="all-overlays-google.js" target="_blank">
|
||||||
|
all-overlays-google.js source</a> to see how this is done.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
19
examples/all-overlays-google.js
Normal file
19
examples/all-overlays-google.js
Normal file
@@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -102,8 +102,8 @@ OpenLayers.Layer.Google.v3 = {
|
|||||||
OpenLayers.Function.bind(this.repositionMapElements, this)
|
OpenLayers.Function.bind(this.repositionMapElements, this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mapObject = mapObject;
|
this.mapObject = mapObject;
|
||||||
|
this.setGMapVisibility(this.visibility);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,7 +146,7 @@ OpenLayers.Layer.Google.v3 = {
|
|||||||
poweredBy.className = "olLayerGooglePoweredBy olLayerGoogleV3 gmnoprint";
|
poweredBy.className = "olLayerGooglePoweredBy olLayerGoogleV3 gmnoprint";
|
||||||
poweredBy.style.display = "";
|
poweredBy.style.display = "";
|
||||||
cache.poweredBy = poweredBy;
|
cache.poweredBy = poweredBy;
|
||||||
|
|
||||||
this.setGMapVisibility(true);
|
this.setGMapVisibility(true);
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -183,7 +183,7 @@ OpenLayers.Layer.Google.v3 = {
|
|||||||
var container = this.mapObject.getDiv();
|
var container = this.mapObject.getDiv();
|
||||||
if (visible === true) {
|
if (visible === true) {
|
||||||
this.mapObject.setMapTypeId(this.type);
|
this.mapObject.setMapTypeId(this.type);
|
||||||
container.style.display = "";
|
container.style.left = "";
|
||||||
if (cache.termsOfUse && cache.termsOfUse.style) {
|
if (cache.termsOfUse && cache.termsOfUse.style) {
|
||||||
cache.termsOfUse.style.left = "";
|
cache.termsOfUse.style.left = "";
|
||||||
cache.termsOfUse.style.display = "";
|
cache.termsOfUse.style.display = "";
|
||||||
@@ -195,7 +195,7 @@ OpenLayers.Layer.Google.v3 = {
|
|||||||
delete cache.displayed;
|
delete cache.displayed;
|
||||||
}
|
}
|
||||||
if (!cache.displayed) {
|
if (!cache.displayed) {
|
||||||
container.style.display = "none";
|
container.style.left = "-9999px";
|
||||||
if (cache.termsOfUse && cache.termsOfUse.style) {
|
if (cache.termsOfUse && cache.termsOfUse.style) {
|
||||||
cache.termsOfUse.style.display = "none";
|
cache.termsOfUse.style.display = "none";
|
||||||
// move ToU far to the left in addition to setting
|
// move ToU far to the left in addition to setting
|
||||||
|
|||||||
@@ -226,7 +226,7 @@
|
|||||||
gmap.repositionMapElements = function() {
|
gmap.repositionMapElements = function() {
|
||||||
++called;
|
++called;
|
||||||
original.apply(gmap, arguments);
|
original.apply(gmap, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
gmap.setVisibility(true);
|
gmap.setVisibility(true);
|
||||||
t.delay_call(2, function() {
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user