This is a migrated thread and some comments may be shown as answers.

Clustering in the VisualisationLayer

1 Answer 119 Views
Map
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 12 Sep 2014, 02:51 PM
Hi,

Can you explain the following settings; the documentation is not very clear

AutoCalculateClusteringThreshold = true;
ClusteringEnabled = true;
ClusteringEnabledThreshold = 18;
ClusteringEnabledThresholdMinItems = 100;


I have changed my code to use the VisualisationLayer instead of a DynamicLayer to try and improve performance.  I used to handle the clustering of my points in the code, but now want to use your mechanism.

My datasource may contain say 5000 pin points, all in the uk.
When I zoom to see all of the uk, I would like the points clustered
When I zoom in, I would like to see the points clustered until we get to a point where we can safely display the points e.g. if there are less than 100 visible points in the viewport.
At the moment, I seem to get clustering all the time, and it shows clusters even when there is just a single point

Thanks
Simon

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 17 Sep 2014, 02:22 PM
Hello Simon,

The ClusteringEnabledThreshold property defines the maximum zoom level for which the clustering functionality. For example if the you set the property to 10 and you zoom in until the zoom level is 11, the clustering will be disabled and all items will be displayed. The ClusteringEnabledThreshold won't be respected by the RadMap if the AutoCalculateClusteringThreshold  property is set to True.

When RadMap calculates the clustering threshold automatically (the AutoCalculateClusteringThreshold is set to True), it uses the ClusteringEnabledThresholdMinItems property to detect whether the number of the items in all clusters is less or equal to its value. If the number of items is smaller than the ClusteringEnabledThresholdMinItems for a specific zoom level, then this level will be used as clustering threshold, which means that clusters will never be generated after this zoom level.

In order to achieve your requirement you can subscribe for the ZoomChanged event of RadMap and in its handler count the visible items. If the point's are less than 100 disable the clustering, otherwise enable it. Here is an example in code:

private void RadMap1_ZoomChanged_1(object sender, System.EventArgs e)
{
    if (this.VisualizationLayer1 == null)
    {
        return;
    }
 
    int visiblePointsCount = 0;
    var mapViewPort = this.RadMap1.LocationRect;
    foreach (object item in this.VisualizationLayer1.Items)
    {
        var point = item as PointData;
        if (mapViewPort.Contains(point.Location))
        {
            visiblePointsCount++;
        }
    }
 
    if (visiblePointsCount < 100 && this.VisualizationLayer1.ClusteringEnabled)
    {
        this.VisualizationLayer1.ClusteringEnabled = false;
    }
    else
    {
        this.VisualizationLayer1.ClusteringEnabled = true;
    }
}

Please let me know if this helps.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Map
Asked by
Simon
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or