Skip to content

Commit

Permalink
fix: initial update of donut clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
turban committed Jan 6, 2020
1 parent f87de9c commit cc9eb90
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/layers/DonutCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DonutCluster extends Cluster {

const mapgl = this.getMapGL()

mapgl.on('data', this.onData)
mapgl.on('sourcedata', this.onSourceData)
mapgl.on('move', this.updateClusters)
mapgl.on('moveend', this.updateClusters)

Expand All @@ -90,7 +90,7 @@ class DonutCluster extends Cluster {

const mapgl = this.getMapGL()

mapgl.off('data', this.onData)
mapgl.off('sourcedata', this.onSourceData)
mapgl.off('move', this.updateClusters)
mapgl.off('moveend', this.updateClusters)

Expand All @@ -102,8 +102,9 @@ class DonutCluster extends Cluster {
this.clusters = {}
}

onData = evt => {
if (evt.sourceId === this.getId() && evt.isSourceLoaded) {
onSourceData = evt => {
if (evt.sourceId === this.getId() && this.getSourceFeatures().length) {
this.getMapGL().off('sourcedata', this.onSourceData)
this.updateClusters()
}
}
Expand Down Expand Up @@ -154,6 +155,11 @@ class DonutCluster extends Cluster {
}
}
}

// Returns source features
getSourceFeatures() {
return this.getMapGL().querySourceFeatures(this.getId())
}
}

export default DonutCluster

0 comments on commit cc9eb90

Please sign in to comment.