Replace source ready flag with loading/ready/error enum

This commit is contained in:
Tom Payne
2013-09-24 15:22:23 +02:00
parent da84dd9253
commit 167b309242
12 changed files with 114 additions and 78 deletions
+34 -4
View File
@@ -1,18 +1,29 @@
goog.provide('ol.source.Source');
goog.provide('ol.source.State');
goog.require('goog.events.EventTarget');
goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.proj');
/**
* @enum {number}
*/
ol.source.State = {
LOADING: 0,
READY: 1,
ERROR: 2
};
/**
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* extent: (ol.Extent|undefined),
* logo: (string|undefined),
* projection: ol.proj.ProjectionLike}}
* projection: ol.proj.ProjectionLike,
* state: (ol.source.State|undefined)}}
*/
ol.source.SourceOptions;
@@ -54,6 +65,13 @@ ol.source.Source = function(options) {
*/
this.logo_ = options.logo;
/**
* @private
* @type {ol.source.State}
*/
this.state_ = goog.isDef(options.state) ?
options.state : ol.source.State.READY;
/**
* @private
* @type {number}
@@ -120,9 +138,11 @@ ol.source.Source.prototype.getRevision = function() {
/**
* @return {boolean} Is ready.
* @return {ol.source.State} State.
*/
ol.source.Source.prototype.isReady = goog.functions.TRUE;
ol.source.Source.prototype.getState = function() {
return this.state_;
};
/**
@@ -149,6 +169,16 @@ ol.source.Source.prototype.setLogo = function(logo) {
};
/**
* @param {ol.source.State} state State.
* @protected
*/
ol.source.Source.prototype.setState = function(state) {
this.state_ = state;
this.dispatchChangeEvent();
};
/**
* @param {ol.proj.Projection} projection Projetion.
*/