Merge pull request #7538 from ahocevar/rem_from_loaded_ext
removeFromLoadedExtents to remove extents that failed to load
This commit is contained in:
@@ -6684,6 +6684,37 @@ olx.source.VectorOptions.prototype.format;
|
||||
* The loader function used to load features, from a remote source for example.
|
||||
* If this is not set and `url` is set, the source will create and use an XHR
|
||||
* feature loader.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```js
|
||||
* var vectorSource = new ol.source.Vector({
|
||||
* format: new ol.format.GeoJSON(),
|
||||
* loader: function(extent, resolution, projection) {
|
||||
* var proj = projection.getCode();
|
||||
* var url = 'https://ahocevar.com/geoserver/wfs?service=WFS&' +
|
||||
* 'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
|
||||
* 'outputFormat=application/json&srsname=' + proj + '&' +
|
||||
* 'bbox=' + extent.join(',') + ',' + proj;
|
||||
* var xhr = new XMLHttpRequest();
|
||||
* xhr.open('GET', url);
|
||||
* var onError = function() {
|
||||
* vectorSource.removeLoadedExtent(extent);
|
||||
* }
|
||||
* xhr.onerror = onError;
|
||||
* xhr.onload = function() {
|
||||
* if (xhr.status == 200) {
|
||||
* vectorSource.addFeatures(
|
||||
* vectorSource.getFormat().readFeatures(xhr.responseText));
|
||||
* } else {
|
||||
* onError();
|
||||
* }
|
||||
* }
|
||||
* xhr.send();
|
||||
* },
|
||||
* strategy: ol.loadingstrategy.bbox
|
||||
* });
|
||||
* ```
|
||||
* @type {ol.FeatureLoader|undefined}
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -762,6 +762,26 @@ ol.source.Vector.prototype.loadFeatures = function(
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove an extent from the list of loaded extents.
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @api
|
||||
*/
|
||||
ol.source.Vector.prototype.removeLoadedExtent = function(extent) {
|
||||
var loadedExtentsRtree = this.loadedExtentsRtree_;
|
||||
var obj;
|
||||
loadedExtentsRtree.forEachInExtent(extent, function(object) {
|
||||
if (ol.extent.equals(object.extent, extent)) {
|
||||
obj = object;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (obj) {
|
||||
loadedExtentsRtree.remove(obj);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove a single feature from the source. If you want to remove all features
|
||||
* at once, use the {@link ol.source.Vector#clear source.clear()} method
|
||||
|
||||
@@ -451,6 +451,19 @@ describe('ol.source.Vector', function() {
|
||||
expect(count1).to.eql(1);
|
||||
expect(count2).to.eql(1);
|
||||
});
|
||||
|
||||
it('removes extents with #removeLoadedExtent()', function(done) {
|
||||
var source = new ol.source.Vector();
|
||||
source.setLoader(function(bbox, resolution, projection) {
|
||||
setTimeout(function() {
|
||||
expect(source.loadedExtentsRtree_.getAll()).to.have.length(1);
|
||||
source.removeLoadedExtent(bbox);
|
||||
expect(source.loadedExtentsRtree_.getAll()).to.have.length(0);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
source.loadFeatures([-10000, -10000, 10000, 10000], 1, ol.proj.get('EPSG:3857'));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user