ol.Tile inherits from goog.events.EventTarget

This commit is contained in:
Éric Lemoine
2012-07-09 21:33:08 +02:00
parent f9cb029a74
commit e4ff1a7574
3 changed files with 15 additions and 15 deletions
+8 -11
View File
@@ -1,13 +1,15 @@
goog.provide('ol.Tile'); goog.provide('ol.Tile');
goog.require('ol.Bounds');
goog.require('goog.events.EventTarget');
goog.require('goog.events'); goog.require('goog.events');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('ol.Bounds');
goog.require('ol.event.Events');
/** /**
* The Tile class. * The Tile class.
* @constructor * @constructor
* @extends {goog.events.EventTarget}
* @param {string} url * @param {string} url
* @param {ol.Bounds|undefined} opt_bounds * @param {ol.Bounds|undefined} opt_bounds
*/ */
@@ -46,13 +48,8 @@ ol.Tile = function(url, opt_bounds) {
this.handleImageLoad, false, this); this.handleImageLoad, false, this);
goog.events.listenOnce(this.img_, goog.events.EventType.ERROR, goog.events.listenOnce(this.img_, goog.events.EventType.ERROR,
this.handleImageError, false, this); this.handleImageError, false, this);
/**
* @private
* @type {ol.event.Events}
*/
this.events_ = new ol.event.Events(this);
}; };
goog.inherits(ol.Tile, goog.events.EventTarget);
/** /**
* @protected * @protected
@@ -104,7 +101,7 @@ ol.Tile.prototype.handleImageLoad = function(evt) {
this.loaded_ = true; this.loaded_ = true;
this.img_.style.visibility = "inherit"; this.img_.style.visibility = "inherit";
this.img_.style.opacity = 1; // TODO: allow for layer opacity 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) { ol.Tile.prototype.handleImageError = function(evt) {
this.loading_ = false; 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() { ol.Tile.prototype.destroy = function() {
this.events_.triggerEvent('destroy'); goog.events.dispatchEvent(this, 'destroy');
}; };
/** /**
+5 -2
View File
@@ -8,6 +8,7 @@ goog.require('ol.renderer.MapRenderer');
goog.require('ol.layer.Layer'); goog.require('ol.layer.Layer');
goog.require('ol.Loc'); goog.require('ol.Loc');
goog.require('goog.events');
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.vec.Mat4'); goog.require('goog.vec.Mat4');
@@ -237,8 +238,10 @@ ol.renderer.WebGL.prototype.draw = function(layers, center, resolution, animate)
tile = row[j]; tile = row[j];
if (!tile.isLoaded()) { if (!tile.isLoaded()) {
if (!tile.isLoading()) { if (!tile.isLoading()) {
tile.register('load', this.handleTileLoad, this); goog.events.listen(tile, 'load', this.handleTileLoad,
tile.register('destroy', this.handleTileDestroy, this); undefined, this);
goog.events.listen(tile, 'destroy', this.handleTileDestroy,
undefined, this);
tile.load(); tile.load();
} }
continue; continue;
+2 -2
View File
@@ -34,7 +34,7 @@ describe("ol.Tile", function() {
}); });
it("fires a load event", function() { it("fires a load event", function() {
var spy = jasmine.createSpy(); var spy = jasmine.createSpy();
tile.events_.register('load', spy); goog.events.listen(tile, 'load', spy);
tile.handleImageLoad(); tile.handleImageLoad();
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
@@ -57,7 +57,7 @@ describe("ol.Tile", function() {
}); });
it("fires a load event", function() { it("fires a load event", function() {
var spy = jasmine.createSpy(); var spy = jasmine.createSpy();
tile.events_.register('error', spy); goog.events.listen(tile, 'error', spy);
tile.handleImageError(); tile.handleImageError();
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });