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
| <template>
| <div class="map-view">
| <div id="choicemap"/>
| <i
| class="el-icon-close map-close"
| @click="hiddenView"/>
| </div>
| </template>
|
| <script type="text/javascript">
| import { getMaxIndex } from '@/utils/index'
| export default {
| name: 'MapView', // 地图详情
| components: {},
| props: {
| /**
| * title 内容
| * lat lng 经纬度
| */
| title: {
| type: String,
| default: ''
| },
| lat: {
| type: Number,
| default: 0
| },
| lng: {
| type: Number,
| default: 0
| }
| },
| data () {
| return {}
| },
| computed: {},
| mounted () {
| this.$el.style.zIndex = getMaxIndex()
| document.body.appendChild(this.$el)
|
| let map = new BMap.Map('choicemap', { enableMapClick: false })
| let point = new BMap.Point(this.lng, this.lat)
| map.centerAndZoom(point, 18)
| map.enableScrollWheelZoom()
|
| let marker = new BMap.Marker(point) // 创建标注
| map.addOverlay(marker) // 将标注添加到地图中
| let infoWindow = new BMap.InfoWindow(this.title) // 创建信息窗口对象
| marker.addEventListener('click', function () {
| map.openInfoWindow(infoWindow, point) // 开启信息窗口
| })
| },
| destroyed () {
| // remove DOM node after destroy
| if (this.$el && this.$el.parentNode) {
| this.$el.parentNode.removeChild(this.$el)
| }
| },
| methods: {
| hiddenView () {
| this.$emit('hidden')
| }
| }
| }
| </script>
| <style lang="less" scoped>
| .map-view {
| position: fixed;
| width: 100%;
| height: 100%;
| top: 0;
| left: 0;
| background-color: #000;
| }
|
| .map-close {
| position: absolute;
| right: 10px;
| top: 10px;
| font-size: 28px;
| color: #fff;
| cursor: pointer;
| }
|
| #choicemap {
| position: absolute;
| left: 100px;
| top: 100px;
| bottom: 100px;
| right: 100px;
| overflow: hidden;
| }
| </style>
|
|