Looking for a solution to add and clear geojson data with the click of a button? Check out this code snippet:
<input type="button" value="ruta vista imss" onclick="rutavistaimss()" >
<script>
var rutavs = {
"type": "Feature",
"properties": {
"name": "ruta vista imss"
},
"geometry": {
"type": "LineString",
"coordinates": rutavistaimsscoords
}
};
var rutavistaimss1 = L.geoJson(rutavs);
let flag = true
function rutavistaimss() {
if (flag) {
// your logic
map.addLayer( rutavistaimss1 );
}
flag = !flag
map.removeLayer( rutavistaimss1 );
}
</script>
Consider incorporating jQuery for additional functionality.