@@ -727,7 +727,7 @@ property available in ``Map``, ``Marker``, ``InfoWindow``, ``Polygon``, ``Polyli
727
727
));
728
728
729
729
On the JavaScript side, you can access these extra data by listening to ``ux:map:pre-connect ``,
730
- ``ux:map:connect ``, ``ux:map:*:before-create ``, ``ux:map:*:after-create `` events::
730
+ ``ux:map:connect ``, ``ux:map:*:before-create ``, ``ux:map:*:after-create `` events:
731
731
732
732
.. code-block :: javascript
733
733
@@ -842,6 +842,45 @@ You can retrieve the map instance using the ``getMap()`` method, and change the
842
842
</button>
843
843
</div>
844
844
845
+ Advanced: Clusters
846
+ ------------------
847
+
848
+ .. versionadded :: 2.29
849
+
850
+ Clusters were added in UX Map 2.29.
851
+
852
+ A cluster is a group of points that are close to each other on a map.
853
+
854
+ Clustering reduces clutter and improves performance when displaying many points.
855
+ This makes maps easier to read and faster to render.
856
+
857
+ UX Map supports two algorithms:
858
+
859
+ - **Grid **: Fast, divides map into cells.
860
+ - **Morton **: Uses Z-order curves for spatial locality.
861
+
862
+ Create a clustering algorithm, cluster your points, and add cluster markers::
863
+
864
+ use Symfony\UX\Map\Cluster\GridClusteringAlgorithm;
865
+ use Symfony\UX\Map\Cluster\MortonClusteringAlgorithm;
866
+ use Symfony\UX\Map\Point;
867
+
868
+ // Initialize clustering algorithm
869
+ $clusteringAlgorithm = new GridClusteringAlgorithm();
870
+ // or
871
+ // $clusteringAlgorithm = new MortonClusteringAlgorithm();
872
+
873
+ // Create clusters of points
874
+ $points = [new Point(48.8566, 2.3522), new Point(45.7640, 4.8357), /* ... */];
875
+ $clusters = $clusteringAlgorithm->cluster($points, zoom: 5.0);
876
+
877
+ // Iterate over each cluster
878
+ foreach ($clusters as $cluster) {
879
+ $cluster->getCenter(); // A Point, representing the cluster center
880
+ $cluster->getPoints(); // A list of Point
881
+ $cluster->count(); // The number of points in the cluster
882
+ }
883
+
845
884
Backward Compatibility promise
846
885
------------------------------
847
886
0 commit comments