|
@@ -1,88 +1,91 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <el-amap :zoom="zoom" :plugin="plugin" :center="center">
|
|
|
- <el-amap-marker :clickable="true"
|
|
|
- :events="marker.events"
|
|
|
- :position="marker.position"
|
|
|
- v-for="(marker, index) in markers"
|
|
|
- :key="index" ></el-amap-marker>
|
|
|
+ <el-amap :zoom="zoom"
|
|
|
+ :plugin="plugin"
|
|
|
+ :center="center">
|
|
|
+ <el-amap-marker :clickable="true"
|
|
|
+ :events="marker.events"
|
|
|
+ :position="marker.position"
|
|
|
+ v-for="(marker, index) in markers"
|
|
|
+ :key="index"></el-amap-marker>
|
|
|
</el-amap>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
export default {
|
|
|
- data () {
|
|
|
- let self = this
|
|
|
- return {
|
|
|
- zoom: 14,
|
|
|
- center: [114.34371, 30.55939],
|
|
|
- markers: [],
|
|
|
- searchResult: [], // 搜索出来的数据
|
|
|
- plugin: [{
|
|
|
- pName: 'Geolocation',
|
|
|
- events: {
|
|
|
- init(o) {
|
|
|
- o.getCurrentPosition((status, result) => {
|
|
|
- if(result && result.position) {
|
|
|
- self.lng = result.position.lng
|
|
|
- self.lat = result.position.lat
|
|
|
- self.center = [self.lng, self.lat]
|
|
|
- self.loaded = true
|
|
|
- self.$nextTick()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }],
|
|
|
- searchOption: {
|
|
|
- pageSize: 1, // 单页显示结果条数
|
|
|
- pageIndex: 1, // 页码
|
|
|
- autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
|
|
|
- },
|
|
|
- addressDetail: null, // 输入详情地址
|
|
|
- teachingSchool: null, // 教学点
|
|
|
+ data () {
|
|
|
|
|
|
+ return {
|
|
|
+ zoom: 14,
|
|
|
+ center: [114.34371, 30.55939],
|
|
|
+ markers: [],
|
|
|
+ searchResult: [], // 搜索出来的数据
|
|
|
+ plugin: [{
|
|
|
+ pName: 'Geolocation',
|
|
|
+ events: {
|
|
|
+ init (o) {
|
|
|
+ o.getCurrentPosition((status, result) => {
|
|
|
+ if (result && result.position) {
|
|
|
+ self.lng = result.position.lng
|
|
|
+ self.lat = result.position.lat
|
|
|
+ self.center = [self.lng, self.lat]
|
|
|
+ self.loaded = true
|
|
|
+ self.$nextTick()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
+ }],
|
|
|
+ searchOption: {
|
|
|
+ pageSize: 1, // 单页显示结果条数
|
|
|
+ pageIndex: 1, // 页码
|
|
|
+ autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
|
|
|
+ },
|
|
|
+ addressDetail: null, // 输入详情地址
|
|
|
+ teachingSchool: null, // 教学点
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ let self = this
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ onSearch () {
|
|
|
+ if (!this.search_value) return
|
|
|
+ this.markers = [] // 重置位置
|
|
|
+ let mapSearch = new AMap.PlaceSearch(this.searchOption)
|
|
|
+ // 目前只需要搜索第一条数据
|
|
|
+ mapSearch.search(this.search_value, (status, sr) => {
|
|
|
+ if (sr && sr.poiList && sr.poiList.count) {
|
|
|
+ let pois = sr.poiList.pois[0]
|
|
|
+ this.searchResult.push(pois)
|
|
|
+ this.markers.push({
|
|
|
+ position: [pois.location.lng, pois.location.lat],
|
|
|
+ events: this.markerEvents(pois)
|
|
|
+ })
|
|
|
+ this.center = [pois.location.lng, pois.location.lat]
|
|
|
+ } else if (sr.poiList === undefined) {
|
|
|
+ throw new Error(sr);
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
- mounted () {
|
|
|
- },
|
|
|
- methods: {
|
|
|
- onSearch() {
|
|
|
- if(!this.search_value) return
|
|
|
- this.markers = [] // 重置位置
|
|
|
- let mapSearch = new AMap.PlaceSearch(this.searchOption)
|
|
|
- // 目前只需要搜索第一条数据
|
|
|
- mapSearch.search(this.search_value, (status, sr) => {
|
|
|
- if(sr && sr.poiList && sr.poiList.count) {
|
|
|
- let pois = sr.poiList.pois[0]
|
|
|
- this.searchResult.push(pois)
|
|
|
- this.markers.push({
|
|
|
- position: [pois.location.lng, pois.location.lat],
|
|
|
- events: this.markerEvents(pois)
|
|
|
- })
|
|
|
- this.center = [pois.location.lng, pois.location.lat]
|
|
|
- } else if (sr.poiList === undefined) {
|
|
|
- throw new Error(sr);
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- markerEvents(pois) {
|
|
|
- // marker 事件列表
|
|
|
- let that = this
|
|
|
- return {
|
|
|
- click: (e) => {
|
|
|
- let geocoder = new AMap.Geocoder()
|
|
|
- geocoder.getAddress(e.lnglat, function(status, result) {
|
|
|
- if(status === 'complete' && result.regeocode) {
|
|
|
- that.addressDetail = result.regeocode.formattedAddress
|
|
|
- } else {
|
|
|
- that.$toast('请重新选择地址')
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ markerEvents (pois) {
|
|
|
+ // marker 事件列表
|
|
|
+ let that = this
|
|
|
+ return {
|
|
|
+ click: (e) => {
|
|
|
+ let geocoder = new AMap.Geocoder()
|
|
|
+ geocoder.getAddress(e.lnglat, function (status, result) {
|
|
|
+ if (status === 'complete' && result.regeocode) {
|
|
|
+ that.addressDetail = result.regeocode.formattedAddress
|
|
|
+ } else {
|
|
|
+ that.$toast('请重新选择地址')
|
|
|
}
|
|
|
+ })
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
<style lang="scss">
|