historyLocation.js
3.25 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
import EventBus from '../event-bus'
import mapService from './mapBService.js'
import MAPGEO from './mapgeo'
//历史停留
const historyLocation = {
data: [],
points:[],
cluster:'',
markers: {},
infowins: {},
bindEvent(){
EventBus.$on('uiMap.historyLocation.draw', (data)=>{
this.destroy();
this.data = data;
let markers=[]
// v1.7.0历史停留为保证地址信息显示与导出一致 取后端返回的address 不需高德逆地址解析
EventBus.$emit('uiMap.historyLocation.transferSuccess', data);
this.data.forEach((item)=>{
let lnglatXY=mapService.getLngLat(item.blng, item.blat);
markers.push(lnglatXY)
let marker = mapService.createHistoryLocationMarker(lnglatXY, AMap);
let infoWindow = mapService.bindLocationInfoWindow(marker, AMap, item);
this.markers[item.idx] = marker;
this.infowins[item.idx] = infoWindow;
// AMap.invoke('addOverlay',this.markers[item.idx])
});
AMap.invoke('setViewport',markers)
this.points=markers
this.createClusterer();
});
EventBus.$on('uiMap.historyLocation.destroy', ()=>{
this.destroy();
});
EventBus.$on('uiMap.historyLocation.openInfoWindow', (idx)=>{
if(this.markers[idx]){
const MAP = mapService.map;
const lnglat = this.markers[idx].getPosition();
// this.infowins[idx].open(MAP, lnglat);
AMap.invoke("mapOpenInfoWindow", this.infowins[idx],lnglat)
AMap.invoke('centerAndZoom',lnglat,10)
}
});
},
createClusterer(){
let map=mapService.mapInstance;
var cluster, markers = [];
for(let idx in this.markers){
markers.push(this.markers[idx]);
}
this.cluster = AMap.invoke('Cluster', markers, data => {
return {
point: [data.latLng.lng, data.latLng.lat],
properties: {
marker: data
}
}
})
AMap.invoke('clusterSetData', this.cluster)
AMap.invoke('clusterAddEventListener', 'click', (e) => {
AMap.invoke('infoWindowDisableCloseOnClick', e.properties.marker.openInfoWindow)
AMap.invoke("mapOpenInfoWindow", e.properties.marker.openInfoWindow,e.properties.marker.getPosition() )
})
},
destroy: function(){
const MAP = mapService.map;
this.data = [];
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 = {};
if (this.cluster) {
AMap.invoke('clusterDestroy')
this.cluster = null;
}
this.clearTimeoutIds();
},
clearTimeoutIds(){
this.timeoutIds && this.timeoutIds.forEach((item)=>{
item && window.clearTimeout(item);
});
this.timeoutIds = []
}
}
export default historyLocation;