From 63629e1ee2bc906c87ad7f9e24b2e201d609e707 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sat, 12 Sep 2015 20:02:14 +0900 Subject: [PATCH] Add tile error handling --- src/ol/featureloader.js | 19 ++++++++++++++----- src/ol/vectortile.js | 15 +++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/ol/featureloader.js b/src/ol/featureloader.js index d53f5ddf2b..cf7a450959 100644 --- a/src/ol/featureloader.js +++ b/src/ol/featureloader.js @@ -46,12 +46,15 @@ ol.FeatureUrlFunction; /** * @param {string|ol.FeatureUrlFunction} url Feature URL service. * @param {ol.format.Feature} format Feature format. - * @param {function(this:ol.source.Vector, Array., ol.proj.Projection)|function(this:ol.source.Vector, Array.)} success + * @param {function(this:ol.VectorTile, Array., ol.proj.Projection)|function(this:ol.source.Vector, Array.)} success * 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. */ -ol.featureloader.loadFeaturesXhr = function(url, format, success) { +ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) { return ( /** * @param {ol.Extent} extent Extent. @@ -107,7 +110,7 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success) { goog.asserts.fail('undefined or null source'); } } else { - // FIXME + failure.call(this); } goog.dispose(xhrIo); }, false, this); @@ -140,6 +143,12 @@ ol.featureloader.tile = function(url, format) { function(features, projection) { this.setProjection(projection); this.setFeatures(features); + }, + /** + * @this {ol.VectorTile} + */ + function() { + this.setState(ol.TileState.ERROR); }); }; @@ -161,5 +170,5 @@ ol.featureloader.xhr = function(url, format) { */ function(features) { this.addFeatures(features); - }); + }, goog.nullFunction); }; diff --git a/src/ol/vectortile.js b/src/ol/vectortile.js index b89b68b527..63810788e9 100644 --- a/src/ol/vectortile.js +++ b/src/ol/vectortile.js @@ -134,8 +134,7 @@ ol.VectorTile.prototype.getProjection = function() { */ ol.VectorTile.prototype.load = function() { if (this.state == ol.TileState.IDLE) { - this.state = ol.TileState.LOADING; - this.changed(); + this.setState(ol.TileState.LOADING); this.tileLoadFunction_(this, this.url_); this.loader_(null, NaN, null); } @@ -147,8 +146,7 @@ ol.VectorTile.prototype.load = function() { */ ol.VectorTile.prototype.setFeatures = function(features) { this.features_ = features; - this.state = ol.TileState.LOADED; - this.changed(); + this.setState(ol.TileState.LOADED); }; @@ -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. * @param {ol.FeatureLoader} loader Feature loader.