Make loadFeaturesFromUrl accept an error callback
This commit is contained in:
@@ -48,12 +48,14 @@ goog.inherits(ol.source.FormatVector, ol.source.Vector);
|
||||
|
||||
/**
|
||||
* @param {goog.Uri|string} url URL.
|
||||
* @param {function(this: T, Array.<ol.Feature>)} callback Callback.
|
||||
* @param {T} thisArg Value to use as `this` when executing `callback`.
|
||||
* @param {function(this: T, Array.<ol.Feature>)} success Success Callback.
|
||||
* @param {function(this: T)} error Error callback.
|
||||
* @param {T} thisArg Value to use as `this` when executing `success` or
|
||||
* `error`.
|
||||
* @template T
|
||||
*/
|
||||
ol.source.FormatVector.prototype.loadFeaturesFromURL =
|
||||
function(url, callback, thisArg) {
|
||||
function(url, success, error, thisArg) {
|
||||
var xhrIo = new goog.net.XhrIo();
|
||||
var type = this.format.getType();
|
||||
var responseType;
|
||||
@@ -97,13 +99,13 @@ ol.source.FormatVector.prototype.loadFeaturesFromURL =
|
||||
goog.asserts.fail();
|
||||
}
|
||||
if (goog.isDefAndNotNull(source)) {
|
||||
callback.call(thisArg, this.readFeatures(source));
|
||||
success.call(thisArg, this.readFeatures(source));
|
||||
} else {
|
||||
this.setState(ol.source.State.ERROR);
|
||||
goog.asserts.fail();
|
||||
}
|
||||
} else {
|
||||
this.setState(ol.source.State.ERROR);
|
||||
error.call(thisArg);
|
||||
}
|
||||
goog.dispose(xhrIo);
|
||||
}, false, this);
|
||||
|
||||
@@ -48,13 +48,15 @@ ol.source.StaticVector = function(options) {
|
||||
if (goog.isDef(options.url) || goog.isDef(options.urls)) {
|
||||
this.setState(ol.source.State.LOADING);
|
||||
if (goog.isDef(options.url)) {
|
||||
this.loadFeaturesFromURL(options.url, this.onFeaturesLoaded_, this);
|
||||
this.loadFeaturesFromURL(options.url,
|
||||
this.onFeaturesLoadedSuccess_, this.onFeaturesLoadedError_, this);
|
||||
}
|
||||
if (goog.isDef(options.urls)) {
|
||||
var urls = options.urls;
|
||||
var i, ii;
|
||||
for (i = 0, ii = urls.length; i < ii; ++i) {
|
||||
this.loadFeaturesFromURL(urls[i], this.onFeaturesLoaded_, this);
|
||||
this.loadFeaturesFromURL(urls[i],
|
||||
this.onFeaturesLoadedSuccess_, this.onFeaturesLoadedError_, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,11 +65,19 @@ ol.source.StaticVector = function(options) {
|
||||
goog.inherits(ol.source.StaticVector, ol.source.FormatVector);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.source.StaticVector.prototype.onFeaturesLoadedError_ = function() {
|
||||
this.setState(ol.source.State.ERROR);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @private
|
||||
*/
|
||||
ol.source.StaticVector.prototype.onFeaturesLoaded_ = function(features) {
|
||||
ol.source.StaticVector.prototype.onFeaturesLoadedSuccess_ = function(features) {
|
||||
this.addFeaturesInternal(features);
|
||||
this.setState(ol.source.State.READY);
|
||||
};
|
||||
|
||||
@@ -184,6 +184,15 @@ ol.source.TileVector.prototype.loadFeatures =
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
|
||||
var tileCoord = [z, 0, 0];
|
||||
var x, y;
|
||||
/**
|
||||
* @param {string} tileKey Tile key.
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @this {ol.source.TileVector}
|
||||
*/
|
||||
function success(tileKey, features) {
|
||||
tiles[tileKey] = features;
|
||||
this.setState(ol.source.State.READY);
|
||||
}
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
var tileKey = this.getTileKeyZXY_(z, x, y);
|
||||
@@ -195,16 +204,8 @@ ol.source.TileVector.prototype.loadFeatures =
|
||||
var url = tileUrlFunction(tileCoord, 1, projection);
|
||||
if (goog.isDef(url)) {
|
||||
tiles[tileKey] = [];
|
||||
this.loadFeaturesFromURL(url, goog.partial(
|
||||
/**
|
||||
* @param {string} tileKey Tile key.
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @this {ol.source.TileVector}
|
||||
*/
|
||||
function(tileKey, features) {
|
||||
tiles[tileKey] = features;
|
||||
this.setState(ol.source.State.READY);
|
||||
}, tileKey), this);
|
||||
this.loadFeaturesFromURL(url, goog.partial(success, tileKey),
|
||||
goog.nullFunction, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user