rename to createClusterFeature

This commit is contained in:
jkonieczny
2021-07-12 19:24:23 +02:00
parent 9fd25dddbf
commit a8f7d955af
2 changed files with 73 additions and 12 deletions

View File

@@ -75,7 +75,7 @@ describe('ol.source.Cluster', function () {
expect(source.getFeatures().length).to.be(1);
expect(source.getFeatures()[0].get('features').length).to.be(2);
});
it('hydrates cluster feature with additional fields', function () {
it('custom cluster feature with additional fields', function () {
const feature1 = new Feature(new Point([0, 0]));
const feature2 = new Feature(new Point([0, 0]));
feature1.set('value', 1);
@@ -84,14 +84,41 @@ describe('ol.source.Cluster', function () {
source: new VectorSource({
features: [feature1, feature2],
}),
hydrate: function (clusterFeature, features) {
clusterFeature.set('sum', 3);
createClusterFeature: function (clusterPoint, features) {
let sum = 0;
for (const ft of features) {
sum += ft.get('value');
}
return new Feature({
geometry: clusterPoint,
sum: sum,
});
},
});
source.loadFeatures(extent, 1, projection);
expect(source.getFeatures().length).to.be(1);
expect(source.getFeatures()[0].get('sum')).to.be(3);
});
it('reacts setCreateClusterFeature', function () {
const feature1 = new Feature(new Point([0, 0]));
const feature2 = new Feature(new Point([0, 0]));
const source = new Cluster({
source: new VectorSource({
features: [feature1, feature2],
}),
});
source.loadFeatures(extent, 1, projection);
expect(source.getFeatures().length).to.be(1);
expect(source.getFeatures()[0].get('sum')).to.be(undefined);
source.setCreateClusterFeature(function (clusterPoint, features) {
return new Feature({
geometry: clusterPoint,
sum: features.length,
});
});
expect(source.getFeatures().length).to.be(1);
expect(source.getFeatures()[0].get('sum')).to.be(2);
});
});
describe('#setDistance', function () {