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

After creating a MarkerClusterer unable to register 'mouseover' event on the clusterer object #715

Open
Ubaid-ur-Rehman opened this issue Aug 4, 2023 · 4 comments
Labels
type: question Request for information or clarification. Not an issue.

Comments

@Ubaid-ur-Rehman
Copy link

Ubaid-ur-Rehman commented Aug 4, 2023

this.googleInfoWindowInvisibleMarkers =new MarkerClusterer({ map : this.map, markers:this.clusterMarkers , renderer : renderer });

this.googleInfoWindowInvisibleMarkers.addListener('mouseover', (cluster) => {
  infoWindow.close();
  let content = '<div id="hover-element">';
  for (let i = 0; i < cluster.length; i++) {
    content += `${cluster[i].title} <br/>`;
  }
  content += '</div>';
  infoWindow.setContent(content);
  infoWindow.open(cluster.getMap(), cluster);
  this.googleMapLastHoverInfoWindow = infoWindow;
});

I want to show some data in the info window after creating the clusterer but the event is not being registered.

@Ubaid-ur-Rehman Ubaid-ur-Rehman added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Aug 4, 2023
@Ubaid-ur-Rehman Ubaid-ur-Rehman changed the title After creating a MarkerClusterer unable to register 'mouseover' event on the clusterer obkec After creating a MarkerClusterer unable to register 'mouseover' event on the clusterer object Aug 4, 2023
@wangela
Copy link
Member

wangela commented Aug 4, 2023

If you would like to upvote the priority of this issue, please comment below or react on the original post above with 👍 so we can see what is popular when we triage.

@Ubaid-ur-Rehman Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

@Ubaid-ur-Rehman
Copy link
Author

Any update on this issue?

@Ubaid-ur-Rehman
Copy link
Author

@wangela Still waiting for response.

@usefulthink
Copy link
Contributor

The Markerclusterer itself doesn't provide any events for clusters and/or markers except for the clusteringbegin / clusteringend and click events.

What you can do is provide your own renderer implementation to the Markerclusterer that will create the cluster markers with the event-handlers set up. Just as a simple example:

import {DefaultRenderer} from '@googlemaps/js-markerclusterer';

class RendererWithEvents extends DefaultRenderer {
  render(cluster: Cluster, stats: ClusterStats, map: google.maps.Map): Marker {
    const marker = super.render(cluster, stats, map);

    // handle events for the newly created marker
    marker.addListener('mouseover', () => {
      console.log('cluster hovered!', cluster) 
    });

    return marker;
  }
}

const clusterer = new MarkerClusterer({ 
  map, 
  markers, 
  renderer: new RendererWithEvents() 
});

@usefulthink usefulthink added type: question Request for information or clarification. Not an issue. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. triage me I really want to be triaged. labels Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants