I want to remove the map based on the selected condition.
.component.ts
dataChanged (selectsensor) {
console.log(selectsensor)
for( var j=0;j<selectsensor.length;j++){
for (var i =0; i< this.sensors.length;i++){
if(this.sensors[i].name == selectsensor[selectsensor.length - 1]){
if(this.sensorsarray.filter(sense=>sense.name == selectsensor[selectsensor.length - 1]).length > 0){
console.log(this.sensorsarray.filter(sense=>sense.name == selectsensor[selectsensor.length - 1]).length);
for(var t=0;t<this.sensorsarray.length;t++){
if(this.sensorsarray[t].name == selectsensor[selectsensor.length - 1]){
this.sensorsarray.splice(t);
}
}
console.log(this.sensorsarray);
alert("Value exists!")
}else{
this.sensorsarray.push(this.sensors[i]);
var v= "map"+ (this.sensorsarray.length - 1 )+"";
map[i] = L.map(v).setView([this.sensors[i].latitude,this.sensors[i].longitude], 11);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: ' <span style="font-size:17px">'+this.sensors[i].name+' </span>'
}).addTo(map[i]);
var latlng = L.latLng(this.sensors[i].latitude, this.sensors[i].longitude)
marker = L.marker(latlng, { icon: sensoricon }).addTo(map[i]);
circlemark[i] = L.circle(latlng, { radius: 5000, weight: 0 }).addTo(map[i]);
}
}
I want to remove the map when the condition is
this.sensorsarray.filter(sense=>sense.name == selectsensor[selectsensor.length - 1]).length > 0)
question from:
https://stackoverflow.com/questions/65938077/how-to-remove-or-empty-the-leaflet-map-based-on-the-condition 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…