# OpenLayers中如何画扇形

1，首先在源码中加入以下代码，最好是在OpenLayers.Geometry.Polygon.createRegularPolygon这个函数的源代码后面加入：

//参数分别是圆心，半径，边数，弧度，旋转角度（即右边半径与x正向轴的角度）
OpenLayers.Geometry.Polygon.createRegularPolygonCurve = function(origin, radius, sides,r,angel) {
var rotation = 360 - r;
var angle = Math.PI * ((1/sides) - (1/2));
if(rotation) {
angle += (rotation / 180) * Math.PI;
}
var rotatedAngle, x, y;
var points = [];
for(var i=0; i<sides; ++i) {
var an = i*((360 - rotation)/360);
rotatedAngle = angle + (an * 2 * Math.PI / sides);
x = origin.x + (radius * Math.cos(rotatedAngle));
y = origin.y + (radius * Math.sin(rotatedAngle));
points.push(new OpenLayers.Geometry.Point(x, y));
}
if(rotation!=0){
points.push(origin);
}
var ring = new OpenLayers.Geometry.LinearRing(points);
ring.rotate(parseFloat(r)+90+parseFloat(angel),origin);
return new OpenLayers.Geometry.Polygon([ring]);};

2，客户端使用例子：

var map=new OpenLayers.Map("map_canvas");//初始化地图对象
vector_site_layer = new OpenLayers.Layer.Vector('Vector Layer');//生成一个图层层，放所有扇形
var origi_point = new OpenLayers.Geometry.Point('100', '40');//根据经纬度生成圆点
//调用画扇形的函数
var sector = new OpenLayers.Geometry.Polygon.createRegularPolygonCurve(
origi_point,//圆心
gain,//半径
100,//边数
antBearing,//弧度
lobeAngle //方向角
);

//通过扇形生成一个Feature，并加入了各种自定义属性
var polygonFeature = new OpenLayers.Feature.Vector(
sector,
{
'id':'sector_',//扇形id
'type':'sector',//类型
'name':'join'//名字
});
vector_site_layer.addFeatures(polygonFeature);//将扇形加入图层

12-29

01-03
11-02
08-13
11-01 7648
11-01 183
08-23 2391
07-17 1718
02-05
04-27 3437
05-13 144
12-02 4748
09-29 4938
08-03 1457
05-15 2023
07-05 235