Skip to content

[Map] Add Clustering Algorithms - #2554

Merged
Kocal merged 1 commit into
symfony:2.xfrom
smnandre:map/feat-clustering
Aug 7, 2025
Merged

Kocal merged 1 commit into
symfony:2.xfrom
smnandre:map/feat-clustering

Conversation

@smnandre

@smnandre smnandre commented Feb 7, 2025 •

Copy link
Copy Markdown
Member
Q A
Bug fix? no
New feature? yes
Issues Fix #...
License MIT

Provide an interface and the first two PHP implementations of Clustering algorithms

  • GridClustering
  • Morton

Performances: < 1ms per 1000 Points *

  • tested on a non production server (... my iMac 😅 )

Next Step will require JS code.

But this is already usefull with PHP classes only, for whomever has large amount of markers

@smnandre
smnandre requested a review from Kocal as a code owner February 7, 2025 22:54
@carsonbot carsonbot added Bug Bug Fix Feature New Feature Map Status: Needs Review Needs to be reviewed labels Feb 7, 2025
@smnandre smnandre removed the Bug Bug Fix label Feb 7, 2025
@smnandre

smnandre commented Feb 9, 2025

Copy link
Copy Markdown
Member Author

(cannot ask for your review @Kocal as you're code owner, i would have otherwise ;) )

@Kocal Kocal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide some examples/use-cases and documentation? I'm not really sure to understand what you are solving right now.

When you say "next step is JS", do you mean https://github.com/Leaflet/Leaflet.markercluster & https://developers.google.com/maps/documentation/javascript/marker-clustering?hl=fr implementation?

@smnandre

smnandre commented Feb 9, 2025

Copy link
Copy Markdown
Member Author

You have 30000 markers in database. Sending them all in HTML is non sense. Clustering them in backend is definitively the way to go. That way you only send data you want to display, and fix the performance problem some people had with too many infowindow for instance.

Moreover it enforces the initial problem this bundle save: abstract the map services and manipulate data / UI from backend.

People that do want to use custom GoogleMaps SDK Methods wont install this Bundle, so -personal opinion- it’s a mistake to base our choices on what they would do there.

Also this would not coexist with Live trait for now.

So Next step is to continue the path and provide the missing link: making the LiveComponent able to react on map events: zoom or pan, clicks, etc.

That’s where I am right now, I Hope i’ve clarified my vision and goal for both this feature and more generally this bundle.

And would love to integrate this Into yours, if you have a différent one :)

@Kocal

Kocal commented Feb 9, 2025

Copy link
Copy Markdown
Member

Thanks for the explanations! I was asking because I didn't see any modifications on Map nor in the documentation, and so I was wondering what you really wanted to do with this PR.

@smnandre

smnandre commented Feb 9, 2025

Copy link
Copy Markdown
Member Author

Yeah i'm sorry I miss time and need to push more often, or i end with hundreds of "features ready at 80%" on my computer and never find time to release them.

Here, it's because two unrelated people asked me for the same exact thing last week, I've reopened my "geo" archives and started to prepare the foundations.

I'd like to end this (documentation included) before 2.24 😅

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Mar 4, 2025
@Kocal

Kocal commented Mar 4, 2025 •

Copy link
Copy Markdown
Member

After a small rebase, that would be perfect 🤓

@rvmourik

rvmourik commented Apr 3, 2025

Copy link
Copy Markdown

Just a question out of curiosity, will this be in 2.24? Thanks in advance

@mart-insiders

mart-insiders commented Jun 16, 2025 •

Copy link
Copy Markdown
Contributor

Hi @rvmourik @Kocal ,
I was wondering what the current state of this feature is and what is required to finish it.

At the moment some issues occur when implementing https://github.com/Leaflet/Leaflet.markercluster with the current leaflet bridge.
The only possible way to add a leaflet layer with clustered markers at the moment is via javascript.
This feels like unnecessary iterations over every marker in your stimulus controller.

`import { Controller } from "@hotwired/stimulus";

/* stimulusFetch: 'lazy' */
export default class extends Controller {
connect() {
this.element.addEventListener('ux:map:connect', this._onConnect);
}

disconnect() {
    this.element.removeEventListener('ux:map:connect', this._onConnect);
}

async _onConnect(event) {
  await import("leaflet.markercluster/dist/leaflet.markercluster-src.js");

  const { map } = event.detail;

  var clusterMarkerLayer = L.markerClusterGroup({
    spiderfyOnMaxZoom: true,
    showCoverageOnHover: false,
    zoomToBoundsOnClick: true
  });

  map.eachLayer(layer => {
    if (!(layer instanceof L.Marker)) {
        return;
    }

    clusterMarkerLayer.addLayer(layer);
    map.removeLayer(layer);
  })

  map.addLayer(clusterMarkerLayer);
}

}`

An issue which occurs is Events are not persisted when creating a marker on this different layer.
Would the following changes suffice to resolve this?

  • Implementation of a Layers object within the Map object or a reference in the Marker object.
  • Changing the doCreateMarker in map_controller.js to add a marker to a configured layer or as a layer to the map.

I would like to hear your opinion on this matter.

@dannyvw

dannyvw commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

@smnandre Do you perhaps have an update for this feature?

@smnandre

Copy link
Copy Markdown
Member Author

100% forgot this one : will rebase/clean tomorrow!

@smnandre
smnandre force-pushed the map/feat-clustering branch 2 times, most recently from 483e534 to f903389 Compare July 10, 2025 16:30
@smnandre

Copy link
Copy Markdown
Member Author

Cleaned a bit:

  • Cluster is now countable + iterable
  • remove getCenterLat / getCenterLng with getCenter(): Point
  • add PHP 8.1/2 support
  • removed readonly classes
  • rebased and changelog updated

Not sure if doc will follow first, or if i first open the PR to integrate this in the components (depending on the time i find)

@Kocal : to me it's ready

Thx @dannyvw for the poke :)

Comment thread src/Map/CHANGELOG.md Resolved
Comment thread src/Map/src/Cluster/Cluster.php Resolved
Comment thread src/Map/src/Cluster/Cluster.php Resolved
Comment thread src/Map/src/Cluster/Cluster.php Resolved
@smnandre

Copy link
Copy Markdown
Member Author

Thanks for all the feedback / suggestions @Kocal : all commited :)

@smnandre
smnandre force-pushed the map/feat-clustering branch from 8a21317 to 0b4eade Compare July 11, 2025 01:28
@Kocal
Kocal force-pushed the map/feat-clustering branch from 0b4eade to 9a98527 Compare August 7, 2025 21:45
@Kocal

Kocal commented Aug 7, 2025 •

Copy link
Copy Markdown
Member

Rebased, conflicts fixed, and added some documentation.

Will merge when CI becomes green

@Kocal
Kocal force-pushed the map/feat-clustering branch from 9a98527 to db2a416 Compare August 7, 2025 21:49
@Kocal

Kocal commented Aug 7, 2025

Copy link
Copy Markdown
Member

Thank you @smnandre.

@Kocal
Kocal merged commit ed402c4 into symfony:2.x Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature Map Status: Reviewed Has been reviewed by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants