// text/mapTrajectory.js
|
Page({
|
data: {
|
curPosiInfo: null, //位置信息 // latitude: 0, longitude: 0,//经纬度
|
markers: null,
|
polyline: [{
|
points: [
|
{ id: 0, latitude: 31.11325, longitude: 121.38206 },
|
{ id: 1, latitude: 31.11305, longitude: 121.38186 },
|
{ id: 2, latitude: 31.11285, longitude: 121.38206 },
|
{ id: 3, latitude: 31.11265, longitude: 121.38186 },
|
{ id: 4, latitude: 31.11255, longitude: 121.38206 },
|
{ id: 5, latitude: 31.11245, longitude: 121.38186 },
|
{ id: 6, latitude: 31.11225, longitude: 121.38206 },
|
{ id: 7, latitude: 31.11205, longitude: 121.38186 }
|
],
|
color: '#F11D36',
|
width: 2,
|
dottedLine: false
|
}]
|
},
|
onLoad: function (options) {
|
var title = options.name;
|
//console.log(options)//
|
if(title!="" || title!=undefined){
|
wx.setNavigationBarTitle({
|
title: title + '巡检记录',
|
});
|
}
|
},
|
onShow: function () {
|
var that=this;
|
that.getlocation();
|
that.setUpIcon();
|
},
|
getlocation: function () {
|
var that=this;
|
wx.getLocation({
|
type: 'gcj02',
|
success: function (res) {
|
that.setData({
|
curPosiInfo:res
|
})
|
},
|
fail:function(res){console.log(res)}
|
});
|
},
|
|
setUpIcon:function(){
|
var that = this;
|
var getlocation = that.data.polyline[0].points;//获取轨迹坐标
|
var startlocation = getlocation[0];//获取轨迹起点坐标
|
var endlocation = getlocation[getlocation.length - 1];//获取轨迹终点坐标
|
var markers = [];
|
for (var i = 0; i <getlocation.length;i++){
|
if (i != 0 && i != 7 && ((i+1) % 3)==0){//去掉第一条和最后一条 轨迹分
|
var center = {};
|
center.id = getlocation[i].id;
|
center.latitude = getlocation[i].latitude;
|
center.longitude = getlocation[i].longitude;
|
center.iconPath = "/images/icons/center.png"
|
markers.push(center);
|
}
|
}
|
console.log('打印被3整除的点:',markers)
|
|
/**设置起点终点图标 */
|
//起点
|
var start = {};
|
start.id = startlocation.id;
|
start.latitude = startlocation.latitude;
|
start.longitude = startlocation.longitude;
|
start.iconPath = "/images/icons/start.png"
|
markers.push(start);
|
|
//终点
|
var end = {};
|
end.id = endlocation.id;
|
end.latitude = endlocation.latitude;
|
end.longitude = endlocation.longitude;
|
end.iconPath = "/images/icons/end.png"
|
markers.push(end);
|
|
|
|
console.log(getlocation, startlocation, endlocation)
|
console.log(start, end, markers)
|
that.setData({
|
markers: markers
|
})
|
},
|
|
onShareAppMessage: function () {}
|
})
|