[ol.Tile] trigger load and error events
This commit is contained in:
@@ -2,6 +2,7 @@ goog.provide('ol.Tile');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.Bounds');
|
||||
goog.require('ol.event.Events');
|
||||
|
||||
/**
|
||||
* The Tile class.
|
||||
@@ -32,6 +33,12 @@ ol.Tile = function(url, 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);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -70,6 +77,7 @@ ol.Tile.prototype.getImg = function() {
|
||||
* @param {goog.events.BrowserEvent} evt Event.
|
||||
*/
|
||||
ol.Tile.prototype.handleImageLoad = function(evt) {
|
||||
this.events_.triggerEvent('load');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -77,6 +85,7 @@ ol.Tile.prototype.handleImageLoad = function(evt) {
|
||||
* @param {goog.events.BrowserEvent} evt Event.
|
||||
*/
|
||||
ol.Tile.prototype.handleImageError = function(evt) {
|
||||
this.events_.triggerEvent('error');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,41 @@
|
||||
describe("ol.Tile", function() {
|
||||
|
||||
describe("creating a tile", function() {
|
||||
describe("create a tile", function() {
|
||||
var tile;
|
||||
beforeEach(function() {
|
||||
tile = new ol.Tile('http://a.url');
|
||||
});
|
||||
it("creates a tile instance", function() {
|
||||
var tile = new ol.Tile();
|
||||
expect(tile).toBeA(ol.Tile);
|
||||
});
|
||||
it("sets an image node in the instance", function() {
|
||||
var tile = new ol.Tile();
|
||||
expect(tile.getImg()).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("handle image load", function() {
|
||||
var tile;
|
||||
beforeEach(function() {
|
||||
tile = new ol.Tile('http://a.url');
|
||||
});
|
||||
it("fires a load event", function() {
|
||||
var spy = jasmine.createSpy();
|
||||
tile.events_.register('load', spy);
|
||||
tile.handleImageLoad();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("handle image error", function() {
|
||||
var tile;
|
||||
beforeEach(function() {
|
||||
tile = new ol.Tile('http://a.url');
|
||||
});
|
||||
it("fires a load event", function() {
|
||||
var spy = jasmine.createSpy();
|
||||
tile.events_.register('error', spy);
|
||||
tile.handleImageError();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user