Named exports from ol/uri
This commit is contained in:
@@ -9,7 +9,7 @@ import EventType from '../events/EventType.js';
|
|||||||
import {containsExtent, getHeight, getWidth} from '../extent.js';
|
import {containsExtent, getHeight, getWidth} from '../extent.js';
|
||||||
import _ol_obj_ from '../obj.js';
|
import _ol_obj_ from '../obj.js';
|
||||||
import ImageSource from '../source/Image.js';
|
import ImageSource from '../source/Image.js';
|
||||||
import _ol_uri_ from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -218,7 +218,7 @@ ImageArcGISRest.prototype.getRequestUrl_ = function(extent, size, pixelRatio, pr
|
|||||||
if (modifiedUrl == url) {
|
if (modifiedUrl == url) {
|
||||||
assert(false, 50); // `options.featureTypes` should be an Array
|
assert(false, 50); // `options.featureTypes` should be an Array
|
||||||
}
|
}
|
||||||
return _ol_uri_.appendParams(modifiedUrl, params);
|
return appendParams(modifiedUrl, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import EventType from '../events/EventType.js';
|
|||||||
import {containsExtent, getCenter, getHeight, getWidth, scaleFromCenter} from '../extent.js';
|
import {containsExtent, getCenter, getHeight, getWidth, scaleFromCenter} from '../extent.js';
|
||||||
import _ol_obj_ from '../obj.js';
|
import _ol_obj_ from '../obj.js';
|
||||||
import ImageSource from '../source/Image.js';
|
import ImageSource from '../source/Image.js';
|
||||||
import _ol_uri_ from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -224,7 +224,7 @@ ImageMapGuide.prototype.getUrl = function(baseUrl, params, extent, size, project
|
|||||||
'SETVIEWCENTERY': center[1]
|
'SETVIEWCENTERY': center[1]
|
||||||
};
|
};
|
||||||
_ol_obj_.assign(baseParams, params);
|
_ol_obj_.assign(baseParams, params);
|
||||||
return _ol_uri_.appendParams(baseUrl, baseParams);
|
return appendParams(baseUrl, baseParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import _ol_reproj_ from '../reproj.js';
|
|||||||
import ImageSource from '../source/Image.js';
|
import ImageSource from '../source/Image.js';
|
||||||
import WMSServerType from '../source/WMSServerType.js';
|
import WMSServerType from '../source/WMSServerType.js';
|
||||||
import _ol_string_ from '../string.js';
|
import _ol_string_ from '../string.js';
|
||||||
import _ol_uri_ from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -308,7 +308,7 @@ ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio, projectio
|
|||||||
}
|
}
|
||||||
params['BBOX'] = bbox.join(',');
|
params['BBOX'] = bbox.join(',');
|
||||||
|
|
||||||
return _ol_uri_.appendParams(/** @type {string} */ (this.url_), params);
|
return appendParams(/** @type {string} */ (this.url_), params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import _ol_obj_ from '../obj.js';
|
|||||||
import _ol_size_ from '../size.js';
|
import _ol_size_ from '../size.js';
|
||||||
import TileImage from '../source/TileImage.js';
|
import TileImage from '../source/TileImage.js';
|
||||||
import _ol_tilecoord_ from '../tilecoord.js';
|
import _ol_tilecoord_ from '../tilecoord.js';
|
||||||
import _ol_uri_ from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -125,7 +125,7 @@ TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExte
|
|||||||
const modifiedUrl = url
|
const modifiedUrl = url
|
||||||
.replace(/MapServer\/?$/, 'MapServer/export')
|
.replace(/MapServer\/?$/, 'MapServer/export')
|
||||||
.replace(/ImageServer\/?$/, 'ImageServer/exportImage');
|
.replace(/ImageServer\/?$/, 'ImageServer/exportImage');
|
||||||
return _ol_uri_.appendParams(modifiedUrl, params);
|
return appendParams(modifiedUrl, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import TileImage from '../source/TileImage.js';
|
|||||||
import WMSServerType from '../source/WMSServerType.js';
|
import WMSServerType from '../source/WMSServerType.js';
|
||||||
import _ol_tilecoord_ from '../tilecoord.js';
|
import _ol_tilecoord_ from '../tilecoord.js';
|
||||||
import _ol_string_ from '../string.js';
|
import _ol_string_ from '../string.js';
|
||||||
import _ol_uri_ from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -250,7 +250,7 @@ TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileExtent,
|
|||||||
const index = modulo(_ol_tilecoord_.hash(tileCoord), urls.length);
|
const index = modulo(_ol_tilecoord_.hash(tileCoord), urls.length);
|
||||||
url = urls[index];
|
url = urls[index];
|
||||||
}
|
}
|
||||||
return _ol_uri_.appendParams(url, params);
|
return appendParams(url, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {get as getProjection, equivalent, transformExtent} from '../proj.js';
|
|||||||
import TileImage from '../source/TileImage.js';
|
import TileImage from '../source/TileImage.js';
|
||||||
import WMTSRequestEncoding from '../source/WMTSRequestEncoding.js';
|
import WMTSRequestEncoding from '../source/WMTSRequestEncoding.js';
|
||||||
import {createFromCapabilitiesMatrixSet} from '../tilegrid/WMTS.js';
|
import {createFromCapabilitiesMatrixSet} from '../tilegrid/WMTS.js';
|
||||||
import _ol_uri_ from '../uri.js';
|
import {appendParams} from '../uri.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -114,7 +114,7 @@ const WMTS = function(options) {
|
|||||||
// special template params
|
// special template params
|
||||||
|
|
||||||
template = (requestEncoding == WMTSRequestEncoding.KVP) ?
|
template = (requestEncoding == WMTSRequestEncoding.KVP) ?
|
||||||
_ol_uri_.appendParams(template, context) :
|
appendParams(template, context) :
|
||||||
template.replace(/\{(\w+?)\}/g, function(m, p) {
|
template.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||||
return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m;
|
return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m;
|
||||||
});
|
});
|
||||||
@@ -138,7 +138,7 @@ const WMTS = function(options) {
|
|||||||
_ol_obj_.assign(localContext, dimensions);
|
_ol_obj_.assign(localContext, dimensions);
|
||||||
let url = template;
|
let url = template;
|
||||||
if (requestEncoding == WMTSRequestEncoding.KVP) {
|
if (requestEncoding == WMTSRequestEncoding.KVP) {
|
||||||
url = _ol_uri_.appendParams(url, localContext);
|
url = appendParams(url, localContext);
|
||||||
} else {
|
} else {
|
||||||
url = url.replace(/\{(\w+?)\}/g, function(m, p) {
|
url = url.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||||
return localContext[p];
|
return localContext[p];
|
||||||
|
|||||||
+2
-4
@@ -1,7 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @module ol/uri
|
* @module ol/uri
|
||||||
*/
|
*/
|
||||||
const _ol_uri_ = {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,7 +11,7 @@ const _ol_uri_ = {};
|
|||||||
* and the values are arbitrary types or arrays.
|
* and the values are arbitrary types or arrays.
|
||||||
* @return {string} The new URI.
|
* @return {string} The new URI.
|
||||||
*/
|
*/
|
||||||
_ol_uri_.appendParams = function(uri, params) {
|
export function appendParams(uri, params) {
|
||||||
const keyParams = [];
|
const keyParams = [];
|
||||||
// Skip any null or undefined parameter values
|
// Skip any null or undefined parameter values
|
||||||
Object.keys(params).forEach(function(k) {
|
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
|
// append ? or & depending on whether uri has existing parameters
|
||||||
uri = uri.indexOf('?') === -1 ? uri + '?' : uri + '&';
|
uri = uri.indexOf('?') === -1 ? uri + '?' : uri + '&';
|
||||||
return uri + qs;
|
return uri + qs;
|
||||||
};
|
}
|
||||||
export default _ol_uri_;
|
|
||||||
|
|||||||
+10
-10
@@ -1,10 +1,10 @@
|
|||||||
import _ol_uri_ from '../../../src/ol/uri.js';
|
import {appendParams} from '../../../src/ol/uri.js';
|
||||||
|
|
||||||
|
|
||||||
describe('ol.uri.appendParams()', function() {
|
describe('ol.uri.appendParams()', function() {
|
||||||
|
|
||||||
it('should append empty STYLES with =', 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',
|
SERVICE: 'WMS',
|
||||||
STYLES: ''
|
STYLES: ''
|
||||||
});
|
});
|
||||||
@@ -12,56 +12,56 @@ describe('ol.uri.appendParams()', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should URL encode values but not names', 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 '
|
'k ': 'v '
|
||||||
});
|
});
|
||||||
expect(url).to.equal('http://example.com/foo?k =v%20');
|
expect(url).to.equal('http://example.com/foo?k =v%20');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append to simple base URL', function() {
|
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'
|
k: 'v'
|
||||||
});
|
});
|
||||||
expect(url).to.equal('http://example.com/foo?k=v');
|
expect(url).to.equal('http://example.com/foo?k=v');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append to base URL with ?', function() {
|
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'
|
k: 'v'
|
||||||
});
|
});
|
||||||
expect(url).to.equal('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() {
|
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'
|
k: 'v'
|
||||||
});
|
});
|
||||||
expect(url).to.equal('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() {
|
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'
|
k: 'v'
|
||||||
});
|
});
|
||||||
expect(url).to.equal('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() {
|
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'
|
k: 'v'
|
||||||
});
|
});
|
||||||
expect(url).to.equal('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() {
|
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'
|
k: 'v'
|
||||||
});
|
});
|
||||||
expect(url).to.equal('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() {
|
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',
|
a: '1',
|
||||||
b: null,
|
b: null,
|
||||||
c: undefined
|
c: undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user