Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenLayers, nice marker clustering

Tags:

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

like image 732
apneadiving Avatar asked Jul 10 '11 15:07

apneadiving


2 Answers

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,   // ...  }); 
like image 165
unibasil Avatar answered Nov 09 '22 07:11

unibasil


Use OpenLayers.Strategy.Cluster for clustering.

  • Example Code
  • Working Example
  • Custom Styling
  • In-depth Explanation
like image 41
igorti Avatar answered Nov 09 '22 05:11

igorti