Skip to content

Commit

Permalink
fix: spider handling
Browse files Browse the repository at this point in the history
  • Loading branch information
turban committed Dec 23, 2019
1 parent a2948b5 commit 3b48c6a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/layers/Cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ class Cluster extends Layer {
this.setOpacity(this.options.opacity)
}

onRemove() {}
onRemove() {
this.spider.unspiderfy()
this.spider = null
}
}

export default Cluster
1 change: 0 additions & 1 deletion src/layers/DonutCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class DonutCluster extends Cluster {
for (const id in this.clusters) {
this.clusters[id].setOpacity(opacity)
}
this.setClusterOpacity(this.spider.getId(), true)
}
}

Expand Down
25 changes: 15 additions & 10 deletions src/layers/Spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,27 @@ const Spider = function(map, options) {
}

const spiderfy = (clusterId, lnglat, features) => {
spider.spiderfy()
spiderId = clusterId
if (clusterId !== spiderId) {
spider.spiderfy(lnglat, features)
spiderId = clusterId

map.on('click', unspiderfy)
}
}

const unspiderfy = () => {
spider.unspiderfy()
if (spiderId) {
spider.unspiderfy()

if (options.onClose) {
options.onClose(spiderId)
}
if (options.onClose) {
options.onClose(spiderId)
}

spiderId = null
}
spiderId = null

const remove = () => map.off('click', unspiderfy)
map.off('click', unspiderfy)
}
}

const isExpanded = clusterId => clusterId === spiderId

Expand Down Expand Up @@ -90,7 +96,6 @@ const Spider = function(map, options) {
spiderfy,
unspiderfy,
setOpacity,
remove,
isExpanded,
getId,
}
Expand Down

0 comments on commit 3b48c6a

Please sign in to comment.