OpenLayers OpenLayers

Changeset 4047

Show
Ignore:
Timestamp:
08/27/07 08:46:29 (1 year ago)
Author:
crschmidt
Message:

(Closes #730) These changes make the permalink smarter in the case where we
already have some URL args in the URL. Thanks to penyaskito for the bug
report.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Control/Permalink.js

    r3984 r4047  
    3636        OpenLayers.Control.prototype.initialize.apply(this, arguments); 
    3737        this.element = OpenLayers.Util.getElement(element);         
    38         if (base) { 
    39             this.base = base; 
    40         } 
     38        this.base = base || document.location.href; 
    4139    }, 
    4240 
     
    117115            } 
    118116        } 
    119         var href = this.base + "?" + lat + "&" + lon + "&" + zoom +  
    120                                    "&" + layers;  
     117         
     118        var href = this.base; 
     119        var paramsString =  lat + "&" + lon + "&" + zoom + "&" + layers;  
     120         
     121        var lastServerChar = href.charAt(href.length - 1); 
     122        if ((lastServerChar == "&") || (lastServerChar == "?")) { 
     123            href += paramsString; 
     124        } else { 
     125            if (href.indexOf('?') == -1) { 
     126                //serverPath has no ? -- add one 
     127                href += '?' + paramsString; 
     128            } else { 
     129                //serverPath contains ?, so must already have paramsString at the end 
     130                href += '&' + paramsString; 
     131            } 
     132        } 
    121133        this.element.href = href; 
    122134    },  
  • trunk/openlayers/tests/Control/test_Permalink.html

    r3534 r4047  
    5050        t.eq(map.controls[3].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." ); 
    5151  } 
     52  function test_05_Control_Permalink_base_with_query (t) { 
     53      t.plan( 3 ); 
     54   
     55      control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar" ); 
     56      map = new OpenLayers.Map('map'); 
     57      layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" ); 
     58      map.addLayer(layer); 
     59      if (!map.getCenter())  map.zoomToMaxExtent(); 
     60      map.addControl(control); 
     61      map.pan(5, 0); 
     62      OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&lat=0&lon=1.75781&zoom=2&layers=B'; 
     63      t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring"); 
     64       
     65      control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar&" ); 
     66      map.addControl(control); 
     67      map.pan(0, 0); 
     68      t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '&'"); 
     69       
     70      control = new OpenLayers.Control.Permalink('permalink', "./edit.html?" ); 
     71      OpenLayers.Util.getElement('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2&layers=B'; 
     72      map.addControl(control); 
     73      map.pan(5, 0); 
     74      map.pan(-5, 0); 
     75      t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'"); 
     76 
     77  } 
    5278  // --> 
    5379  </script>