It seems like there's a limitation to Cluster locations and a bug regarding its Bounds. I noticed that the location of a Cluster is always at the location of the first item added to it. I would expect that it actually would be at the center of all added items. Looking at the ClusterData.Add method it seems like it would be easy to update the Cluster-location there since the bounds are updated each time a new item is added. I tried solving it by overriding the DefaultClusterGenerator like the code below, but then I noticed that the calculation for the Bounds are actually wrong in the ClusterData.Add method. The last Math.Min should be a Math.Max. In the end I had to calculate the Bounds myself, and then update the Cluster Location.
public
class
ClusterGenerator : DefaultClusterGenerator
{
public
override
ClusterData CreateCluster(Location center,
object
item)
{
var clusterData =
base
.CreateCluster(center, item);
clusterData.AutoCalculateBounds =
true
;
clusterData.PropertyChanged +=
this
.ClusterDataOnPropertyChanged;
return
clusterData;
}
private
void
ClusterDataOnPropertyChanged(
object
sender, PropertyChangedEventArgs args)
{
// Check if an item has been added or removed
if
(args.PropertyName == nameof(ClusterData.Count))
{
var clusterData = sender
as
ClusterData;
if
(!clusterData.Bounds.IsEmpty)
{
clusterData.Location = clusterData.Bounds.Center;
}
}
}
}