3a4f9192-65a8-11d5-85c1-0001023952c1"width=500height=400>
并且需要保证TerraExplorer3DWindow对象先于TE对象被初始化,即可消除前面提到的问题。
但在有些时候,我们开发的系统中可能会嵌入许多WEB页面,而且在这些页面中也都会涉及到对TE接口的调用,这时运行我们的系统,也有可能把TerraExplorer软件运行起来,这是我们不想看到的,其实也可以说这就是一种逻辑错误,而消除这个错误的方法很简单,就是我们必须保证所有对TE接口的调用,都要放在TerraExplorer3DWindow对象加载之后。
但是我们如何保证在复杂的系统中,理清他们之间的先后顺序呢?
这里可以给大家介绍一个实用的解决方法。
就是把TE对象放到一个函数里面去初始化,而不是像原来那样直接嵌在页面里。
例如:
function_$SGCreateTEObj()
{
varobj=window.document.getElementById("TE");
if(obj==null)
{
obj=document.createElement('object');
document.body.appendChild(obj);
obj.name="TE";
obj.id="TE";
obj.classid="CLSID:
3a4f9191-65a8-11d5-85c1-0001023952c1";
}
returnobj;
}
这样,在其他需要调用TE接口的时候,我们只需要重新实例化一下TE对象即可。
varTE=_$SGCreateTEObj();
varIPlane=TE.interface("IPlane5");
这时,大家也许还会有疑问,就是对于TE里面的事件接口_ITerraExplorerEvents5该如何引用呢?
在以前Skyline提供给大家的例子中,我们可以看到用javascript中的写法是
functionTE:
:
OnLoadFinished()
{
}
或者用vbscript的写法是
subTE_OnLoadFinished()
endsub
如果说对于TE的事件接口只能用上述固定的方式来实现的话,那么就又回到了最开始的状态,封装TE函数也就没有什么实际意义了。
其实在TE的ITerraExplorer51接口中,我们发现有AttachEvent和DetachEvent两个方法,这样就可以做到我们在需要调用TE的事件接口时Attach,不需要的时候Detach:
function_$SGCreateEvent()
{
varTE=_$SGCreateTEObj();
varITerraExplorer=TE.interface("ITerraExplorer51");
ITerraExplorer.AttachEvent("OnLButtonDown",_$SGEventOnLButtonDown);
}
function_$SGDelEvent()
{
varTE=_$SGCreateTEObj();
varITerraExplorer=TE.interface("ITerraExplorer51");
ITerraExplorer.DetachEvent("OnLButtonDown",_$SGEventOnLButtonDown);
}
如此,我们就可以更加灵活地使用TE的事件接口。
希望上述文字能够给大家提供一些帮助或者启发,感谢大家对Skyline的支持。
三,共享一些可以通过网络访问的MPT地址
skylinesoft官网上的:
skylineglobe.tbp@
bhuvan.tbp@bhuvan1.nrsc.gov.in (印度的)
Macau_v2.mpt@62.28.57.114
mine3D.mpt@tg.geoid.be
四,基于Skyline的TEP5.1.3实现对矢量SHP文件的加载和渲染
我们知道在Skyline的TEP软件中可以添加多种矢量图层,对于常见的SHP文件,我们如何通过接口来开发实现呢?
下面代码是基于C#开发的,供大家参考:
stringXMLLayerInfo=""+
//这里是要加载的shp文件所在的路径
Application.StartupPath+"//shp//DC_FF_Parks.shp"+
"shape01"+
"Name,County"+//这里是设置要加载的shp文件的属性字段
"1";
iLyr=IInfoTree.CreateLayer("point",XMLLayerInfo,0);
iLyr.Load();
iLyr.DisplayAs(ObjectTypeCode.OT_LABEL);
iLyr.SetFeature();
iLyr.SetValue("Text",PropertyValueType.PROPERTY_CLASSIFICATION,"[NAME]0");
//==Appearance
iLyr.SetProperty("ActivationAction",1);
iLyr.SetProperty("LinetoGround",0);
iLyr.SetProperty("LineLength",1000);
iLyr.SetProperty("LineColor",300);
//==TextOptions
iLyr.SetProperty("TextColor",255);
iLyr.SetProperty("TextSize",12);
iLyr.SetProperty("Font","宋体");
iLyr.SetProperty("Bold",1);
iLyr.SetProperty("Underline",1);
iLyr.SetProperty("Italic",1);
iLyr.SetProperty("MultilineJustification",0);
iLyr.SetProperty("BackgroundColor",100);
iLyr.SetProperty("BackgroundOpacity",0);
iLyr.SetProperty("LockMode",0);
//==ImageOptions
iLyr.SetProperty("Imagefile","C:
\\ProgramFiles\\Skyline\\TerraExplorerPro\\Tools\\Data-Library\\Icons\\Letters\\Letter-a.gif");
//==Position
iLyr.SetProperty("AltitudeMethod",1);
iLyr.SetProperty("Altitude",1000);
iLyr.SetProperty("Yaw",10);
iLyr.SetProperty("Pitch",10);
iLyr.SetProperty("Roll",10);
string[]myStrings=newstring[9];
myStrings[0]="0,0";
iLyr.SetProperty("PivotAlignment",myStrings[0]);
//==Geometry
iLyr.SetProperty("Scale",100);
iLyr.SetProperty("LimitGrowth",1);
iLyr.SetProperty("Min.ViewingHeight",100);
iLyr.SetProperty("SmallestVisibleSize",10);
//==Text&ImageAlignment
iLyr.SetProperty("TextRelativetoImage",0);
iLyr.SetProperty("TextAlignment",myStrings[0]);
//==General
iLyr.SetProperty("ShowInBasic",0);
//---------------------------------------------------
ITerraExplorerMessage5cMessage=null;
stringtMessage="HelloSkyline";
MsgTypeeMsgType=MsgType.TYPE_TEXT;
cMessage=IObjectManager.CreateMessage(MsgClient.CLIENT_POPUP,tMessage,eMsgType,_HTML_POPUP_FLAGS.HTML_POPUP_ALLOW_RESIZE,"属性信息",-1,0,0,300,300,0);
iLyr.SetProperty("Message",cMessage.ID.Substring(cMessage.ID.IndexOf('_')+1,(cMessage.ID.Length-cMessage.ID.IndexOf('_')-1)));
//---------------------------------------------------
iLyr.SetProperty("ToolTip","公园");
iLyr.SetProperty("DefaultViewingDistance",1000);
说明:
上面的代码实现了对点类型的SHP文件的加载和在三维场景中的渲染显示。
五,如何在WPF中嵌入Skyline提供的三维控件
以VS2008开发工具以为:
1、创建VisualC#.NETframework3.0WindowsApplication(WPF)工程
2、添加reference到.NET组件WindowsFormsIntegration
3、添加reference到.NET组件System.Windows.Forms
4、添加reference到前面生成的WindowsFormDLL
5、WPF提供了一个WindowsFormsHost类(需要添加usingSystem.Windows.Forms.Integration;)用来做WindowsForm的容器,我们要用到的Form控件就必须放进这个容器里。
我们可以在InitializeComponent()后添加:
WindowsFormsHosthost=newWindowsFormsHost();
AxTerraExplorerX.AxTE3DWindowaxTE3DWindow1=newAxTerraExplorerX.AxTE3DWindow();
host.Child=axTE3DWindow1;
this.TEWindow.Children.Add(host);
以上代码创建一个WindowsForm容器,创建WindowsForm控件,将控件添加到容器里,再将容器添加到Grid里,这样界面上就可以看到Form控件了,其布局将受到Grid的控制。
附后台完整代码:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Data;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Imaging;
usingSystem.Windows.Navigation;
usingSystem.Windows.Shapes;
usingSystem.Windows.Forms.Integration; //在WPF中使用ActiveX控件需要引用的类
usingTerraExplorerX; //Skyline提供的类
namespaceWPFA_DEMO
{
///
///InteractionlogicforWindow1.xaml
///
publicpartialclassWindow1:
Window
{
publicWindow1()
{
InitializeComponent();
WindowsFormsHosthost=newWindowsFormsHost();
AxTerraExplorerX.AxTE3DWindowaxTE3DWindow1=newAxTerraExplorerX.AxTE3DWindow();
host.Child=axTE3DWindow1;
this.TEWindow.Children.Add(host);
}
privateTerraExplorerTE;
privateITerraExplorer51TE51;
privatevoidLoadFLY()
{
this.TE=newTerraExplorerClass();
this.TE51=(ITerraExplorer51)TE;
this.TE51.Load(@"C:
\izhaohe\skyline.fly");
this.TE.OnLoadFinished+=new_ITerraExplorerEvents5_OnLoadFinishedEventHandler(TE_OnLoadFinished);
}
privatevoidWindow_Loaded(objectsender,RoutedEventArgse)
{
LoadFLY();
}
voidTE_OnLoadFinished()
{
//MessageBox.Show("ok");
}
}
}
六,SkylineTEPro6.0版本在二次开发方面的改进总结
2011年4月,Skyline推出了最新版本的软件(version6.0),相对于以前版本软件,新版本软件改善和增加了很多新能功能;同时,开放的APIs也进行了很大的调整,变得更加丰富合理、简单易用。
那么,新版本开放的APIs相对于早期的APIs都有哪些明显变化和改进呢?
1. TerraExplorer与SGWorld的关系?
在新版本的开发及运行环境中,保持了对以前版本APIs支持的兼容性,通过TerraExplorer接口依然可以调用早期版本的功能APIs;但如果使用新版本的APIs,则需要通过SGWorld接口来实现;不同时期的接口可以混合使用;
2. 从软件UI上的变化对应IMenu到ICommand6的变化?
在以前版本中,用户通过IMenu接口可以实现对TerraExplorer(包括View和Pro版本)软件菜单功能的快速调用,而新版本软件的界面风格上做了很大的改变,如果要实现对菜单功能的快速调用,则需要通过ICommand6接口来实现;
3. 从ILayer5到ILayer6的变化?
ILayer6相对ILayer5改进了很多,首先是调整了图层组织结构,增加了FeatureGroups6、FeatureGroup6、Features6、Feature6、IFeatureAttributes6、IFeatureAttribut