Commit 4e9e706e by 前端

Merge branch 'change-map' into 'master'

上线合并

See merge request !2
2 parents 5848fd4c 90922fef
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-11-25 20:11:22
* @LastEditors: limin
* @LastEditTime: 2020-11-25 20:29:36
*/
export default function loadMap ({key='qRLkZJN32WsQe2LMSTjduuTs2TObie3x', v = '3.0'}={}) {
return new Promise(function (resolve, reject) {
if (typeof BMap !== 'undefined') {
resolve(BMap)
return true
}
window.onCallback = function () {
resolve(BMap)
}
let script = document.createElement('script')
script.type = 'text/javascript'
script.src = `//api.map.baidu.com/api?v=${v}&ak=${key}&callback=onCallback`
script.onerror = reject
document.head.appendChild(script)
})
}
......@@ -42,7 +42,7 @@
>
<span :class="[hasLocation ? 'error map-txt' : 'error', isEdit ? 'mapTips-edit': 'mapTips']">{{i.value}}</span>
<gl-button v-if="isEdit && i.label == 'POI位置点'" class="mapTips-button" @click="markAddr(isMarkAddr = true)">标记位置点</gl-button>
<el-amap
<!-- <el-amap
vid='amapDemo'
:center='center'
:amap-manager='amapManager'
......@@ -50,7 +50,9 @@
:events='events'
class='amap-demo'
>
</el-amap>
</el-amap> -->
<div id="container"
class='amap-demo'></div>
</div>
<span v-else-if="i.isImg">
<img
......@@ -155,20 +157,21 @@
</template>
<script>
import VueAMap from 'vue-amap'
// import VueAMap from 'vue-amap'
import Vue from 'vue'
import axios from 'axios'
import qs from 'qs'
import { businessManagenMethods, bizMethods, request } from '@/api'
import loadBMap from '@/common/loadBmap'
import notice from '@/common/notice'
var marker = []
const amapManager = new VueAMap.AMapManager()
VueAMap.initAMapApiLoader({
key: '44cc16e43ad7ed3358df507bd0618181',
plugin: ['AMap.Geocoder'],
uiVersion: '1.0'
})
Vue.use(VueAMap)
// const amapManager = new VueAMap.AMapManager()
// VueAMap.initAMapApiLoader({
// key: '44cc16e43ad7ed3358df507bd0618181',
// plugin: ['AMap.Geocoder'],
// uiVersion: '1.0'
// })
// Vue.use(VueAMap)
export default {
name: 'BusinessDetails',
data() {
......@@ -244,8 +247,9 @@ export default {
isMap: true
}
],
amapManager,
// amapManager,
zoom: 12,
map: null,
// 地图中心点(初始化得有值);也是标记点
center: [113.939723, 22.525351],
events: {
......@@ -401,6 +405,28 @@ export default {
})
},
methods: {
intiBMap(lng = 103.048078, lat = 36.383814) {
var that = this
loadBMap().then(BMap => {
that.map = new BMap.Map('container')
that.map.clearOverlays()
var point = new BMap.Point(Number(lng), Number(lat))
that.map.centerAndZoom(point, this.zoom)
that.map.addEventListener("tilesloaded", function() {
that.assignBasicInfo()
that.map.panTo(point)
});
that.map.addEventListener('click', function(e) {
if (that.isMarkAddr) {
console.log(e)
that.map.clearOverlays()
that.merchantInfo.lng = e.point.lng
that.merchantInfo.lat = e.point.lat
that.getAddress(e.point.lng, e.point.lat)
}
})
})
},
back() {
this.$parent.to(['商户数据平台', '商户数据管理', '商户数据', '商户列表管理', '商户数据列表'])
},
......@@ -426,6 +452,13 @@ export default {
this.merchantInfo.merchantPortrait = this.List[9].value
const params = this.$deep_clone(this.merchantInfo)
delete params.merchantChannelName
params.lat = params.lat.toFixed(6)
params.lng = params.lng.toFixed(6)
let attrList = Object.keys(params)
attrList.forEach(item => {
params[item] = params[item] || ''
})
console.log(params, 'params--')
params.method = bizMethods.MerchantModify
// console.log(params)
request.req(params).then(res => {
......@@ -440,10 +473,16 @@ export default {
this.merchantInfo = JSON.parse(JSON.stringify(this.tempMerchantInfo))
this.List[9].value = this.merchantInfo.merchantPortrait
if (!this.merchantInfo.lng && !this.merchantInfo.lat) {
marker && amapManager._map.remove(marker)
// marker && amapManager._map.remove(marker)
this.map.clearOverlays()
this.hasLocation = false
this.List[10].value = '无位置信息'
} else {
this.List[10].value = this.merchantInfo.address
this.map.clearOverlays()
var point = new BMap.Point(this.merchantInfo.lng, this.merchantInfo.lat)
this.map.centerAndZoom(point, this.zoom)
this.map.panTo(point)
// this.getAddress(this.merchantInfo.lng, this.merchantInfo.lat)
}
}
......@@ -486,10 +525,9 @@ export default {
params.method = bizMethods.Detail
request.req(params).then(res => {
this.merchantInfo = res
console.log(this.merchantInfo)
// this.merchantInfo.lng = ''
// this.merchantInfo.lat = ''
this.assignBasicInfo()
this.intiBMap(this.merchantInfo.lng, this.merchantInfo.lat, true)
this.IdChange[0] = 0
this.basicLoading = false
}).catch(err => {
......@@ -515,27 +553,50 @@ export default {
},
// 根据经纬度获取地址名
getAddress(lng, lat) {
amapManager._map.remove(marker)
marker = []
if (lng && lat) this.center = [+lng, +lat]
var geocoder = new AMap.Geocoder({ // eslint-disable-line
radius: 1000,
extensions: 'all'
})
geocoder.getAddress(this.center, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
const mar = new AMap.Marker({ // eslint-disable-line
position: this.center,
title: result.regeocode.formattedAddress
})
marker.push(mar)
amapManager._map.add(marker)
this.hasLocation = true
this.merchantInfo.lng = this.center[0]
this.merchantInfo.lat = this.center[1]
this.List[10].value = result.regeocode.formattedAddress
}
})
var that = this
var myGeo = new BMap.Geocoder();
// 根据坐标得到地址描述
myGeo.getLocation(new BMap.Point(lng, lat), function(result){
if (result){
console.log(result);
var point = new BMap.Point(lng, lat)
var marker = new BMap.Marker(point)
that.map.addOverlay(marker)
that.merchantInfo.address = result.address
let code = result.content.address_detail.adcode + ''
let name = result.addressComponents
that.merchantInfo.provinceId = code.slice(0,2) + '0000'
that.merchantInfo.provinceName = name.province
that.merchantInfo.cityId = code.slice(0,4) + '00'
that.merchantInfo.cityName = name.city
that.merchantInfo.areaId = code
that.merchantInfo.areaName = name.district
that.List[10].value = result.address
that.hasLocation = true
that.map.panTo(point)
}
});
// amapManager._map.remove(marker)
// marker = []
// if (lng && lat) this.center = [+lng, +lat]
// var geocoder = new AMap.Geocoder({ // eslint-disable-line
// radius: 1000,
// extensions: 'all'
// })
// geocoder.getAddress(this.center, (status, result) => {
// if (status === 'complete' && result.info === 'OK') {
// const mar = new AMap.Marker({ // eslint-disable-line
// position: this.center,
// title: result.regeocode.formattedAddress
// })
// marker.push(mar)
// amapManager._map.add(marker)
// this.hasLocation = true
// this.merchantInfo.lng = this.center[0]
// this.merchantInfo.lat = this.center[1]
// this.List[10].value = result.regeocode.formattedAddress
// }
// })
},
markAddr() {
this.hasLocation = true
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!