Add tile error handling

This commit is contained in:
Andreas Hocevar
2015-09-12 20:02:14 +09:00
parent dbedbc19ee
commit 63629e1ee2
2 changed files with 25 additions and 9 deletions
+14 -5
View File
@@ -46,12 +46,15 @@ ol.FeatureUrlFunction;
/** /**
* @param {string|ol.FeatureUrlFunction} url Feature URL service. * @param {string|ol.FeatureUrlFunction} url Feature URL service.
* @param {ol.format.Feature} format Feature format. * @param {ol.format.Feature} format Feature format.
* @param {function(this:ol.source.Vector, Array.<ol.Feature>, ol.proj.Projection)|function(this:ol.source.Vector, Array.<ol.Feature>)} success * @param {function(this:ol.VectorTile, Array.<ol.Feature>, ol.proj.Projection)|function(this:ol.source.Vector, Array.<ol.Feature>)} success
* Function called with the loaded features and optionally with the data * Function called with the loaded features and optionally with the data
* projection. Called with the vector source as `this`. * projection. Called with the vector tile or source as `this`.
* @param {function(this:ol.source.Vector)} failure
* Function called when loading failed. Called with the vector tile or
* source as `this`.
* @return {ol.FeatureLoader} The feature loader. * @return {ol.FeatureLoader} The feature loader.
*/ */
ol.featureloader.loadFeaturesXhr = function(url, format, success) { ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) {
return ( return (
/** /**
* @param {ol.Extent} extent Extent. * @param {ol.Extent} extent Extent.
@@ -107,7 +110,7 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success) {
goog.asserts.fail('undefined or null source'); goog.asserts.fail('undefined or null source');
} }
} else { } else {
// FIXME failure.call(this);
} }
goog.dispose(xhrIo); goog.dispose(xhrIo);
}, false, this); }, false, this);
@@ -140,6 +143,12 @@ ol.featureloader.tile = function(url, format) {
function(features, projection) { function(features, projection) {
this.setProjection(projection); this.setProjection(projection);
this.setFeatures(features); this.setFeatures(features);
},
/**
* @this {ol.VectorTile}
*/
function() {
this.setState(ol.TileState.ERROR);
}); });
}; };
@@ -161,5 +170,5 @@ ol.featureloader.xhr = function(url, format) {
*/ */
function(features) { function(features) {
this.addFeatures(features); this.addFeatures(features);
}); }, goog.nullFunction);
}; };
+11 -4
View File
@@ -134,8 +134,7 @@ ol.VectorTile.prototype.getProjection = function() {
*/ */
ol.VectorTile.prototype.load = function() { ol.VectorTile.prototype.load = function() {
if (this.state == ol.TileState.IDLE) { if (this.state == ol.TileState.IDLE) {
this.state = ol.TileState.LOADING; this.setState(ol.TileState.LOADING);
this.changed();
this.tileLoadFunction_(this, this.url_); this.tileLoadFunction_(this, this.url_);
this.loader_(null, NaN, null); this.loader_(null, NaN, null);
} }
@@ -147,8 +146,7 @@ ol.VectorTile.prototype.load = function() {
*/ */
ol.VectorTile.prototype.setFeatures = function(features) { ol.VectorTile.prototype.setFeatures = function(features) {
this.features_ = features; this.features_ = features;
this.state = ol.TileState.LOADED; this.setState(ol.TileState.LOADED);
this.changed();
}; };
@@ -160,6 +158,15 @@ ol.VectorTile.prototype.setProjection = function(projection) {
}; };
/**
* @param {ol.TileState} tileState Tile state.
*/
ol.VectorTile.prototype.setState = function(tileState) {
this.state = tileState;
this.changed();
};
/** /**
* Set the feeature loader for reading this tile's features. * Set the feeature loader for reading this tile's features.
* @param {ol.FeatureLoader} loader Feature loader. * @param {ol.FeatureLoader} loader Feature loader.