Merge pull request #5432 from bjornharrtell/rm_goog.uri
Remove use of goog.uri
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
goog.provide('ol.source.ImageArcGISRest');
|
goog.provide('ol.source.ImageArcGISRest');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.Image');
|
goog.require('ol.Image');
|
||||||
goog.require('ol.events');
|
goog.require('ol.events');
|
||||||
@@ -10,6 +9,7 @@ goog.require('ol.extent');
|
|||||||
goog.require('ol.object');
|
goog.require('ol.object');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.source.Image');
|
goog.require('ol.source.Image');
|
||||||
|
goog.require('ol.uri');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,7 +215,7 @@ ol.source.ImageArcGISRest.prototype.getRequestUrl_ = function(extent, size, pixe
|
|||||||
if (modifiedUrl == url) {
|
if (modifiedUrl == url) {
|
||||||
goog.asserts.fail('Unknown Rest Service', url);
|
goog.asserts.fail('Unknown Rest Service', url);
|
||||||
}
|
}
|
||||||
return goog.uri.utils.appendParamsFromMap(modifiedUrl, params);
|
return ol.uri.appendParams(modifiedUrl, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ goog.provide('ol.source.ImageMapGuide');
|
|||||||
|
|
||||||
goog.require('ol.events');
|
goog.require('ol.events');
|
||||||
goog.require('ol.events.EventType');
|
goog.require('ol.events.EventType');
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol.Image');
|
goog.require('ol.Image');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.object');
|
goog.require('ol.object');
|
||||||
goog.require('ol.source.Image');
|
goog.require('ol.source.Image');
|
||||||
|
goog.require('ol.uri');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,7 +222,7 @@ ol.source.ImageMapGuide.prototype.getUrl = function(baseUrl, params, extent, siz
|
|||||||
'SETVIEWCENTERY': center[1]
|
'SETVIEWCENTERY': center[1]
|
||||||
};
|
};
|
||||||
ol.object.assign(baseParams, params);
|
ol.object.assign(baseParams, params);
|
||||||
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
|
return ol.uri.appendParams(baseUrl, baseParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
goog.provide('ol.source.ImageWMS');
|
goog.provide('ol.source.ImageWMS');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.Image');
|
goog.require('ol.Image');
|
||||||
goog.require('ol.events');
|
goog.require('ol.events');
|
||||||
@@ -15,6 +14,7 @@ goog.require('ol.source.Image');
|
|||||||
goog.require('ol.source.wms');
|
goog.require('ol.source.wms');
|
||||||
goog.require('ol.source.wms.ServerType');
|
goog.require('ol.source.wms.ServerType');
|
||||||
goog.require('ol.string');
|
goog.require('ol.string');
|
||||||
|
goog.require('ol.uri');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -312,7 +312,7 @@ ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio,
|
|||||||
}
|
}
|
||||||
params['BBOX'] = bbox.join(',');
|
params['BBOX'] = bbox.join(',');
|
||||||
|
|
||||||
return goog.uri.utils.appendParamsFromMap(this.url_, params);
|
return ol.uri.appendParams(this.url_, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
goog.provide('ol.source.TileArcGISRest');
|
goog.provide('ol.source.TileArcGISRest');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.object');
|
goog.require('ol.object');
|
||||||
@@ -10,6 +9,7 @@ goog.require('ol.proj');
|
|||||||
goog.require('ol.size');
|
goog.require('ol.size');
|
||||||
goog.require('ol.source.TileImage');
|
goog.require('ol.source.TileImage');
|
||||||
goog.require('ol.tilecoord');
|
goog.require('ol.tilecoord');
|
||||||
|
goog.require('ol.uri');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,7 +114,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize
|
|||||||
if (modifiedUrl == url) {
|
if (modifiedUrl == url) {
|
||||||
goog.asserts.fail('Unknown Rest Service', url);
|
goog.asserts.fail('Unknown Rest Service', url);
|
||||||
}
|
}
|
||||||
return goog.uri.utils.appendParamsFromMap(modifiedUrl, params);
|
return ol.uri.appendParams(modifiedUrl, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
goog.provide('ol.source.TileWMS');
|
goog.provide('ol.source.TileWMS');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.object');
|
goog.require('ol.object');
|
||||||
@@ -17,7 +16,7 @@ goog.require('ol.source.wms');
|
|||||||
goog.require('ol.source.wms.ServerType');
|
goog.require('ol.source.wms.ServerType');
|
||||||
goog.require('ol.tilecoord');
|
goog.require('ol.tilecoord');
|
||||||
goog.require('ol.string');
|
goog.require('ol.string');
|
||||||
|
goog.require('ol.uri');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -265,7 +264,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileE
|
|||||||
var index = ol.math.modulo(ol.tilecoord.hash(tileCoord), urls.length);
|
var index = ol.math.modulo(ol.tilecoord.hash(tileCoord), urls.length);
|
||||||
url = urls[index];
|
url = urls[index];
|
||||||
}
|
}
|
||||||
return goog.uri.utils.appendParamsFromMap(url, params);
|
return ol.uri.appendParams(url, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ goog.provide('ol.source.WMTS');
|
|||||||
goog.provide('ol.source.WMTSRequestEncoding');
|
goog.provide('ol.source.WMTSRequestEncoding');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.uri.utils');
|
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.TileUrlFunction');
|
||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
@@ -10,6 +9,7 @@ goog.require('ol.object');
|
|||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.source.TileImage');
|
goog.require('ol.source.TileImage');
|
||||||
goog.require('ol.tilegrid.WMTS');
|
goog.require('ol.tilegrid.WMTS');
|
||||||
|
goog.require('ol.uri');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,7 +123,7 @@ ol.source.WMTS = function(options) {
|
|||||||
// special template params
|
// special template params
|
||||||
|
|
||||||
template = (requestEncoding == ol.source.WMTSRequestEncoding.KVP) ?
|
template = (requestEncoding == ol.source.WMTSRequestEncoding.KVP) ?
|
||||||
goog.uri.utils.appendParamsFromMap(template, context) :
|
ol.uri.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;
|
||||||
});
|
});
|
||||||
@@ -147,7 +147,7 @@ ol.source.WMTS = function(options) {
|
|||||||
ol.object.assign(localContext, dimensions);
|
ol.object.assign(localContext, dimensions);
|
||||||
var url = template;
|
var url = template;
|
||||||
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
||||||
url = goog.uri.utils.appendParamsFromMap(url, localContext);
|
url = ol.uri.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];
|
||||||
|
|||||||
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;
|
||||||
|
};
|
||||||
64
test/spec/ol/uri.test.js
Normal file
64
test/spec/ol/uri.test.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
goog.provide('ol.test.uri');
|
||||||
|
|
||||||
|
describe('ol.uri.appendParams()', function() {
|
||||||
|
|
||||||
|
it('should append empty STYLES with =', function() {
|
||||||
|
var url = ol.uri.appendParams('http://example.com/foo', {
|
||||||
|
SERVICE: 'WMS',
|
||||||
|
STYLES: ''
|
||||||
|
});
|
||||||
|
expect(url).to.equal('http://example.com/foo?SERVICE=WMS&STYLES=');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should URL encode values but not names', function() {
|
||||||
|
var url = ol.uri.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() {
|
||||||
|
var url = ol.uri.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() {
|
||||||
|
var url = ol.uri.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() {
|
||||||
|
var url = ol.uri.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() {
|
||||||
|
var url = ol.uri.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() {
|
||||||
|
var url = ol.uri.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() {
|
||||||
|
var url = ol.uri.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');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
goog.require('ol.uri');
|
||||||
Reference in New Issue
Block a user