diff --git a/spec/suites/core/UtilSpec.js b/spec/suites/core/UtilSpec.js index 09f536df..2e28b319 100644 --- a/spec/suites/core/UtilSpec.js +++ b/spec/suites/core/UtilSpec.js @@ -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 }); \ No newline at end of file diff --git a/src/core/Util.js b/src/core/Util.js index 86875dbc..1dfb09ea 100644 --- a/src/core/Util.js +++ b/src/core/Util.js @@ -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]); } } - return '?' + params.join('&'); + if (existing_url.indexOf('?')===-1) { + return '?' + params.join('&'); + } + else { + return '&' + params.join('&'); + } + }, template: function (str, data) { diff --git a/src/layer/tile/TileLayer.WMS.js b/src/layer/tile/TileLayer.WMS.js index a145537c..1daba748 100644 --- a/src/layer/tile/TileLayer.WMS.js +++ b/src/layer/tile/TileLayer.WMS.js @@ -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) {