// 修改经纬度
changeCenter(zooms) {
this.map.centerAndZoom(
new BMap.Point(this.addForm.longitude, this.addForm.latitude),
zooms || this.map.getZoom()
);
},
// 获取并设置地图中心点
getMapCenter() {
var pos = this.map.getCenter();
this.addForm.longitude = pos.lng;
this.addForm.latitude = pos.lat;
this.setArea(pos);
},
// 修改区域
changeArea() {
let mapInfo = this.$refs.crud.selection[0];
// 设置中心点和放大倍数
this.map.centerAndZoom(
new BMap.Point(mapInfo.longitude, mapInfo.latitude),
this.zooms
);
},
//覆盖物区域
setArea(pos) {
let that = this;
that.map.clearOverlays(); //清除地图覆盖物
var center = new BMap.Point(pos.lng, pos.lat); //创建圆的中心点
var radius =that.addForm.positionRadius; //圆的半径
var style = {
strokeColor: "#4395ff", //边线颜色。
fillColor: "#4395ff", //填充颜色。当参数为空时,圆形将没有填充效果。
strokeWeight: 3, //边线的宽度,以像素为单位。
strokeOpacity: 0.5, //边线透明度,取值范围0 - 1。
fillOpacity: 0.5, //填充的透明度,取值范围0 - 1。
strokeStyle: "solid" //边线的样式,solid或dashed。
};
var circle = new BMap.Circle(center, radius, style); //创建一个圆
that.map.addOverlay(circle); //往地图里添加圆
},
// 地图加载完毕
handlerMap({ BMap, map }) {
let that = this;
that.BMap = BMap;
that.map = map;
if (!that.isadd) {
that.changeArea();
that.changeCenter(this.zooms);
} else {
map.centerAndZoom(that.weather.cityName, this.zooms);
}
map.disableInertialDragging(); //关闭惯性拖拽
// 添加左上角控件
var top_left_navigation = new BMap.NavigationControl(); //右上角,仅包含平移和缩放按钮
map.addControl(top_left_navigation);
// 地图移动结束获取中心点
map.addEventListener(
"moveend",
e => {
that.getMapCenter();
},
false
);
// map缩放事件
map.addEventListener("zoomstart", e => {
that.changeCenter();
});
map.addEventListener("zoomend", e => {
that.changeCenter();
});
window.addEventListener("resize", that.getMapCenter());
},
百度.js添加圆形覆盖物并跟随中心点移动
于 2021-10-26 14:10:00 首次发布