传单javascript-如何清除标记上的setTimeout?
我正在将这样的标记添加到地图中:传单javascript-如何清除标记上的setTimeout?,javascript,jquery,settimeout,leaflet,cleartimeout,Javascript,Jquery,Settimeout,Leaflet,Cleartimeout,我正在将这样的标记添加到地图中: map.addLayer(l), setTimeout(function() { map.removeLayer(l) }, 1e4), 10秒后,每个标记再次移除。现在我想实现这一点,当用户在这10秒内点击一个标记时,市场在地图上保持可见。到目前为止,我已经: l.on('click', function(e) { console.log(e); console.log(e.layer._leaflet_id); console.log(l
map.addLayer(l), setTimeout(function() {
map.removeLayer(l)
}, 1e4),
10秒后,每个标记再次移除。现在我想实现这一点,当用户在这10秒内点击一个标记时,市场在地图上保持可见。到目前为止,我已经:
l.on('click', function(e) {
console.log(e);
console.log(e.layer._leaflet_id);
console.log(l);
clearTimeout(e.layer._leaflet_id);
});
但它现在确实起作用了。你知道我如何实现这一点吗?你需要使用相关ID调用clearTimeout来取消设置超时
var myVar;
timeout_init();
function timeout_init() {
myVar = setTimeout(function(){
$('.marker').hide();
},5000);
}
$( ".marker" ).click(function() {
clearTimeout(myVar);
});
setTimeout
返回一个ID。您需要使用该ID调用clearTimeout
。@MikeC-我尝试通过调用clearTimeout(例如,layer.\u传单\u ID)来实现这一点;它具有setTimeout函数(l)的id。我还尝试了其他一切,但那些标记正在消失:(你确定要将其保存到\u传单\u id
?代码的顶部似乎没有表明这一点。