Merge pull request #1030 from elemoine/touches

Exclude tiles that touches the source extent
This commit is contained in:
Éric Lemoine
2013-09-16 10:00:11 -07:00
4 changed files with 35 additions and 3 deletions

View File

@@ -337,6 +337,19 @@ ol.extent.toString = function(extent) {
}; };
/**
* @param {ol.Extent} extent1 Extent 1.
* @param {ol.Extent} extent2 Extent 2.
* @return {boolean} Touches.
*/
ol.extent.touches = function(extent1, extent2) {
var intersects = ol.extent.intersects(extent1, extent2);
return intersects &&
(extent1[0] == extent2[2] || extent1[2] == extent2[0] ||
extent1[1] == extent2[3] || extent1[3] == extent2[1]);
};
/** /**
* @param {ol.Extent} extent Extent. * @param {ol.Extent} extent Extent.
* @param {ol.TransformFunction} transformFn Transform function. * @param {ol.TransformFunction} transformFn Transform function.

View File

@@ -84,7 +84,8 @@ ol.source.TileWMS = function(options) {
tileExtent = tileGrid.getTileCoordExtent( tileExtent = tileGrid.getTileCoordExtent(
new ol.TileCoord(tileCoord.z, x, tileCoord.y)); new ol.TileCoord(tileCoord.z, x, tileCoord.y));
} }
if (!goog.isNull(extent) && !ol.extent.intersects(tileExtent, extent)) { if (!goog.isNull(extent) && (!ol.extent.intersects(tileExtent, extent) ||
ol.extent.touches(tileExtent, extent))) {
return null; return null;
} }
return new ol.TileCoord(tileCoord.z, x, tileCoord.y); return new ol.TileCoord(tileCoord.z, x, tileCoord.y);

View File

@@ -165,7 +165,8 @@ ol.source.WMTS = function(options) {
tmpTileCoord.y = tileCoord.y; tmpTileCoord.y = tileCoord.y;
tileExtent = tileGrid.getTileCoordExtent(tmpTileCoord, tmpExtent); tileExtent = tileGrid.getTileCoordExtent(tmpTileCoord, tmpExtent);
} }
if (!ol.extent.intersects(tileExtent, extent)) { if (!ol.extent.intersects(tileExtent, extent) ||
ol.extent.touches(tileExtent, extent)) {
return null; return null;
} }
return new ol.TileCoord(tileCoord.z, x, y); return new ol.TileCoord(tileCoord.z, x, y);

View File

@@ -122,7 +122,7 @@ describe('ol.extent', function() {
}); });
}); });
describe('intersect', function() { describe('intersects', function() {
it('returns the expected value', function() { it('returns the expected value', function() {
var intersects = ol.extent.intersects; var intersects = ol.extent.intersects;
@@ -157,6 +157,23 @@ describe('ol.extent', function() {
}); });
}); });
describe('touches', function() {
it('returns the expected value', function() {
var touches = ol.extent.touches;
var extent = [50, 50, 100, 100];
expect(touches(extent, [20, 20, 80, 80])).to.be(false);
expect(touches(extent, [20, 20, 50, 80])).to.be(true);
expect(touches(extent, [20, 20, 50, 40])).to.be(false);
expect(touches(extent, [100, 20, 140, 80])).to.be(true);
expect(touches(extent, [100, 20, 140, 40])).to.be(false);
expect(touches(extent, [20, 20, 80, 50])).to.be(true);
expect(touches(extent, [20, 20, 40, 50])).to.be(false);
expect(touches(extent, [20, 100, 80, 140])).to.be(true);
expect(touches(extent, [20, 100, 40, 140])).to.be(false);
});
});
describe('normalize', function() { describe('normalize', function() {
it('returns the expected coordinate', function() { it('returns the expected coordinate', function() {
var extent = [0, 1, 2, 3]; var extent = [0, 1, 2, 3];