googlemaps / js-markerclusterer

Create and manage clusters for large amounts of markers
https://googlemaps.github.io/js-markerclusterer/
Apache License 2.0
215 stars 83 forks source link

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

Open Ubaid-ur-Rehman opened 1 year ago

Ubaid-ur-Rehman commented 1 year ago
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.

wangela commented 1 year ago

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: 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 commented 1 year ago

Any update on this issue?

Ubaid-ur-Rehman commented 11 months ago

@wangela Still waiting for response.

usefulthink commented 11 months ago

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() 
});
BakerNoorzi commented 3 weeks ago

mhmmm this method doesn't work for me, did it work for you? @Ubaid-ur-Rehman do you have a workaround to get the mouse over functionality?