Angular : 删除 2 个标记之间的 Leaflet 折线

Angular : remove a Leaflet polyline between 2 markers

当我使用 interval 更新数据 json 坐标时,我的最后一个点和第一个点之间的连接路径穿过数据的原始路径 json。

那么如何删除最后一个点标记和第一个点标记之间的 "connection path"?

代码:

export class MapTrackBeforPage implements OnInit {
    map: Map;
    poly:L.Polyline

    protected points: { lat: number, lng: number }[] = [];

    constructor(
        private http: HTTP,
       public zone : NgZone) {

    }

    ionViewDidEnter() {
        this.getmarker()
    }


    async getmarker() {

        this.zone.runTask(()=>{
            setInterval(()=>{
                this.http.get('xxxxxxxxxxxxxxxxxx'', {}, {})
                .then(data => {
                                                           -------------Polyline path ---------
            for (let datas of JSON.parse(data.data)['trail']) {

            this.points.push({ lat: datas.lat, lng: datas.lng })

            let poly = new L.Polyline([this.points], { color: 'red', weight: 3}).addTo(this.map);


            }

             })
            },5000)
        })

    }

}

路径如你所愿,但在你的数据中有一点问题。看我的照片,我认为您的数据中有第一个点两次。使用辅助函数简单地删除冗余。 我发现另一个问题,你有一个区间函数,你没有删除旧坐标,当你得到新坐标时,这些点就会出现问题。