텐센트 맵에 여러 Marker 추가

6779 단어
// 
        init(){
            var self = this;
            this.wSize = {
                wHeight: window.innerHeight-80,
                wWidth: window.innerWidth
            }
            // 
            var citylocation = new qq.maps.CityService({
                complete : function(result){
                    self.map.setCenter(result.detail.latLng);
                }
            });
            citylocation.searchLocalCity();
            var center = new qq.maps.LatLng(39.914850, 116.403765);
            this.map = new qq.maps.Map(document.getElementById("container"),
                {
                    center: center,
                    zoom: 13
                }
            );
            // qq.maps.event.addDomListener(this.map, 'click', function(event) {
            //     self.addMarker(event.latLng);
            // });
        },

 
// 
        workersPos(){
            console.log(this.city3,this.value)
            var self = this;
            axios.get('http://work.121soft.cn:8089/lbs/lbs/public/index.php/api/servicer/getsonmap',{
                params:{
                    rid:this.city3,
                    sid:this.value
                }
            }).then((response)=>{
                console.log(response);
                this.workersInfor = response.data.data; 
                this.setMarker();
            }).catch((response)=>{
                console.log(response)
            })
        },

 
        // 
        deleteOverlays() {
            if (this.markersArray) {
                for (i in this.markersArray) {
                    this.markersArray[i].setMap(null);
                }
                this.markersArray.length = 0;
            }
        },
        // 
        setMarker(){
            this.deleteOverlays();
            var self = this;
            this.latlngs2 = [];
            for (var prop in this.workersInfor) {
                this.latlngs2.push('new qq.maps.LatLng('+this.workersInfor[prop].lat+','+this.workersInfor[prop].lng+')');
            }
            console.log(this.workersInfor)
            for(var i = 0;i < this.latlngs2.length; i++) {
                (function(n){
                    var marker = new qq.maps.Marker({
                        position: eval(self.latlngs2[n]),
                        map: self.map
                    });
                    self.markersArray.push(marker);
                })(i);
            }
        },

 
다음으로 전송:https://www.cnblogs.com/hzx-5/p/9808865.html

좋은 웹페이지 즐겨찾기