[OpenLayers-Commits] r4784 - in trunk/openlayers: lib/OpenLayers tests

commits at openlayers.org commits at openlayers.org
Wed Oct 3 12:17:56 EDT 2007


Author: crschmidt
Date: 2007-10-03 12:17:55 -0400 (Wed, 03 Oct 2007)
New Revision: 4784

Modified:
   trunk/openlayers/lib/OpenLayers/Icon.js
   trunk/openlayers/lib/OpenLayers/Marker.js
   trunk/openlayers/tests/test_Marker.html
Log:
Add API method for changing an icon's marker image.


Modified: trunk/openlayers/lib/OpenLayers/Icon.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Icon.js	2007-10-03 16:15:43 UTC (rev 4783)
+++ trunk/openlayers/lib/OpenLayers/Icon.js	2007-10-03 16:17:55 UTC (rev 4784)
@@ -106,6 +106,18 @@
         }
         this.draw();
     },
+    
+    /**
+     * Method: setUrl
+     * 
+     * url - {String} 
+     */
+    setUrl: function(url) {
+        if (url != null) {
+            this.url = url;
+        }
+        this.draw();
+    },
 
     /** 
      * Method: draw

Modified: trunk/openlayers/lib/OpenLayers/Marker.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Marker.js	2007-10-03 16:15:43 UTC (rev 4783)
+++ trunk/openlayers/lib/OpenLayers/Marker.js	2007-10-03 16:17:55 UTC (rev 4784)
@@ -171,6 +171,16 @@
         this.icon.setOpacity(opacity);
     },
 
+    /**
+     * Method: setUrl
+     * Change URL of the Icon Image.
+     * 
+     * url - {String} 
+     */
+    setUrl: function(url) {
+        this.icon.setUrl(url);
+    },    
+
     /** 
      * Method: display
      * Hide or show the icon

Modified: trunk/openlayers/tests/test_Marker.html
===================================================================
--- trunk/openlayers/tests/test_Marker.html	2007-10-03 16:15:43 UTC (rev 4783)
+++ trunk/openlayers/tests/test_Marker.html	2007-10-03 16:17:55 UTC (rev 4784)
@@ -73,7 +73,35 @@
         t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works");
         map.destroy();
     }
+    
+    function test_03_Marker_setUrl(t) {
+        t.plan( 2 );
+        
+        var map = new OpenLayers.Map("map");
 
+        var url = "http://octo.metacarta.com/cgi-bin/mapserv";
+        layer = new OpenLayers.Layer.WMS(name, url);
+
+        map.addLayer(layer);
+        
+        mlayer = new OpenLayers.Layer.Markers('Test Layer');
+        map.addLayer(mlayer);
+               
+        map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
+
+        //onscreen marker
+        var ll = new OpenLayers.LonLat(0,0);
+        var marker = new OpenLayers.Marker(ll);
+        mlayer.addMarker(marker);
+
+        t.ok(marker.icon.imageDiv.firstChild.src.contains("img/marker.png"), "Marker.png is default URL");
+        
+        marker.setUrl("http://example.com/broken.png");
+        t.eq(marker.icon.imageDiv.firstChild.src, "http://example.com/broken.png", "image source changes correctly.");
+
+        map.destroy();
+    }
+
     function test_04_Marker_moveTo(t) {
         t.plan( 6 );
         



More information about the Commits mailing list