# all files / ol/ uri.js

100% Statements 10/10
100% Branches 6/6
100% Functions 2/2
100% Lines 10/10

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    271×

    1×
    80×

    80×
    775×
    773×

    80×

    80×

    80×
    80×

     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 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;
    };