Merge pull request #6105 from tschaub/feature-loader
Move vector tile loader functions into vector tile module
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
goog.provide('ol.featureloader');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.Tile');
|
||||
goog.require('ol.format.FormatType');
|
||||
goog.require('ol.xml');
|
||||
|
||||
@@ -70,35 +69,6 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an XHR feature loader for a `url` and `format`. The feature loader
|
||||
* loads features (with XHR), parses the features, and adds them to the
|
||||
* vector tile.
|
||||
* @param {string|ol.FeatureUrlFunction} url Feature URL service.
|
||||
* @param {ol.format.Feature} format Feature format.
|
||||
* @return {ol.FeatureLoader} The feature loader.
|
||||
* @api
|
||||
*/
|
||||
ol.featureloader.tile = function(url, format) {
|
||||
return ol.featureloader.loadFeaturesXhr(url, format,
|
||||
/**
|
||||
* @param {Array.<ol.Feature>} features The loaded features.
|
||||
* @param {ol.proj.Projection} dataProjection Data projection.
|
||||
* @this {ol.VectorTile}
|
||||
*/
|
||||
function(features, dataProjection) {
|
||||
this.setProjection(dataProjection);
|
||||
this.setFeatures(features);
|
||||
},
|
||||
/**
|
||||
* @this {ol.VectorTile}
|
||||
*/
|
||||
function() {
|
||||
this.setState(ol.Tile.State.ERROR);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an XHR feature loader for a `url` and `format`. The feature loader
|
||||
* loads features (with XHR), parses the features, and adds them to the
|
||||
|
||||
@@ -5,7 +5,6 @@ goog.require('ol.Tile');
|
||||
goog.require('ol.VectorTile');
|
||||
goog.require('ol.events');
|
||||
goog.require('ol.events.EventType');
|
||||
goog.require('ol.featureloader');
|
||||
goog.require('ol.size');
|
||||
goog.require('ol.source.UrlTile');
|
||||
|
||||
@@ -38,7 +37,7 @@ ol.source.VectorTile = function(options) {
|
||||
state: options.state,
|
||||
tileGrid: options.tileGrid,
|
||||
tileLoadFunction: options.tileLoadFunction ?
|
||||
options.tileLoadFunction : ol.source.VectorTile.defaultTileLoadFunction,
|
||||
options.tileLoadFunction : ol.VectorTile.defaultLoadFunction,
|
||||
tileUrlFunction: options.tileUrlFunction,
|
||||
tilePixelRatio: options.tilePixelRatio,
|
||||
url: options.url,
|
||||
@@ -121,12 +120,3 @@ ol.source.VectorTile.prototype.getTilePixelSize = function(z, pixelRatio, projec
|
||||
var tileSize = ol.size.toSize(this.tileGrid.getTileSize(z));
|
||||
return [Math.round(tileSize[0] * pixelRatio), Math.round(tileSize[1] * pixelRatio)];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.VectorTile} vectorTile Vector tile.
|
||||
* @param {string} url URL.
|
||||
*/
|
||||
ol.source.VectorTile.defaultTileLoadFunction = function(vectorTile, url) {
|
||||
vectorTile.setLoader(ol.featureloader.tile(url, vectorTile.getFormat()));
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ goog.provide('ol.VectorTile');
|
||||
goog.require('ol');
|
||||
goog.require('ol.Tile');
|
||||
goog.require('ol.dom');
|
||||
goog.require('ol.featureloader');
|
||||
|
||||
|
||||
/**
|
||||
@@ -149,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
|
||||
@@ -186,3 +206,16 @@ ol.VectorTile.prototype.setState = function(tileState) {
|
||||
ol.VectorTile.prototype.setLoader = function(loader) {
|
||||
this.loader_ = loader;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the loader for a tile.
|
||||
* @param {ol.VectorTile} tile Vector tile.
|
||||
* @param {string} url URL.
|
||||
*/
|
||||
ol.VectorTile.defaultLoadFunction = function(tile, url) {
|
||||
var loader = ol.featureloader.loadFeaturesXhr(
|
||||
url, tile.getFormat(), tile.onLoad_.bind(tile), tile.onError_.bind(tile));
|
||||
|
||||
tile.setLoader(loader);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user