You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
4.3 KiB
171 lines
4.3 KiB
<template>
|
|
<view>
|
|
|
|
<view class="button-box">
|
|
|
|
<button size="mini" type="primary" @click="getLocations">开始记录</button>
|
|
<button size="mini" type="primary" @click="stopLocation">停止记录</button>
|
|
<button size="mini" :disabled="canClick" type="primary" @click="uploadData">提交记录</button>
|
|
</view>
|
|
<view class="line-box"><input v-model="lineName" placeholder="请输入线路名称" /></view>
|
|
<map :scale="3" :longitude="lon" :latitude="lat" style="width: 100%; height:100vh" :polyline="locationss"></map>
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
canClick:false,
|
|
arrs:[],
|
|
lineName:null,
|
|
lon: 114.57,
|
|
lat: 38.04,
|
|
locationss: [
|
|
{
|
|
points: [],
|
|
color: '#0000AA',
|
|
width: 10,
|
|
arrowLine: true
|
|
},
|
|
// {
|
|
// points: [
|
|
// { latitude: 38.044231770833335, longitude: 115.56865288628472 },
|
|
// { latitude: 39.044231770833335, longitude: 116.56865288628472 },
|
|
// { latitude: 40.044231770833335, longitude: 117.56865288628472 },
|
|
// { latitude: 41.044231770833335, longitude: 118.56865288628472 },
|
|
// { latitude: 42.044231770833335, longitude: 119.56865288628472 },
|
|
// { latitude: 43.044231770833335, longitude: 120.56865288628472 }
|
|
// ],
|
|
// width: 10,
|
|
// color: '#00aa29',
|
|
// arrowLine: true
|
|
// }
|
|
],
|
|
};
|
|
},
|
|
methods:{
|
|
getLocations() {
|
|
let this_ = this;
|
|
this_.arrs = []
|
|
this_.locationss[0].points = []
|
|
uni.startLocationUpdate({
|
|
type:'gcj02',
|
|
altitude:true,
|
|
success: function (res) {
|
|
console.log(res, '开启小程序接收位置消息成功');
|
|
uni.onLocationChange(function (res) {
|
|
console.log(res);
|
|
console.log('纬度:' + res.latitude);
|
|
console.log('经度:' + res.longitude);
|
|
let lng = res.longitude.toFixed(3);
|
|
let lat = res.latitude.toFixed(3);
|
|
this_.arrs.push({ latitude: lat, longitude: lng });
|
|
console.log(this_.arrs,'1' )
|
|
this_.locationss[0].points = this_.arrs;
|
|
this_.locationss = [...this_.locationss];
|
|
console.log(this_.locationss ,'2')
|
|
});
|
|
|
|
},
|
|
fail: (err) => console.error('开启小程序接收位置消息失败:', err),
|
|
complete: (msg) => console.log('调用开启小程序接收位置消息 API 完成')
|
|
});
|
|
},
|
|
updateLocation() {
|
|
uni.onLocationChange(function (res) {
|
|
console.log('纬度:' + res.latitude);
|
|
console.log('经度:' + res.longitude);
|
|
});
|
|
},
|
|
stopLocation() {
|
|
let this_ = this;
|
|
uni.stopLocationUpdate({
|
|
success: (res) =>{
|
|
console.log('关闭成功', this_.locationss)
|
|
} ,
|
|
fail: (err) => console.error('关闭失败:', err),
|
|
complete: (msg) => console.log('调用开启小程序接收位置消息 API 完成')
|
|
});
|
|
},
|
|
clearMap(){
|
|
let this_ = this;
|
|
this_.arrs = []
|
|
this_.locationss[0].points = []
|
|
this_.locationss = [...this_.locationss];
|
|
},
|
|
uploadData(){
|
|
let that = this;
|
|
if(that.lineName == null){
|
|
uni.showToast({
|
|
title:'名称不能为空!',
|
|
icon:'error'
|
|
})
|
|
return false
|
|
}
|
|
console.log(that.arrs)
|
|
if(that.arrs.length==0){
|
|
uni.showToast({
|
|
title:'还没开始记录线路!',
|
|
icon:'error'
|
|
})
|
|
return false
|
|
}
|
|
that.canClick = true
|
|
let line = JSON.stringify(this.arrs);
|
|
uni.request({
|
|
header: { 'Content-Type': 'application/json' },
|
|
url: 'https://zb.aitto.net/prod-api/mobile/line', //仅为示例,并非真实接口地址。
|
|
data: {
|
|
lineName:that.lineName,
|
|
pointJson:line
|
|
},
|
|
method: 'POST',
|
|
success: (res) => {
|
|
uni.showToast({
|
|
title: `保存成功`
|
|
|
|
});
|
|
setTimeout(()=>{
|
|
that.canClick=false
|
|
that.clearMap()
|
|
},3000)
|
|
},
|
|
fail:(err)=>{
|
|
uni.showToast({
|
|
title:'记录失败',
|
|
icon:'none'
|
|
})
|
|
setTimeout(()=>{
|
|
that.canClick=false
|
|
that.clearMap()
|
|
},3000)
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.button-box{
|
|
display: flex;
|
|
justify-content: space-around;
|
|
position: fixed;
|
|
z-index: 999;
|
|
width: 100%;
|
|
top: 200rpx;
|
|
}
|
|
.line-box{
|
|
position: fixed;
|
|
line-height: 40rpx;
|
|
z-index: 999;
|
|
width: 60%;
|
|
left: 5%;
|
|
padding: 5rpx 10rpx;
|
|
top: 100rpx;
|
|
background-color: #d6d6d6;
|
|
color: #333;
|
|
}
|
|
</style>
|
|
|