基于html和javascript脚本实现,把基本的TerraExplorer Pro二次开发的功能体现出来了。能给skyline 开发的初学者一个很好的范例:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>lianxi</title>
</head>
<body OnLoad="Init();">
 <object ;

function Init()
{
    ITerraExplorer = TE.interface("ITerraExplorer5");
 IInformationTree = TE.interface("IInformationTree5");
 IRender = TE.interface("IRender5");
 IObjectManager = TE.interface("IObjectManager5");
 IStartPosition = TE.interface("IStartPosition");
 IContainer = TE.interface("IContainer2");
 IPlane = TE.interface("IPlane5");
 ITerrain = TE.interface("ITerrain4");
 IStartPosition = TE.interface("IStartPosition");
 IRender = TE.interface("IRender5");
 Menu = TE.interface("IMenu");
 ISnapShot = TE.interface("ISnapShot2");
 ITerraExplorer.load("c:\\a.fly");
 window.setTimeout("test()",800);
}
function test()

    IInformationTree.LoadFlyLayerEx("[TE Application Data]\\本人上次的操作记录.fly",0);
 IInformationTree.LoadFlyLayerEx("[TE Application Data]\\本人上次创建的动态路径.fly",0);
}
function SaveAs()
{
    ITerraExplorer.Save();
 alert("保存成功");
}

function SaveAsOther()
{
    var txt = document.getElementById("adr").value;
    if(txt!="")
    {
    ITerraExplorer.SaveAs(txt);
    alert("保存成功");
    }
 else
 alert("请输入要存储的位置!");
}
function Createpolyline()
{
    Polylineflag = true;
 IRender.SetMouseInputMode(1);
}

function CreateDynamic()
{
    Dynamicflag = true;
 IRender.SetMouseInputMode(1);
}

function TE::OnLButtonDown(flag,X,Y,Handled)
{
    if(Polylineflag)
    CreatePolylineVB(X,Y);
 if(Dynamicflag)
    CreateDynamicVB(X,Y);
 if(createpolygoyflag)
    CreatePolygonVB(X,Y)
}

function TE::OnRButtonDown(flag,X,Y,Handled)
{
    Polylineflag = false;
 Dynamicflag = false;
 isLine = false;
 isRoute = false;
    IRender.SetMouseInputMode(0);
 curItemID = "";
 createpolygoyflag = false;
}

function Container()
{
    //欢迎使用本产品!!的地方也可使用 URL定位
    IContainer.HTMLPopup (0, 50,50,350,350,"容器窗口", "欢迎使用本产品!!" ,2, -1 );
}

function ProInfo()
{
    alert(ITerraExplorer.TYPE);
 alert(ITerraExplorer.FlyName);
 alert(ITerraExplorer.DisplayErrorMessages = 1);
}

function MethedInfo()
{
 alert(ITerraExplorer.GetUserUnits(0,3,5,7));
 alert(ITerraExplorer.GetTEVersion("5","00","38"));
}

function ITerrainProInfo()
{
    alert("mpt的文件名:"+ITerrain.MPTName);
 alert("SystemKey的文件名:"+ITerrain.SystemKey);
 alert("GroupKey的文件名:"+ITerrain.GroupKey);
 alert("DatumKey的文件名:"+ITerrain.DatumKey);
 alert("UnitKey的文件名:"+ ITerrain.UnitKey);
 alert("EPSG的文件名:"+ ITerrain.EPSG);
 alert("Description的文件名:"+ ITerrain.Description);
}

function IIStartPositionInfo()
{
 alert("开始坐标X"+IStartPosition.StartX);
 alert("开始坐标Z"+IStartPosition.StartZ);
}

function IRenderProInfo()
{
    alert(IRender.HudMode = 6);
}

function CreateGroup1()
{
    var groupID = null;
 var GroupName = document.getElementById("CG").value;
 if(GroupName!="")
     groupID = IInformationTree.CreateGroup(GroupName,0);
 else
     alert("请输入要创建组的名字!");
}

function TE::OnInfoTreeAction(ItemID,Action,ActionParam)
{
 curItemID = ItemID;
}

function AddG()
{
    IInformationTree.LoadFlyLayer("E:\\skyline\\Terra pro练习http://www.cnblogs.com/shaoge/admin/file://lianxi//124.fly");
 alert("工程添加成功!");
}

function LayerVis()
{
 if (document.getElementById("chk1").checked)
  IInformationTree.SetGroupVisibility(IInformationTree.FindItem("0"),true);
 else
  IInformationTree.SetGroupVisibility(IInformationTree.FindItem("0"),false);
}

function FlyToSomeWhere()
{
    var tName,tX0,tZ0
 tName = document.getElementById("flyName").value;
 tX0 = document.getElementById("flyJD").value;
 tZ0 = document.getElementById("flyWD").value;
 CreateLabelFlyTo(tName,tX0,tZ0);
}

function CreateLabelFlyTo(txt,x1,z1)
{
    var LabelInfo = new Object();
 LabelInfo.Text = txt;
 LabelInfo.Scale = 1;
 LabelInfo.bgColor = 0xff00;
 IObjectManager.CreateLabel(LabelInfo,x1,z1,2000.0);
 IPlane.FlyTo(x1,z1,2000.0,117.98,0,-35,"Oval");
}

function DelObj()
{
    if(curItemID =="")
 {
     alert("请选定你要删除的对象!");
 }
 else
    {
     IInformationTree.DeleteItem(curItemID);
     alert("删除成功!");
     curItemID ="";
    }
}

function InformationTreeVist()
{
    var groupID = IInformationTree.GetNextItem(0, 11);
 if (groupID == 0)
 {
  alert("信息树中无对象!");
  return 0;
 }
 else
     InformationTreeAll(groupID);
}
function InformationTreeAll(groupID)
{
 var a,b,c;
 if (groupID == 0)
  return 0;
 else
 {
  b = confirm(IInformationTree.GetItemName(groupID)+"__ID:"+groupID);
  if(b == false)
  {
       return 0;
  }
  a = groupID;
  groupID = IInformationTree.GetNextItem(groupID,11);
  if(groupID == 0)
  {  
      groupID = IInformationTree.GetNextItem(a,13);
   if(groupID == 0)
   {
       groupID = IInformationTree.GetNextItem(a,15);
    c = groupID; 
    groupID = IInformationTree.GetNextItem(c,13);groupID
    while(groupID == 0 )
       {   
        groupID = IInformationTree.GetNextItem(c,15);
     groupID = IInformationTree.GetNextItem(groupID,13);
     if (groupID == 0)
                  return 0;
    }
   }
  }
  InformationTreeAll(groupID);
 }
}

function LoadFromSaved()
{
    alert(IInformationTree.LoadFlyLayerEx("[TE Application Data]\\e.fly",0));
}

/*function CreateP()
{
    createpflag = true;
 IObjectManage.CreatePyramid(x,y,);
 
}*/
</script>
<script language="vbscript">
 function  CreatePolylineVB(x,y)
    dim outX,outY,outH,ObjectID
 IRender.ScreenToWorld x,y,63,outX,outH,outY,ObjectID
    if curItemID<>"" then
    if IInformationTree.IsGroup(curItemID) then
        if isLine = false then
            isLine = true
         Set IPolyline = IObjectManager.CreatePolyline(0,16744555,2,curItemID,"创建线")
        else
            IPolyline.AddVertex outX,outH,outY,0
        end if
           IInformationTree.SaveFlyLayer "本人上次的操作记录.fly",curItemID
  else
     msgbox "你选择的是对象不能容纳对象,请选择组!"
  end if
 else
     msgbox "请选择容纳对象的组!"
 end if
 
 end function
 
 function CreateDynamicVB(x,y)
    IRender.ScreenToWorld X,Y,63,outX,outH,outY,ObjectID
 if curItemID<>"" then
    if IInformationTree.IsGroup(curItemID) then
       if isRoute = false then
       set Route = IObjectManager.CreateRoute (empty,0,curItemID,"动态路径")
       isRoute = true
       else
       Route.AddWaypoint outX,outH,outY,0,-45,0,-45,0,100,""
       end if
    IInformationTree.SaveFlyLayer "本人上次创建的动态路径.fly",curItemID
  else
  msgbox "你选择的是对象不能容纳对象,请选择组!"
  end if
 else
    msgbox "请选择容纳对象的组!"
 end if
end function

 

function DynamicPlay()
    Route.Play
 msgbox "播放动态路径"
end function

function DynamicP()
    Route.Pause
 msgbox "暂停播放动态路径"
end function

function GetMouseMode()
    msgbox IRender.GetMouseInputMode
end function

function TE_OnFrame()
    dim x1,y1
 IRender.GetMouseInfo 1,x1,y1
 ObjType = 0
 IRender.ScreenToWorld x1,y1,ObjType,WorldX,WorldHeigth,WorldY,ObjectID
 document.getElementById("jd").innerHTML = WorldX
 document.getElementById("wd").innerHTML = WorldY
end function
</script>
</html>


相关文章: