Skip to content

Commit

Permalink
reverting r12185 from #3431
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.openlayers.org/branches/openlayers/2.11@12232 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
  • Loading branch information
ahocevar committed Aug 10, 2011
1 parent 78c2e77 commit 061eeac
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 17 deletions.
12 changes: 5 additions & 7 deletions lib/OpenLayers/Layer.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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<len; ++i) {
var element = this.div.childNodes[i].firstChild;
OpenLayers.Util.modifyDOMElement(element, null, null, null,
null, null, null, opacity);
}
if (this.map != null) {
this.map.events.triggerEvent("changelayer", {
layer: this,
Expand Down
16 changes: 16 additions & 0 deletions lib/OpenLayers/Layer/Markers.js
Expand Up @@ -60,6 +60,22 @@ OpenLayers.Layer.Markers = OpenLayers.Class(OpenLayers.Layer, {
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
},

/**
* APIMethod: setOpacity
* Sets the opacity for all the markers.
*
* Parameter:
* opacity - {Float}
*/
setOpacity: function(opacity) {
if (opacity != this.opacity) {
this.opacity = opacity;
for (var i=0, len=this.markers.length; i<len; i++) {
this.markers[i].setOpacity(this.opacity);
}
}
},

/**
* Method: moveTo
*
Expand Down
16 changes: 16 additions & 0 deletions lib/OpenLayers/Layer/WFS.js
Expand Up @@ -590,5 +590,21 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
return extent;
},

/**
* APIMethod: setOpacity
* Call the setOpacity method of the appropriate parent class to set the
* opacity.
*
* Parameter:
* opacity - {Float}
*/
setOpacity: function (opacity) {
if (this.vectorMode) {
OpenLayers.Layer.Vector.prototype.setOpacity.apply(this, [opacity]);
} else {
OpenLayers.Layer.Markers.prototype.setOpacity.apply(this, [opacity]);
}
},

CLASS_NAME: "OpenLayers.Layer.WFS"
});
12 changes: 2 additions & 10 deletions tests/Layer.html
Expand Up @@ -786,23 +786,21 @@
}

function test_setOpacity(t) {
t.plan(8);
t.plan(5);

var map, layer, log;

map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer("", {opacity: 0.56});
layer = new OpenLayers.Layer("");
map.addLayer(layer);

t.eq(layer.div.style.opacity, "0.56", "initial opacity correctly applied as layer.div style");
log = [];
map.events.register('changelayer', t, function(event) {
log.push({layer: event.layer, property: event.property});
});
layer.setOpacity(0.42);
t.eq(layer.opacity, 0.42,
"setOpacity() set layer.opacity to correct value");
t.eq(layer.div.style.opacity, "0.42", "opacity correctly applied as layer.div style");
t.eq(log.length, 1,
"setOpacity() triggers changelayer once");
t.ok(log[0].layer == layer,
Expand All @@ -815,12 +813,6 @@
layer.setOpacity(0.42);
t.eq(log.length, 0,
"setOpacity() does not trigger changelayer if the opacity value is the same");

// 0 as initial opacity
layer.destroy();
layer = new OpenLayers.Layer("", {opacity: 0});
map.addLayer(layer);
t.eq(layer.div.style.opacity, "0", "initial opacity correctly applied as layer.div style");
}


Expand Down
25 changes: 25 additions & 0 deletions tests/Layer/ArcGIS93Rest.html
Expand Up @@ -195,6 +195,31 @@

}

function test_Layer_AGS93_setOpacity (t) {
var params = {layers: "show:0,2"};
t.plan( 5 );

var map = new OpenLayers.Map('map');
map.projection = "xx";
tParams = { layers: 'show:0,2',
format: 'png'};
tOptions = { 'opacity': '0.5' };
var tLayer = new OpenLayers.Layer.ArcGIS93Rest(name, url, 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_AGS93_noGutters (t) {
t.plan(2);
var map = new OpenLayers.Map('map');
Expand Down
46 changes: 46 additions & 0 deletions tests/Layer/MapServer.html
Expand Up @@ -196,6 +196,31 @@

}

function test_Layer_MapServer_setOpacity (t) {
t.plan( 5 );

var map = new OpenLayers.Map('map');
map.projection = "xx";
tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
tParams = { layers: 'basic',
format: 'image/png'};
tOptions = { 'opacity': '0.5' };
var tLayer = new OpenLayers.Layer.MapServer(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_MapServer_Reproject (t) {
var validkey = (window.location.protocol == "file:") ||
(window.location.host == "localhost") ||
Expand Down Expand Up @@ -386,6 +411,27 @@

}

function test_Layer_MapServer_Untiled_setOpacity (t) {
t.plan( 4 );

var map = new OpenLayers.Map('map');
map.projection = "xx";
tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
tParams = { layers: 'basic',
format: 'image/png'};
tOptions = { 'opacity': '0.5' };
var tLayer = new OpenLayers.Layer.MapServer.Untiled(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");
map.destroy();

}

// DEPRECATED -- REMOVE IN 3.0
function test_Layer_Untiled_MapServer(t) {
t.plan(1);
Expand Down
27 changes: 27 additions & 0 deletions tests/Layer/Markers.html
Expand Up @@ -121,6 +121,33 @@

}

function test_setOpacity(t) {
t.plan(1);

layer = new OpenLayers.Layer.Markers('Test Layer');

var opacity = 0.1234;

for (var i = 0; i < 12; i++) {
layer.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0), new OpenLayers.Icon()));
}

layer.setOpacity(opacity);

for (var i = 0; i < 4; i++) {
layer.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0), new OpenLayers.Icon()));
}

var itWorks = false;
for (var i = 0; i < layer.markers.length; i++) {
itWorks = parseFloat(layer.markers[i].icon.imageDiv.style.opacity) == opacity;
if (!itWorks) {
break;
}
}
t.ok(itWorks, "setOpacity change markers opacity");
}

</script>
</head>
<body>
Expand Down
16 changes: 16 additions & 0 deletions tests/Layer/WFS.html
Expand Up @@ -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);

Expand Down
25 changes: 25 additions & 0 deletions tests/Layer/WMS.html
Expand Up @@ -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") ||
Expand Down

0 comments on commit 061eeac

Please sign in to comment.