signceshi.vue
5.2 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
<div>
<div class="amap-page-container">
<el-amap-search-box class="search-box" :search-option="searchOption" :on-search-result="onSearchResult" ></el-amap-search-box>
<el-amap ref="map" vid="amapDemo" :plugin="plugin" :zoom="zoom" :center="center" class="amap-demo" :events="events">
<el-amap-marker vid="component-marker" :position="makerConf.position" :content="makerConf.content" ></el-amap-marker>
</el-amap>
</div>
<div class="adrs">
<ul>
<li class="" v-for="(item,index) in list" :key="index" :class="currIndex == index ? 'active':''" @click="select(item,index)">
<p class="address">{{item.address}}</p>
<p class="nm">{{item.name}}</p>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
name: 'amap-page',
components: {},
data () {
var me = this
me.city = me.city || '武汉'
return {
list: [],
currIndex: 0,
zoom: 16,
center: [114.397169, 30.50576],
events: {
init: (o) => {
o.setCity(me.city, result => {
console.log('----------setCity', result)
if (result && result.length > 0) {
me.zoom = 16
me.makerConf.position = result
me.getList(result)
}
})
// 去掉logo
document.getElementsByClassName('amap-logo')[0].style.display = 'none'
},
dragend: function (e) {
// console.log("dragging",e,this.getCenter());
var point = this.getCenter()
var pos = [point.lng, point.lat]
me.makerConf.position = [point.lng, point.lat]
me.getList(pos)
}
},
makerConf: {
position: [114.397169, 30.50576],
content: ''
},
searchOption: {
city: me.city,
citylimit: true
},
plugin: [
'ToolBar',
'Scale',
{
pName: 'Geolocation',
events: {
init (o) {
},
complete: function (result) {
// 定位成功
var address = result.formattedAddress
var point = result.position
var obj = {
address: address,
name: '',
location: point
}
me.list = [obj]
me.makerConf.position = [point.lng, point.lat]
},
error: function () {
}
}
}
]
}
},
created () {
var me = this
},
mounted () {
},
methods: {
select: function (item, index) {
var me = this
me.currIndex = index
var point = item.location
me.makerConf.position = [point.lng, point.lat]
me.center = [point.lng, point.lat]
},
// this.$refs.map.$$getCenter()
getList: function (result) {
// 获取列表
var me = this
me.$Geocoder({
lnglatXY: result,
success: function (res) {
if (res.regeocode && res.regeocode.pois) {
me.list = res.regeocode.pois
} else {
me.list = []
}
},
error: function (res) {
me.list = []
}
})
},
onSearchResult (pois) {
// 搜索
const latSum = 0
const lngSum = 0
var me = this
var mymap = me.$refs.map.$$getInstance()
if (pois && pois.length > 0) {
// 如果长度为1则无需转化
var poi = pois[0]
var lng = poi.lng
var lat = poi.lat
me.center = [lng, lat]
me.makerConf.position = [lng, lat]
// me.makerConf.content = poi.name;
me.list = pois
} else {
me.list = []
}
},
$Geocoder (options) {
// 将坐标点转化为,详细地址
options = options || {}
if (AMap) {
AMap.plugin(['AMap.Geocoder'], () => {
const geocoder = new AMap.Geocoder({
radius: options.radius || 1000,
extensions: options.extensions || 'all'
})
var lnglatXY = options.lnglatXY || [114.397169, 30.50576] // 已知点坐标
geocoder.getAddress(lnglatXY, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
options.success && options.success(result)
} else {
options.error && options.error(status, result)
}
})
})
}
}
},
watch: {
list: function () {
this.currIndex = 0
}
}
}
</script>
<style scoped>
.amap-page-container{
height: 300px;
position: relative;
}
.search-box {
position: absolute !important;
top: 25px;
left: 20px;
z-index: 200 !important;
}
.amap-demo {
height: 300px;
}
.amap-logo {
display: none;
}
.amap-copyright {
bottom:-100px;
display: none;
}
.amap-scalecontrol{
bottom: 4px !important;
}
.amap-geolocation-con{
bottom: 30px !important;
z-index: 199 !important;
}
ul li.active{
color: deeppink;
}
</style>