OpenLayers OpenLayers

Ticket #1031: icon.seturl.patch

File icon.seturl.patch, 2.3 kB (added by crschmidt, 1 year ago)

add setURL to marker, icon

  • tests/test_Marker.html

    old new  
    7373        t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works"); 
    7474        map.destroy(); 
    7575    } 
     76     
     77    function test_03_Marker_setUrl(t) { 
     78        t.plan( 2 ); 
     79         
     80        var map = new OpenLayers.Map("map"); 
    7681 
     82        var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 
     83        layer = new OpenLayers.Layer.WMS(name, url); 
     84 
     85        map.addLayer(layer); 
     86         
     87        mlayer = new OpenLayers.Layer.Markers('Test Layer'); 
     88        map.addLayer(mlayer); 
     89                
     90        map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); 
     91 
     92        //onscreen marker 
     93        var ll = new OpenLayers.LonLat(0,0); 
     94        var marker = new OpenLayers.Marker(ll); 
     95        mlayer.addMarker(marker); 
     96 
     97        t.ok(marker.icon.imageDiv.firstChild.src.contains("img/marker.png"), "Marker.png is default URL"); 
     98         
     99        marker.setUrl("http://example.com/broken.png"); 
     100        t.eq(marker.icon.imageDiv.firstChild.src, "http://example.com/broken.png", "image source changes correctly."); 
     101 
     102        map.destroy(); 
     103    } 
     104 
    77105    function test_04_Marker_moveTo(t) { 
    78106        t.plan( 6 ); 
    79107         
  • lib/OpenLayers/Marker.js

    old new  
    171171        this.icon.setOpacity(opacity); 
    172172    }, 
    173173 
     174    /** 
     175     * Method: setUrl 
     176     * Change URL of the Icon Image. 
     177     *  
     178     * url - {String}  
     179     */ 
     180    setUrl: function(url) { 
     181        this.icon.setUrl(url); 
     182    },     
     183 
    174184    /**  
    175185     * Method: display 
    176186     * Hide or show the icon 
  • lib/OpenLayers/Icon.js

    old new  
    106106        } 
    107107        this.draw(); 
    108108    }, 
     109     
     110    /** 
     111     * Method: setUrl 
     112     *  
     113     * url - {String}  
     114     */ 
     115    setUrl: function(url) { 
     116        if (url != null) { 
     117            this.url = url; 
     118        } 
     119        this.draw(); 
     120    }, 
    109121 
    110122    /**  
    111123     * Method: draw