獲取后台數據在高德地圖上畫線


 1         var data =  Iphone.data; //從后台獲取的所有數據
 2         var geocoder = new AMap.Geocoder(); //創建地圖
 3         var cityArr = data.data.citys;   //獲取城市名(一個數組)
 4         var lineArr =[];
 5         var obj = {};
 6         for(var i in cityArr) {
 7            //閉包渲染避免順序錯亂
 8             (function(index) {
 9                 geocoder.getLocation(cityArr[i], function(status, result) {
10                     if (status === 'complete' && result.info === 'OK') {
11                         wlggIphone.methods.geocoder_CallBack(result);
12                         lineArr.push(result.geocodes[0].location);
13                         obj[cityArr[index]] = result.geocodes[0].location;
14                         if(lineArr.length == cityArr.length) {
15                             var arrSolid = [];
16                             var arrDashed = [];
17                             for(var j in cityArr) {
18                                 if(j < (cityArr.length - 2)) {
19                                     arrSolid.push(obj[cityArr[j]]);
20                                 }else if(j == cityArr.length - 2) {
21                                     arrSolid.push(obj[cityArr[j]]);
22                                     arrDashed.push(obj[cityArr[j]]);
23                                 }else {
24                                     arrDashed.push(obj[cityArr[j]]);
25                                 }
26                             }
27                             var polyline = new AMap.Polyline({   
28                                 path: arrSolid,  
29                                 strokeColor:"#66C5FF",//線顏色
30                                 strokeOpacity:1,//線透明度  
31                                 strokeWeight:3,//線寬
32                                 strokeStyle:"solid"//線樣式  
33                             });  
34                             polyline.setMap(map);
35                             var polyline1 = new AMap.Polyline({   
36                                 path: arrDashed,  
37                                 strokeColor:"#66C5FF",//線顏色
38                                 strokeOpacity:1,//線透明度  
39                                 strokeWeight:1,//線寬
40                                 strokeStyle:"dashed"//線樣式  
41                             });  
42                             polyline1.setMap(map);
43                            
44                         } 
45                     }
46                 });
47             })(i)
48         }                
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM