First of all , Hello !
Im using maps and i have question about clustering. Currently im manipulating with 1000 objects and displaying them on my map and clustering them( of course).
But on zoom level 7 i have arround 100 clusters. How can i set that on zoom level 7 i have maybe 5 clusters . Or can you give me idea or example where you are setting different condition for clusters
in attachment is picture on zoomLevel=7 and clusters
Thank you
10 Answers, 1 is accepted
VisualizationLayer has IClusterGenerator instance member which is responsible for the clustering behavior. It has predefined distances for all zoom levels which participate in the calculations whether item belongs to cluster or not. To change this predefined list of distances you can use the following code:
this
.VisualizationLayer1.ClusterGenerator =
new
DefaultClusterGenerator()
{
CloseDistance =
new
double
[]
{
20,
10,
5,
2.5,
1.25,
0.6,
0.3,
0.15,
0.075,
0.037,
0.018,
0.009,
0.0045,
0.0022,
0.0011,
0.00055,
0.00027,
0.000135,
0.000067,
0.000033,
0.000016,
0.000008,
0.000004,
0.000002,
0.000001
}
};
To better understand the cluster calculations , I will paste the CloseDistance property and IsItemInClusterRegion method of the DefaultClusterGenerator class:
/// <summary>
/// Gets or sets array of the doubles which define close distance
/// between 2 locations in degrees for every zoom level.
/// </summary>
/// <remarks>If distance between 2 locations for the given zoom level is
/// less than value in the array, then we consider these 2 locations as close ones.
/// Close locations should be combined into 1 cluster.</remarks>
public
double
[] CloseDistance
{
get
{
return
this
.closeDistance;
}
set
{
this
.closeDistance = value;
}
}
/// <summary>
/// Detects whether given original data item belongs to the region of the specified cluster.
/// </summary>
/// <param name="cluster">Cluster.</param>
/// <param name="info">Map object information.</param>
/// <param name="zoomLevel">Zoom level.</param>
/// <returns>true - if data item belongs to the region of the specified cluster.</returns>
public
virtual
bool
IsItemInClusterRegion(ClusterData cluster, MapObjectInfo info,
int
zoomLevel)
{
Location itemLocation =
this
.Layer.GetLocationFromInfo(info);
bool
isClose =
false
;
if
(zoomLevel > 0)
{
double
width = Math.Abs(cluster.Location.Longitude - itemLocation.Longitude);
double
height = Math.Abs(cluster.Location.Latitude - itemLocation.Latitude);
isClose = width <
this
.closeDistance[zoomLevel - 1]
&& height <
this
.closeDistance[zoomLevel - 1];
}
return
isClose;
}
In future, we will aim at describing this generator in our documentation.
Regards,
Petar Mladenov
Progress Telerik
can you maybe send example of implementing it so i can see it on example ?
thank you
Please find the attached project in which I have changed the clustering distance for level 3:
public
MainWindow()
{
InitializeComponent();
this
.VisualizationLayer1.ClusterGenerator =
new
DefaultClusterGenerator()
{
CloseDistance =
new
double
[]
{
20,
10,
8,
// default is 5
2.5,
1.25,
0.6,
I hope this will help you move forward.
Regards,
Petar Mladenov
Progress Telerik
i see the point.
But i have one problem
I need to put zoom level really high (<15) so my zoom level (1-15) will work
<telerik:RadMap x:Name="radMap" Grid.Row="1" ZoomLevel="10">
if i put zoom level=1 Clustering close distance WONT work . iF i put zoomLevel=15 Clustering close distance will work
If i delete zoomLevel and put it by default Clustering CloseDistance also doesnt work
really weird .
Maybe Bug ??
Thank you
In the attached project, default close distance for zoom level 1 is 20. If you increase it to 200, you will notice there will be single cluster on zoomlevel 1. If you decrease it to 0.02 there will be practically no clusters. You can see the results in the attached pictures. Could you please elaborate a bit more on your scenario and why zoomlevel 1 is problematic. Can you send us some real data (locations) and clsuter distances that we can debug locally and double check for an issue in RadMap's internal code. Thank you in advance.
Regards,
Petar Mladenov
Progress Telerik
In the attached project, default close distance for zoom level 1 is 20. If you increase it to 200, you will notice there will be single cluster on zoomlevel 1. If you decrease it to 0.02 there will be practically no clusters. You can see the results in the attached pictures. Could you please elaborate a bit more on your scenario and why zoomlevel 1 is problematic. Can you send us some real data (locations) and cluster distances that we can debug locally and double check for an issue in RadMap's internal code. Thank you in advance.
Regards,
Petar Mladenov
Progress Telerik
I think you didnt understand me.
i attached pictures of 2 scenario.
1 scenario when i put grid zoom level=15 and then i zoom out and see clustering okay.
2 scenario: if i put grid zoom level=1 then clustering is not working .. also if i delete grid zoom level clustering doesnt work .
Thank you
We understand that by some reason clustering feature does not create clusters in your scenario for initial zoom level 1. Can you send us you RadMap code - its XAML and code behind and some of your locations displayed on the map. Probably this will help us better investigate and give an appropriate advice for your business case. Meanwhile, you can take a quick look at the following list of properties for configuring the cluster generation:
RadMap VisualizationLayer clustering
Can you double check if you use the default values of these properties ?
Regards,
Petar Mladenov
Progress Telerik
link to download 2 files because i canot post rar or zip inside reply
The file is missing (error 404).
What I could suggest in order to prevent sharing your project publicly is to open a new support ticket from your telerik.com account.
Regards,
Martin Ivanov
Progress Telerik