//获取标点与生成线路
getPath:function () {
var centerposition=[];
var path=[];
for(var i=0;i<stationList.length;i++){
path.push(new AMap.LngLat(stationList[i].y,stationList[i].x));
}
AMap.convertFrom(path,'gps',function (status, result) {
if(result.info==='ok'){
// vm.drawStationPoint(stationList)
$.each(result.locations, function (i, coordinate) {
var marker = new AMap.Marker({//创建标记点
position: new AMap.LngLat(coordinate.KL, coordinate.kT), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
// offset: new AMap.Pixel(10, -20),
anchor: 'middle-left'
});
pointList.push(marker);
TextMap.push(new AMap.Text({//创建标签
position:new AMap.LngLat(coordinate.KL, coordinate.kT),
text: stationList[i].name,
offset: new AMap.Pixel(-60, -20)
}));
});
// 创建折线实例
var polyline = new AMap.Polyline({
path: result.locations,
borderWeight: 2, // 线条宽度,默认为 1
strokeColor: 'red', // 线条颜色
lineJoin: 'round' // 折线拐点连接处样式
});
routeList.push(polyline);
map.add(TextMap);
map.add(pointList);//标记点
map.add(routeList);
centerposition=[result.locations[0].KL,result.locations[0].kT];
// map.setCenter(centerposition);//定位
map.setFitView();//默认所有都调整到最佳视野
}
});
},