Image layer renderers add attributions to frame state
This commit is contained in:
@@ -6,6 +6,7 @@ goog.provide('ol.PostRenderFunction');
|
||||
goog.provide('ol.PreRenderFunction');
|
||||
|
||||
goog.require('goog.vec.Mat4');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Color');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Size');
|
||||
@@ -18,6 +19,7 @@ goog.require('ol.layer.LayerState');
|
||||
|
||||
/**
|
||||
* @typedef {{animate: boolean,
|
||||
* attributions: Object.<string, ol.Attribution>,
|
||||
* backgroundColor: ol.Color,
|
||||
* coordinateToPixelMatrix: goog.vec.Mat4.Number,
|
||||
* extent: (null|ol.Extent),
|
||||
|
||||
@@ -5,6 +5,7 @@ goog.require('goog.array');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventTarget');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Extent');
|
||||
|
||||
|
||||
@@ -27,8 +28,15 @@ ol.ImageState = {
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {string} src Image source URI.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {Array.<ol.Attribution>} attributions Attributions.
|
||||
*/
|
||||
ol.Image = function(extent, resolution, src, crossOrigin) {
|
||||
ol.Image = function(extent, resolution, src, crossOrigin, attributions) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.Attribution>}
|
||||
*/
|
||||
this.attributions_ = attributions;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -86,6 +94,14 @@ ol.Image.prototype.dispatchChangeEvent = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.Attribution>} Attributions.
|
||||
*/
|
||||
ol.Image.prototype.getAttributions = function() {
|
||||
return this.attributions_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Extent} Extent.
|
||||
*/
|
||||
|
||||
@@ -664,6 +664,7 @@ ol.Map.prototype.renderFrame_ = function(time) {
|
||||
var view2DState = view2D.getView2DState();
|
||||
frameState = {
|
||||
animate: false,
|
||||
attributions: {},
|
||||
backgroundColor: goog.isDef(backgroundColor) ?
|
||||
backgroundColor : new ol.Color(255, 255, 255, 1),
|
||||
coordinateToPixelMatrix: this.coordinateToPixelMatrix_,
|
||||
|
||||
@@ -94,6 +94,7 @@ ol.renderer.canvas.ImageLayer.prototype.renderFrame =
|
||||
|
||||
if (!goog.isNull(this.image_)) {
|
||||
image = this.image_;
|
||||
|
||||
var imageExtent = image.getExtent();
|
||||
var imageResolution = image.getResolution();
|
||||
var transform = this.transform_;
|
||||
@@ -111,5 +112,7 @@ ol.renderer.canvas.ImageLayer.prototype.renderFrame =
|
||||
(imageExtent.minX - viewCenter.x) / imageResolution,
|
||||
(viewCenter.y - imageExtent.maxY) / imageResolution,
|
||||
0);
|
||||
|
||||
this.updateAttributions(frameState.attributions, image.getAttributions());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -106,6 +106,8 @@ ol.renderer.dom.ImageLayer.prototype.renderFrame =
|
||||
this.image_ = image;
|
||||
}
|
||||
this.setTransform(transform);
|
||||
|
||||
this.updateAttributions(frameState.attributions, image.getAttributions());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ goog.provide('ol.renderer.Layer');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.FrameState');
|
||||
goog.require('ol.Image');
|
||||
goog.require('ol.ImageState');
|
||||
@@ -201,6 +202,23 @@ ol.renderer.Layer.prototype.scheduleExpireCache =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {Object.<string, ol.Attribution>} attributionsSet Attributions
|
||||
* set (target).
|
||||
* @param {Array.<ol.Attribution>} attributions Attributions (source).
|
||||
*/
|
||||
ol.renderer.Layer.prototype.updateAttributions =
|
||||
function(attributionsSet, attributions) {
|
||||
var i;
|
||||
var attribution;
|
||||
for (i = 0; i < attributions.length; ++i) {
|
||||
attribution = attributions[i];
|
||||
attributionsSet[goog.getUid(attribution).toString()] = attribution;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {Object.<string, Object.<string, ol.TileRange>>} usedTiles Used tiles.
|
||||
|
||||
@@ -198,6 +198,8 @@ ol.renderer.webgl.ImageLayer.prototype.renderFrame =
|
||||
|
||||
this.image_ = image;
|
||||
this.texture_ = texture;
|
||||
|
||||
this.updateAttributions(frameState.attributions, image.getAttributions());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -84,7 +84,8 @@ ol.source.ImageSource.prototype.createImage =
|
||||
var imageUrl = this.imageUrlFunction(extent, size);
|
||||
if (goog.isDef(imageUrl)) {
|
||||
image = new ol.Image(
|
||||
extent, resolution, imageUrl, this.crossOrigin_);
|
||||
extent, resolution, imageUrl, this.crossOrigin_,
|
||||
this.getAttributions());
|
||||
}
|
||||
return image;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user