构建多边形和圆形。
注意事项
注意数据的组织方式。
需求分解
- 创建点位数据
- 构建多边形和圆形并显示
方法说明
- SGWorld66.Creator.GeometryCreator.CreateGeometryFromWKT(buffer);
- 创建几何图形数据
- SGWorld66.Creator.CreatePolygon(Geometry,LineColor,FillColor,AltitudeType,GroupID,Description);
- 创建多边形
- SGWorld66.Creator.CreateCircle(Position,Radius,LineColor,FillColor,GroupID,Description);
- 创建圆形
- SGWorld66.ProjectTree.SetVisibility(ID,bShow);
- 设置对象是否可见
Jsp源码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<script type="text/javascript" >
/**
* 初始化
*/
function Init() {
try {
//文件地址
var flyPath = "http://192.168.1.224:8090/xierdun.FLY";
//打开工程
SGWorld66.Project.Open(flyPath);
//构建不规则多边形
var pointsPolygon = SGWorld66.Creator.GeometryCreator.CreateGeometryFromWKT("POLYGON((-114.03822 41.99547,-111.04795 41.99626,-111.05028 40.99663,-109.04763 40.99847,-109.04782 36.99664,-114.04313 36.99656,-114.03822 41.99547))");
var polygon = SGWorld66.Creator.CreatePolygon(pointsPolygon, "#ff0000", SGWorld66.Creator.CreateColor(0, 255, 255, 40), 2, "", "polygon"); //
polygon.LineStyle.Width = 5000; // 5000m (5km)
//构建长方形
var pointsRectangle = SGWorld66.Creator.GeometryCreator.CreateGeometryFromWKT("POLYGON((-111.05265 44.99576,-104.05934 44.99734,-104.05120 41.00322,-111.05028 40.99663,-111.05265 44.99576))");
var rectangle = SGWorld66.Creator.CreatePolygon(pointsRectangle, SGWorld66.Creator.CreateColor(255, 255, 0, 10), null,2,"", "rectangle");
rectangle.LineStyle.Width = 20000; // 20000m (20km)
rectangle.Position.Distance = 1600000;
//构建圆形
var circle = SGWorld66.Creator.CreateCircle(SGWorld66.Creator.CreatePosition(-114.03822,41.99547,0,2), // Pivot
100000.0, // Radius (1000m)
SGWorld66.Creator.CreateColor(0, 0, 0, 0), // Outline color (in this sample, transparent/no outline)
SGWorld66.Creator.CreateColor(200, 50, 50, 128), // Fill color
"",
"circle"
);
circle.Position.Distance = 3000;
//工程目录树中隐藏长方形和圆形
SGWorld66.ProjectTree.SetVisibility(rectangle.ID,false);
SGWorld66.ProjectTree.SetVisibility(circle.ID,false);
} catch (e) {
alert("Error: " + e.description);
}
}
function FlyToProject(){
//获取工程目录树里面图层并转换回Presentation对象,该对象自动转换,详见API文档
var polygon = SGWorld66.ProjectTree.GetObject(SGWorld66.ProjectTree.FindItem("polygon"));
SGWorld66.Navigate.FlyTo(polygon);
//7秒后显示长方形
setTimeout(function(){SGWorld66.ProjectTree.SetVisibility(SGWorld66.ProjectTree.GetObject(SGWorld66.ProjectTree.FindItem("rectangle")).ID,true);},7000);
//8秒后显示长方形
setTimeout(function(){SGWorld66.ProjectTree.SetVisibility(SGWorld66.ProjectTree.GetObject(SGWorld66.ProjectTree.FindItem("circle")).ID,true);},8000);
}
</script>
<style>
.btn{
border: none;
display: inline-block;
outline: 0;
padding: 6px 16px;
margin-bottom: 10px;
vertical-align: middle;
overflow: hidden;
text-decoration: none;
color: #fff;
background-color: #3385ff;
text-align: center;
transition: .2s ease-out;
cursor: pointer;
white-space: nowrap;
width: 100%;
margin-top: 5px;
}
</style>
<body onload = "Init();" style="background-color: black;padding:0; margin:0;overflow: hidden;">
<div style="position: absolute;width: 80%;height: 100%;left: 0%;">
<!--定义一个TerraExplorer 3D窗口对象-->
<object id="TE" classid="clsid:3a4f9192-65a8-11d5-85c1-0001023952c1" style="width: 100%;height: 100%;padding:0; margin:0;"></object>
</div>
<div style=" position: absolute;width: 18%;height: 99%;left: 81%;">
<!--定义一个TerraExplorer 信息窗口对象-->
<object id="TEInformationWindow" classid="CLSID:3a4f9193-65a8-11d5-85c1-0001023952c1" style="width: 100%;height: 50%;"></object>
<!--定义TerraExplorer对象SGWorld66-->
<object id="SGWorld66" classid="CLSID:3a4f9199-65a8-11d5-85c1-0001023952c1" style="visibility:hidden;height:0;"></object>
<div>
<input id="Button1" value="示例按钮-编辑事件" onclick="FlyToProject()" type="button" class="btn"/>
</div>
</div>
</body>
</html>
效果图
参考案例
- http://www.cnblogs.com/yitianhe/archive/2012/09/21/2696563.html