Angular:删除2个标记之间的传单多义线

问题描述 投票:0回答:1

[虽然我正在使用interval更新数据json坐标,但我有最后一个点与第一个点之间的连接路径越过了数据json的原始路径。

enter image description here

那么,如何删除最后一个和第一个点标记之间的“连接路径”?

代码:

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)
        })

    }

}
angular leaflet polyline
1个回答
1
投票
这些路径可以根据需要工作,但是数据中存在一些问题。看我的照片,我认为您的数据中有两次是第一点。使用辅助功能可以轻松删除冗余。enter image description here而且我发现另一个问题,您有一个区间函数,并且您不删除旧坐标,而当您获得新坐标时,这些问题就产生了。
© www.soinside.com 2019 - 2024. All rights reserved.