Rename _ol_ImageState_ to ImageState

This commit is contained in:
Frederic Junod
2017-12-18 10:48:47 +01:00
parent 3e262b4c6b
commit 0a895a2867
10 changed files with 49 additions and 55 deletions
+7 -7
View File
@@ -3,7 +3,7 @@
*/ */
import {inherits} from './index.js'; import {inherits} from './index.js';
import _ol_ImageBase_ from './ImageBase.js'; import _ol_ImageBase_ from './ImageBase.js';
import _ol_ImageState_ from './ImageState.js'; import ImageState from './ImageState.js';
import _ol_events_ from './events.js'; import _ol_events_ from './events.js';
import EventType from './events/EventType.js'; import EventType from './events/EventType.js';
import {getHeight} from './extent.js'; import {getHeight} from './extent.js';
@@ -20,7 +20,7 @@ import {getHeight} from './extent.js';
*/ */
var _ol_Image_ = function(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction) { var _ol_Image_ = function(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction) {
_ol_ImageBase_.call(this, extent, resolution, pixelRatio, _ol_ImageState_.IDLE); _ol_ImageBase_.call(this, extent, resolution, pixelRatio, ImageState.IDLE);
/** /**
* @private * @private
@@ -47,7 +47,7 @@ var _ol_Image_ = function(extent, resolution, pixelRatio, src, crossOrigin, imag
* @protected * @protected
* @type {ol.ImageState} * @type {ol.ImageState}
*/ */
this.state = _ol_ImageState_.IDLE; this.state = ImageState.IDLE;
/** /**
* @private * @private
@@ -75,7 +75,7 @@ _ol_Image_.prototype.getImage = function() {
* @private * @private
*/ */
_ol_Image_.prototype.handleImageError_ = function() { _ol_Image_.prototype.handleImageError_ = function() {
this.state = _ol_ImageState_.ERROR; this.state = ImageState.ERROR;
this.unlistenImage_(); this.unlistenImage_();
this.changed(); this.changed();
}; };
@@ -90,7 +90,7 @@ _ol_Image_.prototype.handleImageLoad_ = function() {
if (this.resolution === undefined) { if (this.resolution === undefined) {
this.resolution = getHeight(this.extent) / this.image_.height; this.resolution = getHeight(this.extent) / this.image_.height;
} }
this.state = _ol_ImageState_.LOADED; this.state = ImageState.LOADED;
this.unlistenImage_(); this.unlistenImage_();
this.changed(); this.changed();
}; };
@@ -104,8 +104,8 @@ _ol_Image_.prototype.handleImageLoad_ = function() {
* @api * @api
*/ */
_ol_Image_.prototype.load = function() { _ol_Image_.prototype.load = function() {
if (this.state == _ol_ImageState_.IDLE || this.state == _ol_ImageState_.ERROR) { if (this.state == ImageState.IDLE || this.state == ImageState.ERROR) {
this.state = _ol_ImageState_.LOADING; this.state = ImageState.LOADING;
this.changed(); this.changed();
this.imageListenerKeys_ = [ this.imageListenerKeys_ = [
_ol_events_.listenOnce(this.image_, EventType.ERROR, _ol_events_.listenOnce(this.image_, EventType.ERROR,
+6 -7
View File
@@ -3,7 +3,7 @@
*/ */
import {inherits} from './index.js'; import {inherits} from './index.js';
import _ol_ImageBase_ from './ImageBase.js'; import _ol_ImageBase_ from './ImageBase.js';
import _ol_ImageState_ from './ImageState.js'; import ImageState from './ImageState.js';
/** /**
* @constructor * @constructor
@@ -24,8 +24,7 @@ var _ol_ImageCanvas_ = function(extent, resolution, pixelRatio, canvas, opt_load
*/ */
this.loader_ = opt_loader !== undefined ? opt_loader : null; this.loader_ = opt_loader !== undefined ? opt_loader : null;
var state = opt_loader !== undefined ? var state = opt_loader !== undefined ? ImageState.IDLE : ImageState.LOADED;
_ol_ImageState_.IDLE : _ol_ImageState_.LOADED;
_ol_ImageBase_.call(this, extent, resolution, pixelRatio, state); _ol_ImageBase_.call(this, extent, resolution, pixelRatio, state);
@@ -63,9 +62,9 @@ _ol_ImageCanvas_.prototype.getError = function() {
_ol_ImageCanvas_.prototype.handleLoad_ = function(err) { _ol_ImageCanvas_.prototype.handleLoad_ = function(err) {
if (err) { if (err) {
this.error_ = err; this.error_ = err;
this.state = _ol_ImageState_.ERROR; this.state = ImageState.ERROR;
} else { } else {
this.state = _ol_ImageState_.LOADED; this.state = ImageState.LOADED;
} }
this.changed(); this.changed();
}; };
@@ -75,8 +74,8 @@ _ol_ImageCanvas_.prototype.handleLoad_ = function(err) {
* @inheritDoc * @inheritDoc
*/ */
_ol_ImageCanvas_.prototype.load = function() { _ol_ImageCanvas_.prototype.load = function() {
if (this.state == _ol_ImageState_.IDLE) { if (this.state == ImageState.IDLE) {
this.state = _ol_ImageState_.LOADING; this.state = ImageState.LOADING;
this.changed(); this.changed();
this.loader_(this.handleLoad_.bind(this)); this.loader_(this.handleLoad_.bind(this));
} }
+6 -8
View File
@@ -2,7 +2,7 @@
* @module ol/renderer/Layer * @module ol/renderer/Layer
*/ */
import {getUid, inherits, nullFunction} from '../index.js'; import {getUid, inherits, nullFunction} from '../index.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import _ol_Observable_ from '../Observable.js'; import _ol_Observable_ from '../Observable.js';
import _ol_TileState_ from '../TileState.js'; import _ol_TileState_ from '../TileState.js';
import _ol_events_ from '../events.js'; import _ol_events_ from '../events.js';
@@ -98,7 +98,7 @@ _ol_renderer_Layer_.prototype.getLayer = function() {
*/ */
_ol_renderer_Layer_.prototype.handleImageChange_ = function(event) { _ol_renderer_Layer_.prototype.handleImageChange_ = function(event) {
var image = /** @type {ol.Image} */ (event.target); var image = /** @type {ol.Image} */ (event.target);
if (image.getState() === _ol_ImageState_.LOADED) { if (image.getState() === ImageState.LOADED) {
this.renderIfReadyAndVisible(); this.renderIfReadyAndVisible();
} }
}; };
@@ -114,16 +114,14 @@ _ol_renderer_Layer_.prototype.handleImageChange_ = function(event) {
*/ */
_ol_renderer_Layer_.prototype.loadImage = function(image) { _ol_renderer_Layer_.prototype.loadImage = function(image) {
var imageState = image.getState(); var imageState = image.getState();
if (imageState != _ol_ImageState_.LOADED && if (imageState != ImageState.LOADED && imageState != ImageState.ERROR) {
imageState != _ol_ImageState_.ERROR) { _ol_events_.listen(image, EventType.CHANGE, this.handleImageChange_, this);
_ol_events_.listen(image, EventType.CHANGE,
this.handleImageChange_, this);
} }
if (imageState == _ol_ImageState_.IDLE) { if (imageState == ImageState.IDLE) {
image.load(); image.load();
imageState = image.getState(); imageState = image.getState();
} }
return imageState == _ol_ImageState_.LOADED; return imageState == ImageState.LOADED;
}; };
+5 -6
View File
@@ -2,7 +2,7 @@
* @module ol/renderer/vector * @module ol/renderer/vector
*/ */
import {getUid} from '../index.js'; import {getUid} from '../index.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import _ol_render_ReplayType_ from '../render/ReplayType.js'; import _ol_render_ReplayType_ from '../render/ReplayType.js';
var _ol_renderer_vector_ = {}; var _ol_renderer_vector_ = {};
@@ -88,11 +88,10 @@ _ol_renderer_vector_.renderFeature = function(
imageStyle = style.getImage(); imageStyle = style.getImage();
if (imageStyle) { if (imageStyle) {
imageState = imageStyle.getImageState(); imageState = imageStyle.getImageState();
if (imageState == _ol_ImageState_.LOADED || if (imageState == ImageState.LOADED || imageState == ImageState.ERROR) {
imageState == _ol_ImageState_.ERROR) {
imageStyle.unlistenImageChange(listener, thisArg); imageStyle.unlistenImageChange(listener, thisArg);
} else { } else {
if (imageState == _ol_ImageState_.IDLE) { if (imageState == ImageState.IDLE) {
imageStyle.load(); imageStyle.load();
} }
imageState = imageStyle.getImageState(); imageState = imageStyle.getImageState();
@@ -256,7 +255,7 @@ _ol_renderer_vector_.renderMultiPolygonGeometry_ = function(replayGroup, geometr
_ol_renderer_vector_.renderPointGeometry_ = function(replayGroup, geometry, style, feature) { _ol_renderer_vector_.renderPointGeometry_ = function(replayGroup, geometry, style, feature) {
var imageStyle = style.getImage(); var imageStyle = style.getImage();
if (imageStyle) { if (imageStyle) {
if (imageStyle.getImageState() != _ol_ImageState_.LOADED) { if (imageStyle.getImageState() != ImageState.LOADED) {
return; return;
} }
var imageReplay = replayGroup.getReplay( var imageReplay = replayGroup.getReplay(
@@ -284,7 +283,7 @@ _ol_renderer_vector_.renderPointGeometry_ = function(replayGroup, geometry, styl
_ol_renderer_vector_.renderMultiPointGeometry_ = function(replayGroup, geometry, style, feature) { _ol_renderer_vector_.renderMultiPointGeometry_ = function(replayGroup, geometry, style, feature) {
var imageStyle = style.getImage(); var imageStyle = style.getImage();
if (imageStyle) { if (imageStyle) {
if (imageStyle.getImageState() != _ol_ImageState_.LOADED) { if (imageStyle.getImageState() != ImageState.LOADED) {
return; return;
} }
var imageReplay = replayGroup.getReplay( var imageReplay = replayGroup.getReplay(
+9 -11
View File
@@ -4,7 +4,7 @@
import {ERROR_THRESHOLD} from './common.js'; import {ERROR_THRESHOLD} from './common.js';
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import _ol_ImageBase_ from '../ImageBase.js'; import _ol_ImageBase_ from '../ImageBase.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import _ol_events_ from '../events.js'; import _ol_events_ from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {getCenter, getIntersection, getHeight, getWidth} from '../extent.js'; import {getCenter, getIntersection, getHeight, getWidth} from '../extent.js';
@@ -100,10 +100,10 @@ var _ol_reproj_Image_ = function(sourceProj, targetProj,
this.sourceListenerKey_ = null; this.sourceListenerKey_ = null;
var state = _ol_ImageState_.LOADED; var state = ImageState.LOADED;
if (this.sourceImage_) { if (this.sourceImage_) {
state = _ol_ImageState_.IDLE; state = ImageState.IDLE;
} }
_ol_ImageBase_.call(this, targetExtent, targetResolution, this.sourcePixelRatio_, state); _ol_ImageBase_.call(this, targetExtent, targetResolution, this.sourcePixelRatio_, state);
@@ -116,7 +116,7 @@ inherits(_ol_reproj_Image_, _ol_ImageBase_);
* @inheritDoc * @inheritDoc
*/ */
_ol_reproj_Image_.prototype.disposeInternal = function() { _ol_reproj_Image_.prototype.disposeInternal = function() {
if (this.state == _ol_ImageState_.LOADING) { if (this.state == ImageState.LOADING) {
this.unlistenSource_(); this.unlistenSource_();
} }
_ol_ImageBase_.prototype.disposeInternal.call(this); _ol_ImageBase_.prototype.disposeInternal.call(this);
@@ -144,7 +144,7 @@ _ol_reproj_Image_.prototype.getProjection = function() {
*/ */
_ol_reproj_Image_.prototype.reproject_ = function() { _ol_reproj_Image_.prototype.reproject_ = function() {
var sourceState = this.sourceImage_.getState(); var sourceState = this.sourceImage_.getState();
if (sourceState == _ol_ImageState_.LOADED) { if (sourceState == ImageState.LOADED) {
var width = getWidth(this.targetExtent_) / this.targetResolution_; var width = getWidth(this.targetExtent_) / this.targetResolution_;
var height = getHeight(this.targetExtent_) / this.targetResolution_; var height = getHeight(this.targetExtent_) / this.targetResolution_;
@@ -164,20 +164,18 @@ _ol_reproj_Image_.prototype.reproject_ = function() {
* @inheritDoc * @inheritDoc
*/ */
_ol_reproj_Image_.prototype.load = function() { _ol_reproj_Image_.prototype.load = function() {
if (this.state == _ol_ImageState_.IDLE) { if (this.state == ImageState.IDLE) {
this.state = _ol_ImageState_.LOADING; this.state = ImageState.LOADING;
this.changed(); this.changed();
var sourceState = this.sourceImage_.getState(); var sourceState = this.sourceImage_.getState();
if (sourceState == _ol_ImageState_.LOADED || if (sourceState == ImageState.LOADED || sourceState == ImageState.ERROR) {
sourceState == _ol_ImageState_.ERROR) {
this.reproject_(); this.reproject_();
} else { } else {
this.sourceListenerKey_ = _ol_events_.listen(this.sourceImage_, this.sourceListenerKey_ = _ol_events_.listen(this.sourceImage_,
EventType.CHANGE, function(e) { EventType.CHANGE, function(e) {
var sourceState = this.sourceImage_.getState(); var sourceState = this.sourceImage_.getState();
if (sourceState == _ol_ImageState_.LOADED || if (sourceState == ImageState.LOADED || sourceState == ImageState.ERROR) {
sourceState == _ol_ImageState_.ERROR) {
this.unlistenSource_(); this.unlistenSource_();
this.reproject_(); this.reproject_();
} }
+4 -4
View File
@@ -3,7 +3,7 @@
*/ */
import {ENABLE_RASTER_REPROJECTION} from '../reproj/common.js'; import {ENABLE_RASTER_REPROJECTION} from '../reproj/common.js';
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import _ol_array_ from '../array.js'; import _ol_array_ from '../array.js';
import Event from '../events/Event.js'; import Event from '../events/Event.js';
import {equals} from '../extent.js'; import {equals} from '../extent.js';
@@ -142,17 +142,17 @@ _ol_source_Image_.prototype.getImageInternal = function(extent, resolution, pixe
_ol_source_Image_.prototype.handleImageChange = function(event) { _ol_source_Image_.prototype.handleImageChange = function(event) {
var image = /** @type {ol.Image} */ (event.target); var image = /** @type {ol.Image} */ (event.target);
switch (image.getState()) { switch (image.getState()) {
case _ol_ImageState_.LOADING: case ImageState.LOADING:
this.dispatchEvent( this.dispatchEvent(
new _ol_source_Image_.Event(_ol_source_Image_.EventType_.IMAGELOADSTART, new _ol_source_Image_.Event(_ol_source_Image_.EventType_.IMAGELOADSTART,
image)); image));
break; break;
case _ol_ImageState_.LOADED: case ImageState.LOADED:
this.dispatchEvent( this.dispatchEvent(
new _ol_source_Image_.Event(_ol_source_Image_.EventType_.IMAGELOADEND, new _ol_source_Image_.Event(_ol_source_Image_.EventType_.IMAGELOADEND,
image)); image));
break; break;
case _ol_ImageState_.ERROR: case ImageState.ERROR:
this.dispatchEvent( this.dispatchEvent(
new _ol_source_Image_.Event(_ol_source_Image_.EventType_.IMAGELOADERROR, new _ol_source_Image_.Event(_ol_source_Image_.EventType_.IMAGELOADERROR,
image)); image));
+2 -2
View File
@@ -3,7 +3,7 @@
*/ */
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import _ol_Image_ from '../Image.js'; import _ol_Image_ from '../Image.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import {createCanvasContext2D} from '../dom.js'; import {createCanvasContext2D} from '../dom.js';
import _ol_events_ from '../events.js'; import _ol_events_ from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
@@ -70,7 +70,7 @@ _ol_source_ImageStatic_.prototype.getImageInternal = function(extent, resolution
* @inheritDoc * @inheritDoc
*/ */
_ol_source_ImageStatic_.prototype.handleImageChange = function(evt) { _ol_source_ImageStatic_.prototype.handleImageChange = function(evt) {
if (this.image_.getState() == _ol_ImageState_.LOADED) { if (this.image_.getState() == ImageState.LOADED) {
var imageExtent = this.image_.getExtent(); var imageExtent = this.image_.getExtent();
var image = this.image_.getImage(); var image = this.image_.getImage();
var imageWidth, imageHeight; var imageWidth, imageHeight;
+2 -2
View File
@@ -2,7 +2,7 @@
* @module ol/style/Icon * @module ol/style/Icon
*/ */
import {getUid, inherits} from '../index.js'; import {getUid, inherits} from '../index.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import _ol_color_ from '../color.js'; import _ol_color_ from '../color.js';
import _ol_events_ from '../events.js'; import _ol_events_ from '../events.js';
@@ -95,7 +95,7 @@ var _ol_style_Icon_ = function(opt_options) {
* @type {ol.ImageState} * @type {ol.ImageState}
*/ */
var imageState = options.src !== undefined ? var imageState = options.src !== undefined ?
_ol_ImageState_.IDLE : _ol_ImageState_.LOADED; ImageState.IDLE : ImageState.LOADED;
/** /**
* @private * @private
+6 -6
View File
@@ -6,7 +6,7 @@ import {createCanvasContext2D} from '../dom.js';
import _ol_events_ from '../events.js'; import _ol_events_ from '../events.js';
import EventTarget from '../events/EventTarget.js'; import EventTarget from '../events/EventTarget.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import _ol_style_ from '../style.js'; import _ol_style_ from '../style.js';
/** /**
@@ -83,7 +83,7 @@ var _ol_style_IconImage_ = function(image, src, size, crossOrigin, imageState,
* @type {boolean} * @type {boolean}
*/ */
this.tainting_ = false; this.tainting_ = false;
if (this.imageState_ == _ol_ImageState_.LOADED) { if (this.imageState_ == ImageState.LOADED) {
this.determineTainting_(); this.determineTainting_();
} }
@@ -140,7 +140,7 @@ _ol_style_IconImage_.prototype.dispatchChangeEvent_ = function() {
* @private * @private
*/ */
_ol_style_IconImage_.prototype.handleImageError_ = function() { _ol_style_IconImage_.prototype.handleImageError_ = function() {
this.imageState_ = _ol_ImageState_.ERROR; this.imageState_ = ImageState.ERROR;
this.unlistenImage_(); this.unlistenImage_();
this.dispatchChangeEvent_(); this.dispatchChangeEvent_();
}; };
@@ -150,7 +150,7 @@ _ol_style_IconImage_.prototype.handleImageError_ = function() {
* @private * @private
*/ */
_ol_style_IconImage_.prototype.handleImageLoad_ = function() { _ol_style_IconImage_.prototype.handleImageLoad_ = function() {
this.imageState_ = _ol_ImageState_.LOADED; this.imageState_ = ImageState.LOADED;
if (this.size_) { if (this.size_) {
this.image_.width = this.size_[0]; this.image_.width = this.size_[0];
this.image_.height = this.size_[1]; this.image_.height = this.size_[1];
@@ -220,8 +220,8 @@ _ol_style_IconImage_.prototype.getSrc = function() {
* Load not yet loaded URI. * Load not yet loaded URI.
*/ */
_ol_style_IconImage_.prototype.load = function() { _ol_style_IconImage_.prototype.load = function() {
if (this.imageState_ == _ol_ImageState_.IDLE) { if (this.imageState_ == ImageState.IDLE) {
this.imageState_ = _ol_ImageState_.LOADING; this.imageState_ = ImageState.LOADING;
this.imageListenerKeys_ = [ this.imageListenerKeys_ = [
_ol_events_.listenOnce(this.image_, EventType.ERROR, _ol_events_.listenOnce(this.image_, EventType.ERROR,
this.handleImageError_, this), this.handleImageError_, this),
+2 -2
View File
@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import {asColorLike} from '../colorlike.js'; import {asColorLike} from '../colorlike.js';
import {createCanvasContext2D} from '../dom.js'; import {createCanvasContext2D} from '../dom.js';
import _ol_has_ from '../has.js'; import _ol_has_ from '../has.js';
import _ol_ImageState_ from '../ImageState.js'; import ImageState from '../ImageState.js';
import _ol_render_canvas_ from '../render/canvas.js'; import _ol_render_canvas_ from '../render/canvas.js';
import _ol_style_Image_ from '../style/Image.js'; import _ol_style_Image_ from '../style/Image.js';
@@ -228,7 +228,7 @@ _ol_style_RegularShape_.prototype.getHitDetectionImageSize = function() {
* @inheritDoc * @inheritDoc
*/ */
_ol_style_RegularShape_.prototype.getImageState = function() { _ol_style_RegularShape_.prototype.getImageState = function() {
return _ol_ImageState_.LOADED; return ImageState.LOADED;
}; };