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() 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