UNPKG

c8y-openlayer

Version:

This module is designed to help integrate Openlayer with Cumulocity IoT

28 lines (25 loc) 877 B
var _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 keyParams = []; // Skip any null or undefined parameter values Object.keys(params).forEach(function(k) { if (params[k] !== null && params[k] !== undefined) { keyParams.push(k + '=' + encodeURIComponent(params[k])); } }); var qs = keyParams.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; }; export default _ol_uri_;