23

このGoogle の例のように、OpenLayers で適切なクラスタリングを行う方法を知っていますか?

4

6 に答える 6

22

上記の例でpointStyleにラベルを追加し、このラベルのコンテキストを説明できます。コードは次のようになります。

var pointStyle = new OpenLayers.Style({
    // ...
    'label': "${label}",
    // ...
  }, {
    context: {
      // ...
      label: function(feature) {
        // clustered features count or blank if feature is not a cluster
        return feature.cluster ? feature.cluster.length : "";  
      }
      // ..
    }
});

var styleMap = new OpenLayers.StyleMap({
  'default': pointStyle,
});

var googleLikeLayer = new OpenLayers.Layer.Vector("GoogleLikeLayer", {
  // ...
  styleMap  : styleMap,
  // ... 
});
于 2012-08-02T23:37:47.653 に答える
13

OpenLayers.Strategy.Clusterクラスタリングに使用します。

于 2011-07-10T16:15:19.527 に答える
8

OpenLayers のいわゆる AnimatedCluster 戦略を実装しました。詳細については、http: //www.acuriousanimal.com/2012/08/19/animated-marker-cluster-strategy-for-openlayers.htmlを参照してください。

これは最初のバージョンにすぎませんが、クラスターに素敵なアニメーションを追加します。改善すべき点はたくさんありますが、それは出発点です。

于 2012-08-22T20:38:19.133 に答える
2

イゴルティが言ったように、これを行うことができます。ソリューションは OpenLayers.Strategy.Cluster クラスを使用し、レイヤーを OpenLayers.Style クラスでスタイリングします...

スタイリング用:

var pointStyle = new OpenLayers.Style({
'default': new OpenLayers.Style({
'pointRadius': '${radius}',
'externalGraphic': '${getgraph}'
....
},{
context:{
radius: function(feature){
    return Math.min(feature.attributes.count,7)+3;
},{
getgraph : function(feature){
    return 'ol/img/googlelike.png';
}}}};

それはあなたを助けなければなりません、あなたにもっと力を!

于 2011-07-13T10:08:47.570 に答える
2

レイヤーに追加されたカスタム属性に基づくクラスタリングの JSfiddle を次に示します。私はこれに少し苦労したので、ここに入れました。また、クラスター化されたデータでズームアウトしたときの要約円グラフ画像の作成も示していますhttp://jsfiddle.net/alexcpn/518p59k4/

このOpenLayers Advanced Clusteringを説明するための小さな openlayer チュートリアルも作成しました

    var getClusterCount = function (feature) {

    var clustercount = {};
    var planningcount = 0;
    var onaircount = 0;
    var inerrorcount = 0;

    for (var i = 0; i < feature.cluster.length; i++) {

        if (feature.cluster[i].attributes.cluster) {
        //THE MOST IMPORTANT LINE IS THE ONE BELOW, While clustering open layers removes the orginial feature layer with its own. So to get the attributes of the feature you have added add it to the openlayer created feature layer
            feature.attributes.cluster = feature.cluster[i].attributes.cluster;
            switch (feature.cluster[i].attributes.cluster) {

 ......
    return clustercount;
};
于 2013-03-28T12:21:27.830 に答える