Commit 9f91db55 by zhangxw

优化修改

1 parent 280269bb
This diff could not be displayed because it is too large.
.map-wrap{ .map-wrap{
position: fixed;
top: 0;
left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
......
{ {
"usingComponents": { "usingComponents": {
"myMap": "../../components/myMap/myMap" "myMap": "../../components/myMap/myMap"
} },
"navigationBarTitleText": "找车"
} }
\ No newline at end of file \ No newline at end of file
<view class="content_page"> <view class="content_page">
<myMap class="my-map" id="myMap" bind:getCarInfoWindowObj="getCarInfoWindowObj" bind:refresh="refresh" includePoints="{{includePoints}}" bind:locationCallback="locationCallback"></myMap> <myMap class="my-map" id="myMap" bind:getCarInfoWindowObj="getCarInfoWindowObj" bind:refresh="refresh" markers="{{markers}}" includePoints="{{includePoints}}" bind:locationCallback="locationCallback"></myMap>
<!-- 找车按钮 --> <!-- 找车按钮 -->
<view wx:if="{{!isSharePage}}" class="icon icon-findcar map-cmd-icon" bindtap="findCarClick"></view> <view wx:if="{{!isSharePage}}" class="icon icon-findcar map-cmd-icon" bindtap="findCarClick"></view>
<!-- 信息窗体内容 --> <!-- 信息窗体内容 -->
......
This diff could not be displayed because it is too large.
...@@ -11,10 +11,12 @@ Page({ ...@@ -11,10 +11,12 @@ Page({
},{ },{
label: '设备号', label: '设备号',
value: '1' value: '1'
},{ }
label: '姓名', // {
value: '3' // label: '姓名',
}], // value: '3'
// }
],
placeholders: [ placeholders: [
'请输入完整的申请单号', '请输入完整的申请单号',
'请输入完整的车架号', '请输入完整的车架号',
...@@ -143,14 +145,14 @@ Page({ ...@@ -143,14 +145,14 @@ Page({
if(inputVal.length<2){ if(inputVal.length<2){
wx.showToast({ wx.showToast({
title: '请输入正确的姓名,至少2个字', title: '请输入正确的姓名,至少2个字',
icon: none icon: 'none'
}); });
return false; return false;
} }
}else if(inputVal.length<6){ }else if(inputVal.length<6){
wx.showToast({ wx.showToast({
title: '请输入至少6位数', title: '请输入至少6位数',
icon: none icon: 'none'
}); });
return false; return false;
} }
......
...@@ -85,96 +85,98 @@ Page({ ...@@ -85,96 +85,98 @@ Page({
wx.request({ wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?key=46XBZ-RVUCD-FI34X-H66JJ-HZ5FS-3YFID&location=`+ e.data[0].gpsLocation.elat + ',' + e.data[0].gpsLocation.elng, url: `https://apis.map.qq.com/ws/geocoder/v1/?key=46XBZ-RVUCD-FI34X-H66JJ-HZ5FS-3YFID&location=`+ e.data[0].gpsLocation.elat + ',' + e.data[0].gpsLocation.elng,
success: res => { success: res => {
let transferAddress = res.data && res.data.result.address_component.province === res.data.result.address_component.city ? (res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough) : (res.data.result.address_component.province + '' + res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough) if (res.statusCode === 200) {
listData.push({ let transferAddress = res.data && res.data.result.address_component.province === res.data.result.address_component.city ? (res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough) : (res.data.result.address_component.province + '' + res.data.result.address_component.city + '' + res.data.result.formatted_addresses.rough)
transferAddress: transferAddress, listData.push({
time: e.data[0].gpsLocation.dateTime transferAddress: transferAddress,
}) time: e.data[0].gpsLocation.dateTime
this.setData({
listData: listData,
scrollIntoViewIndex: '_' + listData.length
})
let isHad = includePoints.length && includePoints.find((item) => item.latitude === e.data[0].gpsLocation.elat && item.longitude === e.data[0].gpsLocation.elng)
if (!isHad) {
includePoints.push({
latitude: e.data[0].gpsLocation.elat,
longitude: e.data[0].gpsLocation.elng
}) })
} this.setData({
this.setData({ listData: listData,
includePoints: includePoints scrollIntoViewIndex: '_' + listData.length
}) })
if (this.data.carMarkers.length <= 0) { let isHad = includePoints.length && includePoints.find((item) => item.latitude === e.data[0].gpsLocation.elat && item.longitude === e.data[0].gpsLocation.elng)
let marker = [{ if (!isHad) {
id: 1, includePoints.push({
width: 15, latitude: e.data[0].gpsLocation.elat,
height: 25, longitude: e.data[0].gpsLocation.elng
latitude: e.data[0].gpsLocation.elat, })
longitude: e.data[0].gpsLocation.elng, }
iconPath: '../../images/car.png' this.setData({
}] includePoints: includePoints
this.myMap.getMapCtx().addMarkers({
markers: marker,
success: () => {
points.push({
latitude: Number(e.data[0].gpsLocation.elat),
longitude: Number(e.data[0].gpsLocation.elng),
})
this.setData({
carMarkers: marker,
points: points,
firstPosLat: Number(e.data[0].gpsLocation.elat),
firstPosLng: Number(e.data[0].gpsLocation.elng)
})
this.moveToLocation(Number(e.data[0].gpsLocation.elat), Number(e.data[0].gpsLocation.elng))
}
}) })
} else { if (this.data.carMarkers.length <= 0) {
if (this.data.firstPosLat !== (Number(e.data[0].gpsLocation.elat)) || this.data.firstPosLng !== (Number(e.data[0].gpsLocation.elng))) {
let marker = [{ let marker = [{
id: 2, id: 1,
width: 15, width: 15,
height: 25, height: 25,
latitude: Number(this.data.firstPosLat), latitude: e.data[0].gpsLocation.elat,
longitude: Number(this.data.firstPosLng), longitude: e.data[0].gpsLocation.elng,
iconPath: '../../images/begin.png' iconPath: '../../images/car.png'
}] }]
this.myMap.getMapCtx().addMarkers({ this.myMap.getMapCtx().addMarkers({
markers: marker, markers: marker,
success: () => { success: () => {
let arr = [{ points.push({
latitude: Number(e.data[0].gpsLocation.elat), latitude: Number(e.data[0].gpsLocation.elat),
longitude: Number(e.data[0].gpsLocation.elng) longitude: Number(e.data[0].gpsLocation.elng),
}]
this.myMap.getMapCtx().translateMarker({
markerId: 1,
destination: {
longitude: Number(e.data[0].gpsLocation.elng),
latitude: Number(e.data[0].gpsLocation.elat),
},
duration: 500,
animationEnd: () => {
this.moveToLocation(e.data[0].gpsLocation.elat, e.data[0].gpsLocation.elng)
this.setData({
points: points.concat(arr),
polyline: [{
points: points.concat(arr),
color: '#0b94db',
width: 6,
arrowLine: true
}]
})
}
}) })
this.setData({
carMarkers: marker,
points: points,
firstPosLat: Number(e.data[0].gpsLocation.elat),
firstPosLng: Number(e.data[0].gpsLocation.elng)
})
this.moveToLocation(Number(e.data[0].gpsLocation.elat), Number(e.data[0].gpsLocation.elng))
} }
}) })
} else { } else {
this.moveToLocation(Number(e.data[0].gpsLocation.elat), Number(e.data[0].gpsLocation.elng)) if (this.data.firstPosLat !== (Number(e.data[0].gpsLocation.elat)) || this.data.firstPosLng !== (Number(e.data[0].gpsLocation.elng))) {
let marker = [{
id: 2,
width: 15,
height: 25,
latitude: Number(this.data.firstPosLat),
longitude: Number(this.data.firstPosLng),
iconPath: '../../images/begin.png'
}]
this.myMap.getMapCtx().addMarkers({
markers: marker,
success: () => {
let arr = [{
latitude: Number(e.data[0].gpsLocation.elat),
longitude: Number(e.data[0].gpsLocation.elng)
}]
this.myMap.getMapCtx().translateMarker({
markerId: 1,
destination: {
longitude: Number(e.data[0].gpsLocation.elng),
latitude: Number(e.data[0].gpsLocation.elat),
},
duration: 500,
animationEnd: () => {
this.moveToLocation(Number(e.data[0].gpsLocation.elat), Number(e.data[0].gpsLocation.elng))
this.setData({
points: points.concat(arr),
polyline: [{
points: points.concat(arr),
color: '#0b94db',
width: 6,
arrowLine: true
}]
})
}
})
}
})
} else {
this.moveToLocation(Number(e.data[0].gpsLocation.elat), Number(e.data[0].gpsLocation.elng))
}
} }
timeoutId = setTimeout(() => {
this.getPosition()
}, 10*1000)
} }
timeoutId = setTimeout(() => {
this.getPosition()
}, 10*1000)
} }
}) })
} }
......
{ {
"usingComponents": {} "usingComponents": {
"myMap": "../../components/myMap/myMap"
},
"navigationBarTitleText": "实时监控"
} }
\ No newline at end of file \ No newline at end of file
This diff could not be displayed because it is too large.
...@@ -29,12 +29,12 @@ Page({ ...@@ -29,12 +29,12 @@ Page({
isReplayIng: false, isReplayIng: false,
polyline: [], polyline: [],
markers: [], markers: [],
duration: 20000, // 回放速度
isShowModel: false, isShowModel: false,
clickItem: null, clickItem: null,
selectTime: '', selectTime: '',
sn: null, sn: null,
type: null type: null,
durationArr: [20000, 15000, 10000, 5000]
}, },
/** /**
...@@ -64,7 +64,6 @@ Page({ ...@@ -64,7 +64,6 @@ Page({
refresh() { refresh() {
if (this.data.polyline.length <= 0) return if (this.data.polyline.length <= 0) return
this.setData({ this.setData({
duration: 20000,
clickItem: null, clickItem: null,
selectTime: '', selectTime: '',
polyline: [], polyline: [],
...@@ -155,15 +154,25 @@ Page({ ...@@ -155,15 +154,25 @@ Page({
} }
let params = {sn: this.data.sn, startTime: _sTime, endTime: _eTime, locationType: this.data.locationType} let params = {sn: this.data.sn, startTime: _sTime, endTime: _eTime, locationType: this.data.locationType}
WXRequest.get('devicemonitor/api/track/playback', params, true).then(res => { WXRequest.get('devicemonitor/api/track/playback', params, true).then(res => {
// let params = {sn: '45111120466', sTime: _sTime, eTime: _eTime}
// WXRequest.get('Track/getTrackHistory', params).then(res => {
let arr = [] let arr = []
var polyline = [] var polyline = []
if (res.code == 200) { if (res.code == 200) {
// if (res.returnCode == 0) {
res.data.forEach(item => { res.data.forEach(item => {
arr.push({ arr.push({
latitude: Number(item.elat), latitude: Number(item.elat),
longitude: Number(item.elng) longitude: Number(item.elng)
}) })
}); });
let obj = {}
let removalArr = arr.reduce((curr, next) => {
/*判断对象中是否已经有该属性 没有的话 push 到 curr数组*/
obj[next.latitude + next.longitude] ? '' : obj[next.latitude + next.longitude] = curr.push(next);
return curr;
}, []);
this.distance(removalArr)
if (res.data.length) { if (res.data.length) {
polyline.push({ polyline.push({
points: arr, points: arr,
...@@ -189,12 +198,39 @@ Page({ ...@@ -189,12 +198,39 @@ Page({
} }
}) })
}, },
// 距离计算总和
distance(arr) {
var s, all = 0
arr.forEach((item, index) => {
if (arr[index + 1]) {
var La1 = arr[index].latitude * Math.PI / 180.0;
var La2 = arr[index + 1].latitude * Math.PI / 180.0;
var La3 = La1 - La2;
var Lb3 = arr[index].longitude * Math.PI / 180.0 - arr[index + 1].longitude * Math.PI / 180.0;
s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
s = s * 6378.137;//地球半径
s = Math.round(s * 10000) / 10000;
all = all + s
}
})
if (all > 10 && all < 100) {
this.setData({
durationArr: [15*1000, 10*1000, 6*1000, 3*1000]
})
} else if (all <= 10) {
this.setData({
durationArr: [8*1000, 6*1000, 4*1000, 2*1000]
})
} else {
this.setData({
durationArr: [20*1000, 15*1000, 10*1000, 5*1000]
})
}
},
// 切换回放速度 // 切换回放速度
speedTypeChange(e) { speedTypeChange(e) {
let arr = [20000, 15000, 10000, 5000]
this.setData({ this.setData({
speedItemsIndex: Number(e.detail.value), speedItemsIndex: Number(e.detail.value)
duration: arr[Number(e.detail.value)]
}) })
this.beginTrack() this.beginTrack()
}, },
...@@ -219,7 +255,7 @@ Page({ ...@@ -219,7 +255,7 @@ Page({
this.myMap.getMapCtx().moveAlong({ this.myMap.getMapCtx().moveAlong({
markerId: 105, markerId: 105,
path: this.data.polyline[0].points, path: this.data.polyline[0].points,
duration: this.data.duration, duration: this.data.durationArr[this.data.speedItemsIndex],
fail: () => { fail: () => {
this.beginTrack() this.beginTrack()
} }
...@@ -250,22 +286,24 @@ Page({ ...@@ -250,22 +286,24 @@ Page({
wx.request({ wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?key=46XBZ-RVUCD-FI34X-H66JJ-HZ5FS-3YFID&location=`+ e.detail.detail.latitude + ',' + e.detail.detail.longitude, url: `https://apis.map.qq.com/ws/geocoder/v1/?key=46XBZ-RVUCD-FI34X-H66JJ-HZ5FS-3YFID&location=`+ e.detail.detail.latitude + ',' + e.detail.detail.longitude,
success: res => { success: res => {
transferAddress = res.data && res.data.result.address_component.province === res.data.result.address_component.city ? (res.data.result.address_component.city + '\n' + res.data.result.formatted_addresses.rough) : (res.data.result.address_component.province + '' + res.data.result.address_component.city + '\n' + res.data.result.formatted_addresses.rough) if (res.statusCode === 200) {
this.myMap.getMapCtx().addMarkers({ transferAddress = res.data && res.data.result.address_component.province === res.data.result.address_component.city ? (res.data.result.address_component.city + '\n' + res.data.result.formatted_addresses.rough) : (res.data.result.address_component.province + '' + res.data.result.address_component.city + '\n' + res.data.result.formatted_addresses.rough)
markers: [{ this.myMap.getMapCtx().addMarkers({
id: 2, markers: [{
latitude: e.detail && e.detail.detail && e.detail.detail.latitude, id: 2,
longitude: e.detail && e.detail.detail && e.detail.detail.longitude, latitude: e.detail && e.detail.detail && e.detail.detail.latitude,
width: 20, longitude: e.detail && e.detail.detail && e.detail.detail.longitude,
height: 30, width: 20,
callout: { height: 30,
content: transferAddress, callout: {
borderRadius: 10, content: transferAddress,
padding: 10, borderRadius: 10,
display: 'ALWAYS' padding: 10,
} display: 'ALWAYS'
}], }
}) }],
})
}
} }
}) })
}, },
......
{ {
"usingComponents": { "usingComponents": {
"myMap": "../../components/myMap/myMap" "myMap": "../../components/myMap/myMap"
} },
"navigationBarTitleText": "轨迹回放"
} }
\ No newline at end of file \ No newline at end of file
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!