需要注意的地方:
要有5个点,而不是4个点,这样保证多边形是闭合的。
获取中心点:polygon.Geometry.Envelope.Centroid
threeDimensional.prototype.ZoomToExtent=function(xmin,xmax,ymin,ymax){
var xmin=parseFloat(GetWebParam("xmin"));
var xmax=parseFloat(GetWebParam("xmax"));
var ymin=parseFloat(GetWebParam("ymin"));
var ymax=parseFloat(GetWebParam("ymax"));
if(xmin&&xmax&&ymin&&ymax){
var pointArray=[];
pointArray.push(xmin);
pointArray.push(ymax);
pointArray.push(0);
pointArray.push(xmax);
pointArray.push(ymax);
pointArray.push(0);
pointArray.push(xmax);
pointArray.push(ymin);
pointArray.push(0);
pointArray.push(xmin);
pointArray.push(ymin);
pointArray.push(0);
pointArray.push(xmin);
pointArray.push(ymax);
pointArray.push(0);
var groupId=SGWorld.ProjectTree.CreateGroup("temp");
//创建一个extent对应的矩形,找到一个合适的高度适应extent(范围)
var polygon=SGWorld.Creator.CreatePolygonFromArray(pointArray,0xFF00FF00,0x00646464,2,groupId);
var dist=polygon.Terrain.GetRecommendedDistance();
var cpos=SGWorld.Creator.CreatePosition(polygon.Geometry.Envelope.Centroid.X, polygon.Geometry.Envelope.Centroid.Y , 0, 0, 0, -89, 0, dist*0.65);
SGWorld.ProjectTree.DeleteItem(groupId);
SGWorld.Navigate.FlyTo(cpos);
}
};
网友评论