resident.js
2.43 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
import EventBus from '../event-bus'
import mapService from './mapService.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 mapapi = mapService.mapapi
const lnglat = this.markers[idx].getPosition()
// this.infowins[idx].open(MAP, lnglat)
mapapi.invoke('mapOpenInfoWindow', this.infowins[idx], lnglat)
// MAP.setZoomAndCenter(MAP.getZoom(), lnglat)
// mapapi.invoke('setViewport', [lnglat])
mapapi.invoke('panTo', lnglat)
// mapapi.invoke('centerAndZoom', mapapi.invoke('Point', lnglat), 15)
}
})
},
draw(data) {
const MAP = mapService.map
this.data = data
MAPGEO.transferAddressByGroup(this, () => {
const mapapi = mapService.mapapi
EventBus.$emit('uiMap.historyLocation.transferSuccess', data)
this.data.forEach((item) => {
if (parseFloat(item.blng) === 0 && parseFloat(item.blat) === 0) return
const marker = mapService.createConstantMarker(mapService.getLngLat(parseFloat(item.blng), parseFloat(item.blat)), MAP)
console.log(marker)
mapapi.invoke('addOverlay', marker)
const infoWindow = mapService.bindResidentInfoWindow(marker, MAP, item)
this.markers[item.idx] = marker
this.infowins[item.idx] = infoWindow
})
console.log(Object.values(this.markers))
const points = Object.values(this.markers).map(item => item.latLng)
mapapi.invoke('setViewport', points)
// mapService.setFitView(MAP)
})
},
intervalDraw() {
},
destroy: function() {
const mapapi = mapService.mapapi
for (const idx in this.markers) {
// MAP.remove(this.markers[idx])
mapapi.invoke('removeOverlay', this.markers[idx])
}
for (const idx in this.infowins) {
// MAP.remove(this.infowins[idx])
mapapi.invoke('removeOverlay', this.infowins[idx])
}
this.markers = {}
this.infowins = {}
this.clearTimeoutIds()
},
clearTimeoutIds() {
this.timeoutIds && this.timeoutIds.forEach((item) => {
item && window.clearTimeout(item)
})
this.timeoutIds = []
}
}
export default resident