无法删除谷歌地图中的事件侦听器
Cannot remove event listener in GoogleMaps
我有一个事件,我点击按钮就注册了:
var paths=[];
var mapPolylineListener=e.addEventToTarget(map,'click',function(event){
//keep adding points to the array
//draw the polyline if there are two points
//extend the polyline with this point once it has been drawn
}
e.addEventToTargetOnce(map,'rightclick',function(event){
console.log('Polyline right click event called');
if(typeof mapPolylineListener!='undefined')
{
console.log('stop drawing the map listener');
//do stuff here like encoding to geometry and making AJAX calls
paths=[];
mapPolylineListener=void 0;
}
事件模块定义以下函数:
addEventToTarget:function(onWhat,eventType,fn)
{
gmaps.event.addListener(onWhat,eventType,fn);
}
addEventToTargetOnce:function(onWhat,eventType,fn)
{
gmaps.event.addListenerOnce(onWhat,eventType,fn);
}
我正在使用requirejs模块,我使用模块来指定功能:
e=gmaps.event;
gmaps=window.google.maps;
在我的控制台中,它显示:
Polyline right click event called
而且检查似乎总是失败
if(typeof mapPolylineListener!='undefined')
所以,我尝试做一个!=null
并if(mapPolylineListener)
检查都失败了。
如何解决此问题以执行 if 块中的代码?
我不确定requirejs模块是如何工作的...由于addEventToTarget
没有返回任何内容,因此我将更改以下内容:
addEventToTarget:function(onWhat,eventType,fn)
{
var handle = gmaps.event.addListener(onWhat,eventType,fn);
return handle;
}
然后拨打removeListener(mapPolylineListener)
e.addEventToTargetOnce(map,'rightclick',function(event){...
相关文章:
- 如何在for循环中添加事件侦听器
- 未命中服务器发送的事件侦听器
- 如何覆盖原型中的事件侦听器
- 无法将事件侦听器附加到画布
- 如何在d3.js中自定义事件侦听器
- 在es6中,将带有回调的事件侦听器设置为可迭代的
- 事件侦听器未在chrome扩展中的options.js中启动
- IE8更改文本区域上的事件侦听器不工作
- 将事件侦听器添加到文档,而不是签入元素存在,然后添加事件侦听器
- javascript删除事件侦听器
- 我应该/如何清除mousemove JQuery事件侦听器
- 在JQuery中使用谷歌地图Api事件/侦听器
- 如何使用我的Jquery代码创建委托事件侦听器
- 'mousemove'画布中的事件侦听器-指针仅在最后一个矩形中更改
- 为什么此事件侦听器不工作
- 是否可以在数字输入框中的小按钮中添加事件侦听器
- 在Google Chrome扩展中添加事件侦听器
- SVG元素在转换后会丢失事件侦听器
- jQuery事件侦听器多次启动
- 如何在不删除类似侦听器的情况下从父对象中删除jQuery事件侦听器