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