Compare commits
No commits in common. "a8e009ec709593c43ab408726ae23c976edf8f71" and "069e307b5ddaa1ca85a30f33f14c7395d0aca529" have entirely different histories.
a8e009ec70
...
069e307b5d
|
@ -95,33 +95,18 @@ 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 })
|
||||||
$this.setCenter({ BMap, map, zoom: 15 }) // 设置中心点
|
map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放,默认关闭
|
||||||
|
$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 = {
|
||||||
|
@ -154,7 +139,7 @@ export default {
|
||||||
this.LATITUDE = point.lat
|
this.LATITUDE = point.lat
|
||||||
},
|
},
|
||||||
// 设置打开中心位置
|
// 设置打开中心位置
|
||||||
setCenter({ BMap, map, zoom }) {
|
setCenter({ BMap, map }) {
|
||||||
var lng = ''
|
var lng = ''
|
||||||
var lat = ''
|
var lat = ''
|
||||||
if (this.LONGITUDE === '' || this.LATITUDE === '') {
|
if (this.LONGITUDE === '' || this.LATITUDE === '') {
|
||||||
|
@ -164,11 +149,11 @@ export default {
|
||||||
lng = this.LONGITUDE
|
lng = this.LONGITUDE
|
||||||
lat = this.LATITUDE
|
lat = this.LATITUDE
|
||||||
}
|
}
|
||||||
map.panTo(new BMap.Point(lng, lat))
|
var point = new BMap.Point(lng, lat)
|
||||||
// 延迟设置缩放级别,确保中心点已经设置
|
const zoom = map.getZoom()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
map.setZoom(15) // 设置适当的缩放级别
|
map.centerAndZoom(point, zoom)
|
||||||
}, 300) // 延迟时间可以根据实际需求调整
|
}, 0)
|
||||||
},
|
},
|
||||||
getClickInfo(e) {
|
getClickInfo(e) {
|
||||||
this.LONGITUDE = e.point.lng
|
this.LONGITUDE = e.point.lng
|
||||||
|
|
Loading…
Reference in New Issue