Compare commits
2 Commits
069e307b5d
...
a8e009ec70
Author | SHA1 | Date |
---|---|---|
mengfanliang | a8e009ec70 | |
mengfanliang | 9accd1e41e |
|
@ -95,18 +95,33 @@ export default {
|
||||||
var geolocation = new BMap.Geolocation()
|
var geolocation = new BMap.Geolocation()
|
||||||
const myGeo = new BMap.Geocoder()
|
const myGeo = new BMap.Geocoder()
|
||||||
var $this = this
|
var $this = this
|
||||||
|
map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放,默认关闭
|
||||||
|
map.addEventListener('zoomend', () => {
|
||||||
|
this.addPoint({
|
||||||
|
LATITUDE: $this.LATITUDE,
|
||||||
|
LONGITUDE: $this.LONGITUDE,
|
||||||
|
BMap,
|
||||||
|
map
|
||||||
|
})
|
||||||
|
})
|
||||||
// 调用百度地图api 中的获取当前位置接口
|
// 调用百度地图api 中的获取当前位置接口
|
||||||
geolocation.getCurrentPosition(function(r) {
|
geolocation.getCurrentPosition(function(r) {
|
||||||
myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), function(result) {
|
myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
$this.ISLOADingMap = false
|
$this.ISLOADingMap = false
|
||||||
$this.$set($this, 'pointLngLat', { lng: result.point.lng, lat: result.point.lat })
|
$this.$set($this, 'pointLngLat', { lng: result.point.lng, lat: result.point.lat })
|
||||||
map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放,默认关闭
|
$this.setCenter({ BMap, map, zoom: 15 }) // 设置中心点
|
||||||
$this.setCenter({ BMap, map })
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
addPoint({ LATITUDE, LONGITUDE, BMap, map }) {
|
||||||
|
if (!LATITUDE) throw new Error('请传入经度')
|
||||||
|
if (!LONGITUDE) throw new Error('请传入纬度')
|
||||||
|
const point = new BMap.Point(LONGITUDE, LATITUDE)
|
||||||
|
const marker = new BMap.Marker(point) // 创建标注
|
||||||
|
map.addOverlay(marker) // 将标注添加到地图中
|
||||||
|
},
|
||||||
// 搜索地图
|
// 搜索地图
|
||||||
querySearch(queryString, cb) {
|
querySearch(queryString, cb) {
|
||||||
var options = {
|
var options = {
|
||||||
|
@ -139,7 +154,7 @@ export default {
|
||||||
this.LATITUDE = point.lat
|
this.LATITUDE = point.lat
|
||||||
},
|
},
|
||||||
// 设置打开中心位置
|
// 设置打开中心位置
|
||||||
setCenter({ BMap, map }) {
|
setCenter({ BMap, map, zoom }) {
|
||||||
var lng = ''
|
var lng = ''
|
||||||
var lat = ''
|
var lat = ''
|
||||||
if (this.LONGITUDE === '' || this.LATITUDE === '') {
|
if (this.LONGITUDE === '' || this.LATITUDE === '') {
|
||||||
|
@ -149,11 +164,11 @@ export default {
|
||||||
lng = this.LONGITUDE
|
lng = this.LONGITUDE
|
||||||
lat = this.LATITUDE
|
lat = this.LATITUDE
|
||||||
}
|
}
|
||||||
var point = new BMap.Point(lng, lat)
|
map.panTo(new BMap.Point(lng, lat))
|
||||||
const zoom = map.getZoom()
|
// 延迟设置缩放级别,确保中心点已经设置
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
map.centerAndZoom(point, zoom)
|
map.setZoom(15) // 设置适当的缩放级别
|
||||||
}, 0)
|
}, 300) // 延迟时间可以根据实际需求调整
|
||||||
},
|
},
|
||||||
getClickInfo(e) {
|
getClickInfo(e) {
|
||||||
this.LONGITUDE = e.point.lng
|
this.LONGITUDE = e.point.lng
|
||||||
|
|
Loading…
Reference in New Issue