Last active
April 29, 2017 19:05
-
-
Save davidroman0O/1458d454721624c7c46630259843c394 to your computer and use it in GitHub Desktop.
Medium Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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