在openlayers 2.8中,根据票证https://trac.osgeo.org/openlayers/ticket/1815,有一个与集群策略相关的阈值。
在openlayers 3中,没有任何地方提及它(战略范式似乎也消失了)。 http://openlayers.org/en/master/apidoc/ol.source.Cluster.html
有谁知道这个功能是否有票证?
答案 0 :(得分:0)
范式发生了很大变化。在OpenLayers 3中,您可以创建一个具有群集样式的新图层,以及"阈值"在图层选项中设置为maxResolution或minResolution。 类似于:
var clusterLayer = new ol.layer.Vector({
visible: true,
zIndex: insightMap.totalServcies - element.SortOrder,
id: Id,
serviceId: element.Id,
minResolution: clusteringThreshold,
cluster: true,
});
您也可以根据文档使用minZoom和maxZoom,但我们遇到过一致性问题。
答案 1 :(得分:0)
实际上有可能具有适当的群集阈值,而无需重新编译库。您需要在样式函数中使用每个要素的几何形状(来自群集的features
属性)。
const noClusterStyles = [];
vectorLayer.setStyle(feature => {
const features = feature.get('features');
if (features.length > 5) {
return clusterStyle;
} else {
for (let i = 0; ii = features.length; i < ii; ++i) {
const clone = noClusterStyles[i] ? noClusterStyles[i] : noClusterStyle.clone();
clone.setGeometry(features[i].getGeometry());
noClusterStyles[i] = clone;
}
noClusterStyles.length = features.length;
return noClusterStyles;
}
});
另一种解决方案将需要修改OL3库本身。
ol.source.Cluster.prototype.cluster_函数具有以下代码段:
var neighbors = this.source_.getFeaturesInExtent(extent);
ol.DEBUG && console.assert(neighbors.length >= 1, 'at least one neighbor found');
neighbors = neighbors.filter(function(neighbor) {
var uid = ol.getUid(neighbor).toString();
if (!(uid in clustered)) {
clustered[uid] = true;
return true;
} else {
return false;
}
});
// Add the following
// If one element has more too many neighbors, register it as a cluster of one
// Size-based styling should be handled separately, in the layer style function
let THRESHOLD= 3;
if(neighbors.length > THRESHOLD) {
this.features_.push(this.createCluster_(neighbors));
} else {
for(var j = 0 ; j < neighbors.length ; j++) {
this.features_.push(this.createCluster_([neighbors[j]]));
}
}