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 handle rotation
// FIXME probably need to abstract out a "layers listener" // FIXME probably need to abstract out a "layers listener"
// FIXME handle layer order // FIXME handle layer order
// FIXME handle not-ready layers
goog.provide('ol.view.Attribution'); goog.provide('ol.view.Attribution');
@@ -76,21 +75,12 @@ ol.view.Attribution = function(map) {
goog.inherits(ol.view.Attribution, ol.View); goog.inherits(ol.view.Attribution, ol.View);
/**
* @inheritDoc
*/
ol.view.Attribution.prototype.getElement = function() {
return this.ulElement_;
};
/** /**
* @param {ol.Layer} layer Layer. * @param {ol.Layer} layer Layer.
* @protected * @private
*/ */
ol.view.Attribution.prototype.handleLayerAdd = function(layer) { ol.view.Attribution.prototype.createAttributionElementsForLayer_ =
function(layer) {
var layerKey = goog.getUid(layer);
var map = this.getMap(); var map = this.getMap();
var mapIsDef = map.isDef(); var mapIsDef = map.isDef();
@@ -100,11 +90,11 @@ ol.view.Attribution.prototype.handleLayerAdd = function(layer) {
var layerVisible = layer.getVisible(); var layerVisible = layer.getVisible();
this.layerVisibleChangeListenerKeys_[layerKey] = goog.events.listen( var store = layer.getStore();
layer, ol.Object.getChangedEventType(ol.LayerProperty.VISIBLE), var attributions = store.getAttributions();
this.handleLayerVisibleChanged, false, this); if (!goog.isNull(attributions)) {
goog.array.forEach(layer.getStore().getAttributions(), function(attribution) { goog.array.forEach(attributions, function(attribution) {
var attributionKey = goog.getUid(attribution); var attributionKey = goog.getUid(attribution);
@@ -122,6 +112,47 @@ ol.view.Attribution.prototype.handleLayerAdd = function(layer) {
}, this); }, 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);
}; };