Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add click output to clusterer #22020

Closed
maartenvanasperen opened this issue Feb 25, 2021 · 3 comments · Fixed by #22345
Closed

Add click output to clusterer #22020

maartenvanasperen opened this issue Feb 25, 2021 · 3 comments · Fixed by #22345
Assignees
Labels
area: google-maps feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@maartenvanasperen
Copy link

What are you trying to do?

I am trying to create a listener on a marker cluster. So I can get all markers from that clicked cluster event.
But It doesn't seem to work with a google maps example and I cant find any documentation about cluster clicks on https://github.com/angular/components/blob/master/src/google-maps/map-marker-clusterer/README.md.

What troubleshooting steps have you tried?

I tried to add a listener to the MapMarkerClusterer, see code below. The listener code is from this example: https://github.com/googlemaps/js-markerclustererplus/blob/df5fcb3dca33051ad6690093a5ca51e4d5c81de9/examples/events_example.html#L65
I also tried the default (click) from Angular, but I don't get an event.

Current code (not working)

// map.component.html

<map-marker-clusterer (click)="clusterClick()" [zoomOnClick]="false">
            <map-marker #marker="mapMarker" *ngFor="let result of results"
                        [position]="result.position"
                        [options]="markerOptions"
                        (mapClick)="selectMarker(marker, result)"
            >
            </map-marker>
       </map-marker-clusterer>
// map.component.ts

@ViewChild(MapMarkerClusterer, { static: false }) markerClusterer: MarkerClusterer;

for (const markerCluster of this.markerClusterer.getClusters()) {
          google.maps.event.addListener(markerCluster, 'click', c => {
              console.log(c.getMarkers());
          });
 }

Environment

  • Angular: 8
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu):

So how can I get a cluster click event to work, so I can get all the markers from that cluster and implement that in my code?

@maartenvanasperen maartenvanasperen added needs triage This issue needs to be triaged by the team troubleshooting This issue is not reporting an issue, but just asking for help labels Feb 25, 2021
@crisbeto
Copy link
Member

crisbeto commented Mar 1, 2021

Looks like the event is called clusterclick https://stackoverflow.com/questions/5710568/markerclusterer-on-click-zoom. We should have an Output for this on the MapMarkerClusterer component.

@crisbeto crisbeto added area: google-maps feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team troubleshooting This issue is not reporting an issue, but just asking for help labels Mar 1, 2021
@crisbeto crisbeto changed the title help(COMPONENT): Cluster click event in map marker clusterer is not working? Add click output to clusterer Mar 1, 2021
@maartenvanasperen
Copy link
Author

@crisbeto thanks for your reply! clusterclick is deprecated https://github.com/googlemaps/js-markerclustererplus/blob/82f1b7026b8458a719d1e59135adda4033cca8cd/src/markerclusterer.ts#L33-L34 that is why I used click.

And that library is used, as seen here: https://github.com/angular/components/tree/master/src/google-maps/map-marker-clusterer

The MapMarkerClusterer component wraps the MarkerClusterer class from the Google Maps JavaScript MarkerClustererPlus Library.

@crisbeto crisbeto self-assigned this Mar 25, 2021
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 25, 2021
Adds an event that emits when a cluster has been clicked.

Fixes angular#22020.
wagnermaciel pushed a commit that referenced this issue Mar 29, 2021
Adds an event that emits when a cluster has been clicked.

Fixes #22020.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: google-maps feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants