Merge pull request #1702 from igrcic/tileWMS-extents-1701

Do not request tiles outside of extents for TileWMS source
This commit is contained in:
Éric Lemoine
2014-02-17 14:17:27 +01:00
2 changed files with 48 additions and 0 deletions

View File

@@ -346,6 +346,13 @@ ol.source.TileWMS.prototype.tileUrlFunction_ =
tileExtent = ol.extent.buffer(tileExtent,
tileResolution * gutter, tileExtent);
}
var extent = this.getExtent();
if (!goog.isNull(extent) && (!ol.extent.intersects(tileExtent, extent) ||
ol.extent.touches(tileExtent, extent))) {
return undefined;
}
if (pixelRatio != 1) {
tileSize = (tileSize * pixelRatio + 0.5) | 0;
}

View File

@@ -104,6 +104,46 @@ describe('ol.source.TileWMS', function() {
});
describe('#tileUrlFunction', function() {
it('returns a tile if it is contained within layers extent', function() {
options.extent = [-80, -40, -50, -10];
var source = new ol.source.TileWMS(options);
var tileCoord = new ol.TileCoord(3, 2, 1);
var url = source.tileUrlFunction(tileCoord, 1, ol.proj.get('EPSG:4326'));
var uri = new goog.Uri(url);
var queryData = uri.getQueryData();
expect(queryData.get('BBOX')).to.be('-45,-90,0,-45');
});
it('returns a tile if it intersects layers extent', function() {
options.extent = [-80, -40, -40, -10];
var source = new ol.source.TileWMS(options);
var tileCoord = new ol.TileCoord(3, 3, 1);
var url = source.tileUrlFunction(tileCoord, 1, ol.proj.get('EPSG:4326'));
var uri = new goog.Uri(url);
var queryData = uri.getQueryData();
expect(queryData.get('BBOX')).to.be('-45,-45,0,0');
});
it('does not return a tile if it touches layers extent', function() {
options.extent = [-80, -40, -45, -10];
var source = new ol.source.TileWMS(options);
var tileCoord = new ol.TileCoord(3, 3, 1);
var url = source.tileUrlFunction(tileCoord, 1, ol.proj.get('EPSG:4326'));
expect(url).to.be(undefined);
});
it('does not return a tile outside of layers extent', function() {
options.extent = [-80, -40, -45, -10];
var source = new ol.source.TileWMS(options);
var tileCoord = new ol.TileCoord(3, 4, 2);
var url = source.tileUrlFunction(tileCoord, 1, ol.proj.get('EPSG:4326'));
expect(url).to.be(undefined);
});
});
describe('#getGetFeatureInfo', function() {
it('returns the expected GetFeatureInfo URL', function() {
@@ -177,4 +217,5 @@ describe('ol.source.TileWMS', function() {
goog.require('goog.Uri');
goog.require('ol.ImageTile');
goog.require('ol.source.TileWMS');
goog.require('ol.TileCoord');
goog.require('ol.proj');