Skip to main content
deleted 244 characters in body
Source Link

I am doing queries toI'm filtering a geojson layer by user inputs,and works fine for the first query, 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 queryfilter?,

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

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

var    user = L.geoJson(data, { 

        filter: function (feature, layer) {
        return feature.properties.nom_dpto == input;
    },

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

First filter

New filter (shouldn't have the first one

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 user = null;
    var input = document.getElementById("userInput").value;

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

var user = 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(user)
    map.removeLayer(boyaca)
});
$("#form").click(function() {
    console.log(map.hasLayer(user) + " ----") //first time returns false, second true
    map.removeLayer(alldeptos)
    map.removeLayer(boyaca)
    map.removeLayer(user)
    map.addLayer(user)
    console.log(map.hasLayer(caldas) + " +++++")//true always
    //map.removeLayer(user)
});
$("#boyaca").click(function() {
    map.addLayer(boyaca)
    map.removeLayer(alldeptos)
    map.removeLayer(user)
});
});     
}

I'm filtering a geojson layer by user inputs,and works fine for the first query, 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 filter?,

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

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

    user = L.geoJson(data, { 

        filter: function (feature, layer) {
            //console.log(feature)
            return feature.properties.nom_dpto == input;
        },

    });
    });
    $("#allbus").click(function() {
        map.addLayer(alldeptos)
        map.removeLayer(user)
    });
    $("#form").click(function() {
        map.removeLayer(alldeptos)
        map.removeLayer(user)
        map.addLayer(user)
    });
   });      
}

First filter

New filter (shouldn't have the first one

deleted 16 characters in body
Source Link

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 caldasuser = null;
    var input = document.getElementById("userInput").value;

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

var caldasuser = 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(caldasuser)
    map.removeLayer(boyaca)
});
$("#form").click(function() {
    console.log(map.hasLayer(caldasuser) + " ----") //first time returns false, second true
    map.removeLayer(alldeptos)
    map.removeLayer(boyaca)
    map.removeLayer(caldasuser)
    map.addLayer(caldasuser)
    console.log(map.hasLayer(caldas) + " +++++")//true always
    //map.removeLayer(caldasuser)
});
$("#boyaca").click(function() {
    map.addLayer(boyaca)
    map.removeLayer(alldeptos)
    map.removeLayer(caldasuser)
});
});     
}

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)
});
});     
}

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 user = null;
    var input = document.getElementById("userInput").value;

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

var user = 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(user)
    map.removeLayer(boyaca)
});
$("#form").click(function() {
    console.log(map.hasLayer(user) + " ----") //first time returns false, second true
    map.removeLayer(alldeptos)
    map.removeLayer(boyaca)
    map.removeLayer(user)
    map.addLayer(user)
    console.log(map.hasLayer(caldas) + " +++++")//true always
    //map.removeLayer(user)
});
$("#boyaca").click(function() {
    map.addLayer(boyaca)
    map.removeLayer(alldeptos)
    map.removeLayer(user)
});
});     
}
Source Link

Leaflet add layer by user input

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)
});
});     
}