2

I am using the cluster strategy for mapping a large number of features in OpenLayers, now I would like to find a good solution for providing info about the features contained in a cluster selected by the user. In other words whenever the user selects one cluster I would like to explode the cluster with as many markers as the features contained in it, of course selectable markers.

Could anybody help me?

I attached an image about how the markers around the selected cluster would look like.

enter image description here

1

Your problem is accessing to the clustered elements or to create the expanding animation?

This is what I use to access to any feature attribute:

                if(feature.attributes.count>1) {
                    var sumValue = 0;
                    for (var i=0; i<feature.cluster.length; i++) {
                        sumValue += feature.cluster[i].attributes['val'];
                    }
                    var averageValue = sumValue/feature.cluster.length;
                    return averageValue.toFixed(1);
                } else return feature.attributes.val; 

In that way I get the clustered elements' values average, but this allows you to get every clustered elements value and show it.

You can set attributes in that way:

            var pointFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lon,lat));       
            pointFeature.attributes = {
                val: mks[i].m,
                id: mks[i].id,
            };
            features[i] = pointFeature;
  • Thanks alberto for your answer.Actually I know how to access the clusters' elements, my problem is related to how to explode – defelix Jan 31 '14 at 10:42
  • Sorry Alberto. Actually I know how to access the clusters' elements, my problem is related to how to explode the features around that selected cluster. In other words I would like to draw around the cluster as many markers as the features contained in the cluster. – defelix Jan 31 '14 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.