Skip to content

Instantly share code, notes, and snippets.

@davidroman0O
Last active April 29, 2017 19:05
Show Gist options
  • Save davidroman0O/1458d454721624c7c46630259843c394 to your computer and use it in GitHub Desktop.
Save davidroman0O/1458d454721624c7c46630259843c394 to your computer and use it in GitHub Desktop.
Medium Gist
import supercluster from 'supercluster';
componentWillReceiveProps(nextProps) {
const markers = this.createMarkersForLocations(nextProps);
if (markers && Object.keys(markers)) {
const clusters = {};
this.setState({
mapLock: true
});
Object.keys(markers).forEach(categoryKey => {
// Recalculate cluster trees
const cluster = supercluster({
radius: 60,
maxZoom: 16,
});
cluster.load(markers[categoryKey]);
clusters[categoryKey] = cluster;
});
this.setState({
clusters,
mapLock: false
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment