Enable use of custom XHR loader for TileVector sources
This commit is contained in:
@@ -4022,10 +4022,11 @@ olx.source.TileImageOptions.prototype.wrapX;
|
||||
|
||||
/**
|
||||
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
|
||||
* format: ol.format.Feature,
|
||||
* format: (ol.format.Feature|undefined),
|
||||
* logo: (string|olx.LogoOptions|undefined),
|
||||
* tileGrid: ol.tilegrid.TileGrid,
|
||||
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
|
||||
* tileLoadFunction: (ol.TileVectorLoadFunctionType|undefined),
|
||||
* url: (string|undefined),
|
||||
* urls: (Array.<string>|undefined),
|
||||
* wrapX: (boolean|undefined)}}
|
||||
@@ -4043,8 +4044,8 @@ olx.source.TileVectorOptions.prototype.attributions;
|
||||
|
||||
|
||||
/**
|
||||
* Format.
|
||||
* @type {ol.format.Feature}
|
||||
* Format. Required unless tileLoadFunction is used.
|
||||
* @type {ol.format.Feature|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.format;
|
||||
@@ -4075,6 +4076,16 @@ olx.source.TileVectorOptions.prototype.tileGrid;
|
||||
olx.source.TileVectorOptions.prototype.tileUrlFunction;
|
||||
|
||||
|
||||
/**
|
||||
* Optional function to override the default loading and format parsing behaviour.
|
||||
* If this option is used format is ignored and the provided function will be
|
||||
* responsible for data retrieval and transformation into features.
|
||||
* @type {ol.TileVectorLoadFunctionType|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.tileLoadFunction;
|
||||
|
||||
|
||||
/**
|
||||
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
|
||||
* @type {string|undefined}
|
||||
|
||||
@@ -34,12 +34,9 @@ ol.source.TileVector = function(options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.format.Feature}
|
||||
* @type {ol.format.Feature|undefined}
|
||||
*/
|
||||
this.format_ = options.format;
|
||||
|
||||
goog.asserts.assert(goog.isDefAndNotNull(this.format_),
|
||||
'ol.source.TileVector requires a format');
|
||||
this.format_ = goog.isDef(options.format) ? options.format : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -53,6 +50,17 @@ ol.source.TileVector = function(options) {
|
||||
*/
|
||||
this.tileUrlFunction_ = ol.TileUrlFunction.nullTileUrlFunction;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?ol.TileVectorLoadFunctionType}
|
||||
*/
|
||||
this.tileLoadFunction_ = goog.isDef(options.tileLoadFunction) ?
|
||||
options.tileLoadFunction : null;
|
||||
|
||||
goog.asserts.assert(!goog.isNull(this.format_) ||
|
||||
!goog.isNull(this.tileLoadFunction_),
|
||||
'Either format or tileLoadFunction are required');
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, Array.<ol.Feature>>}
|
||||
@@ -299,9 +307,14 @@ ol.source.TileVector.prototype.loadFeatures =
|
||||
tileUrlFunction(urlTileCoord, 1, projection);
|
||||
if (goog.isDef(url)) {
|
||||
tiles[tileKey] = [];
|
||||
var loader = ol.featureloader.loadFeaturesXhr(url, this.format_,
|
||||
goog.partial(success, tileKey));
|
||||
loader.call(this, extent, resolution, projection);
|
||||
var tileSuccess = goog.partial(success, tileKey);
|
||||
if (!goog.isNull(this.tileLoadFunction_)) {
|
||||
this.tileLoadFunction_(url, tileSuccess);
|
||||
} else {
|
||||
var loader = ol.featureloader.loadFeaturesXhr(url,
|
||||
/** @type {ol.format.Feature} */ (this.format_), tileSuccess);
|
||||
loader.call(this, extent, resolution, projection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
goog.provide('ol.TileLoadFunctionType');
|
||||
goog.provide('ol.TileVectorLoadFunctionType');
|
||||
|
||||
|
||||
/**
|
||||
@@ -9,3 +10,13 @@ goog.provide('ol.TileLoadFunctionType');
|
||||
* @api
|
||||
*/
|
||||
ol.TileLoadFunctionType;
|
||||
|
||||
|
||||
/**
|
||||
* A function that is called with a tile url for the features to load and
|
||||
* a callback that takes the loaded features as argument.
|
||||
*
|
||||
* @typedef {function(string, function(Array.<ol.Feature>))}
|
||||
* @api
|
||||
*/
|
||||
ol.TileVectorLoadFunctionType;
|
||||
|
||||
Reference in New Issue
Block a user