@@ -727,7 +727,7 @@ property available in ``Map``, ``Marker``, ``InfoWindow``, ``Polygon``, ``Polyli
727727 ));
728728
729729On 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:
731731
732732.. code-block :: javascript
733733
@@ -842,6 +842,45 @@ You can retrieve the map instance using the ``getMap()`` method, and change the
842842 </button>
843843 </div>
844844
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+
845884Backward Compatibility promise
846885------------------------------
847886
0 commit comments