Merge pull request #4414 from ahocevar/imageurlfunction-bye-bye
Remove ol.ImageUrlFunction
This commit is contained in:
@@ -1,46 +0,0 @@
|
|||||||
goog.provide('ol.ImageUrlFunction');
|
|
||||||
goog.provide('ol.ImageUrlFunctionType');
|
|
||||||
|
|
||||||
goog.require('ol.Size');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {function(this:ol.source.Image, ol.Extent, ol.Size,
|
|
||||||
* ol.proj.Projection): (string|undefined)}
|
|
||||||
*/
|
|
||||||
ol.ImageUrlFunctionType;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} baseUrl Base URL (may have query data).
|
|
||||||
* @param {Object.<string,*>} params to encode in the URL.
|
|
||||||
* @param {function(string, Object.<string,*>, ol.Extent, ol.Size,
|
|
||||||
* ol.proj.Projection): (string|undefined)} paramsFunction params function.
|
|
||||||
* @return {ol.ImageUrlFunctionType} Image URL function.
|
|
||||||
*/
|
|
||||||
ol.ImageUrlFunction.createFromParamsFunction =
|
|
||||||
function(baseUrl, params, paramsFunction) {
|
|
||||||
return (
|
|
||||||
/**
|
|
||||||
* @this {ol.source.Image}
|
|
||||||
* @param {ol.Extent} extent Extent.
|
|
||||||
* @param {ol.Size} size Size.
|
|
||||||
* @param {ol.proj.Projection} projection Projection.
|
|
||||||
* @return {string|undefined} URL.
|
|
||||||
*/
|
|
||||||
function(extent, size, projection) {
|
|
||||||
return paramsFunction(baseUrl, params, extent, size, projection);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @this {ol.source.Image}
|
|
||||||
* @param {ol.Extent} extent Extent.
|
|
||||||
* @param {ol.Size} size Size.
|
|
||||||
* @return {string|undefined} Image URL.
|
|
||||||
*/
|
|
||||||
ol.ImageUrlFunction.nullImageUrlFunction =
|
|
||||||
function(extent, size) {
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
@@ -6,7 +6,6 @@ goog.require('goog.object');
|
|||||||
goog.require('goog.uri.utils');
|
goog.require('goog.uri.utils');
|
||||||
goog.require('ol.Image');
|
goog.require('ol.Image');
|
||||||
goog.require('ol.ImageLoadFunctionType');
|
goog.require('ol.ImageLoadFunctionType');
|
||||||
goog.require('ol.ImageUrlFunction');
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.source.Image');
|
goog.require('ol.source.Image');
|
||||||
|
|
||||||
@@ -49,19 +48,11 @@ ol.source.ImageMapGuide = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.params_ = options.params !== undefined ? options.params : {};
|
this.params_ = options.params !== undefined ? options.params : {};
|
||||||
|
|
||||||
var imageUrlFunction;
|
|
||||||
if (options.url !== undefined) {
|
|
||||||
imageUrlFunction = ol.ImageUrlFunction.createFromParamsFunction(
|
|
||||||
options.url, this.params_, goog.bind(this.getUrl, this));
|
|
||||||
} else {
|
|
||||||
imageUrlFunction = ol.ImageUrlFunction.nullImageUrlFunction;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.ImageUrlFunctionType}
|
* @type {string|undefined}
|
||||||
*/
|
*/
|
||||||
this.imageUrlFunction_ = imageUrlFunction;
|
this.url_ = options.url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -148,8 +139,9 @@ ol.source.ImageMapGuide.prototype.getImageInternal =
|
|||||||
var height = ol.extent.getHeight(extent) / resolution;
|
var height = ol.extent.getHeight(extent) / resolution;
|
||||||
var size = [width * pixelRatio, height * pixelRatio];
|
var size = [width * pixelRatio, height * pixelRatio];
|
||||||
|
|
||||||
var imageUrl = this.imageUrlFunction_(extent, size, projection);
|
if (this.url_ !== undefined) {
|
||||||
if (imageUrl !== undefined) {
|
var imageUrl = this.getUrl(this.url_, this.params_, extent, size,
|
||||||
|
projection);
|
||||||
image = new ol.Image(extent, resolution, pixelRatio,
|
image = new ol.Image(extent, resolution, pixelRatio,
|
||||||
this.getAttributions(), imageUrl, this.crossOrigin_,
|
this.getAttributions(), imageUrl, this.crossOrigin_,
|
||||||
this.imageLoadFunction_);
|
this.imageLoadFunction_);
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
goog.provide('ol.test.ImageUrlFunction');
|
|
||||||
|
|
||||||
describe('ol.ImageUrlFunction', function() {
|
|
||||||
|
|
||||||
describe('#createFromParamsFunction', function() {
|
|
||||||
|
|
||||||
it('is a defined function', function() {
|
|
||||||
expect(ol.ImageUrlFunction.createFromParamsFunction).to.not.be(undefined);
|
|
||||||
expect(ol.ImageUrlFunction.createFromParamsFunction).to.be.a(Function);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns a function that throws when called (no arguments)', function() {
|
|
||||||
var got = ol.ImageUrlFunction.createFromParamsFunction();
|
|
||||||
expect(function() {
|
|
||||||
got();
|
|
||||||
}).to.throwException();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns a function that doesn\'t throw when called (valid arguments)',
|
|
||||||
function() {
|
|
||||||
var baseUrl = 'foo',
|
|
||||||
params = {foo: 'bar'},
|
|
||||||
paramsFunction = sinon.spy(),
|
|
||||||
got = ol.ImageUrlFunction.createFromParamsFunction(baseUrl,
|
|
||||||
params, paramsFunction);
|
|
||||||
|
|
||||||
expect(function() {
|
|
||||||
got();
|
|
||||||
}).to.not.throwException();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('passes given baseUrl to given paramsFunction', function() {
|
|
||||||
var baseUrl = 'foo',
|
|
||||||
params = {foo: 'bar'},
|
|
||||||
spy = sinon.spy(),
|
|
||||||
got = ol.ImageUrlFunction.createFromParamsFunction(baseUrl, params,
|
|
||||||
spy);
|
|
||||||
|
|
||||||
got();
|
|
||||||
|
|
||||||
expect(spy.called).to.be(true);
|
|
||||||
expect(spy.calledOnce).to.be(true);
|
|
||||||
expect(spy.calledWith(baseUrl)).to.be(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('passes given params to given paramsFunction', function() {
|
|
||||||
var baseUrl = 'foo',
|
|
||||||
params = {foo: 'bar'},
|
|
||||||
spy = sinon.spy(),
|
|
||||||
got = ol.ImageUrlFunction.createFromParamsFunction(baseUrl, params,
|
|
||||||
spy);
|
|
||||||
|
|
||||||
got();
|
|
||||||
|
|
||||||
expect(spy.called).to.be(true);
|
|
||||||
expect(spy.calledOnce).to.be(true);
|
|
||||||
expect(spy.calledWith(baseUrl, params)).to.be(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('passes five params to given paramsFunction', function() {
|
|
||||||
var baseUrl = 'foo',
|
|
||||||
params = {foo: 'bar'},
|
|
||||||
extent = [1, 2, 3, 4],
|
|
||||||
size = [47, 11],
|
|
||||||
projection = ol.proj.get('CRS:84'),
|
|
||||||
spy = sinon.spy(),
|
|
||||||
firstArgs,
|
|
||||||
got = ol.ImageUrlFunction.createFromParamsFunction(baseUrl, params,
|
|
||||||
spy);
|
|
||||||
|
|
||||||
got(extent, size, projection);
|
|
||||||
firstArgs = spy.args[0];
|
|
||||||
|
|
||||||
expect(spy.called).to.be(true);
|
|
||||||
expect(spy.calledOnce).to.be(true);
|
|
||||||
|
|
||||||
expect(firstArgs.length).to.be(5);
|
|
||||||
expect(firstArgs).to.eql([baseUrl, params, extent, size, projection]);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#nullImageUrlFunction', function() {
|
|
||||||
|
|
||||||
it('is a defined function', function() {
|
|
||||||
expect(ol.ImageUrlFunction.nullImageUrlFunction).to.not.be(undefined);
|
|
||||||
expect(ol.ImageUrlFunction.nullImageUrlFunction).to.be.a(Function);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('always returns undefined', function() {
|
|
||||||
var got = ol.ImageUrlFunction.nullImageUrlFunction();
|
|
||||||
expect(got).to.be(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
goog.require('ol.proj');
|
|
||||||
goog.require('ol.ImageUrlFunction');
|
|
||||||
Reference in New Issue
Block a user