Commit e73a3e2f authored by 黄奎's avatar 黄奎

页面修改

parent 6f465ab2
...@@ -70,7 +70,6 @@ ...@@ -70,7 +70,6 @@
// 地图实例 // 地图实例
mapBuild() { mapBuild() {
if (this.locationArray && this.locationArray.length > 0) { if (this.locationArray && this.locationArray.length > 0) {
let lat = parseFloat(this.locationArray[0].lat) let lat = parseFloat(this.locationArray[0].lat)
let lng = parseFloat(this.locationArray[0].lng) let lng = parseFloat(this.locationArray[0].lng)
let center = { let center = {
...@@ -117,44 +116,61 @@ ...@@ -117,44 +116,61 @@
this.directionsDisplay.setMap(this.map); this.directionsDisplay.setMap(this.map);
this.calcRoute() 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 () { // 创建路径规划 calcRoute: function () { // 创建路径规划
// 分解数据 获得起 止 以及中间数据 // 分解数据 获得起 止 以及中间数据
console.log(this.locationArray, '加载后....'); if (this.locationArray && this.locationArray.length > 0) {
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)
let _this = this; let _this = this;
let start = lat + ',' + lng;
let end = elat + ',' + elng;
let waypoints = []; let waypoints = [];
if (this.locationArray.length > 2) {
this.locationArray.forEach((x, index) => { this.locationArray.forEach((x, index) => {
if (index >= 1 && index !== (this.locationArray.length - 1)) { if (x.lat && x.lng) {
let obj = { let obj = {
location: x.lat + ',' + x.lng 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 = { // 组装连线数据 let request = { // 组装连线数据
origin: start, // 起 origin: start, // 起
destination: end, // 止 destination: end, // 止
travelMode: google.maps.TravelMode.DRIVING, travelMode: google.maps.TravelMode.DRIVING,
// waypoints: [{location:"30.5226477,104.05806469999993"},{location:"30.67416759999999,104.04721970000003"}] // 中间点数据 waypoints:[]
}; };
if (waypoints.length > 0) { if (waypoints && waypoints.length > 0) {
request.waypoints = waypoints 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) { _this.directionsService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) { if (status == google.maps.DirectionsStatus.OK) {
_this.directionsDisplay.setDirections(result); _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