视口平移到所在坐标
js
import { fromLonLat } from 'ol/proj'
// 地图平移到所在坐标
// region: 区划信息
moveToLocation (region) {
const level = region.level
const zoom = 7 + level
// 设置缩放
this.map.getView().setZoom(zoom)
const location = region.longitude + ',' + region.latitude
if (region?.longitude) {
let coordinate = location.split(',').map(item => {
return Number(item)
})
if (coordinate?.length) {
// 当当前地图是EPSG 3857 转化成4326
if (this.mapPointType === 'EPSG:3857') {
coordinate = fromLonLat(coordinate, 'EPSG:3857')
}
// 设置选中为中心点
this.map.getView().animate({
center: coordinate
})
}
} else {
this.$notify.warning({
title: '该区划没有坐标信息无法定位!'
})
}
},