Merge pull request #7274 from bartvde/set-loader

Add ability to change the loader of a vector source
This commit is contained in:
Bart van den Eijnden
2017-09-20 16:43:21 +02:00
committed by GitHub
2 changed files with 34 additions and 0 deletions

View File

@@ -823,6 +823,17 @@ ol.source.Vector.prototype.removeFromIdIndex_ = function(feature) {
};
/**
* Set the new loader of the source. The next loadFeatures call will use the
* new loader.
* @param {ol.FeatureLoader} loader The loader to set.
* @api
*/
ol.source.Vector.prototype.setLoader = function(loader) {
this.loader_ = loader;
};
/**
* @classdesc
* Events emitted by {@link ol.source.Vector} instances are instances of this

View File

@@ -430,6 +430,29 @@ describe('ol.source.Vector', function() {
});
});
describe('with setLoader', function() {
it('it will change the loader function', function() {
var count1 = 0;
var loader1 = function(bbox, resolution, projection) {
count1++;
};
var count2 = 0;
var loader2 = function(bbox, resolution, projection) {
count2++;
};
var source = new ol.source.Vector({loader: loader1});
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
ol.proj.get('EPSG:3857'));
source.setLoader(loader2);
source.clear();
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
ol.proj.get('EPSG:3857'));
expect(count1).to.eql(1);
expect(count2).to.eql(1);
});
});
});
describe('the feature id index', function() {