Merge pull request #2971 from elemoine/tilevector
Two ol.source.TileVector fixes
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);
|
||||
};
|
||||
|
||||
@@ -185,6 +185,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);
|
||||
@@ -196,16 +205,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ goog.provide('ol.tilegrid.TileGrid');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.TileCoord');
|
||||
@@ -101,12 +102,16 @@ ol.tilegrid.TileGrid.tmpTileCoord_ = [0, 0, 0];
|
||||
|
||||
|
||||
/**
|
||||
* Returns the identity function. May be overridden in subclasses.
|
||||
* @param {{extent: (ol.Extent|undefined),
|
||||
* wrapX: (boolean|undefined)}=} opt_options Options.
|
||||
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
|
||||
* ol.TileCoord} Tile coordinate transform.
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.createTileCoordTransform = goog.abstractMethod;
|
||||
ol.tilegrid.TileGrid.prototype.createTileCoordTransform =
|
||||
function(opt_options) {
|
||||
return goog.functions.identity;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user