Support wrapX for attributions
This commit is contained in:
+30
-7
@@ -1,5 +1,7 @@
|
|||||||
goog.provide('ol.Attribution');
|
goog.provide('ol.Attribution');
|
||||||
|
|
||||||
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.math');
|
||||||
goog.require('ol.TileRange');
|
goog.require('ol.TileRange');
|
||||||
|
|
||||||
|
|
||||||
@@ -54,22 +56,43 @@ ol.Attribution.prototype.getHTML = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object.<string, ol.TileRange>} tileRanges Tile ranges.
|
* @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.
|
* @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_)) {
|
if (goog.isNull(this.tileRanges_)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var i, ii, tileRange, z;
|
var i, ii, tileRange, zKey;
|
||||||
for (z in tileRanges) {
|
for (zKey in tileRanges) {
|
||||||
if (!(z in this.tileRanges_)) {
|
if (!(zKey in this.tileRanges_)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tileRange = tileRanges[z];
|
tileRange = tileRanges[zKey];
|
||||||
for (i = 0, ii = this.tileRanges_[z].length; i < ii; ++i) {
|
var testTileRange;
|
||||||
if (this.tileRanges_[z][i].intersects(tileRange)) {
|
for (i = 0, ii = this.tileRanges_[zKey].length; i < ii; ++i) {
|
||||||
|
testTileRange = this.tileRanges_[zKey][i];
|
||||||
|
if (testTileRange.intersects(tileRange)) {
|
||||||
return true;
|
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;
|
return false;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
goog.provide('ol.control.Attribution');
|
goog.provide('ol.control.Attribution');
|
||||||
|
|
||||||
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.dom');
|
goog.require('goog.dom');
|
||||||
goog.require('goog.dom.TagName');
|
goog.require('goog.dom.TagName');
|
||||||
goog.require('goog.dom.classlist');
|
goog.require('goog.dom.classlist');
|
||||||
@@ -12,6 +13,7 @@ goog.require('goog.style');
|
|||||||
goog.require('ol.Attribution');
|
goog.require('ol.Attribution');
|
||||||
goog.require('ol.control.Control');
|
goog.require('ol.control.Control');
|
||||||
goog.require('ol.css');
|
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) {
|
ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
|
||||||
var i, ii, j, jj, tileRanges, source, sourceAttribution,
|
var i, ii, j, jj, tileRanges, source, sourceAttribution,
|
||||||
sourceAttributionKey, sourceAttributions, sourceKey;
|
sourceAttributionKey, sourceAttributions, sourceKey;
|
||||||
|
var intersectsTileRange;
|
||||||
var layerStatesArray = frameState.layerStatesArray;
|
var layerStatesArray = frameState.layerStatesArray;
|
||||||
/** @type {Object.<string, ol.Attribution>} */
|
/** @type {Object.<string, ol.Attribution>} */
|
||||||
var attributions = goog.object.clone(frameState.attributions);
|
var attributions = goog.object.clone(frameState.attributions);
|
||||||
/** @type {Object.<string, ol.Attribution>} */
|
/** @type {Object.<string, ol.Attribution>} */
|
||||||
var hiddenAttributions = {};
|
var hiddenAttributions = {};
|
||||||
|
var projection = frameState.viewState.projection;
|
||||||
|
goog.asserts.assert(!goog.isNull(projection));
|
||||||
for (i = 0, ii = layerStatesArray.length; i < ii; i++) {
|
for (i = 0, ii = layerStatesArray.length; i < ii; i++) {
|
||||||
source = layerStatesArray[i].layer.getSource();
|
source = layerStatesArray[i].layer.getSource();
|
||||||
if (goog.isNull(source)) {
|
if (goog.isNull(source)) {
|
||||||
@@ -180,14 +185,21 @@ ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tileRanges = frameState.usedTiles[sourceKey];
|
tileRanges = frameState.usedTiles[sourceKey];
|
||||||
if (goog.isDef(tileRanges) &&
|
if (goog.isDef(tileRanges)) {
|
||||||
sourceAttribution.intersectsAnyTileRange(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) {
|
if (sourceAttributionKey in hiddenAttributions) {
|
||||||
delete hiddenAttributions[sourceAttributionKey];
|
delete hiddenAttributions[sourceAttributionKey];
|
||||||
}
|
}
|
||||||
attributions[sourceAttributionKey] = sourceAttribution;
|
attributions[sourceAttributionKey] = sourceAttribution;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
hiddenAttributions[sourceAttributionKey] = sourceAttribution;
|
hiddenAttributions[sourceAttributionKey] = sourceAttribution;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user