Replace extentUrlFunction with generic loadingFunction

This commit is contained in:
Tom Payne
2014-03-13 20:39:58 +01:00
parent b8869805a7
commit 9e75684823
3 changed files with 16 additions and 15 deletions

View File

@@ -87,14 +87,17 @@ var styles = {
}
};
var epsg3857ToEPSG4326 = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
var vectorSource = new ol.source.ServerVector({
extentUrlFunction: function(extent, resolution) {
var epsg4326Extent = epsg3857ToEPSG4326(extent, []);
return 'http://overpass-api.de/api/xapi?map?bbox=' +
epsg4326Extent.join(',');
},
format: new ol.format.OSMXML(),
loadingFunction: function(extent, resolution, projection) {
var transform = ol.proj.getTransform(projection, 'EPSG:4326');
var epsg4326Extent = transform(extent, []);
var url = 'http://overpass-api.de/api/xapi?map?bbox=' +
epsg4326Extent.join(',');
$.ajax(url).then(function(response) {
vectorSource.readFeatures(response);
});
},
loadingStrategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
maxZoom: 19
})),

View File

@@ -908,9 +908,8 @@
* @typedef {Object} olx.source.ServerVectorOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {ol.Extent|undefined} extent Extent.
* @property {function(ol.Extent, number, ol.proj.Projection): string} extentUrlFunction Extent URL function.
* @property {Object.<string, string>|undefined} headers Headers.
* @property {ol.format.Feature} format Format.
* @property {function(this: ol.source.ServerVector, ol.Extent, number, ol.proj.Projection)} loadingFunction Loading function.
* @property {function(ol.Extent, number): Array.<ol.Extent>} loadingStrategy Loading strategy.
* @property {string|undefined} logo Logo.
* @property {ol.proj.ProjectionLike} projection Projection.

View File

@@ -19,7 +19,6 @@ ol.source.ServerVector = function(options) {
attributions: options.attributions,
extent: options.extent,
format: options.format,
headers: options.headers,
logo: options.logo,
projection: options.projection
});
@@ -32,15 +31,16 @@ ol.source.ServerVector = function(options) {
/**
* @private
* @type {function(ol.Extent, number): Array.<ol.Extent>}
* @type {function(this: ol.source.ServerVector, ol.Extent, number,
* ol.proj.Projection): string}
*/
this.loadingStrategy_ = options.loadingStrategy;
this.loadingFunction_ = options.loadingFunction;
/**
* @private
* @type {function(ol.Extent, number, ol.proj.Projection): string}
* @type {function(ol.Extent, number): Array.<ol.Extent>}
*/
this.extentUrlFunction_ = options.extentUrlFunction;
this.loadingStrategy_ = options.loadingStrategy;
/**
* @private
@@ -90,8 +90,7 @@ ol.source.ServerVector.prototype.loadFeatures =
return ol.extent.containsExtent(object.extent, extentToLoad);
});
if (!alreadyLoaded) {
var url = this.extentUrlFunction_(extentToLoad, resolution, projection);
this.loadFeaturesFromURL(url);
this.loadingFunction_.call(this, extentToLoad, resolution, projection);
loadedExtents.insert(extentToLoad, {extent: extentToLoad.slice()});
}
}