resident.js
2.63 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
/*
* @Author: 'wangzhihui' '1733904062@qq.com'
* @Date: 2024-11-28 16:37:15
* @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditTime: 2024-12-30 15:13:49
* @FilePath: \oEshield\src\utils\resident.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import EventBus from '../event-bus'
import mapService from './mapBService.js'
import MAPGEO from './mapgeo'
//常驻地
const resident = {
data: [],
markers: {},
infowins: {},
bindEvent(){
EventBus.$on('uiMap.resident.draw', (data)=>{
this.destroy();
this.draw(data);
});
EventBus.$on('uiMap.resident.destroy', ()=>{
this.destroy()
});
EventBus.$on('uiMap.resident.openInfoWindow', (idx)=>{
if(this.markers[idx]){
const lnglat = this.markers[idx].getPosition();
AMap.invoke("mapOpenInfoWindow", this.infowins[idx],lnglat)
AMap.invoke('centerAndZoom',lnglat,13)
}
});
},
draw(data){
const MAP = mapService.map;
this.data = data;
let paths=[]
// v1.7.0常驻地为保证导出内容与显示一致 取后端返回的address 不需高德逆地址解析
EventBus.$emit('uiMap.historyLocation.transferSuccess', data);
this.data.forEach((item)=>{
if(parseFloat(item.blng) === 0 && parseFloat(item.blat) === 0) return;
let lnglatXY=mapService.getLngLat(parseFloat(item.blng), parseFloat(item.blat));
paths.push(lnglatXY)
let marker = mapService.createConstantMarker(lnglatXY, MAP);
let infoWindow = mapService.bindResidentInfoWindow(marker, MAP, item);
this.markers[item.idx] = marker;
this.infowins[item.idx] = infoWindow;
MAP.invoke('addOverlay',this.markers[item.idx])
});
AMap.invoke('setViewport',paths)
// mapService.invoke('panTo', MAP.getCenter())
},
intervalDraw(){
},
destroy: function(){
for(let idx in this.markers){
AMap.invoke('removeOverlay',this.markers[idx])
}
for(let idx in this.infowins){
AMap.invoke('mapCloseInfoWindow')
}
this.markers = {};
this.infowins = {};
this.clearTimeoutIds();
},
clearTimeoutIds(){
this.timeoutIds && this.timeoutIds.forEach((item)=>{
item && window.clearTimeout(item);
});
this.timeoutIds = []
}
}
export default resident;