如何根据条件移除或清空传单地图
How to remove or empty the leaflet map based on the 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]);
}
}
我想在条件为
this.sensorsarray.filter(sense=>sense.name == selectsensor[selectsensor.length - 1]).length > 0)
可以通过以下方式删除地图:
map.remove()
那么它应该看起来像你:
this.sensorsarray.filter(sense=>sense.name == selectsensor[selectsensor.length - 1]).length > 0){
map[i].remove()
}
我想根据所选条件删除地图。
.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]);
}
}
我想在条件为 this.sensorsarray.filter(sense=>sense.name == selectsensor[selectsensor.length - 1]).length > 0)
可以通过以下方式删除地图:
map.remove()
那么它应该看起来像你:
this.sensorsarray.filter(sense=>sense.name == selectsensor[selectsensor.length - 1]).length > 0){
map[i].remove()
}