[OpenLayers-Commits] r12185 - in trunk/openlayers: lib/OpenLayers
lib/OpenLayers/Layer tests tests/Layer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Jul 25 07:42:44 EDT 2011
Author: ahocevar
Date: 2011-07-25 04:42:43 -0700 (Mon, 25 Jul 2011)
New Revision: 12185
Modified:
trunk/openlayers/lib/OpenLayers/Layer.js
trunk/openlayers/lib/OpenLayers/Layer/Markers.js
trunk/openlayers/lib/OpenLayers/Layer/WFS.js
trunk/openlayers/tests/Layer.html
trunk/openlayers/tests/Layer/ArcGIS93Rest.html
trunk/openlayers/tests/Layer/MapServer.html
trunk/openlayers/tests/Layer/Markers.html
trunk/openlayers/tests/Layer/WFS.html
trunk/openlayers/tests/Layer/WMS.html
Log:
Set opacity on layer div, not on tiles and markers. r=fredj (closes #3431)
Modified: trunk/openlayers/lib/OpenLayers/Layer/Markers.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Markers.js 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/lib/OpenLayers/Layer/Markers.js 2011-07-25 11:42:43 UTC (rev 12185)
@@ -60,22 +60,6 @@
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
*
Modified: trunk/openlayers/lib/OpenLayers/Layer/WFS.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/WFS.js 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/lib/OpenLayers/Layer/WFS.js 2011-07-25 11:42:43 UTC (rev 12185)
@@ -590,21 +590,5 @@
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"
});
Modified: trunk/openlayers/lib/OpenLayers/Layer.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer.js 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/lib/OpenLayers/Layer.js 2011-07-25 11:42:43 UTC (rev 12185)
@@ -349,6 +349,11 @@
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);
@@ -1269,11 +1274,8 @@
setOpacity: function(opacity) {
if (opacity != this.opacity) {
this.opacity = 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);
- }
+ OpenLayers.Util.modifyDOMElement(this.div, null, null, null,
+ null, null, null, opacity);
if (this.map != null) {
this.map.events.triggerEvent("changelayer", {
layer: this,
Modified: trunk/openlayers/tests/Layer/ArcGIS93Rest.html
===================================================================
--- trunk/openlayers/tests/Layer/ArcGIS93Rest.html 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/tests/Layer/ArcGIS93Rest.html 2011-07-25 11:42:43 UTC (rev 12185)
@@ -195,31 +195,6 @@
}
- 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');
Modified: trunk/openlayers/tests/Layer/MapServer.html
===================================================================
--- trunk/openlayers/tests/Layer/MapServer.html 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/tests/Layer/MapServer.html 2011-07-25 11:42:43 UTC (rev 12185)
@@ -196,31 +196,6 @@
}
- 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") ||
@@ -411,27 +386,6 @@
}
- 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);
Modified: trunk/openlayers/tests/Layer/Markers.html
===================================================================
--- trunk/openlayers/tests/Layer/Markers.html 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/tests/Layer/Markers.html 2011-07-25 11:42:43 UTC (rev 12185)
@@ -121,33 +121,6 @@
}
- 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>
Modified: trunk/openlayers/tests/Layer/WFS.html
===================================================================
--- trunk/openlayers/tests/Layer/WFS.html 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/tests/Layer/WFS.html 2011-07-25 11:42:43 UTC (rev 12185)
@@ -25,22 +25,6 @@
}
- 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);
Modified: trunk/openlayers/tests/Layer/WMS.html
===================================================================
--- trunk/openlayers/tests/Layer/WMS.html 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/tests/Layer/WMS.html 2011-07-25 11:42:43 UTC (rev 12185)
@@ -281,31 +281,6 @@
}
- 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") ||
Modified: trunk/openlayers/tests/Layer.html
===================================================================
--- trunk/openlayers/tests/Layer.html 2011-07-25 08:52:15 UTC (rev 12184)
+++ trunk/openlayers/tests/Layer.html 2011-07-25 11:42:43 UTC (rev 12185)
@@ -786,14 +786,15 @@
}
function test_setOpacity(t) {
- t.plan(5);
+ t.plan(8);
var map, layer, log;
map = new OpenLayers.Map("map");
- layer = new OpenLayers.Layer("");
+ layer = new OpenLayers.Layer("", {opacity: 0.56});
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});
@@ -801,6 +802,7 @@
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,
@@ -813,6 +815,12 @@
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");
}
More information about the Commits
mailing list