map.vue
8.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<template>
<div class="" style="width: 100%;height: 100%">
<div class="search">
<div class="psearch" @click="$router.push({name:'search'})">
<div>
<div></div>
</div>
<div>
<span id="searchName">搜索</span>
</div>
</div>
</div>
<div class="parkList" @click="toParkList">
<div class="iconlist icon iconfont"></div>
列表
</div>
<baidu-map class="map" :center="center"
@ready="handler"
:zoom="16">
<bm-label content="22" :position="{lng: 116.3666882, lat: 39.9283467}" :labelStyle="{color: '#fff', fontSize : '16px',background:'#f0f',borderRadius: '50%',padding:'3px'}" title="Hover me"/>
</baidu-map>
<div class="onepark" v-show="parkShow" @click="gaodec">
<div class="neir">
<div class="leftinfo">
<div class="lname">
<span class="bg00f" v-if="this.oneparkObject.idleberths>10" style="background: #0f0">充足</span>
<span class="bg00f" v-else-if="this.oneparkObject.idleberths>0&&this.oneparkObject.idleberths<10"
style="background: #ff9e04">紧张</span>
<span class="bg00f"
v-else-if="this.oneparkObject.idleberths==0&&this.oneparkObject.totalberths&&this.oneparkObject.totalberths!=0&&this.oneparkObject.totalberths!='0'"
style="background: #f00">停满</span>
<span class="bg00f" v-else style="background: #0f0">充足</span>
<span id="parkname">{{ oneparkObject.name }}</span>
</div>
<div class="lnum">
当前车位:<span class="font00f" id="kongnum">{{ oneparkObject.idleberths }}</span>/<span id="allnum">{{ oneparkObject.totalberths }}</span>
</div>
<div class="ladres">
<span id="laddre">{{ oneparkObject.address }}</span>
<span id="distace" class="font0f0">距离您{{ dis }}km</span>
</div>
</div>
<div class="rightinfo">
<div><i class="icon iconfont"></i></div>
<div>导航</div>
</div>
</div>
</div>
<popComponents
:latitude="latitude"
:longitude="longitude"
:popupFlag="popupVisible" :parkName="name" :idleberths="idleberths" :juli="julis" :num="n">
</popComponents>
</div>
</template>
<script>
import popComponents from './popComponents.vue'
import {queryParkingLots} from '@/api/map/map.js'
export default {
components:{
popComponents
},
data() {
return {
center: {}, // 定位中心点
// zoom: 3
parkShow: false, // 搜索完毕下方展示
oneparkObject: {}, // 下方展示数据对象
dis:'', // 两点之间距离计算
popupVisible: false,
n:10,
setTimeoutTimer:'',
latitude:'',
longitude:'',
name:'',
idleberths:'',
julis:''
}
},
methods: {
handler: function ({ BMap, map }) {
map.enableScrollWheelZoom(true); //开启滚轮缩放
// map.centerAndZoom('青岛市', 13)
const hide = console.log("正在获取当前省市请稍候..", 0);
const _this = this;
const geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(
function (r) {
setTimeout(hide, 1000);
console.log(r);
// 存储获取的中心点
let zbCenter = {
lng: r.longitude,
lat: r.latitude
}
localStorage.setItem('zbcenter', JSON.stringify(zbCenter))
if (_this.$route.query.name) { // 搜索完毕走这
console.log('1')
_this.center = { lng: _this.$route.query.lng, lat: _this.$route.query.lat }; // 设置center属性值
_this.queryParkingLots(_this.$route.query.lng, _this.$route.query.lat)
} else { // 第一次进入地图走这
console.log('2')
_this.center = { lng: r.longitude, lat: r.latitude }; // 设置center属性值
}
// _this.autoLocationPoint = { lng: r.longitude, lat: r.latitude } // 自定义覆盖物
_this.initLocation = true;
},
{ enableHighAccuracy: true }
);
window.map = map;
// 赋值,方便调用,本节被用到
this.BMap = BMap;
this.map = map;
},
// 获取下方数据
queryParkingLots: function (lon, lat) {
var salt = this.$utils.myCommonSalt(32);
var jsondata = {
app_id: this.$utils.myVarAppid,
deviceInfo: this.$utils.myDeviceInfo,
latitude: lat,
longitude: lon,
salt: salt,
sign_type: 'md5',
type: '01',
limit: '2000',
isShowOther: '0'
}
jsondata.sign = this.$utils.signObject(jsondata)
queryParkingLots(jsondata).then(response => {
console.log(response.data[0])
let datas = response.data[0]
let center = JSON.parse(localStorage.getItem('zbcenter'))
this.dis = this.GetDistance(center.lat,center.lng,response.data[0].latitude,response.data[0].longitude)
console.log(this.dis)
this.oneparkObject = response.data[0]
this.parkShow = true
this.name = datas.name
this.latitude = datas.latitude
this.longitude = datas.longitude
this.idleberths = datas.idleberths
this.julis = this.dis
})
},
// 百度地图开发,计算两个点间直线距离js方法(忽略坐标系误差,同样适用于其他地图)
Rad: function (d) {
return d * Math.PI / 180.0; //经纬度转换成三角函数中度分表形式。
},
//计算距离,参数分别为第一点的纬度,经度;第二点的纬度,经度
GetDistance: function (lat1, lng1, lat2, lng2) {
var radLat1 = this.Rad(lat1);
var radLat2 = this.Rad(lat2);
var a = radLat1 - radLat2;
var b = this.Rad(lng1) - this.Rad(lng2);
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378.137; // 地球半径,千米;
s = Math.round(s * 100) / 100; //输出为公里
// s = Math.round(s * 1000) / 1; //单位修改为米,取整
//s=s.toFixed(4);
return s;
},
// 前往车场列表
toParkList: function () {
let me = this
this.$router.push({
name: 'parkList',
query: me.center
})
},
gaodec: function () {
this.popupVisible = true
let me = this
this.n = 10
this.setTimeoutTimer = setInterval(function () {
if(me.n == 0){
window.location.href = "http://api.map.baidu.com/marker?location="+this.latitude+","+this.longitude+"&title=目标地址&content="+this.name+"&output=html&src=webapp.baidu.openAPIdemo"
return
}
me.n --
console.log(me.n)
},1000)
},
}
}
</script>
<style scoped lang="scss">
.parkList {
position: absolute;
right: 10%;
top: 80px;
padding: 3px 8px;
background: #fff;
border: 1px solid #000;
cursor: pointer;
z-index: 887;
text-align: center;
}
.search {
position: absolute;
width: 100%;
padding: 0 10%;
top: 15px;
box-sizing: border-box;
z-index: 887;
height: 40px;
}
.search .psearch {
background: #fff;
width: 100%;
height: 100%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
border-radius: 4px;
}
.search .psearch > div {
float: left;
height: 40px;
line-height: 40px;
font-size: 13px;
color: #C0C0C0;
}
.search .psearch > div:first-child {
width: 87%;
padding-left: 10px;
box-sizing: border-box;
}
.search .psearch > div:first-child > div {
height: 40px;
background: #C0C0C0;
width: 1px;
float: right;
}
.search .psearch > div:last-child {
width: 13%;
text-align: center;
}
.map {
width: 100%;
height: 100%;
}
.onepark {
width: 100%;
position: absolute;
bottom: 0;
z-index: 887;
padding: 8px 10px;
box-sizing: border-box;
}
.neir {
width: 100%;
background: #0D9BF2;
/*border-radius: 5px;*/
border: 1px solid #9B9B9B;
display: table;
background: #307ff5;
}
.neir > div {
display: inline-block;
height: 100px;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
vertical-align: middle;
display: table-cell;
}
.neir > div.leftinfo {
background: #fff;
width: 80%;
}
.neir > div.rightinfo {
width: 20%;
text-align: center;
color: #fff;
font-size: 14px;
}
.neir > div.rightinfo i {
font-size: 30px;
color: #fff;
}
.leftinfo .bg00f {
background: #00ff00;
color: #fff;
border-radius: 3px;
font-size: 12px;
padding: 3px 5px;
}
.leftinfo .font00f {
color: #0f0;
}
.leftinfo .ladres .font0f0 {
color: #00f;
}
</style>