diff --git a/src/ol/attribution.js b/src/ol/attribution.js index da38e4a388..d234c36515 100644 --- a/src/ol/attribution.js +++ b/src/ol/attribution.js @@ -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.} 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; diff --git a/src/ol/control/attributioncontrol.js b/src/ol/control/attributioncontrol.js index a2623b956b..0d00b8d6c7 100644 --- a/src/ol/control/attributioncontrol.js +++ b/src/ol/control/attributioncontrol.js @@ -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.} */ var attributions = goog.object.clone(frameState.attributions); /** @type {Object.} */ 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; } }