Remove use of goog.uri
This commit is contained in:
21
src/ol/uri.js
Normal file
21
src/ol/uri.js
Normal file
@@ -0,0 +1,21 @@
|
||||
goog.provide('ol.uri');
|
||||
|
||||
|
||||
/**
|
||||
* Appends query parameters to a URI.
|
||||
*
|
||||
* @param {string} uri The original URI, which may already have query data.
|
||||
* @param {!Object} params An object where keys are URI-encoded parameter keys,
|
||||
* and the values are arbitrary types or arrays.
|
||||
* @return {string} The new URI.
|
||||
*/
|
||||
ol.uri.appendParams = function(uri, params) {
|
||||
var qs = Object.keys(params).map(function(k) {
|
||||
return k + '=' + encodeURIComponent(params[k]);
|
||||
}).join('&');
|
||||
// remove any trailing ? or &
|
||||
uri = uri.replace(/[?&]$/, '')
|
||||
// append ? or & depending on whether uri has existing parameters
|
||||
uri = uri.indexOf('?') === -1 ? uri + '?' : uri + '&'
|
||||
return uri + qs;
|
||||
};
|
||||
Reference in New Issue
Block a user