Can someone explain why the markers aren't disappearing after 2sec?

Viewed 33

Code for the markers:

function getClickedLanLon(e) {

    var lat,
        lon,
        zoom;

    lat = e.latlng.lat;
    lon = e.latlng.lng;
    zoom = map.getZoom();

    marker = new L.Marker(new L.LatLng(lat, lon), {icon: CF});
    map.addLayer(marker);
    marker.bindPopup("Cat Spotted").addTo(map);

}

Code to get the markers to disappear after 2 sec:

map.on('click', getClickedLanLon);

var marker;
timeout_init();

function timeout_init() {
    marker = setTimeout(function(){
    $('.marker').hide(); },2000);
}

$( ".marker" ).click(function() {
    clearTimeout(myVar);
}.addto(map));
0 Answers
Related