Merge pull request #5801 from fredj/rm_ol.style.ImageState

Remove ol.style.ImageState and use ol.ImageState instead
This commit is contained in:
Frédéric Junod
2016-08-29 11:16:48 +02:00
committed by GitHub
13 changed files with 79 additions and 93 deletions

View File

@@ -1,8 +1,8 @@
goog.provide('ol.Image');
goog.require('ol');
goog.require('ol.Image');
goog.require('ol.ImageBase');
goog.require('ol.ImageState');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol.extent');
@@ -23,7 +23,7 @@ goog.require('ol.obj');
ol.Image = function(extent, resolution, pixelRatio, attributions, src,
crossOrigin, imageLoadFunction) {
ol.ImageBase.call(this, extent, resolution, pixelRatio, ol.ImageState.IDLE,
ol.ImageBase.call(this, extent, resolution, pixelRatio, ol.Image.State.IDLE,
attributions);
/**
@@ -55,9 +55,9 @@ ol.Image = function(extent, resolution, pixelRatio, attributions, src,
/**
* @protected
* @type {ol.ImageState}
* @type {ol.Image.State}
*/
this.state = ol.ImageState.IDLE;
this.state = ol.Image.State.IDLE;
/**
* @private
@@ -100,7 +100,7 @@ ol.Image.prototype.getImage = function(opt_context) {
* @private
*/
ol.Image.prototype.handleImageError_ = function() {
this.state = ol.ImageState.ERROR;
this.state = ol.Image.State.ERROR;
this.unlistenImage_();
this.changed();
};
@@ -115,7 +115,7 @@ ol.Image.prototype.handleImageLoad_ = function() {
if (this.resolution === undefined) {
this.resolution = ol.extent.getHeight(this.extent) / this.image_.height;
}
this.state = ol.ImageState.LOADED;
this.state = ol.Image.State.LOADED;
this.unlistenImage_();
this.changed();
};
@@ -128,8 +128,8 @@ ol.Image.prototype.handleImageLoad_ = function() {
* @api
*/
ol.Image.prototype.load = function() {
if (this.state == ol.ImageState.IDLE || this.state == ol.ImageState.ERROR) {
this.state = ol.ImageState.LOADING;
if (this.state == ol.Image.State.IDLE || this.state == ol.Image.State.ERROR) {
this.state = ol.Image.State.LOADING;
this.changed();
goog.DEBUG && console.assert(!this.imageListenerKeys_,
'this.imageListenerKeys_ should be null');
@@ -161,3 +161,14 @@ ol.Image.prototype.unlistenImage_ = function() {
this.imageListenerKeys_.forEach(ol.events.unlistenByKey);
this.imageListenerKeys_ = null;
};
/**
* @enum {number}
*/
ol.Image.State = {
IDLE: 0,
LOADING: 1,
LOADED: 2,
ERROR: 3
};

View File

@@ -1,29 +1,17 @@
goog.provide('ol.ImageBase');
goog.provide('ol.ImageState');
goog.require('ol');
goog.require('ol.events.EventTarget');
goog.require('ol.events.EventType');
/**
* @enum {number}
*/
ol.ImageState = {
IDLE: 0,
LOADING: 1,
LOADED: 2,
ERROR: 3
};
/**
* @constructor
* @extends {ol.events.EventTarget}
* @param {ol.Extent} extent Extent.
* @param {number|undefined} resolution Resolution.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.ImageState} state State.
* @param {ol.Image.State} state State.
* @param {Array.<ol.Attribution>} attributions Attributions.
*/
ol.ImageBase = function(extent, resolution, pixelRatio, state, attributions) {
@@ -56,7 +44,7 @@ ol.ImageBase = function(extent, resolution, pixelRatio, state, attributions) {
/**
* @protected
* @type {ol.ImageState}
* @type {ol.Image.State}
*/
this.state = state;
@@ -114,7 +102,7 @@ ol.ImageBase.prototype.getResolution = function() {
/**
* @return {ol.ImageState} State.
* @return {ol.Image.State} State.
*/
ol.ImageBase.prototype.getState = function() {
return this.state;

View File

@@ -1,8 +1,8 @@
goog.provide('ol.ImageCanvas');
goog.require('ol');
goog.require('ol.Image');
goog.require('ol.ImageBase');
goog.require('ol.ImageState');
/**
@@ -27,7 +27,7 @@ ol.ImageCanvas = function(extent, resolution, pixelRatio, attributions,
this.loader_ = opt_loader !== undefined ? opt_loader : null;
var state = opt_loader !== undefined ?
ol.ImageState.IDLE : ol.ImageState.LOADED;
ol.Image.State.IDLE : ol.Image.State.LOADED;
ol.ImageBase.call(this, extent, resolution, pixelRatio, state, attributions);
@@ -64,9 +64,9 @@ ol.ImageCanvas.prototype.getError = function() {
ol.ImageCanvas.prototype.handleLoad_ = function(err) {
if (err) {
this.error_ = err;
this.state = ol.ImageState.ERROR;
this.state = ol.Image.State.ERROR;
} else {
this.state = ol.ImageState.LOADED;
this.state = ol.Image.State.LOADED;
}
this.changed();
};
@@ -76,9 +76,9 @@ ol.ImageCanvas.prototype.handleLoad_ = function(err) {
* Trigger drawing on canvas.
*/
ol.ImageCanvas.prototype.load = function() {
if (this.state == ol.ImageState.IDLE) {
if (this.state == ol.Image.State.IDLE) {
goog.DEBUG && console.assert(this.loader_, 'this.loader_ must be set');
this.state = ol.ImageState.LOADING;
this.state = ol.Image.State.LOADING;
this.changed();
this.loader_(this.handleLoad_.bind(this));
}

View File

@@ -1,7 +1,7 @@
goog.provide('ol.renderer.Layer');
goog.require('ol');
goog.require('ol.ImageState');
goog.require('ol.Image');
goog.require('ol.Observable');
goog.require('ol.Tile');
goog.require('ol.asserts');
@@ -121,7 +121,7 @@ ol.renderer.Layer.prototype.getLayer = function() {
*/
ol.renderer.Layer.prototype.handleImageChange_ = function(event) {
var image = /** @type {ol.Image} */ (event.target);
if (image.getState() === ol.ImageState.LOADED) {
if (image.getState() === ol.Image.State.LOADED) {
this.renderIfReadyAndVisible();
}
};
@@ -137,24 +137,24 @@ ol.renderer.Layer.prototype.handleImageChange_ = function(event) {
*/
ol.renderer.Layer.prototype.loadImage = function(image) {
var imageState = image.getState();
if (imageState != ol.ImageState.LOADED &&
imageState != ol.ImageState.ERROR) {
if (imageState != ol.Image.State.LOADED &&
imageState != ol.Image.State.ERROR) {
// the image is either "idle" or "loading", register the change
// listener (a noop if the listener was already registered)
goog.DEBUG && console.assert(imageState == ol.ImageState.IDLE ||
imageState == ol.ImageState.LOADING,
goog.DEBUG && console.assert(imageState == ol.Image.State.IDLE ||
imageState == ol.Image.State.LOADING,
'imageState is "idle" or "loading"');
ol.events.listen(image, ol.events.EventType.CHANGE,
this.handleImageChange_, this);
}
if (imageState == ol.ImageState.IDLE) {
if (imageState == ol.Image.State.IDLE) {
image.load();
imageState = image.getState();
goog.DEBUG && console.assert(imageState == ol.ImageState.LOADING ||
imageState == ol.ImageState.LOADED,
goog.DEBUG && console.assert(imageState == ol.Image.State.LOADING ||
imageState == ol.Image.State.LOADED,
'imageState is "loading" or "loaded"');
}
return imageState == ol.ImageState.LOADED;
return imageState == ol.Image.State.LOADED;
};

View File

@@ -1,8 +1,8 @@
goog.provide('ol.renderer.vector');
goog.require('ol');
goog.require('ol.Image');
goog.require('ol.render.ReplayType');
goog.require('ol.style.ImageState');
/**
@@ -79,15 +79,15 @@ ol.renderer.vector.renderFeature = function(
imageStyle = style.getImage();
if (imageStyle) {
imageState = imageStyle.getImageState();
if (imageState == ol.style.ImageState.LOADED ||
imageState == ol.style.ImageState.ERROR) {
if (imageState == ol.Image.State.LOADED ||
imageState == ol.Image.State.ERROR) {
imageStyle.unlistenImageChange(listener, thisArg);
} else {
if (imageState == ol.style.ImageState.IDLE) {
if (imageState == ol.Image.State.IDLE) {
imageStyle.load();
}
imageState = imageStyle.getImageState();
goog.DEBUG && console.assert(imageState == ol.style.ImageState.LOADING,
goog.DEBUG && console.assert(imageState == ol.Image.State.LOADING,
'imageState should be LOADING');
imageStyle.listenImageChange(listener, thisArg);
loading = true;
@@ -227,7 +227,7 @@ ol.renderer.vector.renderMultiPolygonGeometry_ = function(replayGroup, geometry,
ol.renderer.vector.renderPointGeometry_ = function(replayGroup, geometry, style, feature) {
var imageStyle = style.getImage();
if (imageStyle) {
if (imageStyle.getImageState() != ol.style.ImageState.LOADED) {
if (imageStyle.getImageState() != ol.Image.State.LOADED) {
return;
}
var imageReplay = replayGroup.getReplay(
@@ -256,7 +256,7 @@ ol.renderer.vector.renderPointGeometry_ = function(replayGroup, geometry, style,
ol.renderer.vector.renderMultiPointGeometry_ = function(replayGroup, geometry, style, feature) {
var imageStyle = style.getImage();
if (imageStyle) {
if (imageStyle.getImageState() != ol.style.ImageState.LOADED) {
if (imageStyle.getImageState() != ol.Image.State.LOADED) {
return;
}
var imageReplay = replayGroup.getReplay(

View File

@@ -1,8 +1,8 @@
goog.provide('ol.reproj.Image');
goog.require('ol');
goog.require('ol.Image');
goog.require('ol.ImageBase');
goog.require('ol.ImageState');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol.extent');
@@ -99,11 +99,11 @@ ol.reproj.Image = function(sourceProj, targetProj,
this.sourceListenerKey_ = null;
var state = ol.ImageState.LOADED;
var state = ol.Image.State.LOADED;
var attributions = [];
if (this.sourceImage_) {
state = ol.ImageState.IDLE;
state = ol.Image.State.IDLE;
attributions = this.sourceImage_.getAttributions();
}
@@ -117,7 +117,7 @@ ol.inherits(ol.reproj.Image, ol.ImageBase);
* @inheritDoc
*/
ol.reproj.Image.prototype.disposeInternal = function() {
if (this.state == ol.ImageState.LOADING) {
if (this.state == ol.Image.State.LOADING) {
this.unlistenSource_();
}
ol.ImageBase.prototype.disposeInternal.call(this);
@@ -145,7 +145,7 @@ ol.reproj.Image.prototype.getProjection = function() {
*/
ol.reproj.Image.prototype.reproject_ = function() {
var sourceState = this.sourceImage_.getState();
if (sourceState == ol.ImageState.LOADED) {
if (sourceState == ol.Image.State.LOADED) {
var width = ol.extent.getWidth(this.targetExtent_) / this.targetResolution_;
var height =
ol.extent.getHeight(this.targetExtent_) / this.targetResolution_;
@@ -166,20 +166,20 @@ ol.reproj.Image.prototype.reproject_ = function() {
* @inheritDoc
*/
ol.reproj.Image.prototype.load = function() {
if (this.state == ol.ImageState.IDLE) {
this.state = ol.ImageState.LOADING;
if (this.state == ol.Image.State.IDLE) {
this.state = ol.Image.State.LOADING;
this.changed();
var sourceState = this.sourceImage_.getState();
if (sourceState == ol.ImageState.LOADED ||
sourceState == ol.ImageState.ERROR) {
if (sourceState == ol.Image.State.LOADED ||
sourceState == ol.Image.State.ERROR) {
this.reproject_();
} else {
this.sourceListenerKey_ = ol.events.listen(this.sourceImage_,
ol.events.EventType.CHANGE, function(e) {
var sourceState = this.sourceImage_.getState();
if (sourceState == ol.ImageState.LOADED ||
sourceState == ol.ImageState.ERROR) {
if (sourceState == ol.Image.State.LOADED ||
sourceState == ol.Image.State.ERROR) {
this.unlistenSource_();
this.reproject_();
}

View File

@@ -2,7 +2,7 @@ goog.provide('ol.source.Image');
goog.provide('ol.source.ImageEvent');
goog.require('ol');
goog.require('ol.ImageState');
goog.require('ol.Image');
goog.require('ol.array');
goog.require('ol.events.Event');
goog.require('ol.extent');
@@ -148,17 +148,17 @@ ol.source.Image.prototype.getImageInternal = function(extent, resolution, pixelR
ol.source.Image.prototype.handleImageChange = function(event) {
var image = /** @type {ol.Image} */ (event.target);
switch (image.getState()) {
case ol.ImageState.LOADING:
case ol.Image.State.LOADING:
this.dispatchEvent(
new ol.source.ImageEvent(ol.source.ImageEventType.IMAGELOADSTART,
image));
break;
case ol.ImageState.LOADED:
case ol.Image.State.LOADED:
this.dispatchEvent(
new ol.source.ImageEvent(ol.source.ImageEventType.IMAGELOADEND,
image));
break;
case ol.ImageState.ERROR:
case ol.Image.State.ERROR:
this.dispatchEvent(
new ol.source.ImageEvent(ol.source.ImageEventType.IMAGELOADERROR,
image));

View File

@@ -2,7 +2,6 @@ goog.provide('ol.source.ImageStatic');
goog.require('ol');
goog.require('ol.Image');
goog.require('ol.ImageState');
goog.require('ol.dom');
goog.require('ol.events');
goog.require('ol.events.EventType');
@@ -71,7 +70,7 @@ ol.source.ImageStatic.prototype.getImageInternal = function(extent, resolution,
* @inheritDoc
*/
ol.source.ImageStatic.prototype.handleImageChange = function(evt) {
if (this.image_.getState() == ol.ImageState.LOADED) {
if (this.image_.getState() == ol.Image.State.LOADED) {
var imageExtent = this.image_.getExtent();
var image = this.image_.getImage();
var imageWidth, imageHeight;

View File

@@ -5,9 +5,9 @@ goog.require('ol.color');
goog.require('ol.colorlike');
goog.require('ol.dom');
goog.require('ol.has');
goog.require('ol.Image');
goog.require('ol.render.canvas');
goog.require('ol.style.Image');
goog.require('ol.style.ImageState');
/**
@@ -150,7 +150,7 @@ ol.style.Circle.prototype.getImage = function(pixelRatio) {
* @inheritDoc
*/
ol.style.Circle.prototype.getImageState = function() {
return ol.style.ImageState.LOADED;
return ol.Image.State.LOADED;
};

View File

@@ -7,9 +7,9 @@ goog.require('ol.asserts');
goog.require('ol.color');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol.Image');
goog.require('ol.style.IconImage');
goog.require('ol.style.Image');
goog.require('ol.style.ImageState');
/**
@@ -113,10 +113,10 @@ ol.style.Icon = function(opt_options) {
6); // A defined and non-empty `src` or `image` must be provided
/**
* @type {ol.style.ImageState}
* @type {ol.Image.State}
*/
var imageState = options.src !== undefined ?
ol.style.ImageState.IDLE : ol.style.ImageState.LOADED;
ol.Image.State.IDLE : ol.Image.State.LOADED;
/**
* @type {ol.Color}

View File

@@ -5,8 +5,8 @@ goog.require('ol.dom');
goog.require('ol.events');
goog.require('ol.events.EventTarget');
goog.require('ol.events.EventType');
goog.require('ol.Image');
goog.require('ol.style');
goog.require('ol.style.ImageState');
/**
@@ -15,7 +15,7 @@ goog.require('ol.style.ImageState');
* @param {string|undefined} src Src.
* @param {ol.Size} size Size.
* @param {?string} crossOrigin Cross origin.
* @param {ol.style.ImageState} imageState Image state.
* @param {ol.Image.State} imageState Image state.
* @param {ol.Color} color Color.
* @extends {ol.events.EventTarget}
*/
@@ -62,7 +62,7 @@ ol.style.IconImage = function(image, src, size, crossOrigin, imageState,
/**
* @private
* @type {ol.style.ImageState}
* @type {ol.Image.State}
*/
this.imageState_ = imageState;
@@ -83,7 +83,7 @@ ol.style.IconImage = function(image, src, size, crossOrigin, imageState,
* @type {boolean}
*/
this.tainting_ = false;
if (this.imageState_ == ol.style.ImageState.LOADED) {
if (this.imageState_ == ol.Image.State.LOADED) {
this.determineTainting_();
}
@@ -96,7 +96,7 @@ ol.inherits(ol.style.IconImage, ol.events.EventTarget);
* @param {string} src Src.
* @param {ol.Size} size Size.
* @param {?string} crossOrigin Cross origin.
* @param {ol.style.ImageState} imageState Image state.
* @param {ol.Image.State} imageState Image state.
* @param {ol.Color} color Color.
* @return {ol.style.IconImage} Icon image.
*/
@@ -139,7 +139,7 @@ ol.style.IconImage.prototype.dispatchChangeEvent_ = function() {
* @private
*/
ol.style.IconImage.prototype.handleImageError_ = function() {
this.imageState_ = ol.style.ImageState.ERROR;
this.imageState_ = ol.Image.State.ERROR;
this.unlistenImage_();
this.dispatchChangeEvent_();
};
@@ -149,7 +149,7 @@ ol.style.IconImage.prototype.handleImageError_ = function() {
* @private
*/
ol.style.IconImage.prototype.handleImageLoad_ = function() {
this.imageState_ = ol.style.ImageState.LOADED;
this.imageState_ = ol.Image.State.LOADED;
if (this.size_) {
this.image_.width = this.size_[0];
this.image_.height = this.size_[1];
@@ -172,7 +172,7 @@ ol.style.IconImage.prototype.getImage = function(pixelRatio) {
/**
* @return {ol.style.ImageState} Image state.
* @return {ol.Image.State} Image state.
*/
ol.style.IconImage.prototype.getImageState = function() {
return this.imageState_;
@@ -219,12 +219,12 @@ ol.style.IconImage.prototype.getSrc = function() {
* Load not yet loaded URI.
*/
ol.style.IconImage.prototype.load = function() {
if (this.imageState_ == ol.style.ImageState.IDLE) {
if (this.imageState_ == ol.Image.State.IDLE) {
goog.DEBUG && console.assert(this.src_ !== undefined,
'this.src_ must not be undefined');
goog.DEBUG && console.assert(!this.imageListenerKeys_,
'no listener keys existing');
this.imageState_ = ol.style.ImageState.LOADING;
this.imageState_ = ol.Image.State.LOADING;
this.imageListenerKeys_ = [
ol.events.listenOnce(this.image_, ol.events.EventType.ERROR,
this.handleImageError_, this),

View File

@@ -1,16 +1,4 @@
goog.provide('ol.style.Image');
goog.provide('ol.style.ImageState');
/**
* @enum {number}
*/
ol.style.ImageState = {
IDLE: 0,
LOADING: 1,
LOADED: 2,
ERROR: 3
};
/**
@@ -136,7 +124,7 @@ ol.style.Image.prototype.getHitDetectionImage = function(pixelRatio) {};
/**
* @abstract
* @return {ol.style.ImageState} Image state.
* @return {ol.Image.State} Image state.
*/
ol.style.Image.prototype.getImageState = function() {};

View File

@@ -5,9 +5,9 @@ goog.require('ol.color');
goog.require('ol.colorlike');
goog.require('ol.dom');
goog.require('ol.has');
goog.require('ol.Image');
goog.require('ol.render.canvas');
goog.require('ol.style.Image');
goog.require('ol.style.ImageState');
/**
@@ -205,7 +205,7 @@ ol.style.RegularShape.prototype.getHitDetectionImageSize = function() {
* @inheritDoc
*/
ol.style.RegularShape.prototype.getImageState = function() {
return ol.style.ImageState.LOADED;
return ol.Image.State.LOADED;
};