AMap.vue
9.83 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<template>
<div class="map-container">
<div id="mapContainer" class="map"></div>
<!-- <div v-if="map" class="tool-bar">-->
<!-- <div class="tool-item" @click="setLocation()">-->
<!-- <img-->
<!-- src="../../../assets/img/location.png"-->
<!-- class="tool-icon tool-icon-default"-->
<!-- />-->
<!-- <img-->
<!-- src="../../../assets/img/active-location.png"-->
<!-- class="tool-icon tool-icon-active"-->
<!-- />-->
<!-- </div>-->
<!-- <div class="tool-item" @click="zoomIn()">+</div>-->
<!-- <div class="tool-item" @click="zoomOut()">-</div>-->
<!-- </div>-->
</div>
</template>
<script>
import AMapLoader from '@amap/amap-jsapi-loader'
import blueIcon from '@/assets/images/location.png'
export default {
props: {
data: {
type: Array,
default: () => {
return []
}
},
},
data() {
return {
map: null,
list: [],
centerPoint: {
lng: 116.367683,
lat: 39.978279
},
circlePoint: {
lng: 116.367837,
lat: 39.978076
},
screenWidth: null,
zoomCtrl: null,
infoWindow: null,
infoWarning: null,
defaultZoom: 5,
active: 0,
emergency: []
}
},
watch: {
data: {
immediate: true,
deep: true,
handler(val) {
console.log("val",val)
this.list = val || []
this.defaultZoom = 5
console.log("this.listq",this.list)
if (!this.map) {
this.initMap()
}
setTimeout(() => {
this.refreshMap()
}, 300)
}
},
},
mounted() {
this.initMap()
},
methods: {
initMap() {
window._AMapSecurityConfig = {
securityJsCode: process.env.VUE_APP_AMAP_CODE
}
AMapLoader.load({
key: process.env.VUE_APP_AMAP_KEY,
version: '2.0',
plugins: ['AMap.ToolBar'],
AMapUI: {
version: '1.1',
plugins: ['control/BasicControl']
}
})
.then(AMap => {
const options = {
viewMode: '2D',
pitch: 40,
center: [this.centerPoint.lng, this.centerPoint.lat],
zoom: this.defaultZoom,
layers: [
// 卫星
new AMap.TileLayer.Satellite(),
// 路网
new AMap.TileLayer.RoadNet()
],
// scrollWheel: true
}
this.map = new AMap.Map('mapContainer', options)
// this.map.on('click', () => {
// if (this.infoWindow) {
// this.infoWindow.close()
// this.infoWindow = null
// this.infoWarning = null
// }
// })
this.refreshMap()
})
.catch(e => {
console.error('地图加载失败', e)
})
},
zoomIn() {
this.map.zoomIn()
},
zoomOut() {
this.map.zoomOut()
},
setLocation(lng, lat) {
console.log("lnglat",lng,lat)
if (lng && lat) {
console.log("mapref")
let pointCenter = [lng, lat]
this.map.setZoomAndCenter(15, pointCenter, true)
this.refreshMap()
} else {
const center = [this.centerPoint.lng, this.centerPoint.lat]
this.map.setZoomAndCenter(this.defaultZoom, center, true)
}
},
refreshMap() {
if (!this.map) {
return
}
this.map.clearMap()
console.log("this.list",this.list)
this.list.forEach(async (item, index) => {
const point = new AMap.LngLat(item.f_jd, item.f_wd)
console.log("point",point)
var blueMark = new AMap.Icon({
size: new AMap.Size(30, 38), // 图标尺寸
image: blueIcon, // Icon的图像,本地图标Vue引入
imageSize: new AMap.Size(30, 38), // 根据所设置的大小拉伸或压缩图片
});
const marker = new AMap.Marker({
icon: blueMark,
position: point,
clickable: true,
offset: new AMap.Pixel(-25, -25),
})
// marker.on('click', () => {
// this.displayInfo(point, item)
// })
this.map.add(marker)
})
},
async displayInfo(point, item) {
this.centerPoint = {
lng: item.f_jd,
lat: item.f_wd
}
let pointer = new AMap.LngLat(item.f_jd, item.f_wd)
this.map.setCenter([pointer.KL,pointer.kT])
const content = `<div class='info-window'>
<div class='title'>气瓶信息</div>
<div class='line'></div>
<div>气瓶编号:${item.f_qpbh}</div>
<div>气瓶规格: ${item.f_qpgg}${item.F_czjz}</div>
<div>地址: ${item.F_dqs}${item.F_dqq}${item.F_dqjd}</div>
</div>`
this.infoWindow = new AMap.InfoWindow({
isCustom: true,
content: [content],
offset: new AMap.Pixel(150, -50)
})
this.infoWindow.open(this.map, point)
},
}
}
</script>
<style scoped lang="scss">
@import './style';
.map-container {
width: 100%;
height: 100%;
position: relative;
.tool-bar {
position: absolute;
bottom: 30px;
right: 30px;
background-color: #2b2b2b;
color: #ffffff;
.tool-item {
width: 26px;
height: 26px;
cursor: pointer;
box-shadow: 1px 2px 1px rgba(0, 0, 0, 0.15);
display: flex;
justify-content: center;
align-items: center;
color: #999999;
font-size: 20px;
.tool-icon {
width: 16px;
height: 16px;
}
.tool-icon-default {
display: inline-block;
}
.tool-icon-active {
display: none;
}
&:hover {
color: #1782e5;
.tool-icon-active {
display: inline-block !important;
}
.tool-icon-default {
display: none !important;
}
}
}
}
::v-deep .amap-info-contentContainer {
display: flex;
}
.map {
width: 100%;
height: 100%;
::v-deep {
.anchorBL {
display: none;
}
.amap-logo {
display: none !important;
}
.info-warning {
width: 300px;
height: 240px;
//background-color: #051d4f;
font-family: SourceHanSansCN-Medium;
box-sizing: border-box;
color: #ffffff;
border-radius: 10px;
border: 2px solid #98333b;
padding: 13px 15px 0px 20px;
.warning-h3 {
text-align: center;
font-weight: normal;
font-size: 16px;
margin: 0px 0px 7px 0px;
padding: 0px;
}
.info-warning-row {
display: flex;
flex-direction: column;
width: 100%;
overflow: auto;
.info-warning-title {
display: flex;
width: 100%;
justify-content: space-between;
margin-bottom: 15px;
.info-depth,
.info-depth-active {
width: 30%;
text-align: center;
background-color: #475676;
border-radius: 16px;
padding: 3px 8px;
}
.info-depth-active {
background-color: #0041c3;
}
.info-depth:nth-child(1),
.info-depth:nth-child(2) {
margin-right: 15px;
}
}
.info-dataWarning {
width: 100%;
height: 127px;
overflow: hidden;
overflow: auto;
}
#info-dataWarning {
color: #fff;
}
// 预警处理方案的滚动条
.info-dataWarning::-webkit-scrollbar {
// display: none; //隐藏滚动条
}
/*定义整体的宽度*/
.info-dataWarning::-webkit-scrollbar {
width: 6px;
}
/*定义滚动条轨道*/
.info-dataWarning::-webkit-scrollbar-track {
border-radius: 5px;
}
/*定义滑块*/
.info-dataWarning::-webkit-scrollbar-thumb {
border-radius: 5px;
background: rgba(27, 140, 236, 0.5);
}
}
}
.info-window {
background-color: #ffffff;
width: 300px;
min-height: 150px;
height: auto;
box-sizing: border-box;
font-family: SourceHanSansCN-Medium;
position: relative;
border-radius: 10px;
padding: 20px 10px 10px 10px;
.title {
color: gray;
font-size: 18px;
}
div {
height: 24px;
line-height: 24px;
}
.line {
width: 100%;
height: 1px;
background-color: gray;
margin: 10px 0;
}
.commondis {
display: flex;
justify-content: space-around;
align-items: center;
}
}
.BMap_stdMpZoom {
bottom: 180px;
.BMap_stdMpZoomIn {
background-color: #2b2b2b;
border-bottom-color: #000;
}
.BMap_stdMpZoomOut {
background-color: #2b2b2b;
}
}
}
}
@media all and (max-width: 1600px) {
.tool-bar {
right: calc(30% + 40px) !important;
}
}
}
</style>