After r10021 we lost the ability to set the opacity of a Google layer. This makes layer.setOpacity work again by setting the opactiy of the shared GMap container. r=bartvde (pullup #2562)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10174 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-04-07 22:35:59 +00:00
parent d5daa28fed
commit 295363fe58
2 changed files with 81 additions and 1 deletions

View File

@@ -234,7 +234,57 @@
t.debug_print("Google tests can't be run from " +
window.location.host);
}
}
}
function test_setOpacity(t) {
t.plan(6);
var map = new OpenLayers.Map("map");
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: G_HYBRID_MAP, numZoomLevels: 20}
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: G_SATELLITE_MAP, numZoomLevels: 22}
);
map.addLayers([gmap, ghyb, gsat]);
map.zoomToMaxExtent();
var container = map.baseLayer.mapObject.getContainer();
var opacityCheck = function(opacity) {
var style = container.style;
var current = style.opacity === "" ? 1 : parseFloat(style.opacity);
if (style.filter && !style.opacity) {
current = Number(style.filter.replace(/alpha\(opacity=(.+?)\)/, "$1"));
}
return (current === opacity);
};
gmap.setOpacity(0.5);
t.ok(opacityCheck(0.5), "container opacity set for visible layer");
ghyb.setOpacity(0.75);
t.ok(opacityCheck(0.5), "container opacity not changed if layer not visible");
map.setBaseLayer(ghyb);
t.ok(opacityCheck(0.75), "container opacity changed to 0.75 when layer becomes visible");
map.setBaseLayer(gsat);
t.ok(opacityCheck(1), "container opacity set to 1 by default");
gsat.setOpacity(0.25);
t.ok(opacityCheck(0.25), "container opacity changed to 0.25 for visible layer");
map.setBaseLayer(gmap);
t.ok(opacityCheck(0.5), "container opacity set to layer opacity");
map.destroy();
}
function test_Layer_Google_setGMapVisibility(t) {
if(validkey) {