Move loader functions and response handlers to tile module

This commit is contained in:
Tim Schaub
2016-11-11 05:35:20 -07:00
parent b829471c85
commit a20bd72aa9
4 changed files with 88 additions and 80 deletions
+24 -1
View File
@@ -150,6 +150,25 @@ ol.VectorTile.prototype.load = function() {
};
/**
* Handler for successful tile load.
* @param {Array.<ol.Feature>} features The loaded features.
* @param {ol.proj.Projection} dataProjection Data projection.
*/
ol.VectorTile.prototype.onLoad_ = function(features, dataProjection) {
this.setProjection(dataProjection);
this.setFeatures(features);
};
/**
* Handler for tile load errors.
*/
ol.VectorTile.prototype.onError_ = function() {
this.setState(ol.Tile.State.ERROR);
};
/**
* @param {Array.<ol.Feature>} features Features.
* @api
@@ -190,9 +209,13 @@ ol.VectorTile.prototype.setLoader = function(loader) {
/**
* Sets the loader for a tile.
* @param {ol.VectorTile} tile Vector tile.
* @param {string} url URL.
*/
ol.VectorTile.defaultLoadFunction = function(tile, url) {
tile.setLoader(ol.featureloader.tile(url, tile.getFormat()));
var loader = ol.featureloader.loadFeaturesXhr(
url, tile.getFormat(), tile.onLoad_.bind(tile), tile.onError_.bind(tile));
tile.setLoader(loader);
};