根据圆心和半径操作圆。
(基础知识请阅读http://wiki.njrgrj.com:8989/webdoc/view/Pub2c90a40975d3e77f01777695a2bd49ca.html)
新增圆要注意的是要转换圆的半径
let metersPerUnit = this.map
.getView()
.getProjection()
.getMetersPerUnit();
let circleRadius = circleData.radius / metersPerUnit;
let center = [circleData.longitude, circleData.latitude];
步骤:1、新增元素
2、把元素添加到图层数据源上
3、把图层数据源放到图层上
4、把图层添加到地图上
let circle0 = new ol.geom.Circle(center, circleRadius);
this.circle = new ol.Feature({
geometry: circle0,
key: circleData.key
});
this.circle.setStyle(
new ol.style.Style({
fill: new ol.style.Fill({
color: circleData.color
})
})
);
this.circleSource.addFeature(this.circle);
var vector = new ol.source.Vector({});
vector = new ol.layer.Vector({
source: this.circleSource
});
this.map.addLayer(vector);
this.circleSource.removeFeature(this.circleSource.undefIdIndex_[ele]);
1、修改圆位置以及半径,要注意先删除地图上原有的圆,再重新添加
2、本文的地图用的是EPSG:4326也就是WGS84坐标系,不同的坐标系对投影的转换方法是不一样的。(如果画出来的圆边缘都是锯齿,说明转换方法错误)