Commit 1027c9c7 authored by rencs's avatar rencs
parents d2a5a3ff b3ed9e7f
...@@ -45,10 +45,26 @@ ...@@ -45,10 +45,26 @@
</el-autocomplete> </el-autocomplete>
</el-col> </el-col>
</el-form-item> </el-form-item>
<el-form-item label="" prop="lat"> <el-form-item label="" prop="lat" v-if="showMap">
<div id="map-container"> <baidu-map
style="height: 345px;width:610px;margin-right: 63px;min-width: 610px;"
</div> :zoom="zoom"
:dragging="true"
:scroll-wheel-zoom="true"
@ready="handler"
@click="getPoint"
>
<bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
<bm-geolocation
style="width: 100px; height: 100px"
anchor="BMAP_ANCHOR_BOTTOM_RIGHT"
:showAddressBar="true"
:autoLocation="true"
></bm-geolocation>
<bm-marker
:position="{ lng: form.lng, lat: form.lat }"
></bm-marker>
</baidu-map>
</el-form-item> </el-form-item>
<el-form-item label="公司简介" prop="intro"> <el-form-item label="公司简介" prop="intro">
<el-col :span="20"> <el-col :span="20">
...@@ -79,6 +95,8 @@ export default { ...@@ -79,6 +95,8 @@ export default {
}, },
data() { data() {
return { return {
zoom: 15,  //地图展示级别
showMap: false,
form: { form: {
id: undefined, id: undefined,
phone: undefined, // 联系电话 phone: undefined, // 联系电话
...@@ -126,62 +144,44 @@ export default { ...@@ -126,62 +144,44 @@ export default {
}, },
async mounted() { async mounted() {
await loadBMap('gvQPveN9YrlPSgKUMPK2u2u2BA4yQFRm') await loadBMap('gvQPveN9YrlPSgKUMPK2u2u2BA4yQFRm')
this.initMap() this.getCompanyInfo()
}, },
methods: { methods: {
initMap() { /**
var that = this; * 加载地图
this.map = new BMap.Map("map-container", {enableMapClick:false}) //新建地图实例,enableMapClick:false :禁用地图默认点击弹框 * */
var point = new BMap.Point(this.form.lng, this.form.lat); handler ({BMap, map}) {
this.map.centerAndZoom(point,19) let that = this
var point = new BMap.Point(this.form.lng, this.form.lat);//定义一个中心点坐标
/** 设置图像标注并绑定拖拽标注结束后事件 */ map.centerAndZoom(point,12);//设定地图的中心点和坐标并将地图显示在地图容器中
this.mk = new BMap.Marker(point,{enableDragging:true}) //创建一个图像标注实例,enableDragging:是否启用拖拽,默认为false window.map = map;//将map变量存储在全局
this.map.addOverlay(this.mk) //将覆盖物添加到地图中 map.enableDragging();//启用地图拖拽事件,默认启用(可不写)
this.mk.addEventListener('dragend', function(e){ map.enableScrollWheelZoom();//启用地图滚轮放大缩小
that.getAddrByPoint(e.point) //拖拽结束后调用逆地址解析函数,e.point为拖拽后的地理坐标 map.enableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写)
}); map.enableKeyboard();//启用键盘上下左右键移动地图
//向地图中添加缩略图控件
/** 添加(右上角)平移缩放控件 */ var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
var navigationControl = new BMap.NavigationControl({ //创建一个特定样式的地图平移缩放控件 map.addControl(ctrl_ove);
anchor: BMAP_ANCHOR_TOP_RIGHT, //靠右上角位置 //向地图中添加比例尺控件
type: BMAP_NAVIGATION_CONTROL_SMALL //SMALL控件类型 var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
}); map.addControl(ctrl_sca);
this.map.addControl(navigationControl ) //将控件添加到地图 window.map.panTo(point) //将地图的中心点更改为选定坐标点
/** 添加(左下角)定位控件 */
var geolocationControl = new BMap.GeolocationControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT}) //创建一个地图定位控件
geolocationControl.addEventListener("locationSuccess", function(e){ //绑定定位成功后事件
that.getAddrByPoint(e.point) //定位成功后调用逆地址解析函数
});
geolocationControl.addEventListener("locationError",function(e){ //绑定定位失败后事件
// alert(e.message);
console.log("绑定定位失败后事件",e.message)
});
this.map.addControl(geolocationControl) //将控件添加到地图
/** 浏览器定位 */
this.geolocation()
/** 绑定点击地图任意点事件 */
this.map.addEventListener('click', function(e){ //给地图绑定点击事件
that.getAddrByPoint(e.point) //点击后调用逆地址解析函数
});
}, },
/** /**
* 逆地址解析函数(根据坐标点获取详细地址) * 点击地图取点
* @param {Object} point 百度地图坐标点,必传 * @param e
*/ */
getAddrByPoint(point){ getPoint(e){ //点击地图获取一些信息,
var that = this; let geocoder= new BMap.Geocoder(); //创建地址解析器的实例
var geco = new BMap.Geocoder(); geocoder.getLocation(e.point,rs=>{
geco.getLocation(point, function(res){ this.form.address = rs.address; //记录该点的详细地址信息
console.log(res) //内容见下图 this.form.lat = rs.point.lat;
that.mk.setPosition(point) //重新设置标注的地理坐标 this.form.lng = rs.point.lng;
that.map.panTo(point) //将地图的中心点更改为给定的点 window.map.clearOverlays() //清除地图上所有覆盖物
that.form.address = res.address; //记录该点的详细地址信息 this.mk = new BMap.Marker(rs.point) //根据所选坐标重新创建Marker
that.form.lat = point.lat window.map.addOverlay(this.mk) //将覆盖物重新添加到地图中
that.form.lng = point.lng window.map.panTo(rs.point) //将地图的中心点更改为选定坐标点
// that.form.addrPoint = point; //记录当前坐标点 });
})
}, },
/** /**
* 浏览器定位函数 * 浏览器定位函数
...@@ -191,7 +191,7 @@ export default { ...@@ -191,7 +191,7 @@ export default {
var geolocation = new BMap.Geolocation(); var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(res){ geolocation.getCurrentPosition(function(res){
if(this.getStatus() == BMAP_STATUS_SUCCESS){ if(this.getStatus() == BMAP_STATUS_SUCCESS){
that.getAddrByPoint(res.point) //当成功时,调用逆地址解析函数 that.getPoint(res.point) //当成功时,调用逆地址解析函数
} else { } else {
// alert('failed'+this.getStatus()); //失败时,弹出失败状态码 // alert('failed'+this.getStatus()); //失败时,弹出失败状态码
console.log("失败状态码",this.getStatus()) console.log("失败状态码",this.getStatus())
...@@ -215,7 +215,7 @@ export default { ...@@ -215,7 +215,7 @@ export default {
} }
} }
} }
var local = new BMap.LocalSearch(this.map, options) //创建LocalSearch构造函数 var local = new BMap.LocalSearch(window.map, options) //创建LocalSearch构造函数
local.search(str) //调用search方法,根据检索词str发起检索 local.search(str) //调用search方法,根据检索词str发起检索
}, },
/** /**
...@@ -224,15 +224,14 @@ export default { ...@@ -224,15 +224,14 @@ export default {
handleSelect(item) { handleSelect(item) {
this.form.address = item.address + item.title; //记录详细地址,含建筑物名 this.form.address = item.address + item.title; //记录详细地址,含建筑物名
// this.form.addrPoint = item.point; //记录当前选中地址坐标 // this.form.addrPoint = item.point; //记录当前选中地址坐标
this.form.lat = point.lat this.form.lat = item.point.lat
this.form.lng = point.lng this.form.lng = item.point.lng
this.map.clearOverlays() //清除地图上所有覆盖物 window.map.clearOverlays() //清除地图上所有覆盖物
this.mk = new BMap.Marker(item.point) //根据所选坐标重新创建Marker this.mk = new BMap.Marker(item.point) //根据所选坐标重新创建Marker
this.map.addOverlay(this.mk) //将覆盖物重新添加到地图中 window.map.addOverlay(this.mk) //将覆盖物重新添加到地图中
this.map.panTo(item.point) //将地图的中心点更改为选定坐标点 window.map.panTo(item.point) //将地图的中心点更改为选定坐标点
}, },
onContentChange (val) { onContentChange (val) {
console.log(val)
}, },
afterChange () { afterChange () {
...@@ -252,6 +251,7 @@ export default { ...@@ -252,6 +251,7 @@ export default {
lat: parseFloat(res.data.lat), // 经纬度 lat: parseFloat(res.data.lat), // 经纬度
intro: res.data.intro // 简介 intro: res.data.intro // 简介
} }
this.showMap = true
} else { } else {
this.$notify({ this.$notify({
title: "失败", title: "失败",
...@@ -260,7 +260,6 @@ export default { ...@@ -260,7 +260,6 @@ export default {
duration: 2000 duration: 2000
}); });
} }
this.initMap()
}); });
}, },
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment