Allow source to be set after layer construction

This commit is contained in:
Tim Schaub
2014-10-23 09:24:03 -06:00
parent c06774acb5
commit d712b2ba54
12 changed files with 157 additions and 15 deletions

View File

@@ -15,10 +15,11 @@ goog.require('ol.layer.Layer');
* @constructor
* @extends {ol.layer.Layer}
* @fires ol.render.Event
* @param {olx.layer.ImageOptions} options Layer options.
* @param {olx.layer.ImageOptions=} opt_options Layer options.
* @api stable
*/
ol.layer.Image = function(options) {
ol.layer.Image = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
goog.base(this, /** @type {olx.layer.LayerOptions} */ (options));
};
goog.inherits(ol.layer.Image, ol.layer.Layer);

View File

@@ -7,6 +7,7 @@ goog.require('goog.object');
goog.require('ol.Object');
goog.require('ol.layer.Base');
goog.require('ol.layer.LayerProperty');
goog.require('ol.source.State');
@@ -42,7 +43,8 @@ ol.layer.Layer = function(options) {
ol.Object.getChangeEventType(ol.layer.LayerProperty.SOURCE),
this.handleSourcePropertyChange_, false, this);
this.setSource(options.source);
var source = goog.isDef(options.source) ? options.source : null;
this.setSource(source);
};
goog.inherits(ol.layer.Layer, ol.layer.Base);
@@ -83,7 +85,7 @@ ol.layer.Layer.prototype.getLayerStatesArray = function(opt_states) {
/**
* Get the layer source.
* @return {ol.source.Source} Source.
* @return {ol.source.Source} The layer source (or `null` if not yet set).
* @observable
* @api stable
*/
@@ -102,7 +104,14 @@ goog.exportProperty(
* @inheritDoc
*/
ol.layer.Layer.prototype.getSourceState = function() {
return this.getSource().getState();
var source = this.getSource();
var state;
if (!goog.isNull(source)) {
state = source.getState();
} else {
state = ol.source.State.UNDEFINED;
}
return state;
};

View File

@@ -24,10 +24,11 @@ ol.layer.TileProperty = {
* @constructor
* @extends {ol.layer.Layer}
* @fires ol.render.Event
* @param {olx.layer.TileOptions} options Tile layer options.
* @param {olx.layer.TileOptions=} opt_options Tile layer options.
* @api stable
*/
ol.layer.Tile = function(options) {
ol.layer.Tile = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
goog.base(this, /** @type {olx.layer.LayerOptions} */ (options));
};
goog.inherits(ol.layer.Tile, ol.layer.Layer);