这个有现成的代码,把代码做一个简要的说明,具体实现效果,是在TE的地图画一个饼状图。
<script type="text/javascript">
function createpie() {
//设置简单参数,包括半径等参数
var sum = 0;
var radius = 100;
var angle = 0;
var i;
//根据饼状图的分块,设置不同的颜色
var color = [0x0000a0, 0x00ff60, 0x8000a0, 0xa0ff00, 0xff00ff, 0xff2000, 0x20c080, 0x402020, 0x8020a0, 0xff6060, 0xc0ffff, 0xff6060, 0x800040, 0xa00020];
for (i = 1; i < 10; i++) {
sum += i;
}
//选择中心的位置,也可以自定义进行设置
var cenpoint = SGWorld.Window.CenterPixelToWorld(0);
var cpoint = cenpoint.Position;
var sx = SGWorld.CoordServices.MoveCoord(cpoint.X, cpoint.Y, radius, 0).X;
var sy = SGWorld.CoordServices.MoveCoord(cpoint.X, cpoint.Y, radius, 0).Y;
//根据每块的比例,设置旋转的角度,在polygon添加点
for (i = 1; i < 10; i++) {
var color1 = color[i];
var langle = angle + parseFloat(i) / parseFloat(sum) * 360;
var east = radius * Math.cos(2 * Math.PI * langle / 360);
var north = radius * Math.sin(2 * Math.PI * langle / 360);
var movcod = SGWorld.CoordServices.MoveCoord(cpoint.X, cpoint.Y, east, north);
var polygon = "POLYGON((" + cpoint.X.toString() + " " + cpoint.Y.toString() + "," + sx.toString() + " " + sy.toString();
var spl = (langle - angle) / 2;
for (var j = 0; j < spl; j++) {
var sinint = Math.sin((angle + j * 2) * Math.PI / 180) * radius;
var cosint = Math.cos((angle + j * 2) * Math.PI / 180) * radius;
var movcodspl = SGWorld.CoordServices.MoveCoord(cpoint.X, cpoint.Y, cosint, sinint);
polygon += "," + movcodspl.X.toString() + " " + movcodspl.Y.toString();
}
polygon += "," + movcod.X.toString() + " " + movcod.Y.toString() + "," + cpoint.X.toString() + " " + cpoint.Y.toString() + "))";
var igeometry = SGWorld.Creator.GeometryCreator.CreateGeometryFromWKT(polygon);
//根据点创建polygon
var ipolygon = SGWorld.Creator.CreatePolygon(igeometry, color1, color1, 0, 0, "polygon");
ipolygon.FillStyle.Color.SetAlpha(0.5);
sx = movcod.X;
sy = movcod.Y;
angle = langle;
}
}
本文出自 “wclwksn_GIS” 博客,请务必保留此出处http://speciallst.blog.51cto.com/9749849/1852972
原文地址:http://speciallst.blog.51cto.com/9749849/1852972