ol.Tile inherits from goog.events.EventTarget
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
goog.provide('ol.Tile');
|
||||
|
||||
goog.require('ol.Bounds');
|
||||
|
||||
goog.require('goog.events.EventTarget');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Bounds');
|
||||
goog.require('ol.event.Events');
|
||||
|
||||
/**
|
||||
* The Tile class.
|
||||
* @constructor
|
||||
* @extends {goog.events.EventTarget}
|
||||
* @param {string} url
|
||||
* @param {ol.Bounds|undefined} opt_bounds
|
||||
*/
|
||||
@@ -46,13 +48,8 @@ ol.Tile = function(url, opt_bounds) {
|
||||
this.handleImageLoad, false, this);
|
||||
goog.events.listenOnce(this.img_, goog.events.EventType.ERROR,
|
||||
this.handleImageError, false, this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.event.Events}
|
||||
*/
|
||||
this.events_ = new ol.event.Events(this);
|
||||
};
|
||||
goog.inherits(ol.Tile, goog.events.EventTarget);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
@@ -104,7 +101,7 @@ ol.Tile.prototype.handleImageLoad = function(evt) {
|
||||
this.loaded_ = true;
|
||||
this.img_.style.visibility = "inherit";
|
||||
this.img_.style.opacity = 1; // TODO: allow for layer opacity
|
||||
this.events_.triggerEvent('load');
|
||||
goog.events.dispatchEvent(this, 'load');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -113,7 +110,7 @@ ol.Tile.prototype.handleImageLoad = function(evt) {
|
||||
*/
|
||||
ol.Tile.prototype.handleImageError = function(evt) {
|
||||
this.loading_ = false;
|
||||
this.events_.triggerEvent('error');
|
||||
goog.events.dispatchEvent(this, 'error');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -136,7 +133,7 @@ ol.Tile.prototype.isLoading = function() {
|
||||
*
|
||||
*/
|
||||
ol.Tile.prototype.destroy = function() {
|
||||
this.events_.triggerEvent('destroy');
|
||||
goog.events.dispatchEvent(this, 'destroy');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ goog.require('ol.renderer.MapRenderer');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.Loc');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.vec.Mat4');
|
||||
@@ -237,8 +238,10 @@ ol.renderer.WebGL.prototype.draw = function(layers, center, resolution, animate)
|
||||
tile = row[j];
|
||||
if (!tile.isLoaded()) {
|
||||
if (!tile.isLoading()) {
|
||||
tile.register('load', this.handleTileLoad, this);
|
||||
tile.register('destroy', this.handleTileDestroy, this);
|
||||
goog.events.listen(tile, 'load', this.handleTileLoad,
|
||||
undefined, this);
|
||||
goog.events.listen(tile, 'destroy', this.handleTileDestroy,
|
||||
undefined, this);
|
||||
tile.load();
|
||||
}
|
||||
continue;
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("ol.Tile", function() {
|
||||
});
|
||||
it("fires a load event", function() {
|
||||
var spy = jasmine.createSpy();
|
||||
tile.events_.register('load', spy);
|
||||
goog.events.listen(tile, 'load', spy);
|
||||
tile.handleImageLoad();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
@@ -57,7 +57,7 @@ describe("ol.Tile", function() {
|
||||
});
|
||||
it("fires a load event", function() {
|
||||
var spy = jasmine.createSpy();
|
||||
tile.events_.register('error', spy);
|
||||
goog.events.listen(tile, 'error', spy);
|
||||
tile.handleImageError();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user