Support wrapX for attributions
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
goog.provide('ol.Attribution');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.TileRange');
|
||||
|
||||
|
||||
@@ -54,22 +56,43 @@ ol.Attribution.prototype.getHTML = function() {
|
||||
|
||||
/**
|
||||
* @param {Object.<string, ol.TileRange>} tileRanges Tile ranges.
|
||||
* @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @param {!ol.proj.Projection} projection Projection.
|
||||
* @return {boolean} Intersects any tile range.
|
||||
*/
|
||||
ol.Attribution.prototype.intersectsAnyTileRange = function(tileRanges) {
|
||||
ol.Attribution.prototype.intersectsAnyTileRange =
|
||||
function(tileRanges, tileGrid, projection) {
|
||||
if (goog.isNull(this.tileRanges_)) {
|
||||
return true;
|
||||
}
|
||||
var i, ii, tileRange, z;
|
||||
for (z in tileRanges) {
|
||||
if (!(z in this.tileRanges_)) {
|
||||
var i, ii, tileRange, zKey;
|
||||
for (zKey in tileRanges) {
|
||||
if (!(zKey in this.tileRanges_)) {
|
||||
continue;
|
||||
}
|
||||
tileRange = tileRanges[z];
|
||||
for (i = 0, ii = this.tileRanges_[z].length; i < ii; ++i) {
|
||||
if (this.tileRanges_[z][i].intersects(tileRange)) {
|
||||
tileRange = tileRanges[zKey];
|
||||
var testTileRange;
|
||||
for (i = 0, ii = this.tileRanges_[zKey].length; i < ii; ++i) {
|
||||
testTileRange = this.tileRanges_[zKey][i];
|
||||
if (testTileRange.intersects(tileRange)) {
|
||||
return true;
|
||||
}
|
||||
var extentTileRange = tileGrid.getTileRangeForExtentAndZ(
|
||||
ol.tilegrid.extentFromProjection(projection), parseInt(zKey, 10));
|
||||
var width = extentTileRange.getWidth();
|
||||
if (tileRange.minX < extentTileRange.minX ||
|
||||
tileRange.maxX > extentTileRange.maxX) {
|
||||
if (testTileRange.intersects(new ol.TileRange(
|
||||
goog.math.modulo(tileRange.minX, width),
|
||||
goog.math.modulo(tileRange.maxX, width),
|
||||
tileRange.minY, tileRange.maxY))) {
|
||||
return true;
|
||||
}
|
||||
if (tileRange.getWidth() > width &&
|
||||
testTileRange.intersects(extentTileRange)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
goog.provide('ol.control.Attribution');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.dom.classlist');
|
||||
@@ -12,6 +13,7 @@ goog.require('goog.style');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('ol.css');
|
||||
goog.require('ol.source.Tile');
|
||||
|
||||
|
||||
|
||||
@@ -158,11 +160,14 @@ goog.inherits(ol.control.Attribution, ol.control.Control);
|
||||
ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
|
||||
var i, ii, j, jj, tileRanges, source, sourceAttribution,
|
||||
sourceAttributionKey, sourceAttributions, sourceKey;
|
||||
var intersectsTileRange;
|
||||
var layerStatesArray = frameState.layerStatesArray;
|
||||
/** @type {Object.<string, ol.Attribution>} */
|
||||
var attributions = goog.object.clone(frameState.attributions);
|
||||
/** @type {Object.<string, ol.Attribution>} */
|
||||
var hiddenAttributions = {};
|
||||
var projection = frameState.viewState.projection;
|
||||
goog.asserts.assert(!goog.isNull(projection));
|
||||
for (i = 0, ii = layerStatesArray.length; i < ii; i++) {
|
||||
source = layerStatesArray[i].layer.getSource();
|
||||
if (goog.isNull(source)) {
|
||||
@@ -180,14 +185,21 @@ ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
|
||||
continue;
|
||||
}
|
||||
tileRanges = frameState.usedTiles[sourceKey];
|
||||
if (goog.isDef(tileRanges) &&
|
||||
sourceAttribution.intersectsAnyTileRange(tileRanges)) {
|
||||
if (goog.isDef(tileRanges)) {
|
||||
goog.asserts.assertInstanceof(source, ol.source.Tile);
|
||||
var tileGrid = source.getTileGridForProjection(projection);
|
||||
goog.asserts.assert(!goog.isNull(tileGrid));
|
||||
intersectsTileRange = sourceAttribution.intersectsAnyTileRange(
|
||||
tileRanges, tileGrid, projection);
|
||||
} else {
|
||||
intersectsTileRange = false;
|
||||
}
|
||||
if (intersectsTileRange) {
|
||||
if (sourceAttributionKey in hiddenAttributions) {
|
||||
delete hiddenAttributions[sourceAttributionKey];
|
||||
}
|
||||
attributions[sourceAttributionKey] = sourceAttribution;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
hiddenAttributions[sourceAttributionKey] = sourceAttribution;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user