VEShapeLayer.GetClusteredShapes Method

You are not viewing the latest version of the AJAX control. Bing Maps AJAX V7 is the recommended JavaScript control for Bing Maps. If you need this documentation, it is available in as a CHM or PDF download.

Returns an array of VEClusterSpecification Class objects representing the calculated pushpin clusters.



Parameter Description


A VEClusteringType Enumeration specifying the algorithm used to determine which pushpins to cluster.

An array of VEClusterSpecification Class objects that represent the pushpin clusters of the shape layer.

The GetClusteredShapes method can be used to calculate the pushpin clusters before clustering is set.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
      <title>Pushpin Clustering</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <script type="text/javascript" src=""></script>

      <script type="text/javascript">
         var map = null;

         var p1 = new VELatLong(45.0118,-111.06687);
         var p2 = new VELatLong(45.0117,-111.06687);
         var p3 = new VELatLong(45.0116,-111.06687);
         var p4 = new VELatLong(45.0115,-111.06687);

         var layer = null;         

         function GetMap()
            map = new VEMap('myMap');


         function AddLayer()
            layer = new VEShapeLayer();
            layer.SetTitle("Clustered Pushpins");
            p1Shape = new VEShape(VEShapeType.Pushpin, p1);
            p2Shape = new VEShape(VEShapeType.Pushpin, p2);
            p3Shape = new VEShape(VEShapeType.Pushpin, p3);
            p4Shape = new VEShape(VEShapeType.Pushpin, p4);

            // Add the pushpins to the map

            //Specifying clustering

            //Set the map view and zoom out to see the clustering
            map.SetMapView(new Array(p1, p2, p3, p4));
        function GetClusteredShapes()
           var clusterShapes = new Array();
           clusterShapes = layer.GetClusteredShapes(VEClusteringType.Grid);
           alert("The pushpins can be clustered into " + clusterShapes.length + " shapes.");

           if(clusterShapes.length != 0)
              var cluster1Count = clusterShapes[0].Shapes.length;
              alert("There are " + cluster1Count + " pushpins in the first cluster.");

   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:600px; height:400px;"></div>
      <input type="button" name="btnAddLayer" value="Add Clustered Pushpins" onclick="AddLayer();"/>
      <input type="button" name="btnGetClusteredShapes" value="Get the Clustered Shapes" onclick="GetClusteredShapes();"/>