Handle not-ready layers in attribution view

This commit is contained in:
Tom Payne
2012-08-02 14:43:20 +02:00
parent 53f1397109
commit 5d870e62c2
+48 -17
View File
@@ -1,7 +1,6 @@
// FIXME handle rotation
// FIXME probably need to abstract out a "layers listener"
// FIXME handle layer order
// FIXME handle not-ready layers
goog.provide('ol.view.Attribution');
@@ -76,21 +75,12 @@ ol.view.Attribution = function(map) {
goog.inherits(ol.view.Attribution, ol.View);
/**
* @inheritDoc
*/
ol.view.Attribution.prototype.getElement = function() {
return this.ulElement_;
};
/**
* @param {ol.Layer} layer Layer.
* @protected
* @private
*/
ol.view.Attribution.prototype.handleLayerAdd = function(layer) {
var layerKey = goog.getUid(layer);
ol.view.Attribution.prototype.createAttributionElementsForLayer_ =
function(layer) {
var map = this.getMap();
var mapIsDef = map.isDef();
@@ -100,11 +90,11 @@ ol.view.Attribution.prototype.handleLayerAdd = function(layer) {
var layerVisible = layer.getVisible();
this.layerVisibleChangeListenerKeys_[layerKey] = goog.events.listen(
layer, ol.Object.getChangedEventType(ol.LayerProperty.VISIBLE),
this.handleLayerVisibleChanged, false, this);
var store = layer.getStore();
var attributions = store.getAttributions();
if (!goog.isNull(attributions)) {
goog.array.forEach(layer.getStore().getAttributions(), function(attribution) {
goog.array.forEach(attributions, function(attribution) {
var attributionKey = goog.getUid(attribution);
@@ -122,6 +112,47 @@ ol.view.Attribution.prototype.handleLayerAdd = function(layer) {
}, this);
}
};
/**
* @inheritDoc
*/
ol.view.Attribution.prototype.getElement = function() {
return this.ulElement_;
};
/**
* @param {ol.Layer} layer Layer.
* @protected
*/
ol.view.Attribution.prototype.handleLayerAdd = function(layer) {
var layerKey = goog.getUid(layer);
this.layerVisibleChangeListenerKeys_[layerKey] = goog.events.listen(
layer, ol.Object.getChangedEventType(ol.LayerProperty.VISIBLE),
this.handleLayerVisibleChanged, false, this);
if (layer.getStore().isReady()) {
this.createAttributionElementsForLayer_(layer);
} else {
goog.events.listenOnce(layer, goog.events.EventType.LOAD,
this.handleLayerLoad, false, this);
}
};
/**
* @param {goog.events.Event} event Event.
*/
ol.view.Attribution.prototype.handleLayerLoad = function(event) {
var layer = /** @type {ol.Layer} */ event.target;
this.createAttributionElementsForLayer_(layer);
};