Commit 57e10616 authored by 黄奎's avatar 黄奎

1

parent c4c36a59
<template> <template>
<div> <div>
<div style="text-align: center;display: flex;justify-content: center;"> <div style="text-align: center;display: flex;justify-content: center;">
<el-input class="w300" style="margin-right: 10px;" id="suggestId" v-model="city" <el-input class="w300" style="margin-right: 10px;" id="suggestId" v-model="city" placeholder="请输入需要检索的地名"
placeholder="请输入需要检索的地名" name="address_detail" @input="search"/> name="address_detail" @input="search" />
<!-- <input type="button" class="normalBtn sureBtn" value="搜索" @click="search"/> --> <!-- <input type="button" class="normalBtn sureBtn" value="搜索" @click="search"/> -->
</div> </div>
<div style="height: 310px;width: 100%;margin-top: 15px;" :id="`allmap_${id}${type}_${index}`"></div> <div style="height: 310px;width: 100%;margin-top: 15px;" :id="`allmap_${id}${type}_${index}`"></div>
<div style="margin-top: 10px;" v-if="address_detail">已选地址:{{address_detail}}</div> <div style="margin-top: 10px;" v-if="address_detail">已选地址:{{ address_detail }}</div>
<div class="btnList"> <div class="btnList">
<input type="button" class="normalBtn sureBtn" value="确定" @click="sendMsg"/> <input type="button" class="normalBtn sureBtn" value="确定" @click="sendMsg" />
<input type="button" class="hollowFixedBtn" value="取消" @click="closeDialog"/> <input type="button" class="hollowFixedBtn" value="取消" @click="closeDialog" />
</div> </div>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
props: ["Address","id","type","index"], props: ["Address", "id", "type", "index"],
data(){ data() {
return{ return {
city: '', city: '',
address_detail: null, //详细地址 address_detail: null, //详细地址
userlocation: null, userlocation: null,
dataList: null, dataList: null,
point: { point: {
lng:'', lng: '',
lat: '' lat: ''
}, },
} }
}, },
watch: { watch: {
Address: { Address: {
handler(newValue) { handler(newValue) {
this.city = this.Address this.city = this.Address
if(!newValue){ if (!newValue) {
this.getcity() this.getcity()
}else{ } else {
this.search() this.search()
} }
}, },
immediate: true immediate: true
}, },
}, },
mounted() { mounted() {
this.city = this.Address this.city = this.Address
this.getcity() this.getcity()
}, },
methods:{ methods: {
closeDialog() { closeDialog() {
this.$emit("refList"); this.$emit("refList");
}, },
sendMsg() { sendMsg() {
if (!this.point.lng) { if (!this.point.lng) {
this.Error("请点击地图上你需要选择的地址"); this.Error("请点击地图上你需要选择的地址");
} else { } else {
this.$emit("headCallBack", this.point,this.type,this.index,this.address_detail); this.$emit("headCallBack", this.point, this.type, this.index, this.address_detail);
this.$emit("refList"); this.$emit("refList");
} }
}, },
search(){ search() {
var that = this var that = this
var map = new BMap.Map(`allmap_${that.id}${that.type}_${that.index}`) var map = new BMap.Map(`allmap_${that.id}${that.type}_${that.index}`)
var local = new BMap.LocalSearch(map, { // 智能搜索 var local = new BMap.LocalSearch(map, { // 智能搜索
onSearchComplete: function (){ onSearchComplete: function () {
if(local.getResults()&&local.getResults().getPoi(0)&&local.getResults().getPoi(0).point){ if (local.getResults() && local.getResults().getPoi(0) && local.getResults().getPoi(0).point) {
that.userlocation = local.getResults().getPoi(0).point // 获取第一个智能搜索的结果 that.userlocation = local.getResults().getPoi(0).point // 获取第一个智能搜索的结果
that.point.lat = that.userlocation.lat that.point.lat = that.userlocation.lat
that.point.lng = that.userlocation.lng that.point.lng = that.userlocation.lng
map.centerAndZoom(that.userlocation, 15) // map.centerAndZoom(that.userlocation, 15)
map.addOverlay(new BMap.Marker(that.userlocation)) // 添加标注 map.addOverlay(new BMap.Marker(that.userlocation)) // 添加标注
} }
} }
}) })
local.search(that.city) local.search(that.city)
map.addEventListener('click', function(e,target) { // map.addEventListener('click', function (e, target) {
// var point = new BMap.Point(e.point.lng, e.point.lat) // 创建点坐标,汉得公司的经纬度坐标 // // var point = new BMap.Point(e.point.lng, e.point.lat) // 创建点坐标,汉得公司的经纬度坐标
// map.centerAndZoom(point, 11) // // map.centerAndZoom(point, 11)
// that.point = e.point // // that.point = e.point
}) // })
var gc = new BMap.Geocoder(); var gc = new BMap.Geocoder();
map.addEventListener('mousedown', function(type) { map.addEventListener('mousedown', function (type) {
var pt = type.point; var pt = type.point;
gc.getLocation(pt, function(rs){ gc.getLocation(pt, function (rs) {
var addComp = rs.addressComponents; var addComp = rs.addressComponents;
that.address_detail = addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber that.address_detail = addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber
}) })
}) })
}, },
getcity(){ getcity() {
this.$nextTick(function() { this.$nextTick(function () {
var that = this var that = this
// 创建Map实例 // 创建Map实例
var map = new BMap.Map(`allmap_${that.id}${that.type}_${that.index}`) var map = new BMap.Map(`allmap_${that.id}${that.type}_${that.index}`)
// 获取当前位置 // 获取当前位置
var geolocation = new BMap.Geolocation(); var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){ geolocation.getCurrentPosition(function (r) {
if(r){ if (r) {
var mk = new BMap.Marker(r.point); var mk = new BMap.Marker(r.point);
map.addOverlay(mk); map.addOverlay(mk);
map.panTo(r.point); map.panTo(r.point);
that.address_detail = addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber that.address_detail = addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber
that.point.lng = r.point.lng that.point.lng = r.point.lng
that.point.lat = r.point.lat that.point.lat = r.point.lat
console.log(that.address_detail,'城市===') console.log(that.address_detail, '城市===')
console.log('您的位置:'+r.point.lng+','+r.point.lat); console.log('您的位置:' + r.point.lng + ',' + r.point.lat);
} }
else { else {
console.log('failed'); console.log('failed');
} }
}); });
// 点击地图 // 点击地图
map.addEventListener('click', function(e,target) { // map.addEventListener('click', function (e, target) {
// var point = new BMap.Point(e.point.lng, e.point.lat) // 创建点坐标,汉得公司的经纬度坐标 // // console.log('4545')
// map.centerAndZoom(point, 11) // // var point = new BMap.Point(e.point.lng, e.point.lat) // 创建点坐标,汉得公司的经纬度坐标
// that.point = e.point // // map.centerAndZoom(point, 11)
}) // // that.point = e.point
// })
var gc = new BMap.Geocoder(); var gc = new BMap.Geocoder();
map.addEventListener('mousedown', function(type) { map.addEventListener('mousedown', function (type) {
map.centerAndZoom(type.point, 11) // map.centerAndZoom(type.point, 11)
that.point = type.point that.point = type.point
var pt = type.point; var pt = type.point;
gc.getLocation(pt, function(rs){ gc.getLocation(pt, function (rs) {
var addComp = rs.addressComponents; var addComp = rs.addressComponents;
that.address_detail = addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber that.address_detail = addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber
}) })
}) })
// 初始化地图,设置中心点坐标, // 初始化地图,设置中心点坐标,
if(that.point.lat){ if (that.point.lat) {
var point = new BMap.Point(that.point.lat, that.point.lng) // 创建点坐标 // var point = new BMap.Point(that.point.lat, that.point.lng) // 创建点坐标
map.centerAndZoom(point, 11) // map.centerAndZoom(point, 11)
}else{ } else {
map.centerAndZoom(new BMap.Point(104.073652,30.664369), 11); // map.centerAndZoom(new BMap.Point(104.073652, 30.664369), 11);
} }
map.enableScrollWheelZoom() map.enableScrollWheelZoom()
if(that.Address){ if (that.Address) {
that.search() that.search()
} }
}) })
}, },
} }
} }
</script> </script>
<style scoped> <style scoped>
.btnList { .btnList {
margin: 15px 0 0 auto; margin: 15px 0 0 auto;
text-align: right; text-align: right;
margin-bottom: 15px; margin-bottom: 15px;
} }
</style> </style>
\ No newline at end of file
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