You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reviewed clustering point data web sdk. resolved 12 issues. improved overall score by 6 points - style improved from 83 to 100. clarity improved from 75 to 91. tone improved from 83 to 88.
Copy file name to clipboardExpand all lines: articles/azure-maps/clustering-point-data-web-sdk.md
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Clustering point data on a map | Microsoft Azure Maps
3
-
description: In this article, you will learn how to cluster point data and render it on a map using the Microsoft Azure Maps Web SDK.
3
+
description: In this article, you'll learn how to cluster point data and render it on a map using the Microsoft Azure Maps Web SDK.
4
4
author: rbrundritt
5
5
ms.author: richbrun
6
6
ms.date: 07/29/2019
@@ -13,15 +13,15 @@ ms.custom: codepen
13
13
14
14
# Clustering point data
15
15
16
-
When visualizing many data points on the map, points overlap each other, the map looks cluttered and it becomes difficult to see and use. Clustering of point data can be used to improve this user experience. Clustering point data is the process of combining point data that are near each other and representing them on the map as a single clustered data point. As the user zooms into the map, the clusters break apart into their individual data points.
16
+
When visualizing many data points on the map, data points may overlap over each other. The overlap may cause the map may become unreadable and difficult to use. Clustering point data is the process of combining point data that are near each other and representing them on the map as a single clustered data point. As the user zooms into the map, the clusters break apart into their individual data points. When you work with large number of data points, use the clustering processes to improve your user experience.
Clustering can easily be enabled on the `DataSource` class by setting the `cluster` option to true. Additionally, the pixel radius to select nearby points to combine into a cluster can be set using the `clusterRadius` and a zoom level can be specified at which to disable the clustering logic using the `clusterMaxZoom` option. Here is an example of how to enable clustering in a data source.
24
+
Enable clustering in the `DataSource` class by setting the `cluster` option to true. Set `ClusterRadius`to selects nearby points and combines them into a cluster. The value of `ClusterRadius` is in pixels. Use `clusterMaxZoom` to Specify a zoom level at which to disable the clustering logic. Here is an example of how to enable clustering in a data source.
25
25
26
26
```javascript
27
27
//Create a data source and enable clustering.
@@ -39,9 +39,9 @@ var datasource = new atlas.source.DataSource(null, {
39
39
```
40
40
41
41
> [!TIP]
42
-
> If two data points are close together on the ground, it is possible the cluster will never break apart, no matter how close the user zooms in. To address this, you can set the `clusterMaxZoom` option of the data source which specifies at the zoom level to disable the clustering logic and simply display everything.
42
+
> If two data points are close together on the ground, it's possible the cluster will never break apart, no matter how close the user zooms in. To address this, you can set the `clusterMaxZoom` option to disable the clustering logic and simply display everything.
43
43
44
-
The `DataSource` class also has the following methods related to clustering:
44
+
Here are additional methods that the `DataSource` class provides for clustering:
45
45
46
46
| Method | Return type | Description |
47
47
|--------|-------------|-------------|
@@ -51,7 +51,9 @@ The `DataSource` class also has the following methods related to clustering:
51
51
52
52
## Display clusters using a bubble layer
53
53
54
-
A bubble layer is a great way to render clustered points as you can easily scale the radius and change the color them based on the number of points in the cluster by using an expression. When displaying clusters using a bubble layer, you should also use a separate layer for rendering unclustered data points. It is often nice to also be able to display the size of the cluster on top of the bubbles. A symbol layer with text and no icon can be used to achieve this behavior.
54
+
A bubble layer is a great way to render clustered points. Use expressions to scale the radius and change the color based on the number of points in the cluster. If you display clusters using a bubble layer, then you should use a separate layer to render unclustered data points.
55
+
56
+
To display the size of the cluster on top of the bubble, use a symbol layer with text, and don't use an icon.
55
57
56
58
<br/>
57
59
@@ -62,7 +64,9 @@ A bubble layer is a great way to render clustered points as you can easily scale
62
64
63
65
## Display clusters using a symbol layer
64
66
65
-
When visualizing the point data using the Symbol layer, by default it will automatically hide symbols that overlap each other to create a cleaner experience, however this may not be the desired experience if you want to see the density of data points on the map. Setting the `allowOverlap` option of the Symbol layers `iconOptions` property to `true` disables this experience but will result in all the symbols being displayed. Using clustering allows you to see the density of all the data while creating a nice clean user experience. In this sample, custom symbols will be used to represent clusters and individual data points.
67
+
When visualizing data points, the symbol layer automatically hides symbols that overlap each other to ensure a cleaner user interface. This default behavior might be undesirable if you want to show the data points density on the map. However, these settings can be changed. To display all symbols, set the `allowOverlap` option of the Symbol layers `iconOptions` property to `true`.
68
+
69
+
Use clustering to show the data points density while keeping a clean user interface. The sample below shows you how to add custom symbols and represent clusters and individual data points using the symbol layer.
66
70
67
71
<br/>
68
72
@@ -73,7 +77,7 @@ When visualizing the point data using the Symbol layer, by default it will autom
73
77
74
78
## Clustering and the heat maps layer
75
79
76
-
Heat maps are a great way to display the density of data on the map. This visualization can handle a large number of data points on its own, but it can handle even more data if the data points are clustered and the cluster size is used as the weight of the heat map. Set the `weight` option of the heat map layer to `['get', 'point_count']` to achieve this. When the cluster radius is small, the heat map will look nearly identical to a heat map using the unclustered data points but will perform much better. However, the smaller the cluster radius, the more accurate the heat map will be but with less of a performance benefit.
80
+
Heat maps are a great way to display the density of data on the map. This visualization method can handle a large number of data points on its own. If the data points are clustered and the cluster size is used as the weight of the heat map, then the heat map can handle even more data. To achieve this option, set the `weight` option of the heat map layer to `['get', 'point_count']`. When the cluster radius is small, the heat map will look nearly identical to a heat map using the unclustered data points, but it will perform much better. However, the smaller the cluster radius, the more accurate the heat map will be, but with fewer performance benefits.
77
81
78
82
<br/>
79
83
@@ -84,16 +88,16 @@ Heat maps are a great way to display the density of data on the map. This visual
84
88
85
89
## Mouse events on clustered data points
86
90
87
-
When mouse events occur on a layer that contain clustered data points, the clustered data point will be returned to the event as a GeoJSON point feature object. This point feature will have the following properties:
91
+
When mouse events occur on a layer that contains clustered data points, the clustered data point return to the event as a GeoJSON point feature object. This point feature will have the following properties:
|`cluster`| boolean | Indicates if feature represents a cluster. |
92
96
|`cluster_id`| string | A unique ID for the cluster that can be used with the DataSource `getClusterExpansionZoom`, `getClusterChildren`, and `getClusterLeaves` methods. |
93
97
|`point_count`| number | The number of points the cluster contains. |
94
-
|`point_count_abbreviated`| string | A string that abbreviates the `point_count` value if it is long. (for example, 4,000 becomes 4K) |
98
+
|`point_count_abbreviated`| string | A string that abbreviates the `point_count` value if it's long. (for example, 4,000 becomes 4K) |
95
99
96
-
This example takes a bubble layer that renders cluster points and adds a click event that when triggered, calculate, and zoom the map to the next zoom level at which the cluster will break apartusing the `getClusterExpansionZoom` method of the `DataSource` class and the `cluster_id` property of the clicked clustered data point.
100
+
This example takes a bubble layer that renders cluster points and adds a click event. When the click event triggers, the code calculates and zooms the map to the next zoom level, at which the cluster breaks apart. This functionality is implemented using the `getClusterExpansionZoom` method of the `DataSource` class and the `cluster_id` property of the clicked clustered data point.
97
101
98
102
<br/>
99
103
@@ -104,7 +108,7 @@ This example takes a bubble layer that renders cluster points and adds a click e
104
108
105
109
## Display cluster area
106
110
107
-
The point data that a cluster represents is spread over an area. In this sample when the mouse is hovered over a cluster, the individual data points it contains (leaves) will be used to calculate a convex hull and displayed on the map to show the area. All points contained in a cluster can be retrieved from the data source using the `getClusterLeaves` method. A convex hull is a polygon that wraps a set of points like an elastic band and can be calculated using the `atlas.math.getConvexHull` method.
111
+
The point data that a cluster represents is spread over an area. In this sample when the mouse is hovered over a cluster, two main behaviors occur. First, the individual data points contained in the cluster will be used to calculate a convex hull. Then, the convex hull will be displayed on the map to show an area. A convex hull is a polygon that wraps a set of points like an elastic band and can be calculated using the `atlas.math.getConvexHull` method. All points contained in a cluster can be retrieved from the data source using the `getClusterLeaves` method.
108
112
109
113
<br/>
110
114
@@ -115,9 +119,9 @@ The point data that a cluster represents is spread over an area. In this sample
115
119
116
120
## Aggregating data in clusters
117
121
118
-
Often clusters are represented using a symbol with the number of points that are within the cluster, however sometimes it is desirable to further customize the style of clusters based on some metric, like the total revenue of all points within a cluster. With cluster aggregates custom properties can be created and populated using an [aggregate expression](data-driven-style-expressions-web-sdk.md#aggregate-expression) calculation. Cluster aggregates can be defined in `clusterProperties` option of the `DataSource`.
122
+
Often clusters are represented using a symbol with the number of points that are within the cluster. But, sometimes it's desirable to customize the style of clusters with additional metrics. With cluster aggregates, custom properties can be created and populated using an [aggregate expression](data-driven-style-expressions-web-sdk.md#aggregate-expression) calculation. Cluster aggregates can be defined in `clusterProperties` option of the `DataSource`.
119
123
120
-
The following sample uses an aggregate expression to calculate a count based on the entity type property of each data point in a cluster.
124
+
The following sample uses an aggregate expression. The code calculates a count based on the entity type property of each data point in a cluster. When a user clicks on a cluster, a popup shows with additional information about the cluster.
0 commit comments