diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 763e3800a0..4a2cc4b8eb 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -349,11 +349,6 @@ OpenLayers.Layer = OpenLayers.Class({ this.div.style.width = "100%"; this.div.style.height = "100%"; this.div.dir = "ltr"; - if (this.opacity != null) { - OpenLayers.Util.modifyDOMElement( - this.div, null, null, null, null, null, null, this.opacity - ); - } this.events = new OpenLayers.Events(this, this.div, this.EVENT_TYPES); @@ -1274,8 +1269,11 @@ OpenLayers.Layer = OpenLayers.Class({ setOpacity: function(opacity) { if (opacity != this.opacity) { this.opacity = opacity; - OpenLayers.Util.modifyDOMElement(this.div, null, null, null, - null, null, null, opacity); + for(var i=0, len=this.div.childNodes.length; i diff --git a/tests/Layer/WFS.html b/tests/Layer/WFS.html index b9f85182d2..42b566acfe 100644 --- a/tests/Layer/WFS.html +++ b/tests/Layer/WFS.html @@ -25,6 +25,22 @@ } + function test_Layer_WFS_setOpacity(t) { + t.plan(3); + + var layer = new OpenLayers.Layer.WFS(name, "url", {}); + layer.setOpacity(.5); + t.eq(layer.opacity, 0.5, "vector setOpacity didn't fail"); + var layer = new OpenLayers.Layer.WFS(name, "url", {}, {'featureClass': OpenLayers.Feature.WFS}); + var marker = new OpenLayers.Marker(new OpenLayers.LonLat(0,0)); + marker.setOpacity = function() { + t.ok(true, "Marker setOpacity was called"); + } + layer.addMarker(marker); + layer.setOpacity(.6); + t.eq(layer.opacity, 0.6, "setOpacity didn't fail on markers"); + } + function test_Layer_WFS_destroy(t) { t.plan(13); diff --git a/tests/Layer/WMS.html b/tests/Layer/WMS.html index 557395df30..05b2adb64c 100644 --- a/tests/Layer/WMS.html +++ b/tests/Layer/WMS.html @@ -281,6 +281,31 @@ } + function test_Layer_WMS_setOpacity (t) { + t.plan( 5 ); + + var map = new OpenLayers.Map('map'); + map.projection = "xx"; + tUrl = "http://octo.metacarta.com/cgi-bin/mapserv"; + tParams = { layers: 'basic', + format: 'image/png'}; + tOptions = { 'opacity': '0.5' }; + var tLayer = new OpenLayers.Layer.WMS(name, tUrl, tParams, tOptions); + map.addLayer(tLayer); + map.zoomToMaxExtent(); + t.eq(tLayer.opacity, "0.5", "Opacity is set correctly"); + t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct"); + tLayer.setOpacity("0.6"); + t.eq(tLayer.opacity, "0.6", "setOpacity works properly"); + t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly"); + var pixel = new OpenLayers.Pixel(5,6); + var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); + tile.draw(); + t.eq(parseFloat(tile.imgDiv.style.opacity), 0.6, "Tile opacity is set correctly"); + + map.destroy(); + } + function test_Layer_WMS_Reproject (t) { var validkey = (window.location.protocol == "file:") || (window.location.host == "localhost") ||