请在这里有人可以帮助我 那是我的代码,我不知道为什么当我添加函数(AffichageChemin)时我只有地图而没有标记。 通常,代码将在greenIcon的最后5个位置显示标记,在redIcon的其他位置显示5个标记。
var markers;
markers = new L.LayerGroup().addTo(myfrugalmap);
let timer = TimerObservable.create(0, 10000);
let chemin = [];
this.subscription = timer.subscribe(t => {
this.raspiService.Localize().subscribe(
result => {
this.positions = result;
markers.clearLayers();
// mar.addTo(markers); with this ligne I have just the last position
AffichageChemin(this.positions, chemin, greenIcon, redIcon, markers);
myfrugalmap.removeLayer(mar);
}
)
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
function AffichageChemin(posi, chemin, greenIcon, redIcon, myfrugalmap) {
const x0 = 47.761488100;
const y0 = 2.367695100;
const px = 0.0000047816;
const py = 0.000007895;
let xpo = this.posi.x;
let ypo = this.posi.y;
chemin[0] = posi;
chemin[1] = posi;
chemin[2] = posi;
chemin[3] = posi;
let k = 0;
let j = 3;
chemin[k] = posi;
L.marker([x0 + xpo * px - 0.16 * px, y0 + ypo * py - 0.16 * py], {
icon: greenIcon
}).addTo(myfrugalmap);
while (k < 4) {
L.marker(chemin[k], {
icon: redIcon
}).addTo(myfrugalmap);
k++;
}
while (j > 0) {
chemin[j] = chemin[j - 1];
j--;
}
}