I am doing queries to a geojson layer, and works fine for the first query, the problem is with the second so on. starting from the second query brings me the last layer plus the new one I already tried map.removeLayer(layer) any ideas on how can I get only the new query?


    function query(data) {
        var input=null;
        var caldas = null;
        var input = document.getElementById("userInput").value;

    departamentos.then(function(data) {
    var alldeptos = L.geoJson(data);

    var caldas = L.geoJson(data, {
        filter: function (feature, layer) {
            return feature.properties.nom_dpto == input;
        },

    });
    var boyaca = L.geoJson(data, {
        filter: function(feature, layer) {
            return feature.properties.nom_dpto == "BOYACA";
        },
    });
    $("#all").click(function() {
        map.addLayer(alldeptos)
        map.removeLayer(caldas)
        map.removeLayer(boyaca)
    });
    $("#form").click(function() {
        console.log(map.hasLayer(caldas) + " ----") //first time returns false, second true
        map.removeLayer(alldeptos)
        map.removeLayer(boyaca)
        map.removeLayer(caldas)
        map.addLayer(caldas)
        console.log(map.hasLayer(caldas) + " +++++")//true always
        //map.removeLayer(caldas)
    });
    $("#boyaca").click(function() {
        map.addLayer(boyaca)
        map.removeLayer(alldeptos)
        map.removeLayer(caldas)
    });
    });     
    }