More context for url functions

With this change, url functions are called in the scope of the
source they are configured for. This allows us to simplify the
url function generation for WMS, using a more generic
createFromParamsFunction factory, and the source's new params
member.

Note that there is also a new url member for WMS sources. This
is the WMS base url (the first one in case there is an array of
urls for faster tile access). This can be used for accessing
other WMS services (especially GetFeatureInfo).
This commit is contained in:
ahocevar
2013-03-20 10:45:54 +01:00
parent 4fe67f09c0
commit 46ca98e484
10 changed files with 128 additions and 51 deletions

View File

@@ -0,0 +1,40 @@
goog.provide('ol.source.test.wms');
describe('ol.source.wms', function() {
describe('ol.source.wms.getUrl', function() {
var that = {params: {}};
it('creates expected URL', function() {
var epsg3857 = ol.projection.get('EPSG:3857');
var tileGrid = ol.tilegrid.getForProjection(epsg3857);
var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction(
'http://wms?foo=bar', ol.source.wms.getUrl);
var tileCoord = new ol.TileCoord(1, 0, 0);
var tileUrl = tileUrlFunction.call(that, tileCoord, tileGrid, epsg3857);
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
'STYLES=&CRS=EPSG%3A3857&BBOX=' +
'-20037508.342789244%2C-20037508.342789244%2C0%2C0';
expect(tileUrl).to.eql(expected);
});
it('creates expected URL respecting axis orientation', function() {
var epsg4326 = ol.projection.get('EPSG:4326');
var tileGrid = ol.tilegrid.getForProjection(epsg4326);
var tileUrlFunction = ol.TileUrlFunction.createFromParamsFunction(
'http://wms?foo=bar', ol.source.wms.getUrl);
var tileCoord = new ol.TileCoord(1, 0, 0);
var tileUrl = tileUrlFunction.call(that, tileCoord, tileGrid, epsg4326);
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
'STYLES=&CRS=EPSG%3A4326&BBOX=-90%2C-180%2C90%2C0';
expect(tileUrl).to.eql(expected);
});
});
});
goog.require('ol.TileCoord');
goog.require('ol.projection');
goog.require('ol.source.wms');
goog.require('ol.tilegrid');