Commit e73a3e2f authored by 黄奎's avatar 黄奎

页面修改

parent 6f465ab2
......@@ -70,7 +70,6 @@
// 地图实例
mapBuild() {
if (this.locationArray && this.locationArray.length > 0) {
let lat = parseFloat(this.locationArray[0].lat)
let lng = parseFloat(this.locationArray[0].lng)
let center = {
......@@ -117,44 +116,61 @@
this.directionsDisplay.setMap(this.map);
this.calcRoute()
}
},
checkItemIsExists(arr, checkItem) {
var isExists = false;
for (var i = 0; i < arr.length; i++) {
if (arr[i].location == checkItem.location && !isExists) {
isExists = true;
}
}
return isExists;
},
calcRoute: function () { // 创建路径规划
// 分解数据 获得起 止 以及中间数据
console.log(this.locationArray, '加载后....');
let lat = parseFloat(this.locationArray[0].lat)
let lng = parseFloat(this.locationArray[0].lng)
let elat = parseFloat(this.locationArray[this.locationArray.length - 1].lat)
let elng = parseFloat(this.locationArray[this.locationArray.length - 1].lng)
if (this.locationArray && this.locationArray.length > 0) {
let _this = this;
let start = lat + ',' + lng;
let end = elat + ',' + elng;
let waypoints = [];
if (this.locationArray.length > 2) {
this.locationArray.forEach((x, index) => {
if (index >= 1 && index !== (this.locationArray.length - 1)) {
if (x.lat && x.lng) {
let obj = {
location: x.lat + ',' + x.lng
}
waypoints.push(obj)
if (!_this.checkItemIsExists(waypoints, obj)) {
waypoints.push(obj);
}
});
}
});
var startArray = waypoints[0].location.split(',');
var endArray = waypoints[waypoints.length - 1].location.split(',');
let lat = parseFloat(startArray[0]);
let lng = parseFloat(startArray[1]);
let elat = parseFloat(endArray[0]);
let elng = parseFloat(endArray[1]);
let start = lat + ',' + lng;
let end = elat + ',' + elng;
let request = { // 组装连线数据
origin: start, // 起
destination: end, // 止
travelMode: google.maps.TravelMode.DRIVING,
// waypoints: [{location:"30.5226477,104.05806469999993"},{location:"30.67416759999999,104.04721970000003"}] // 中间点数据
waypoints:[]
};
if (waypoints.length > 0) {
request.waypoints = waypoints
if (waypoints && waypoints.length > 0) {
if (waypoints.length > 2) {
waypoints.forEach((item, index) => {
if (index != 0 && index != waypoints.length - 1) {
request.waypoints.push(item);
}
console.log(waypoints, 'waypointsss')
})
}
}
console.log(request, 'request')
_this.directionsService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) {
_this.directionsDisplay.setDirections(result);
}
});
}
},
},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment