handle existing query strings for WMS urls , #973

This commit is contained in:
snkashis 2012-12-22 17:47:38 -05:00
parent a82ed0a3e2
commit 8c7c06431a
3 changed files with 31 additions and 5 deletions

View File

@ -61,6 +61,28 @@ describe('Util', function() {
});
});
describe('#getParamString', function() {
it('should create a valid query string for appending depending on url input', function() {
var a = {
url:"http://example.com/get",
obj:{bar: 7, baz: 3},
result:"?bar=7&baz=3"
}
expect(L.Util.getParamString(a.obj,a.url)).toEqual(a.result);
var b = {
url:"http://example.com/get?justone=qs",
obj:{bar: 7, baz: 3},
result:"&bar=7&baz=3"
}
expect(L.Util.getParamString(b.obj,b.url)).toEqual(b.result);
});
});
// TODO cancel/requestAnimFrame?
// TODO limitExecByInterval
@ -71,7 +93,5 @@ describe('Util', function() {
// TODO setOptions
// TODO getParamString
// TODO template
});

View File

@ -77,14 +77,20 @@ L.Util = {
return obj.options;
},
getParamString: function (obj) {
getParamString: function (obj, existing_url) {
var params = [];
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
params.push(i + '=' + obj[i]);
}
}
if (existing_url.indexOf('?')===-1) {
return '?' + params.join('&');
}
else {
return '&' + params.join('&');
}
},
template: function (str, data) {

View File

@ -64,7 +64,7 @@ L.TileLayer.WMS = L.TileLayer.extend({
url = L.Util.template(this._url, {s: this._getSubdomain(tilePoint)});
return url + L.Util.getParamString(this.wmsParams) + "&bbox=" + bbox;
return url + L.Util.getParamString(this.wmsParams, url) + "&bbox=" + bbox;
},
setParams: function (params, noRedraw) {