bug出现在我想移除给地图添加的监听事件,移除失败。最后发现是给map.off()方法传递的this指针异常,导致找不到要删除的函数:
initListenMap(val, type) {
const map = this.sdMap.map
const that = this
const zoomevent = function () {
const code = that.params.code
that.domStr.zoom = that.sdMap.zoom
if (that.params.clusterKey) {
that.params.clusterKey = false
return
}
that.requestCluster(code, 2)
}
const dragendevent = function () {
const code = that.params.code
that.requestCluster(code, 1)
}
if (val) {
map.on('zoomend', zoomevent)
map.on('dragend', dragendevent)
} else {
map.off('zoomend', zoomevent)
map.off('dragend', dragendevent)
}
},
将zoomevent和dragendevent事件放到option api methods中即可。