创建飞行路径,点击开始按钮后,按照设定的路线飞行一圈。
注意事项
该章难点在于如何确定飞行点位的xy值、高度、偏航角度、旋转角度、距离,善用以下两行代码可以方便的确定地图上点位的坐标值,然后通过放置点位后,在浏览器中使用属性进行精确化的调整和确定后,再回到代码中进行修改,这样才能方便快捷的做出路径飞行。
var mInfo = SGWorld66.Window.GetMouseInfo();
var ptwInfo = SGWorld66.Window.PixelToWorld(mInfo.X,mInfo.Y,-1);
alert(ptwInfo.Position.X + "/" + ptwInfo.Position.Y);
需求分解
- 创建坐标点位
- 创建位置点(可视化偏航角度、旋转角度,利用位置点在浏览器右键属性中进行调整,方便快捷)
- 创建飞行路线
- 从工程目录树中获取飞行路线对象并开启飞行
方法说明
- SGWorld66.Creator.CreateLocation(Position,GroupID,Description);
- 创建位置点
- SGWorld66.Creator.CreatePresentation(GroupID,Description);
- 创建飞行路线
- IPresentation66.CreateLocationStep(AdvancedType,WaitTime,Description,Position);
- 添加飞行步骤
- IPresentation66.PlayAlgorithm = 1;
- 设置飞行方式
- IPresentation66.PlayMode = 1;
- 设置自动飞行
- IPresentation66.PlaySpeedFactor = 0;
- 设置飞行速度
- IPresentation66.Play(0);
- 播放飞行路线
Jsp源码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%
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 flyPath = SGWorld66.ProjectTree.CreateGroup("FlyPath");
var p1 = SGWorld66.Creator.CreatePosition(110.9898247,19.64392506,40,0,310,-12,0,100);
var p2 = SGWorld66.Creator.CreatePosition(110.9896247,19.64653288,40,0,250,-12,0,100);
var p3 = SGWorld66.Creator.CreatePosition(110.9876747,19.64603288,40,0,155,-12,0,100);
var p4 = SGWorld66.Creator.CreatePosition(110.9855247,19.64523288,40,0,140,-20,0,40);
var p5 = SGWorld66.Creator.CreatePosition(110.9855247,19.64392506,70,0,70,-12,0,80);
var p6 = SGWorld66.Creator.CreatePosition(110.9870247,19.64392506,30,0,355,-12.8,0,120);
//创建Label,方便查看并修改点位,创建出来后可以右键直接修改对应的属性进行调整完后再在代码中完善
createPointList(p1);
createPointList(p2);
createPointList(p3);
createPointList(p4);
createPointList(p5);
createPointList(p6);
//在工程树下创建位置点
SGWorld66.Creator.CreateLocation(p1,flyPath,"1号点");
SGWorld66.Creator.CreateLocation(p2,flyPath,"2号点");
SGWorld66.Creator.CreateLocation(p3,flyPath,"3号点");
SGWorld66.Creator.CreateLocation(p4,flyPath,"4号点");
SGWorld66.Creator.CreateLocation(p5,flyPath,"5号点");
SGWorld66.Creator.CreateLocation(p6,flyPath,"6号点");
//创建飞行路线
var presentation = SGWorld66.Creator.CreatePresentation(flyPath,"自动飞行路线");
//添加飞行路径
presentation.CreateLocationStep(1,1,"1",p1);
presentation.CreateLocationStep(1,1,"2",p2);
presentation.CreateLocationStep(1,1,"3",p3);
presentation.CreateLocationStep(1,1,"4",p4);
presentation.CreateLocationStep(1,1,"5",p5);
presentation.CreateLocationStep(1,1,"6",p6);
presentation.CreateLocationStep(1,1,"1.1",p1);
//飞行方式
presentation.PlayAlgorithm = 1;
//自动飞行
presentation.PlayMode = 1;
//飞行速度
presentation.PlaySpeedFactor = 0;
} catch (e) {
alert("Error: " + e.description);
}
}
/**
*设置文本标注样式
*/
function createLabelStyle(nBGRValue,dAlpha,FontName,FontSize,Scale,Bold){
// C1. Create label syle
var cLabelStyle = SGWorld66.Creator.CreateLabelStyle();
// C2. Change label style settings
var nBGRValue = nBGRValue; // Blue
var dAlpha = dAlpha; // 50% opacity
var cBackgroundColor = cLabelStyle.BackgroundColor; // Get label style background color
cBackgroundColor.FromBGRColor(nBGRValue); // Set background to blue
cBackgroundColor.SetAlpha(dAlpha); // Set transparency to 50%
cLabelStyle.BackgroundColor = cBackgroundColor; // Set label style background color
cLabelStyle.FontName = FontName; // Set font name
cLabelStyle.FontSize = FontSize; // Set font size
cLabelStyle.Italic = false; // Set label style font to italic
cLabelStyle.Scale = Scale; // Set label style scale
cLabelStyle.Bold = Bold;
//cLabelStyle.MaxViewingHeight = MaxViewingHeight;
cLabelStyle.LimitScreenSize = true;
cLabelStyle.LineToGround = true;
//cLabelStyle.MinViewingHeight = MinViewingHeight;
return cLabelStyle;
}
/**
*创建标签
*/
function createPointList(Pos){
var current = SGWorld66.ProjectTree.FindItem("");
var labelStyle = createLabelStyle(0xFF0000,0,"微软雅黑",20,200,true);
var textLabelObj = SGWorld66.Creator.CreateLabel(Pos, "","http://192.168.1.222:9090/skyline/test/tv.png", labelStyle, current, "");
return textLabelObj;
}
/**
*开启飞行路径自动播放-飞行到指定点位后,播放飞行路线
*/
function FlyPresentation(){
//飞行到目标点-先飞行到起始点位p1,后续再触发飞行路线,可以缓解画面跳转冲突感
SGWorld66.Navigate.FlyTo(p1);
//获取工程目录树里面图层并转换回Presentation对象,该对象自动转换,详见API文档
var l = SGWorld66.ProjectTree.GetObject(SGWorld66.ProjectTree.FindItem("FlyPath\\自动飞行路线"));
//延迟5秒后触发飞行
setTimeout(function(){l.Play(0);},5000);
}
</script>
<body onload = "Init();">
<!--定义一个TerraExplorer 3D窗口对象-->
<object id="TE" classid="clsid:3a4f9192-65a8-11d5-85c1-0001023952c1" onmousemove="OnMouseMoved()" style="width: 80%;height: 95%"></object>
<!--定义TerraExplorer对象SGWorld65-->
<object id="SGWorld66" classid="CLSID:3A4F9199-65A8-11D5-85C1-0001023952C1" style="visibility:hidden;height:0 "></object>
<!--定义一个TerraExplorer 信息窗口对象-->
<object id="TEInformationWindow" classid="CLSID:3a4f9193-65a8-11d5-85c1-0001023952c1" width="15%" height="95%"></object>
<div id="addUrlDiv">
<input id="Button4" type="button" value="测试飞行路径5" onclick="FlyPresentation()" />
</div>
</body>
</html>