diff --git a/src/ol/source/ImageArcGISRest.js b/src/ol/source/ImageArcGISRest.js index ea67456744..db617cb67e 100644 --- a/src/ol/source/ImageArcGISRest.js +++ b/src/ol/source/ImageArcGISRest.js @@ -9,7 +9,7 @@ import EventType from '../events/EventType.js'; import {containsExtent, getHeight, getWidth} from '../extent.js'; import _ol_obj_ from '../obj.js'; import ImageSource from '../source/Image.js'; -import _ol_uri_ from '../uri.js'; +import {appendParams} from '../uri.js'; /** * @classdesc @@ -218,7 +218,7 @@ ImageArcGISRest.prototype.getRequestUrl_ = function(extent, size, pixelRatio, pr if (modifiedUrl == url) { assert(false, 50); // `options.featureTypes` should be an Array } - return _ol_uri_.appendParams(modifiedUrl, params); + return appendParams(modifiedUrl, params); }; diff --git a/src/ol/source/ImageMapGuide.js b/src/ol/source/ImageMapGuide.js index a16a16478a..4b128ef038 100644 --- a/src/ol/source/ImageMapGuide.js +++ b/src/ol/source/ImageMapGuide.js @@ -8,7 +8,7 @@ import EventType from '../events/EventType.js'; import {containsExtent, getCenter, getHeight, getWidth, scaleFromCenter} from '../extent.js'; import _ol_obj_ from '../obj.js'; import ImageSource from '../source/Image.js'; -import _ol_uri_ from '../uri.js'; +import {appendParams} from '../uri.js'; /** * @classdesc @@ -224,7 +224,7 @@ ImageMapGuide.prototype.getUrl = function(baseUrl, params, extent, size, project 'SETVIEWCENTERY': center[1] }; _ol_obj_.assign(baseParams, params); - return _ol_uri_.appendParams(baseUrl, baseParams); + return appendParams(baseUrl, baseParams); }; diff --git a/src/ol/source/ImageWMS.js b/src/ol/source/ImageWMS.js index 8d240cbe26..4db630d0a2 100644 --- a/src/ol/source/ImageWMS.js +++ b/src/ol/source/ImageWMS.js @@ -15,7 +15,7 @@ import _ol_reproj_ from '../reproj.js'; import ImageSource from '../source/Image.js'; import WMSServerType from '../source/WMSServerType.js'; import _ol_string_ from '../string.js'; -import _ol_uri_ from '../uri.js'; +import {appendParams} from '../uri.js'; /** * @classdesc @@ -308,7 +308,7 @@ ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio, projectio } params['BBOX'] = bbox.join(','); - return _ol_uri_.appendParams(/** @type {string} */ (this.url_), params); + return appendParams(/** @type {string} */ (this.url_), params); }; diff --git a/src/ol/source/TileArcGISRest.js b/src/ol/source/TileArcGISRest.js index af0da1b4ed..e1f196d0af 100644 --- a/src/ol/source/TileArcGISRest.js +++ b/src/ol/source/TileArcGISRest.js @@ -8,7 +8,7 @@ import _ol_obj_ from '../obj.js'; import _ol_size_ from '../size.js'; import TileImage from '../source/TileImage.js'; import _ol_tilecoord_ from '../tilecoord.js'; -import _ol_uri_ from '../uri.js'; +import {appendParams} from '../uri.js'; /** * @classdesc @@ -125,7 +125,7 @@ TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExte const modifiedUrl = url .replace(/MapServer\/?$/, 'MapServer/export') .replace(/ImageServer\/?$/, 'ImageServer/exportImage'); - return _ol_uri_.appendParams(modifiedUrl, params); + return appendParams(modifiedUrl, params); }; diff --git a/src/ol/source/TileWMS.js b/src/ol/source/TileWMS.js index 23180d8a21..eaa1df5706 100644 --- a/src/ol/source/TileWMS.js +++ b/src/ol/source/TileWMS.js @@ -15,7 +15,7 @@ import TileImage from '../source/TileImage.js'; import WMSServerType from '../source/WMSServerType.js'; import _ol_tilecoord_ from '../tilecoord.js'; import _ol_string_ from '../string.js'; -import _ol_uri_ from '../uri.js'; +import {appendParams} from '../uri.js'; /** * @classdesc @@ -250,7 +250,7 @@ TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExtent, const index = modulo(_ol_tilecoord_.hash(tileCoord), urls.length); url = urls[index]; } - return _ol_uri_.appendParams(url, params); + return appendParams(url, params); }; diff --git a/src/ol/source/WMTS.js b/src/ol/source/WMTS.js index 125201b51b..182f34ce8a 100644 --- a/src/ol/source/WMTS.js +++ b/src/ol/source/WMTS.js @@ -10,7 +10,7 @@ import {get as getProjection, equivalent, transformExtent} from '../proj.js'; import TileImage from '../source/TileImage.js'; import WMTSRequestEncoding from '../source/WMTSRequestEncoding.js'; import {createFromCapabilitiesMatrixSet} from '../tilegrid/WMTS.js'; -import _ol_uri_ from '../uri.js'; +import {appendParams} from '../uri.js'; /** * @classdesc @@ -114,7 +114,7 @@ const WMTS = function(options) { // special template params template = (requestEncoding == WMTSRequestEncoding.KVP) ? - _ol_uri_.appendParams(template, context) : + appendParams(template, context) : template.replace(/\{(\w+?)\}/g, function(m, p) { return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m; }); @@ -138,7 +138,7 @@ const WMTS = function(options) { _ol_obj_.assign(localContext, dimensions); let url = template; if (requestEncoding == WMTSRequestEncoding.KVP) { - url = _ol_uri_.appendParams(url, localContext); + url = appendParams(url, localContext); } else { url = url.replace(/\{(\w+?)\}/g, function(m, p) { return localContext[p]; diff --git a/src/ol/uri.js b/src/ol/uri.js index 0fe4f0731a..f2264156c1 100644 --- a/src/ol/uri.js +++ b/src/ol/uri.js @@ -1,7 +1,6 @@ /** * @module ol/uri */ -const _ol_uri_ = {}; /** @@ -12,7 +11,7 @@ const _ol_uri_ = {}; * and the values are arbitrary types or arrays. * @return {string} The new URI. */ -_ol_uri_.appendParams = function(uri, params) { +export function appendParams(uri, params) { const keyParams = []; // Skip any null or undefined parameter values Object.keys(params).forEach(function(k) { @@ -26,5 +25,4 @@ _ol_uri_.appendParams = function(uri, params) { // append ? or & depending on whether uri has existing parameters uri = uri.indexOf('?') === -1 ? uri + '?' : uri + '&'; return uri + qs; -}; -export default _ol_uri_; +} diff --git a/test/spec/ol/uri.test.js b/test/spec/ol/uri.test.js index 3f0cbacaf7..24eb203238 100644 --- a/test/spec/ol/uri.test.js +++ b/test/spec/ol/uri.test.js @@ -1,10 +1,10 @@ -import _ol_uri_ from '../../../src/ol/uri.js'; +import {appendParams} from '../../../src/ol/uri.js'; describe('ol.uri.appendParams()', function() { it('should append empty STYLES with =', function() { - const url = _ol_uri_.appendParams('http://example.com/foo', { + const url = appendParams('http://example.com/foo', { SERVICE: 'WMS', STYLES: '' }); @@ -12,56 +12,56 @@ describe('ol.uri.appendParams()', function() { }); it('should URL encode values but not names', function() { - const url = _ol_uri_.appendParams('http://example.com/foo', { + const url = appendParams('http://example.com/foo', { 'k ': 'v ' }); expect(url).to.equal('http://example.com/foo?k =v%20'); }); it('should append to simple base URL', function() { - const url = _ol_uri_.appendParams('http://example.com/foo', { + const url = appendParams('http://example.com/foo', { k: 'v' }); expect(url).to.equal('http://example.com/foo?k=v'); }); it('should append to base URL with ?', function() { - const url = _ol_uri_.appendParams('http://example.com/foo?', { + const url = appendParams('http://example.com/foo?', { k: 'v' }); expect(url).to.equal('http://example.com/foo?k=v'); }); it('should append to base URL with single existing param', function() { - const url = _ol_uri_.appendParams('http://example.com/foo?bar=bam', { + const url = appendParams('http://example.com/foo?bar=bam', { k: 'v' }); expect(url).to.equal('http://example.com/foo?bar=bam&k=v'); }); it('should append to base URL with single existing param and extraneous &', function() { - const url = _ol_uri_.appendParams('http://example.com/foo?bar=bam&', { + const url = appendParams('http://example.com/foo?bar=bam&', { k: 'v' }); expect(url).to.equal('http://example.com/foo?bar=bam&k=v'); }); it('should append to base URL with two existing params', function() { - const url = _ol_uri_.appendParams('http://example.com/foo?bar=bam&baz=bat', { + const url = appendParams('http://example.com/foo?bar=bam&baz=bat', { k: 'v' }); expect(url).to.equal('http://example.com/foo?bar=bam&baz=bat&k=v'); }); it('should append to base URL with three existing params last one empty', function() { - const url = _ol_uri_.appendParams('http://example.com/foo?bar=bam&baz=bat&bop=', { + const url = appendParams('http://example.com/foo?bar=bam&baz=bat&bop=', { k: 'v' }); expect(url).to.equal('http://example.com/foo?bar=bam&baz=bat&bop=&k=v'); }); it('should not append null or undefined parameters to the url', function() { - const url = _ol_uri_.appendParams('http://example.com/foo', { + const url = appendParams('http://example.com/foo', { a: '1', b: null, c: undefined