OpenLayers, nice marker clustering

前端 未结 6 1197
刺人心
刺人心 2020-12-12 18:50

Do you know how to have a nice clustering in OpenLayers such as this google example ?

6条回答
  •  遥遥无期
    2020-12-12 19:06

    You can add label to pointStyle in above example and explain context of this label. Your code should be something like this:

    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,
      // ... 
    });
    

提交回复
热议问题