views:

52

answers:

2

Suppose I have a virtual earth shape layer called shapeLayer1 (my creative energy is apparently at an alltime low).

When i call the GetClusteredShapes method I get an array of VEClusterSpecification objects that represent each and every one of my currently visible clusters; no problem there. But when I call the GetClusterShape() method it returns null... null! Why on earth would it do that? I used firebug to confirm that the private variable of the VEClusterSpecification that's supposed to hold a reference to the shape is indeed null so it's not the method that's causing the problem.

Some have suggested that this is actually documented behavior

Returns null if a VEClusterSpecification object was returned from the VEShapeLayer.GetClusteredShapes Method

But looking at the current MSDN documentation for the VEShape class it says:

Returns if a VEClusterSpecification object was returned from the VEShapeLayer.GetClusteredShapes Method

Is this a bug or a feature? Is there any known workarounds or (if it is a bug) some plan on when they are going to fix it?

A: 

I know it sux... I'm still looking at the code but from what I can tell they want you to set the custom stuff using the VEClusteringOptions callback method. This doesn't work for for me because I'm using a custom infobox but it may help someone else, using the method below you have complete access to the shapes inside the cluster.

function clusteringCallback(clusters)
{
   for (var i=0; i < clusters.length; ++i)
   {
        var cluster = clusters[i];
        var clusterShape = cluster.GetClusterShape();
        clusterShape.SetCustomIcon("<div class='cluster'><div class='text'>"+cluster.Shapes.length+"</div></div>");
        clusterShape.SetTitle("This is my Cluster #" + i);
        clusterShape.SetDescription("This cluster has " + cluster.Shapes.length + " shapes in it!");
   }
}

function SetClustering() 
{
    var options =  new VEClusteringOptions();
    options.Callback = clusteringCallback;
    shapeLayer.SetClusteringConfiguration(VEClusteringType.Grid, options);
}
MyWhirledView
A: 

If you need to get the layer id from the layer which the clustershape belongs to you can do it like this:

var layerId = clusters[i].Shapes[0].GetShapeLayer().MsnId;

if you find another way, please inform us ;-)

simon