Merge pull request #3989 from fredj/3938
Handle JSONP errors in ol.source.TileJSON
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// FIXME add some error checking
|
||||
// FIXME check order of async callbacks
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,8 @@ ol.source.TileJSON = function(options) {
|
||||
});
|
||||
|
||||
var request = new goog.net.Jsonp(options.url);
|
||||
request.send(undefined, goog.bind(this.handleTileJSONResponse, this));
|
||||
request.send(undefined, goog.bind(this.handleTileJSONResponse, this),
|
||||
goog.bind(this.handleTileJSONError, this));
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.TileJSON, ol.source.TileImage);
|
||||
@@ -100,3 +100,11 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
|
||||
this.setState(ol.source.State.READY);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.source.TileJSON.prototype.handleTileJSONError = function() {
|
||||
this.setState(ol.source.State.ERROR);
|
||||
};
|
||||
|
||||
@@ -3,6 +3,19 @@ goog.provide('ol.test.source.TileJSON');
|
||||
|
||||
describe('ol.source.TileJSON', function() {
|
||||
|
||||
describe('#getState', function() {
|
||||
it('returns ol.source.State.ERROR on HTTP 404', function() {
|
||||
var changeSpy = sinon.spy(function(event) {
|
||||
expect(event.target.getState()).to.eql('error');
|
||||
});
|
||||
var source = new ol.source.TileJSON({
|
||||
url: 'invalid.jsonp'
|
||||
});
|
||||
goog.events.listen(source, 'change', changeSpy);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tileUrlFunction', function() {
|
||||
|
||||
var source, tileGrid;
|
||||
@@ -74,5 +87,7 @@ describe('ol.source.TileJSON', function() {
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.net.Jsonp');
|
||||
goog.require('ol.source.State');
|
||||
goog.require('ol.source.TileJSON');
|
||||
|
||||
Reference in New Issue
Block a user