gpt4 book ai didi

javascript - Openlayers 3 - 聚类和线条组合

转载 作者:行者123 更新时间:2023-11-29 15:29:29 25 4
gpt4 key购买 nike

我的目标是在 View 中聚集许多坐标。这些点之间也可以有“连接”,我想将其显示为 LineString。

我尝试了很多,但找不到将 Lines 集成到 Cluster 中的方法。

我的当前(稳定)状态可以在这里看到: Fiddle

var clusterSource = new ol.source.Cluster({
distance: 20,
source: vectorDevices
});

如果这两个点“合并”到集群中,如果连接消失或者是集群本身的一部分,那就太好了。

谁能帮帮我?

我尝试将 vectorLine 作为源添加到 Cluster fiddle

var clusterSource = new ol.source.Cluster({
distance: 20,
source: [vectorDevices, vectorLine]
});

或通过 addFeature fiddle

clusterSource.addFeature(vectorLine);

最佳答案

我认为您目前无法向集群添加线路。 Openlayers 3(从 v 3.14.2 开始)聚类只允许您聚类点。如果您查看 ol.source.Cluster 的源代码,就会发现其中的所有特征都必须是点。(来自https://github.com/openlayers/ol3/blob/v3.14.2/src/ol/source/clustersource.js)

ol.source.Cluster.prototype.createCluster_ = function(features) {
var length = features.length;
var centroid = [0, 0];
for (var i = 0; i < length; i++) {
var geometry = features[i].getGeometry();
goog.asserts.assert(geometry instanceof ol.geom.Point,
'feature geometry is a ol.geom.Point instance');
var coordinates = geometry.getCoordinates();
ol.coordinate.add(centroid, coordinates);
}
ol.coordinate.scale(centroid, 1 / length);

var cluster = new ol.Feature(new ol.geom.Point(centroid));
cluster.set('features', features);
return cluster;
};

我认为你最好的选择是在点聚集时以某种方式将线层的可见性更改为 false。

编辑:然而,这可能会在 ol 的下一个版本中发生变化,一个拉取请求 (https://github.com/openlayers/ol3/pull/4917) 已被合并,其中有一个 geometryFunction 选项。

关于javascript - Openlayers 3 - 聚类和线条组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36152063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com