googlemaps / googlemaps/js-markerclusterer

renderer not returning correct number of clusters

Open
#482 1 comment 1 reaction 1 assignee Claimed by @amuramoto View on GitHub
triage me type: bug
Dominant language
TypeScript
Stars
293
Forks
104
Avg merge
3m
Merged PRs (30d)
18

Description

I believe there is some lost behaviour between [@googlemaps/markerclustererplus](https://www.npmjs.com/package/@googlemaps/markerclustererplus) and [js-markerclusterer](https://github.com/googlemaps/js-markerclusterer)

the clusters returned from [@googlemaps/markerclustererplus](https://www.npmjs.com/package/@googlemaps/markerclustererplus) will also return a cluster for single markers. This allows me to set the clusters outside of google.map.Marker by using React.useState(), check for cluster.getMarkers().length > 1 and if so render a specific custom react component for the cluster icon and another custom react component for when getMarkers().length === 1.

The clusters returned from [@googlemaps/markerclusterer](https://github.com/googlemaps/js-markerclusterer) will ONLY return clusters where markers.length >= 2. This is the case even though `stats` will return a cluster count including clusters where markers.length === 1. Also, the protected clusters response from const markerClustererResponse = initialiseMarkerClusterer(map, propertyMarkers) will also include clusters where markers.length === 1.

[@googlemaps/markerclustererplus](https://www.npmjs.com/package/@googlemaps/markerclustererplus) IMPLEMENTATION

```
const StaticGoogleMap = ({properties = mockData}): JSX.Element => {
const [clusters, setClusters] = useState([]);

const onGoogleApiLoaded = ({map, maps}) => {
extendMapBoundsAndZoom(map, maps, properties);

const propertyMarkers = initialisePropertyMarkers(properties);
const markerClustererResponse = initialiseMarkerClusterer(map, propertyMarkers)

map.addListener('tilesloaded', () => {
setClusters(markerClustererResponse.getClusters());
});
}

return (



{clusters.map((cluster, index) => {
const propertyIndex = index + 1;

return cluster.getMarkers().length > 1 ? (

) : (

)
})}


);
};

export default StaticGoogleMap;
```

[@googlemaps/markerclusterer](https://github.com/googlemaps/js-markerclusterer) IMPLEMENTATION

```
const renderer = {
render(cluster, stats) {
**console.log(cluster)**; // RETURNS ONLY CLUSTERS WITH MARKERS.LENGTH >= 2.
**console.log(stats)**; // RETURNS stats.cluster NOT CONSISTENT WITH cluster response. It returns clusters where there is only one marker.

return new google.maps.Marker({
....
});
}
}

new MarkerClusterer({map, markers, renderer});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.