问题描述:
百度地图 api 一个怪问题(removeEventListener 部分不好使)
详细描述见 : http://www.douban.com/note/330806232/?type=like
为两个或多个事件增加同名函数test1_func,再分别remove时,第一个会失效。
map.addEventListener("zoomend", test1_func);
map.addEventListener("dragend", test1_func);
map.removeEventListener("zoomend", test1_func);
map.removeEventListener("dragend", test1_func);
map.addEventListener("zoomend", test2_func);
map.addEventListener("dragend", test2_func);
解决方案:将同名函数换成每个事件一个函数名,就好了啊。
map.addEventListener("zoomend", test11_func);
map.addEventListener("dragend", test1_func);map.removeEventListener("zoomend", test11_func);
map.removeEventListener("dragend", test1_func);
map.addEventListener("zoomend", test22_func);
map.addEventListener("dragend", test2_func);
function test1_func(){
alert(1);
}
function test2_func(){
alert(2);
}
function test11_func(){
alert(11);
}
function test22_func(){
alert(22);
}
完善api:增加向google一样的
EventWrapper.clearInstanceListeners(map); // 清除map实例所有的事件监听函数
详见:http://blog.csdn.net/sup_heaven/article/details/8461569