Merge pull request #1231 from snkashis/fix_wms_params

handle existing query strings for WMS urls , #973
This commit is contained in:
Vladimir Agafonkin 2012-12-27 11:42:31 -08:00
commit 5109492a35
3 changed files with 33 additions and 6 deletions

View File

@ -61,6 +61,35 @@ 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);
var c = {
url: undefined,
obj: {bar: 7, baz: 3},
result: "?bar=7&baz=3"
};
expect(L.Util.getParamString(c.obj,c.url)).toEqual(c.result);
});
});
// TODO cancel/requestAnimFrame?
// TODO limitExecByInterval
@ -71,7 +100,5 @@ describe('Util', function() {
// TODO setOptions
// TODO getParamString
// TODO template
});

View File

@ -77,14 +77,14 @@ L.Util = {
return obj.options;
},
getParamString: function (obj) {
getParamString: function (obj, existingUrl) {
var params = [];
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
params.push(i + '=' + obj[i]);
}
}
return '?' + params.join('&');
return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + 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) {