Replace source ready flag with loading/ready/error enum
This commit is contained in:
@@ -9,6 +9,7 @@ goog.require('ol.TileRange');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.State');
|
||||
goog.require('ol.source.TileImage');
|
||||
goog.require('ol.tilegrid.XYZ');
|
||||
|
||||
@@ -25,6 +26,7 @@ ol.source.BingMaps = function(options) {
|
||||
crossOrigin: 'anonymous',
|
||||
opaque: true,
|
||||
projection: ol.proj.get('EPSG:3857'),
|
||||
state: ol.source.State.LOADING,
|
||||
tileLoadFunction: options.tileLoadFunction
|
||||
});
|
||||
|
||||
@@ -34,12 +36,6 @@ ol.source.BingMaps = function(options) {
|
||||
*/
|
||||
this.culture_ = goog.isDef(options.culture) ? options.culture : 'en-us';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.ready_ = false;
|
||||
|
||||
var uri = new goog.Uri(
|
||||
'//dev.virtualearth.net/REST/v1/Imagery/Metadata/' + options.style);
|
||||
var jsonp = new goog.net.Jsonp(uri, 'jsonp');
|
||||
@@ -139,16 +135,6 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
||||
|
||||
this.setLogo(brandLogoUri);
|
||||
|
||||
this.ready_ = true;
|
||||
|
||||
this.dispatchChangeEvent();
|
||||
this.setState(ol.source.State.READY);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.BingMaps.prototype.isReady = function() {
|
||||
return this.ready_;
|
||||
};
|
||||
|
||||
+34
-4
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@ goog.require('ol.TileRange');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.State');
|
||||
goog.require('ol.source.TileImage');
|
||||
goog.require('ol.tilegrid.XYZ');
|
||||
|
||||
@@ -46,15 +47,10 @@ ol.source.TileJSON = function(options) {
|
||||
goog.base(this, {
|
||||
crossOrigin: options.crossOrigin,
|
||||
projection: ol.proj.get('EPSG:3857'),
|
||||
state: ol.source.State.LOADING,
|
||||
tileLoadFunction: options.tileLoadFunction
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.ready_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!goog.async.Deferred}
|
||||
@@ -118,16 +114,6 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
|
||||
]);
|
||||
}
|
||||
|
||||
this.ready_ = true;
|
||||
|
||||
this.dispatchChangeEvent();
|
||||
this.setState(ol.source.State.READY);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileJSON.prototype.isReady = function() {
|
||||
return this.ready_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user