Angular OpenLayers 6-从映射禁用事件侦听器

Angular OpenLayers 6-从映射禁用事件侦听器,angular,events,listener,openlayers,Angular,Events,Listener,Openlayers,如何禁用地图上的单击事件?我正在尝试使用map.un,但它不起作用。unByKey不起作用 import unByKey 'unByKey' is declared but its value is never read.ts(6133) Module '"/node_modules/@types/ol/Observable/index"' has no exported member 'unByKey' 使用复选框进行尝试,事件将添加到地图中,但当我取消选中复选框并选中复

如何禁用地图上的单击事件?我正在尝试使用map.un,但它不起作用。unByKey不起作用

import unByKey
'unByKey' is declared but its value is never read.ts(6133)
Module '"/node_modules/@types/ol/Observable/index"' has no exported member 'unByKey'
使用复选框进行尝试,事件将添加到地图中,但当我取消选中复选框并选中复选框时,它将被复制

function onClickDetail(evt) {
      console.log('Done');
};

    if (isCheck) 
    {
      map.on('singleclick',onClickDetail);
    }
    else
    {
      map.un('singleclick',onClickDetail);
    }
5次后重新激活复选框


您必须在函数的外部定义函数
onClickDetail
AddWMSLayer
。否则,它将始终是一个新函数“指针”,并且引用将不同。

您能再显示一点代码吗?e、 g.
map
变量和if/else所在的函数。有一个问题,没有方法将map重置为默认状态?我不知道。但我根本不是OpenLayers方面的专家。