allow hydrating clustered features

This commit is contained in:
jkonieczny
2021-07-08 20:06:18 +02:00
parent e791bf4e33
commit 9fd25dddbf
2 changed files with 28 additions and 0 deletions

View File

@@ -38,6 +38,8 @@ import {getUid} from '../util.js';
* return feature.getGeometry();
* }
* ```
* @property {function(Feature, Array<Feature>):any} [hydrate] Function called after creating
* cluster feature
* See {@link module:ol/geom/Polygon~Polygon#getInteriorPoint} for a way to get a cluster
* calculation point for polygons.
* @property {VectorSource} [source] Source.
@@ -108,6 +110,12 @@ class Cluster extends VectorSource {
return geometry;
};
/**
* @type {function(Feature, Array<Feature>):any}
* @protected
*/
this.hydrate = options.hydrate;
/**
* @type {VectorSource}
* @protected
@@ -295,6 +303,9 @@ class Cluster extends VectorSource {
centroid[1] * (1 - ratio) + searchCenter[1] * ratio,
]);
const cluster = new Feature(geometry);
if (this.hydrate) {
this.hydrate(cluster, features);
}
cluster.set('features', features, true);
return cluster;
}