|
@@ -1,40 +1,92 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <baidu-map class="map"
|
|
|
- ak="cpq3rAsODbEpnA8avGt0FWFI7vUIfzgr"
|
|
|
- :center="center"
|
|
|
- :zoom="zoom"
|
|
|
- @ready="handler">
|
|
|
- </baidu-map>
|
|
|
+ <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>
|
|
|
-import BaiduMap from 'vue-baidu-map/components/map/Map.vue'
|
|
|
export default {
|
|
|
- data () {
|
|
|
- return {
|
|
|
- center: { lng: 116, lat: 116 },
|
|
|
- zoom: 20
|
|
|
+ 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, // 教学点
|
|
|
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 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('请重新选择地址')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- },
|
|
|
- mounted () {
|
|
|
- },
|
|
|
- components: {
|
|
|
- BaiduMap,
|
|
|
- },
|
|
|
- methods: {
|
|
|
- handler () {
|
|
|
- //{ BMap, map }
|
|
|
- this.center.lng = 116.404
|
|
|
- this.center.lat = 39.915
|
|
|
- this.zoom = 15
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
</script>
|
|
|
<style lang="scss">
|
|
|
-.map {
|
|
|
+.el-vue-amap-container {
|
|
|
width: 100%;
|
|
|
height: 500px;
|
|
|
}
|