我正在向我的 map 添加这样的标记:
map.addLayer(l), setTimeout(function() {
map.removeLayer(l)
}, 1e4),
10 秒后再次删除每个标记。现在我想实现的是,当用户在这 10 秒内点击市场在 map 上保持可见的标记时。到目前为止,我有:
l.on('click', function(e) {
console.log(e);
console.log(e.layer._leaflet_id);
console.log(l);
clearTimeout(e.layer._leaflet_id);
});
但它现在确实有效。知道如何实现这一点吗?
最佳答案
您需要使用相关ID调用clearTimeout来取消setTimeout。
var myVar;
timeout_init();
function timeout_init() {
myVar = setTimeout(function(){
$('.marker').hide();
},5000);
}
$( ".marker" ).click(function() {
clearTimeout(myVar);
});
关于javascript - 传单javascript - 如何清除标记上的setTimeout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29310798/