[OpenLayers-Commits] r12232 - in branches/openlayers/2.11:
lib/OpenLayers lib/OpenLayers/Layer tests tests/Layer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Aug 10 04:41:38 EDT 2011
Author: ahocevar
Date: 2011-08-10 01:41:37 -0700 (Wed, 10 Aug 2011)
New Revision: 12232
Modified:
branches/openlayers/2.11/lib/OpenLayers/Layer.js
branches/openlayers/2.11/lib/OpenLayers/Layer/Markers.js
branches/openlayers/2.11/lib/OpenLayers/Layer/WFS.js
branches/openlayers/2.11/tests/Layer.html
branches/openlayers/2.11/tests/Layer/ArcGIS93Rest.html
branches/openlayers/2.11/tests/Layer/MapServer.html
branches/openlayers/2.11/tests/Layer/Markers.html
branches/openlayers/2.11/tests/Layer/WFS.html
branches/openlayers/2.11/tests/Layer/WMS.html
Log:
reverting r12185 from #3431
Modified: branches/openlayers/2.11/lib/OpenLayers/Layer/Markers.js
===================================================================
--- branches/openlayers/2.11/lib/OpenLayers/Layer/Markers.js 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/lib/OpenLayers/Layer/Markers.js 2011-08-10 08:41:37 UTC (rev 12232)
@@ -60,6 +60,22 @@
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: branches/openlayers/2.11/lib/OpenLayers/Layer/WFS.js
===================================================================
--- branches/openlayers/2.11/lib/OpenLayers/Layer/WFS.js 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/lib/OpenLayers/Layer/WFS.js 2011-08-10 08:41:37 UTC (rev 12232)
@@ -590,5 +590,21 @@
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: branches/openlayers/2.11/lib/OpenLayers/Layer.js
===================================================================
--- branches/openlayers/2.11/lib/OpenLayers/Layer.js 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/lib/OpenLayers/Layer.js 2011-08-10 08:41:37 UTC (rev 12232)
@@ -349,11 +349,6 @@
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 @@
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,
Modified: branches/openlayers/2.11/tests/Layer/ArcGIS93Rest.html
===================================================================
--- branches/openlayers/2.11/tests/Layer/ArcGIS93Rest.html 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/tests/Layer/ArcGIS93Rest.html 2011-08-10 08:41:37 UTC (rev 12232)
@@ -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');
Modified: branches/openlayers/2.11/tests/Layer/MapServer.html
===================================================================
--- branches/openlayers/2.11/tests/Layer/MapServer.html 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/tests/Layer/MapServer.html 2011-08-10 08:41:37 UTC (rev 12232)
@@ -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") ||
@@ -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);
Modified: branches/openlayers/2.11/tests/Layer/Markers.html
===================================================================
--- branches/openlayers/2.11/tests/Layer/Markers.html 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/tests/Layer/Markers.html 2011-08-10 08:41:37 UTC (rev 12232)
@@ -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>
Modified: branches/openlayers/2.11/tests/Layer/WFS.html
===================================================================
--- branches/openlayers/2.11/tests/Layer/WFS.html 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/tests/Layer/WFS.html 2011-08-10 08:41:37 UTC (rev 12232)
@@ -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);
Modified: branches/openlayers/2.11/tests/Layer/WMS.html
===================================================================
--- branches/openlayers/2.11/tests/Layer/WMS.html 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/tests/Layer/WMS.html 2011-08-10 08:41:37 UTC (rev 12232)
@@ -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") ||
Modified: branches/openlayers/2.11/tests/Layer.html
===================================================================
--- branches/openlayers/2.11/tests/Layer.html 2011-08-10 08:35:27 UTC (rev 12231)
+++ branches/openlayers/2.11/tests/Layer.html 2011-08-10 08:41:37 UTC (rev 12232)
@@ -786,15 +786,14 @@
}
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});
@@ -802,7 +801,6 @@
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,
@@ -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");
}
More information about the Commits
mailing list