Compare commits

..

2 Commits

1 changed files with 22 additions and 7 deletions

View File

@ -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