[英]leaflet javascript - how to clearTimeout a setTimeout on a marker?
我在地圖上添加了這樣的標記:
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來取消setTimeout。
var myVar;
timeout_init();
function timeout_init() {
myVar = setTimeout(function(){
$('.marker').hide();
},5000);
}
$( ".marker" ).click(function() {
clearTimeout(myVar);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.