Handle attribution visiblity for tile layers
This commit is contained in:
@@ -7,36 +7,25 @@ goog.require('ol.Extent');
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} minZ Minimum Z.
|
||||
* @param {number} maxZ Maximum Z.
|
||||
*/
|
||||
ol.CoverageArea = function(extent, minZ, maxZ) {
|
||||
ol.CoverageArea = function(extent) {
|
||||
|
||||
/**
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.extent = extent;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.minZ = minZ;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxZ = maxZ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} z Z.
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {boolean} Intersects.
|
||||
*/
|
||||
ol.CoverageArea.prototype.intersectsWithZ = function(extent, z) {
|
||||
return this.extent.intersects(extent) && this.minZ <= z && z <= this.maxZ;
|
||||
ol.CoverageArea.prototype.intersectsExtentAndResolution =
|
||||
function(extent, resolution) {
|
||||
return this.extent.intersects(extent);
|
||||
};
|
||||
|
||||
|
||||
@@ -46,5 +35,5 @@ ol.CoverageArea.prototype.intersectsWithZ = function(extent, z) {
|
||||
*/
|
||||
ol.CoverageArea.prototype.transform = function(transformFn) {
|
||||
var extent = this.extent.transform(transformFn);
|
||||
return new ol.CoverageArea(extent, this.minZ, this.maxZ);
|
||||
return new ol.CoverageArea(extent);
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ goog.require('goog.Uri');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.net.Jsonp');
|
||||
goog.require('ol.TileCoverageArea');
|
||||
goog.require('ol.TileLayer');
|
||||
goog.require('ol.TileStore');
|
||||
goog.require('ol.tilegrid.XYZ');
|
||||
@@ -117,7 +118,8 @@ ol.tilestore.BingMaps.prototype.handleImageryMetadataResponse =
|
||||
var zoomMin = resource.zoomMin;
|
||||
var zoomMax = resource.zoomMax;
|
||||
var tileSize = new ol.Size(resource.imageWidth, resource.imageHeight);
|
||||
this.tileGrid = new ol.tilegrid.XYZ(zoomMax, tileSize);
|
||||
var tileGrid = new ol.tilegrid.XYZ(zoomMax, tileSize);
|
||||
this.tileGrid = tileGrid;
|
||||
|
||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
function(tileCoord) {
|
||||
@@ -162,7 +164,7 @@ ol.tilestore.BingMaps.prototype.handleImageryMetadataResponse =
|
||||
var extent = new ol.Extent(bbox[1], bbox[0], bbox[3], bbox[2]);
|
||||
var minZ = coverageArea.zoomMin;
|
||||
var maxZ = coverageArea.zoomMax;
|
||||
return new ol.CoverageArea(extent, minZ, maxZ);
|
||||
return new ol.TileCoverageArea(tileGrid, extent, minZ, maxZ);
|
||||
});
|
||||
return new ol.Attribution(html, coverageAreas, projection);
|
||||
});
|
||||
|
||||
59
src/ol/tile/tilecoveragearea.js
Normal file
59
src/ol/tile/tilecoveragearea.js
Normal file
@@ -0,0 +1,59 @@
|
||||
goog.provide('ol.TileCoverageArea');
|
||||
|
||||
goog.require('ol.CoverageArea');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.TileGrid');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.CoverageArea}
|
||||
* @param {ol.TileGrid} tileGrid Tile grid.
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} minZ Minimum Z.
|
||||
* @param {number} maxZ Maximum Z.
|
||||
*/
|
||||
ol.TileCoverageArea = function(tileGrid, extent, minZ, maxZ) {
|
||||
|
||||
goog.base(this, extent);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.TileGrid}
|
||||
*/
|
||||
this.tileGrid_ = tileGrid;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.minZ = minZ;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxZ = maxZ;
|
||||
|
||||
};
|
||||
goog.inherits(ol.TileCoverageArea, ol.CoverageArea);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.TileCoverageArea.prototype.intersectsExtentAndResolution =
|
||||
function(extent, resolution) {
|
||||
var z = this.tileGrid_.getZForResolution(resolution);
|
||||
return this.minZ <= z && z <= this.maxZ &&
|
||||
goog.base(this, 'intersectsExtentAndResolution', extent, resolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TransformFunction} transformFn Transform.
|
||||
* @return {ol.TileCoverageArea} Transformed tile coverage area.
|
||||
*/
|
||||
ol.TileCoverageArea.prototype.transform = function(transformFn) {
|
||||
var extent = this.extent.transform(transformFn);
|
||||
return new ol.TileCoverageArea(this.tileGrid_, extent, this.minZ, this.maxZ);
|
||||
};
|
||||
@@ -86,7 +86,7 @@ ol.view.Attribution.prototype.createAttributionElementsForLayer_ =
|
||||
var mapIsDef = map.isDef();
|
||||
var mapExtent = /** @type {ol.Extent} */ map.getExtent();
|
||||
var mapProjection = /** @type {ol.Projection} */ map.getProjection();
|
||||
var mapZ = 10; // FIXME
|
||||
var mapResolution = map.getResolution();
|
||||
|
||||
var layerVisible = layer.getVisible();
|
||||
|
||||
@@ -103,7 +103,7 @@ ol.view.Attribution.prototype.createAttributionElementsForLayer_ =
|
||||
|
||||
var attributionVisible = mapIsDef && layerVisible &&
|
||||
this.getAttributionVisiblity_(
|
||||
attribution, mapExtent, mapZ, mapProjection);
|
||||
attribution, mapExtent, mapResolution, mapProjection);
|
||||
goog.style.showElement(attributionElement, attributionVisible);
|
||||
|
||||
this.ulElement_.appendChild(attributionElement);
|
||||
@@ -188,12 +188,12 @@ ol.view.Attribution.prototype.handleLayerVisibleChanged = function(event) {
|
||||
var mapIsDef = map.isDef();
|
||||
var mapExtent = /** @type {ol.Extent} */ map.getExtent();
|
||||
var mapProjection = /** @type {ol.Projection} */ map.getProjection();
|
||||
var mapZ = 10; // FIXME
|
||||
var mapResolution = /** @type {number} */ map.getResolution();
|
||||
|
||||
var layer = /** @type {ol.Layer} */ event.target;
|
||||
|
||||
this.updateLayerAttributionsVisibility_(
|
||||
layer, mapIsDef, mapExtent, mapZ, mapProjection);
|
||||
layer, mapIsDef, mapExtent, mapResolution, mapProjection);
|
||||
|
||||
};
|
||||
|
||||
@@ -241,12 +241,12 @@ ol.view.Attribution.prototype.handleMapChanged = function() {
|
||||
var mapIsDef = map.isDef();
|
||||
var mapExtent = /** @type {ol.Extent} */ map.getExtent();
|
||||
var mapProjection = /** @type {ol.Projection} */ map.getProjection();
|
||||
var mapZ = 10; // FIXME
|
||||
var mapResolution = /** @type {number} */ map.getResolution();
|
||||
|
||||
var layers = map.getLayers();
|
||||
layers.forEach(function(layer) {
|
||||
this.updateLayerAttributionsVisibility_(
|
||||
layer, mapIsDef, mapExtent, mapZ, mapProjection);
|
||||
layer, mapIsDef, mapExtent, mapResolution, mapProjection);
|
||||
}, this);
|
||||
|
||||
};
|
||||
@@ -279,13 +279,13 @@ ol.view.Attribution.prototype.handleMapLayersChanged = function() {
|
||||
/**
|
||||
* @param {ol.Attribution} attribution Attribution.
|
||||
* @param {ol.Extent} mapExtent Map extent.
|
||||
* @param {number} mapZ Map Z.
|
||||
* @param {number} mapResolution Map resolution.
|
||||
* @param {ol.Projection} mapProjection Map projection.
|
||||
* @return {boolean} Attribution visibility.
|
||||
* @private
|
||||
*/
|
||||
ol.view.Attribution.prototype.getAttributionVisiblity_ =
|
||||
function(attribution, mapExtent, mapZ, mapProjection) {
|
||||
function(attribution, mapExtent, mapResolution, mapProjection) {
|
||||
|
||||
var attributionKey = goog.getUid(attribution);
|
||||
|
||||
@@ -314,7 +314,8 @@ ol.view.Attribution.prototype.getAttributionVisiblity_ =
|
||||
attributionVisible = goog.array.some(
|
||||
coverageAreas,
|
||||
function(coverageArea) {
|
||||
return coverageArea.intersectsWithZ(mapExtent, mapZ);
|
||||
return coverageArea.intersectsExtentAndResolution(
|
||||
mapExtent, mapResolution);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -327,18 +328,18 @@ ol.view.Attribution.prototype.getAttributionVisiblity_ =
|
||||
* @param {ol.Layer} layer Layer.
|
||||
* @param {boolean} mapIsDef Map is defined.
|
||||
* @param {ol.Extent} mapExtent Map extent.
|
||||
* @param {number} mapZ Map Z.
|
||||
* @param {number} mapResolution Map resolution.
|
||||
* @param {ol.Projection} mapProjection Map projection.
|
||||
* @private
|
||||
*/
|
||||
ol.view.Attribution.prototype.updateLayerAttributionsVisibility_ =
|
||||
function(layer, mapIsDef, mapExtent, mapZ, mapProjection) {
|
||||
function(layer, mapIsDef, mapExtent, mapResolution, mapProjection) {
|
||||
var layerVisible = layer.getVisible();
|
||||
goog.array.forEach(layer.getStore().getAttributions(), function(attribution) {
|
||||
var attributionKey = goog.getUid(attribution);
|
||||
var attributionVisible = mapIsDef && layerVisible &&
|
||||
this.getAttributionVisiblity_(
|
||||
attribution, mapExtent, mapZ, mapProjection);
|
||||
attribution, mapExtent, mapResolution, mapProjection);
|
||||
var attributionElement = this.attributionElements_[attributionKey];
|
||||
goog.style.showElement(attributionElement, attributionVisible);
|
||||
}, this);
|
||||
|
||||
Reference in New Issue
Block a user