一、根据所在地区划分区域
getcity:所在地区名称
color:区域颜色
// 根据所在地区名称划分区域
getBoundary(getcity, color) {
var that = this;
var bdary = new BMapGL.Boundary();
bdary.get(getcity, function (rs) {
//获取行政区域
// map.clearOverlays() //清除地图覆盖物
var pointArray = []
var ply = new BMapGL.Polygon(rs.boundaries, {
strokeWeight: 2,//边框线条粗细
strokeColor: 'red',//边框颜色
fillOpacity: 0.5,//区域颜色透明度
fillColor: color,//区域颜色
})
map.addOverlay(ply) //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
二、根据经纬度节点绘制区域
arrNeed:标签名
color:区域颜色
arrNeed:经纬度坐标
//根据经纬度节点绘制区域
getarea(nameLable, color, arrNeed) {
let that = this;
// var arrNeed = JSON.parse(that.gridNode) //将经纬度转换为JSON格式
let needPoint = [];
arrNeed.forEach(item => {
needPoint.push(new BMapGL.Point(item.lng, item.lat))
})
polygon = new BMapGL.Polygon(needPoint, {
strokeColor: "red",//边框颜色
fillColor: color,//区域颜色
strokeWeight: 3,//边框线条粗细
strokeOpacity: 0.8//区域颜色透明度
});
polygon.name = nameLable
map.addOverlay(polygon);
}