OpenLayers OpenLayers

Ticket #730: permalink_querystring.patch

File permalink_querystring.patch, 3.2 kB (added by crschmidt, 1 year ago)
  • tests/Control/test_Permalink.html

    old new  
    4949        map.addControl(control); 
    5050        t.eq(map.controls[3].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." ); 
    5151  } 
     52  function test_03_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> 
    5480</head> 
  • lib/OpenLayers/Control/Permalink.js

    old new  
    3939        this.element = OpenLayers.Util.getElement(element);         
    4040        if (base) { 
    4141            this.base = base; 
    42         } 
     42        } else { 
     43            this.base = document.location.href; 
     44        }     
    4345    }, 
    4446 
    4547    /** 
     
    118120                layers += (layer.getVisibility()) ? "T" : "F";            
    119121            } 
    120122        } 
    121         var href = this.base + "?" + lat + "&" + lon + "&" + zoom +  
    122                                    "&" + layers;  
     123         
     124        var href = this.base; 
     125        var paramsString =  lat + "&" + lon + "&" + zoom + "&" + layers;  
     126         
     127        var lastServerChar = href.charAt(href.length - 1); 
     128        if ((lastServerChar == "&") || (lastServerChar == "?")) { 
     129            href += paramsString; 
     130        } else { 
     131            if (href.indexOf('?') == -1) { 
     132                //serverPath has no ? -- add one 
     133                href += '?' + paramsString; 
     134            } else { 
     135                //serverPath contains ?, so must already have paramsString at the end 
     136                href += '&' + paramsString; 
     137            } 
     138        } 
    123139        this.element.href = href; 
    124140    },  
    125141