OpenLayers OpenLayers

Ticket #359: permalink.2.patch

File permalink.2.patch, 3.4 kB (added by crschmidt, 1 year ago)
  • tests/Control/test_Permalink.html

    old new  
    1010        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" ); 
    1111        t.eq( control.displayClass,  "olControlPermalink", "displayClass is correct" ); 
    1212    } 
     13     
     14    function test_Control_Permalink_uncentered (t) { 
     15        t.plan( 1 ); 
     16     
     17        control = new OpenLayers.Control.Permalink('permalink'); 
     18        map = new OpenLayers.Map('map'); 
     19        map.addControl(control); 
     20        map.events.triggerEvent("changelayer", {}); 
     21        t.ok(true, "permalink didn't bomb out."); 
     22    }    
     23     
    1324    function test_02_Control_Permalink_updateLinks (t) { 
    1425        t.plan( 2 ); 
    1526     
    1627        control = new OpenLayers.Control.Permalink('permalink'); 
    17         t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" ); 
    1828        map = new OpenLayers.Map('map'); 
    1929        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); 
    2030        map.addLayer(layer); 
     31        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, {'isBaseLayer': false}); 
     32        map.addLayer(layer); 
     33        layer.setVisibility(true); 
    2134        if (!map.getCenter())  map.zoomToMaxExtent(); 
    2235        map.addControl(control); 
    2336        map.pan(5, 0); 
    24         if (/MSIE/.test(navigator.userAgent)) { 
    25             t.eq(OpenLayers.Util.getElement('permalink').href, "?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink"); 
    26         } else { 
    27             t.eq(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink"); 
    28         } 
     37        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=BT"), 'pan sets permalink'); 
     38         
     39        map.layers[1].setVisibility(false); 
     40         
     41        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=BF"), 'setVisibility sets permalink'); 
    2942    } 
    3043    function test_03_Control_Permalink_updateLinksBase (t) { 
    3144        t.plan( 2 ); 
  • lib/OpenLayers/Control/Permalink.js

    old new  
    9696            this.div.appendChild(this.element); 
    9797        } 
    9898        this.map.events.register('moveend', this, this.updateLink); 
     99        this.map.events.register('changelayer', this, this.updateLink); 
     100        this.map.events.register('changebaselayer', this, this.updateLink); 
    99101        return this.div; 
    100102    }, 
    101103    
     
    104106     */ 
    105107    updateLink: function() { 
    106108        var center = this.map.getCenter(); 
     109         
     110        // Map not initialized yet. Return null. 
     111        if (!center) { return null; } 
     112         
    107113        var zoom = "zoom=" + this.map.getZoom();  
    108114        var lat = "lat=" + Math.round(center.lat*100000)/100000; 
    109115        var lon = "lon=" + Math.round(center.lon*100000)/100000;