2016-03-22 7 views
3

私の目的は、ビュー内に多くの座標をクラスタリングすることです。また、このポイントには線種として表示したい「接続」があります。Openlayers 3 - クラスタリングとラインの組み合わせ

私はたくさん試しましたが、私はラインをクラスタに統合する方法を見つけることができません。

私の現在の(安定した)状態

はここで見ることができます:2つの点がクラスタに「マージ」 Fiddle

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

場合conntectionが消えるまたはクラスタ自体の一部である場合、それは素晴らしいことです。

誰でも手伝ってもらえますか?

私は、私はあなたが現在クラスタに行を追加することができると思ういけないクラスタ fiddle

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

またはaddFeature 経由fiddle

clusterSource.addFeature(vectorLine); 

答えて

1

へのソースとして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では、geometryFunctionオプションを持つプル要求(https://github.com/openlayers/ol3/pull/4917)がマージされています。

関連する問題