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.
VEShapeLayer.GetClusteredShapes(type);
Parameters
Parameter | Description |
---|---|
type |
A VEClusteringType Enumeration specifying the algorithm used to determine which pushpins to cluster. |
Return Value
An array of VEClusterSpecification Class objects that represent the pushpin clusters of the shape layer.
Remarks
The GetClusteredShapes method can be used to calculate the pushpin clusters before clustering is set.
Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Pushpin Clustering</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></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');
map.LoadMap();
}
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
layer.AddShape(p1Shape);
layer.AddShape(p2Shape);
layer.AddShape(p3Shape);
layer.AddShape(p4Shape);
//Specifying clustering
layer.SetClusteringConfiguration(VEClusteringType.Grid);
map.AddShapeLayer(layer);
//Set the map view and zoom out to see the clustering
map.SetMapView(new Array(p1, p2, p3, p4));
map.SetZoomLevel(14);
}
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.");
}
}
</script>
</head>
<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();"/>
</body>
</html>