[OpenLayers-Dev] Fwd: [OpenLayers-Commits] r5509 - in trunk/openlayers: lib/OpenLayers lib/OpenLayers/Layer tests/Layer

Erik Uzureau erik.uzureau at metacarta.com
Wed Jan 9 19:52:55 EST 2008


A comment related to this patch.

The commit done here is very good... what i'm actually wondering about
is the original setOpacity() function as defined on the
OpenLayers.Layer object.

Why are we doing DOMElement modifications at this level? the basic
Layer object does not own images and should not know anything about
them. just like this patch overrides setOpacity() to individually set
the opacity of its markers, so should the Grid layer iterate through
its tiles and call setOpacity() on each of them.

no?



---------- Forwarded message ----------
From: commits at openlayers.org <commits at openlayers.org>
Date: Dec 19, 2007 9:00 AM
Subject: [OpenLayers-Commits] r5509 - in trunk/openlayers:
lib/OpenLayers lib/OpenLayers/Layer tests/Layer
To: commits at openlayers.org


Author: fredj
Date: 2007-12-19 10:00:49 -0500 (Wed, 19 Dec 2007)
New Revision: 5509

Modified:
  trunk/openlayers/lib/OpenLayers/Layer.js
  trunk/openlayers/lib/OpenLayers/Layer/Markers.js
  trunk/openlayers/tests/Layer/test_Markers.html
Log:
OpenLayers.Layer.Markers - propagate layer's opacity to the markers. Thanks
ahughes for the bug report and crschmidt for review and advices. (Closes #1114)



Modified: trunk/openlayers/lib/OpenLayers/Layer/Markers.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Markers.js    2007-12-19
12:51:06 UTC (rev 5508)
+++ trunk/openlayers/lib/OpenLayers/Layer/Markers.js    2007-12-19
15:00:49 UTC (rev 5509)
@@ -57,7 +57,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; i < this.markers.length; i++) {
+                this.markers[i].setOpacity(this.opacity);
+            }
+        }
+    },
+
    /**
     * Method: moveTo
     *
@@ -85,6 +100,11 @@
     */
    addMarker: function(marker) {
        this.markers.push(marker);
+
+        if (this.opacity != null) {
+            marker.setOpacity(this.opacity);
+        }
+
        if (this.map && this.map.getExtent()) {
            marker.map = this.map;
            this.drawMarker(marker);

Modified: trunk/openlayers/lib/OpenLayers/Layer.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer.js    2007-12-19 12:51:06
UTC (rev 5508)
+++ trunk/openlayers/lib/OpenLayers/Layer.js    2007-12-19 15:00:49
UTC (rev 5509)
@@ -29,6 +29,12 @@
     */
    div: null,

+    /**
+     * Property: opacity
+     * {Float} The layer's opacity. Float number between 0.0 and 1.0.
+     */
+    opacity: null,
+
    /**
     * Constant: EVENT_TYPES
     * {Array(String)} Supported application event types

Modified: trunk/openlayers/tests/Layer/test_Markers.html
===================================================================
--- trunk/openlayers/tests/Layer/test_Markers.html      2007-12-19
12:51:06 UTC (rev 5508)
+++ trunk/openlayers/tests/Layer/test_Markers.html      2007-12-19
15:00:49 UTC (rev 5509)
@@ -77,7 +77,33 @@

    }

+    function test_Layer_Markers_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>

_______________________________________________
Commits mailing list
Commits at openlayers.org
http://openlayers.org/mailman/listinfo/commits



More information about the Dev mailing list