Replace extentUrlFunction with generic loadingFunction
This commit is contained in:
@@ -87,14 +87,17 @@ var styles = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var epsg3857ToEPSG4326 = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
|
||||||
var vectorSource = new ol.source.ServerVector({
|
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(),
|
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({
|
loadingStrategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
|
||||||
maxZoom: 19
|
maxZoom: 19
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -908,9 +908,8 @@
|
|||||||
* @typedef {Object} olx.source.ServerVectorOptions
|
* @typedef {Object} olx.source.ServerVectorOptions
|
||||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||||
* @property {ol.Extent|undefined} extent Extent.
|
* @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 {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 {function(ol.Extent, number): Array.<ol.Extent>} loadingStrategy Loading strategy.
|
||||||
* @property {string|undefined} logo Logo.
|
* @property {string|undefined} logo Logo.
|
||||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ ol.source.ServerVector = function(options) {
|
|||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
extent: options.extent,
|
extent: options.extent,
|
||||||
format: options.format,
|
format: options.format,
|
||||||
headers: options.headers,
|
|
||||||
logo: options.logo,
|
logo: options.logo,
|
||||||
projection: options.projection
|
projection: options.projection
|
||||||
});
|
});
|
||||||
@@ -32,15 +31,16 @@ ol.source.ServerVector = function(options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @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
|
* @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
|
* @private
|
||||||
@@ -90,8 +90,7 @@ ol.source.ServerVector.prototype.loadFeatures =
|
|||||||
return ol.extent.containsExtent(object.extent, extentToLoad);
|
return ol.extent.containsExtent(object.extent, extentToLoad);
|
||||||
});
|
});
|
||||||
if (!alreadyLoaded) {
|
if (!alreadyLoaded) {
|
||||||
var url = this.extentUrlFunction_(extentToLoad, resolution, projection);
|
this.loadingFunction_.call(this, extentToLoad, resolution, projection);
|
||||||
this.loadFeaturesFromURL(url);
|
|
||||||
loadedExtents.insert(extentToLoad, {extent: extentToLoad.slice()});
|
loadedExtents.insert(extentToLoad, {extent: extentToLoad.slice()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user