删除 Cesium 中的事件监听器
我进行了相当多的搜索,以找到在 Cesium 中删除事件侦听器的正确方法。我相信我的困惑在于是否将 Cesium 事件视为常规 dom 事件(由于缺乏关于 javascript 中一般事件的知识)。我正在创建一个屏幕空间事件,如下所示:
var handler = new Cesium.ScreenSpaceEventHandler(canvas);
handler.setInputAction(function (movement) {
var picked = scene.pick(movement.endPosition);
if (Cesium.defined(picked) && picked.id === someEntity) {
labelEntity.position = someEntity.position;
labelEntity.label.show = true;
} else {
labelEntity.label.show = false;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
我的问题是,如何删除此事件? handler.destroy() 是否会删除与处理程序关联的所有事件侦听器,或者我是否必须通过指向 cesium 映射 dom 元素并调用 removeEventListener
来删除事件侦听器它?如果是这种情况,应该将哪些参数传递给 removeEventListener
?
I searched quite a bit to find out the correct way to remove event listeners in Cesium. I believe the confusion I have is around whether to treat Cesium events as regular dom events (due to a lack of knowledge about events in general in javascript). I am creating a screen space event like below:
var handler = new Cesium.ScreenSpaceEventHandler(canvas);
handler.setInputAction(function (movement) {
var picked = scene.pick(movement.endPosition);
if (Cesium.defined(picked) && picked.id === someEntity) {
labelEntity.position = someEntity.position;
labelEntity.label.show = true;
} else {
labelEntity.label.show = false;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
My question is, how can I remove this event? Is handler.destroy()
removes all the event listeners associated with handler, or do I specifically have to remove event listeners by pointing to the cesium map dom element and calling removeEventListener
on it? If that's the case, what parameters should be passed to removeEventListener
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
removeInputAction
的参数为只是type
和可选的modifer
,看起来您没有使用修饰符(SHIFT 键、ALT 键等),因此对于您上面发布的代码,删除将是:
The parameters for
removeInputAction
are just thetype
and optionally themodifer
, and it looks like you're not using the modifier (SHIFT key, ALT key etc.)So for the code you posted above, the removal would be: