Commit a7e84d6c authored by 琉璃丶c's avatar 琉璃丶c

1.完成 物流信息 页面的地图在运输中的状态绘制逻辑

parent 8daf1cdc
<template> <template>
<div id="aMapContainer"> <div id="aMapContainer"></div>
</div>
</template> </template>
<script> <script>
export default { export default {
name: 'AMapView', name: 'AMapView',
data () {
return {
icons: {
startIcon: require('@/assets/img/start.png'),
currentIcon: require('@/assets/img/sph_car.png'),
endIcon: require('@/assets/img/end.png')
}
}
},
props: { props: {
transport: {
type: Boolean,
default: false
},
pointList: { pointList: {
type: Array, type: Array,
default: () => { default: () => {
...@@ -38,10 +49,15 @@ export default { ...@@ -38,10 +49,15 @@ export default {
methods: { methods: {
initAMap() { initAMap() {
let map = new AMap.Map('aMapContainer', { let map = new AMap.Map('aMapContainer', {
resizeEnable: true resizeEnable: true,
zoom: 11,
zooms: [5, 15]
}) })
// this.drawDriveLine(map) if (this.transport) {
this.drawPointLine(map) this.drawExelState(map)
} else {
this.drawPointLine(map)
}
}, },
/* 根据点数组画线 */ /* 根据点数组画线 */
drawPointLine(map) { drawPointLine(map) {
...@@ -81,7 +97,6 @@ export default { ...@@ -81,7 +97,6 @@ export default {
AMap.convertFrom(aMapTemp, 'gps', function (status, result) { AMap.convertFrom(aMapTemp, 'gps', function (status, result) {
if (result.info === 'ok') { if (result.info === 'ok') {
let aMapLngLat = result.locations let aMapLngLat = result.locations
console.log(aMapLngLat)
// 转换成高德数据后,替换源数据 // 转换成高德数据后,替换源数据
aMapLngLat.forEach((lngLat, i) => { aMapLngLat.forEach((lngLat, i) => {
itemArr[i].x = lngLat.lng itemArr[i].x = lngLat.lng
...@@ -90,23 +105,28 @@ export default { ...@@ -90,23 +105,28 @@ export default {
// 绘制起点 // 绘制起点
if (tdIndex === 0) { if (tdIndex === 0) {
let startMarker = new AMap.Marker({ let startMarker = new AMap.Marker({
position: aMapLngLat[0] position: aMapLngLat[0],
offset: new AMap.Pixel(-15, -38),
icon: _this.icons.startIcon
}) })
startMarker.setLabel({ startMarker.setLabel({
offset: new AMap.Pixel(4, 0), //设置文本标注偏移量 offset: new AMap.Pixel(4, 0), // 设置文本标注偏移量
content: `<div class='marker'>${_this.drivePoint.startPoint.address}</div>`, //设置文本标注内容 content: `<div class='marker'>${_this.drivePoint.startPoint.address}</div>`, // 设置文本标注内容
direction: 'right' //设置文本标注方位 direction: 'right' // 设置文本标注方位
}) })
map.add(startMarker) map.add(startMarker)
} }
// 绘制终点
if (tdIndex === tdGroup.length - 1) { if (tdIndex === tdGroup.length - 1) {
let endMarker = new AMap.Marker({ let endMarker = new AMap.Marker({
position: aMapLngLat[aMapLngLat.length - 1] position: aMapLngLat[aMapLngLat.length - 1],
offset: new AMap.Pixel(-15, -38),
icon: _this.icons.endIcon
}) })
endMarker.setLabel({ endMarker.setLabel({
offset: new AMap.Pixel(4, 0), //设置文本标注偏移量 offset: new AMap.Pixel(4, 0), // 设置文本标注偏移量
content: `<div class='marker'>${_this.drivePoint.endPoint.address}</div>`, //设置文本标注内容 content: `<div class='marker'>${_this.drivePoint.endPoint.address}</div>`, // 设置文本标注内容
direction: 'right' //设置文本标注方位 direction: 'right' // 设置文本标注方位
}) })
map.add(endMarker) map.add(endMarker)
} }
...@@ -140,25 +160,59 @@ export default { ...@@ -140,25 +160,59 @@ export default {
}) })
}) })
}, },
/* 根据起点和终点绘制线路 */ /* 绘制起点和终点,并绘制车的位置 */
drawDriveLine(map) { drawExelState(map) {
// 构造路线导航类 let _this = this
let driving = new AMap.Driving({ // 获取Gis点数据的最后一位
map: map, let currentItem = _this.pointList.slice(-1)[0]
showTraffic: false
}) let startPoint = new AMap.LngLat(_this.drivePoint.startPoint.longitude, _this.drivePoint.startPoint.latitude)
let startPoint = new AMap.LngLat(this.drivePoint.startPoint.longitude, this.drivePoint.startPoint.latitude) let currentPoint = new AMap.LngLat(currentItem.longitude, currentItem.latitude)
let endPoint = new AMap.LngLat(this.drivePoint.endPoint.longitude, this.drivePoint.endPoint.latitude) let endPoint = new AMap.LngLat(_this.drivePoint.endPoint.longitude, _this.drivePoint.endPoint.latitude)
// let startPoint = new AMap.LngLat(parseFloat(this.pointList[this.pointList.length - 1].longitude), parseFloat(this.pointList[this.pointList.length - 1].latitude)) // 塞入临时数据
// let endPoint = new AMap.LngLat(parseFloat(this.pointList[0].longitude), parseFloat(this.pointList[0].latitude)) let aMapTemp = [startPoint, currentPoint, endPoint]
console.log('start=> ', startPoint, ' end=> ', endPoint) // 转换成高德点
// 根据起终点经纬度规划驾车导航路线 AMap.convertFrom(aMapTemp, 'gps', function (status, result) {
driving.search(startPoint, endPoint, function(status, result) { if (result.info === 'ok') {
// result 即是对应的驾车导航信息,相关数据结构文档请参考 let aMapLngLat = result.locations
if (status === 'complete') { console.log(aMapLngLat)
console.log('绘制驾车路线完成') // 开始绘制起点
} else { let startMarker = new AMap.Marker({
console.log('获取驾车数据失败:' + result) position: aMapLngLat[0],
icon: _this.icons.startIcon,
offset: new AMap.Pixel(-15, -38)
})
startMarker.setLabel({
offset: new AMap.Pixel(4, 0), // 设置文本标注偏移量
content: `<div class='marker'>${_this.drivePoint.startPoint.address}</div>`, // 设置文本标注内容
direction: 'right' // 设置文本标注方位
})
map.add(startMarker)
// 开始绘制车辆位置
let currentMarker = new AMap.Marker({
position: aMapLngLat[1],
angle: parseInt(currentItem.direction),
offset: new AMap.Pixel(-15, -20),
icon: new AMap.Icon({
image: _this.icons.currentIcon,
size: new AMap.Size(52, 52), // 图标大小
imageSize: new AMap.Size(30, 40)
})
})
map.add(currentMarker)
// 开始绘制终点
let endMarker = new AMap.Marker({
position: aMapLngLat[2],
icon: _this.icons.endIcon,
offset: new AMap.Pixel(-15, -38)
})
endMarker.setLabel({
offset: new AMap.Pixel(4, 0), // 设置文本标注偏移量
content: `<div class='marker'>${_this.drivePoint.endPoint.address}</div>`, // 设置文本标注内容
direction: 'right' // 设置文本标注方位
})
map.add(endMarker)
} }
}) })
} }
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
<van-empty description="暂无数据" <van-empty description="暂无数据"
v-if="!shippingInfo&&!shippingInfo.shippingNo&& v-if="!shippingInfo&&!shippingInfo.shippingNo&&
(!stepList|| stepList.length<0)&&(!mapPointList||mapPointList.length < 0)"/> (!stepList|| stepList.length<0)&&(!mapPointList||mapPointList.length < 0)"/>
<!-- <map-view :point-list="mapPointList" v-if="mapPointList&&mapPointList.length > 0"/>--> <a-map-view :transport="(this.shippingInfo.signTime === '')" :point-list="mapPointList" :drive-point="driveLine" v-if="mapPointList&&mapPointList.length > 0"/>
<a-map-view :point-list="mapPointList" :drive-point="driveLine" v-if="mapPointList&&mapPointList.length > 0"/>
<div class="logistics-header" v-if="shippingInfo&&shippingInfo.shippingNo"> <div class="logistics-header" v-if="shippingInfo&&shippingInfo.shippingNo">
<div class="header-title"> <div class="header-title">
<van-icon class="logistic-logo" :name="icons.logo"/> <van-icon class="logistic-logo" :name="icons.logo"/>
...@@ -106,6 +105,7 @@ export default { ...@@ -106,6 +105,7 @@ export default {
}, },
/* 获取运单信息 */ /* 获取运单信息 */
getShippingData() { getShippingData() {
console.log(this.orderInfo)
let data = { let data = {
'orderId': '', 'orderId': '',
'orderNo': this.orderInfo.orderNo, // '879202103190016', 'orderNo': this.orderInfo.orderNo, // '879202103190016',
......
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