From 635191f31d80f5921a5fe184cd127e6f391e161a Mon Sep 17 00:00:00 2001 From: "kikitte.lee" Date: Thu, 25 Mar 2021 13:16:35 +0800 Subject: [PATCH] call the success callback after the features are added --- src/ol/featureloader.js | 2 +- test/spec/ol/source/vector.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ol/featureloader.js b/src/ol/featureloader.js index 6c146b1b63..26ef3be66b 100644 --- a/src/ol/featureloader.js +++ b/src/ol/featureloader.js @@ -156,10 +156,10 @@ export function xhr(url, format) { * projection. */ function (features, dataProjection) { + source.addFeatures(features); if (success !== undefined) { success(features); } - source.addFeatures(features); }, /* FIXME handle error */ failure ? failure : VOID ); diff --git a/test/spec/ol/source/vector.test.js b/test/spec/ol/source/vector.test.js index 7bf8df9aec..ad69fea674 100644 --- a/test/spec/ol/source/vector.test.js +++ b/test/spec/ol/source/vector.test.js @@ -571,6 +571,24 @@ describe('ol.source.Vector', function () { ); }); + it('fires the FEATURESLOADEND event after the features are added', function (done) { + const source = new VectorSource({ + format: new GeoJSON(), + url: 'spec/ol/source/vectorsource/single-feature.json', + }); + source.on('featuresloadend', function () { + const features = source.getFeatures(); + expect(features).to.be.an('array'); + expect(features.length).to.be(1); + 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(),