activeLocation.vue
2.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
<template>
<v-full-layout class="active_location">
<template slot="breadcrumb">
<el-breadcrumb-item>激活位置</el-breadcrumb-item>
</template>
<template slot="main">
<div id="map" class="map-container"></div>
</template>
</v-full-layout>
</template>
<script>
import mapService from 'utils/mapService.js'
import "utils/mapEvent.js";
import EventBus from '../../event-bus'
import remoteLoad from "utils/remoteLoad.js";
import {CONSTANT} from '../../constant'
export default {
data() {
return {
AMap: null,
mapObj: null,
checkLoadedTimeoutId: "",
};
},
created() {
console.log(history.state)
if (window.AMap) {
this.initMap();
} else {
remoteLoad(`${CONSTANT.AMAP_URL}`).then(() => {
remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(
() => {
this.initMap();
}
);
});
}
},
methods: {
// 初始化地图
initMap() {
let check = () => {
if (this.checkLoadedTimeoutId) {
window.clearTimeout(this.checkLoadedTimeoutId);
}
return setTimeout(() => {
if (
"AMap" in window &&
typeof AMap.Map == "function" &&
!this.mapObj
) {
window.AMap = AMap;
this.mapObj = mapService.init("map");
this.isInitMap = true;
let o = history.state;
console.log(o)
if (o.lng || o.bsLng) {
o.elat = o.lat;
o.elng = o.lng;
this.addLocation(o);
}
} else {
this.checkLoadedTimeoutId = check();
}
}, 100);
};
this.checkLoadedTimeoutId = check();
},
// 添加位置点
addLocation(row) {
let drawData = row;
EventBus.$emit("uiMap.monitor.drawMaker", drawData, true);
},
},
};
</script>
<style lang="scss" scoped>
.active_location {
.full-width {
position: absolute;
top: 0px;
height: 100%;
left: 0;
width: 100%;
bottom: 0;
.map-container {
width: 100%;
height: 100%;
z-index: 100;
position: absolute;
top: 0px;
left: 0;
bottom: 0;
overflow: hidden;
}
}
}
</style>