Merge pull request #11628 from simonseyock/vector-source-load-events

VectorSource load events
This commit is contained in:
Andreas Hocevar
2020-10-27 19:42:45 +01:00
committed by GitHub
6 changed files with 283 additions and 109 deletions

View File

@@ -19,8 +19,10 @@ describe('ol.featureloader', function () {
it('adds features to the source', function (done) {
loader = xhr(url, format);
source.on('addfeature', function (e) {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
setTimeout(function () {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
}, 0);
});
loader.call(source, [], 1, 'EPSG:3857');
});
@@ -33,8 +35,10 @@ describe('ol.featureloader', function () {
loader = xhr(url, format);
source.on('addfeature', function (e) {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
setTimeout(function () {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
}, 0);
});
loader.call(source, [], 1, 'EPSG:3857');
});
@@ -54,5 +58,23 @@ describe('ol.featureloader', function () {
loader.call(source, [], 1, 'EPSG:3857');
});
});
it('it calls the success callback', function (done) {
const errorSpy = sinon.spy();
loader = xhr(url, format);
loader.call(
source,
[],
1,
'EPSG:3857',
function () {
setTimeout(function () {
expect(errorSpy.callCount).to.be(0);
done();
}, 0);
},
errorSpy
);
});
});
});

View File

@@ -559,6 +559,35 @@ describe('ol.source.Vector', function () {
});
describe('#loadFeatures', function () {
it('fires the FEATURESLOADSTART event', function (done) {
const source = new VectorSource();
source.on('featuresloadstart', function () {
done();
});
source.loadFeatures(
[-10000, -10000, 10000, 10000],
1,
getProjection('EPSG:3857')
);
});
it('fires the FEATURESLOADEND event if the default load function is used', function (done) {
const source = new VectorSource({
format: new GeoJSON(),
url: 'spec/ol/source/vectorsource/single-feature.json',
});
source.on('featuresloadend', function (event) {
expect(event.features).to.be.an('array');
expect(event.features.length).to.be(1);
done();
});
source.loadFeatures(
[-10000, -10000, 10000, 10000],
1,
getProjection('EPSG:3857')
);
});
describe('with the "bbox" strategy', function () {
it('requests the view extent plus render buffer', function (done) {
const center = [-97.6114, 38.8403];
@@ -661,6 +690,54 @@ describe('ol.source.Vector', function () {
getProjection('EPSG:3857')
);
});
it('fires the FEATURESLOADEND event if the load function uses the callback', function (done) {
const source = new VectorSource();
const spy = sinon.spy();
source.on('featuresloadend', spy);
const features = [new Feature(), new Feature()];
source.setLoader(function (bbox, resolution, projection, success) {
success(features);
setTimeout(function () {
expect(spy.calledOnce).to.be(true);
const event = spy.getCall(0).args[0];
expect(event.features).to.be(features);
done();
}, 0);
});
source.loadFeatures(
[-10000, -10000, 10000, 10000],
1,
getProjection('EPSG:3857')
);
});
it('fires the FEATURESLOADERROR event if the load function uses the callback', function (done) {
const source = new VectorSource();
const spy = sinon.spy();
source.on('featuresloaderror', spy);
source.setLoader(function (
bbox,
resolution,
projection,
success,
failure
) {
failure();
setTimeout(function () {
expect(spy.calledOnce).to.be(true);
done();
}, 0);
});
source.loadFeatures(
[-10000, -10000, 10000, 10000],
1,
getProjection('EPSG:3857')
);
});
});
});