




已阅读5页,还剩34页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Skyline二次开发培训教程2011年04月 目录1接口简介32 COM介绍32.1什么是COM32.2 COM组件32.3 为什么要介绍COM33 创建客户端应用程序43.1 C#编程环境43.2 JavaScript编程环境104开发接口应用举例194.1 ISGWorld6194.2 IAnalysis6214.3 IApplication6234.4 ICommand6244.5 ICoordServices6254.6 ICreator6274.7 IDateTime6314.8 INavigate6324.9 IProject6334.10 IProjectTree6344.11 ITerrain6364.12 ITEVersion6374.13 IWindow6381接口简介TerraExplorer API提供了一套强大的接口用来集成TerraExplorer、TerraExplorer Pro 和用户自定义应用。它提供了一些访问外部信息扩展的方法,比如:访问数据库或基础地理空间数据。所有这些以COM协议为基础的API接口都可以通过脚本语言操作(例如vbscript、Javascript),也可以通过非脚本语言来控制操作(例如:C+、VB、Delphi或者.net)。TerraExplorer也提供了一套ActiveX控件,可以将3D窗口、信息树和导航图以控件对象的方式嵌入到用户自定义的可视化界面中。2 COM介绍2.1什么是COM COM是Microsoft组件对象模型(Component Object Model)的简称。COM是一个说明如何建立可动态交替更新组件的规范。它提供了客户和组件为保证能够互操作应该遵循的标准。该标准对于组件架构的重要性同其他任何一个具有可交替更新部分的系统是一样的。举个例子,如果没有国家标准(GB),那么各个厂家所生产的零件及产品将不能实现互换性。各个厂家各自为政,若电机上的螺栓坏了,就要买原来厂家生产的螺栓,相当不方便。2.2 COM组件COM组件由以Win 32动态连接库(DLL)或可执行文件(EXE)形式发布的可执行代码组成。遵循COM规范编写出来的组件将能够满足对组件架构的所有要求。那么,COM组件有什么好处呢?它到底是什么东西呢?2.3 为什么要介绍COM作为传统软件的应用程序在发行之后,使用者要想省略掉其中的某些内容,或者感觉应用程序的某些部分还不够完善,希望得到更好的版本,只有等到软件发行商将新版本重新全部编译并推出后,使用者的这一梦想才能实现。这是传统软件的典型发行方式。但是,这却严重妨碍了软件使用人员的工作效率,使得使用者想做某件事,而软件却没有相应的实现部分。这使得软件的使用范围大幅度缩小,同时也使得商家频于软件升级方面的应酬,而实际上应用程序的开发进度却丝毫得不到加快。但是,自从COM出现以后,以上问题就基本上迎刃而解了。有了COM,软件开发人员就可以在应用程序发行后仍可以对它进行修改或给它加上一些新的特性,这大大方便了使用者,因为应用程序能够在更高的程度上被定制,使应用更加灵活、更具动态性。于是,将可能出现这样的情况:每个使用者都在使用相同的软件,而实际上每个使用者的软件却大相径庭。软件开发人员可以用逐步添加的方式开发程序,而不是每隔一两年将其完全重写一遍,这又在很大程度上加快了应用程序的开发进度。3 创建客户端应用程序3.1 C#编程环境以下步骤为使用ISWorld6接口创建一个C#客户端应用程序(开发环境Visual Studio2010):1. 添加ActiveX控件到工具箱-设计视图,右击工具箱,选择“选择项”,在“COM组件”标签中选择TE3DWindow Class, TEInformationWindow Class 和TENavigationMap Class,单击确定, TE3DWindow Class, TEInformation Window Class和TENavigationMap Class添加到工具箱中。2. 设置工程参考-右击解决方案资源管理器中的“引用”,选择“添加引用”/COM 标签,选择“TerraExplorerX 1.0 Type Library”,单击确定,将其添加到引用中。3. 添加Using指令-在工程中添加”using TerraExplorerX;”4. 添加控件-将工具箱中的TE3DWindow Class, TEInformationWindow Class 和TENavigationMap Class拖到窗体中,创建用户界面。5. 创建TerraExplorer对象-SGWorld对象是TE接口的入口点,通过该对象可以访问TE中的其他接口。 This.sgworld=new SGWorld(); 在此基础上,可以根据功能需求进行程序开发。以下代码为一个简单例子。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using TerraExplorerX;namespace Test public partial class Form1 : Form public Form1() InitializeComponent(); sgworld = null; tCreate = null; LBPos = null; tWindow = null; tNavigate = null; myPolylin = null; myPolygon = null; bMove = false; geoPoints = null; pixelToWorld = null; tProjectTree = null; tAnalysis = null; tCoordServices = null; LBPos = new List(); operateType = 0; private SGWorld sgworld; private ICreator6 tCreate; private IWindow6 tWindow; private INavigate6 tNavigate; private IAnalysis6 tAnalysis; private IProjectTree6 tProjectTree; private ICoordServices6 tCoordServices; private int operateType; private ITerrainPolyline6 myPolylin; private ITerrainPolygon6 myPolygon; private bool bMove; private List LBPos; private double geoPoints; private IWorldPointInfo6 pixelToWorld; private void Form1_Load(object sender, EventArgs e) if (sgworld = null) sgworld = new SGWorld(); sgworld.OnLButtonUp += new _ISGWorld6Events_OnLButtonUpEventHandler(sgworld_OnLButtonUp); sgworld.OnRButtonUp += new _ISGWorld6Events_OnRButtonUpEventHandler(sgworld_OnRButtonUp); sgworld.OnFrame += new _ISGWorld6Events_OnFrameEventHandler(sgworld_OnFrame); tCreate = sgworld.Creator; tWindow = sgworld.Window; tNavigate = sgworld.Navigate; tProjectTree = sgworld.ProjectTree; tAnalysis = sgworld.Analysis; tCoordServices = sgworld.CoordServices; sgworld.Open(E:Skyline培训教材dataSan Francisco样例数据Default.fly); tWindow.HideMessageBarText(); bool sgworld_OnLButtonUp(int Flags, int X, int Y) if (operateType 0) IWorldPointInfo6 worldPoint = tWindow.PixelToWorld(X, Y, WorldPointType.WPT_ALL); IPosition6 pos = worldPoint.Position; LBPos.Add(pos); List points = new List(); foreach (IPosition6 temppos in LBPos) points.Add(temppos.X); points.Add(temppos.Y); points.Add(temppos.Altitude); geoPoints = points.ToArray(); switch (operateType) case 1: case 2: bMove = true; break; case 3: var location= tCreate.CreateLocation(LBPos0, 0, Location); operateType = 0; tWindow.SetInputMode(MouseInputMode.MI_FREE_FLIGHT, , false); location.Position .Pitch = -45; location.Position.Distance = 80000; tNavigate.FlyTo(location, ActionCode.AC_FLYTO); break; case 4: ITerrainLabel6 label= tCreate.CreateLabel(LBPos0, dfdfdfdf, , null , 0, 标签); operateType = 0; tWindow.SetInputMode(MouseInputMode.MI_FREE_FLIGHT, , false); break; case 5: pixelToWorld = tWindow.PixelToWorld(X, Y, WorldPointType.WPT_MODEL ); operateType = 0; tWindow.SetInputMode(MouseInputMode.MI_FREE_FLIGHT, , false);/ if (pixelToWorld = null) MessageBox.Show(对象类型选择错误); else MessageBox .Show (objectid:+pixelToWorld .ObjectID + position:+pixelToWorld .Position .X + type:+pixelToWorld .Type .ToString (); break; return false; void sgworld_OnFrame() if (bMove) IMouseInfo6 mouseInfo = tWindow.GetMouseInfo(); IWorldPointInfo6 worldPoint = tWindow.PixelToWorld(mouseInfo.X, mouseInfo.Y, WorldPointType.WPT_ALL); IPosition6 pos = worldPoint.Position; double movePos = new double pos.X, pos.Y, pos.Altitude ; double tempPos = new doublegeoPoints.Length + 3; geoPoints.CopyTo(tempPos, 0); movePos.CopyTo(tempPos, geoPoints.Length); switch (operateType) case 1: if (myPolylin != null) tCreate.DeleteObject(myPolylin.ID); myPolylin = tCreate.CreatePolylineFromArray(tempPos, Color.Red, AltitudeTypeCode.ATC_ON_TERRAIN, 0, myPolyline); break; case 2: if (myPolygon != null ) tCreate.DeleteObject(myPolygon.ID); if (tempPos.Length = 9) ILinearRing lineRing = tCreate.GeometryCreator.CreateLinearRingGeometry(tempPos);/创建环必须大于等于三个点 myPolygon = tCreate.CreatePolygon(lineRing, Color.Red, Color.White, AltitudeTypeCode.ATC_ON_TERRAIN, 0, myPolygon); break; bool sgworld_OnRButtonUp(int Flags, int X, int Y) if (operateType 0) switch (operateType) case 1: if (myPolylin != null) tCreate.DeleteObject(myPolylin.ID); myPolylin = null; ITerrainPolyline6 Polylin = tCreate.CreatePolylineFromArray(geoPoints, Color.White, AltitudeTypeCode.ATC_ON_TERRAIN, 0, myPolyline); Polylin.SaveInFlyFile = true; operateType = 0; bMove = false; tWindow.SetInputMode(MouseInputMode.MI_FREE_FLIGHT , , false); break; case 2: if (myPolygon !=null ) tCreate.DeleteObject (myPolygon .ID ); myPolygon =null ; ILinearRing lineRing = tCreate.GeometryCreator.CreateLinearRingGeometry(geoPoints); ITerrainPolygon6 Polygon = tCreate.CreatePolygon(lineRing, Color.Red, Color.White, AltitudeTypeCode.ATC_ON_TERRAIN, 0, myPolygon); Polygon.SaveInFlyFile = true; operateType =0; bMove =false ; tWindow .SetInputMode (MouseInputMode .MI_FREE_FLIGHT ,false ); break ; return true; private void btnPolyline_Click(object sender, EventArgs e) operateType = 1; tWindow.SetInputMode(MouseInputMode.MI_COM_CLIENT, , false); LBPos = new List(); private void btnPolygon_Click(object sender, EventArgs e) operateType = 2; tWindow.SetInputMode(MouseInputMode .MI_COM_CLIENT,false ); LBPos = new List(); private void btnLocation_Click(object sender, EventArgs e) operateType = 3; tWindow.SetInputMode(MouseInputMode .MI_COM_CLIENT ,false ); LBPos = new List(); private void btnLabel_Click(object sender, EventArgs e) operateType = 4; tWindow.SetInputMode(MouseInputMode .MI_COM_CLIENT ,false ); LBPos = new List(); 3.2 JavaScript编程环境以下步骤为使用TE接口创建一个JavaScript客户端应用程序:1. 添加ActiveX控件到网页-通过标记可将3D Window、Information tree、Navigation Map控件嵌入到网页中。三个控件在Web页中的声明如下:注:三个控件的CLASSID 均是唯一的,使用时请别混淆。每个嵌入的对象ID是可以更改的。2. 创建TerraExplorer对象-使用标记定义一个TerraExplorer对象或编写函数创建一个TerraExplorer对象。/*/function CreateSGWorld() obj = document.getElementById(sgworld); if (obj = null) obj = document.createElement(object); document.body.appendChild(obj); obj.id = sgworld; = sgworld; obj.classid = CLSID:3a4f91b0-65a8-11d5-85c1-0001023952c1; Var sgworld=CreateSGWorld();在此基础上,可以根据功能需求进行程序开发。以下代码为一个简单例子。 脚本开发练习 var sgworld=null; var tProjectTree = null; var tProject = null; var tCreator = null; var tCommand = null; var tWindow = null; var tNavigate = null; var points = new Array(); var opertype = 0; var bMove = false; var myPolygon = null; var myPolyline = null; /- /接口实例化 /- function Init() sgworld = CreateSGWorld(); tProject = sgworld.Project; tProjectTree = sgworld.ProjectTree; tCreator = sgworld.Creator; tCommand = sgworld.Command; tWindow = sgworld.Window; tNavigate = sgworld.Navigate; sgworld.AttachEvent(OnLButtonUp,OnLButtonUp); sgworld.AttachEvent(OnRButtonUp,OnRButtonUp); sgworld.AttachEvent(OnFrame,OnFrame); function CreateSGWorld() obj = document.getElementById(sgworld); if (obj = null) obj = document.createElement(object);/创建元素 document.body.appendChild(obj); obj.id = sgworld; = sgworld; obj.classid = CLSID:3a4f91b0-65a8-11d5-85c1-0001023952c1; return obj; /- /加载fly数据 /- function LoadFly() sgworld.Open(F:testfly.fly); /- /加载矢量数据 /- function LoadFeatureLayer() var ConnectString=FileName=f:Continents.shp;TEPlugName=OGR; var layer = tCreator.CreateFeatureLayer(continents, ConnectString, 0); var featureGroups = layer.FeatureGroups; featureGroups.SetProperty(Fill Opacity, 100) layer.Save(); /- /三种导航模式 /- function Drag(code,parameter) tCommand.Execute(code, parameter); function Slide(code, parameter) tCommand.Execute(code,parameter); function TurnTilt(code, parameter) tCommand.Execute(code,parameter); /- /创建临时组 /- function CreateGroup(GroupName, ParentGroupID) tProjectTree.CreateGroup(GroupName, ParentGroupID); /- /创建标签 opertype=1 /- function CreateLabel() opertype = 1; tWindow.SetInputMode(1, , false); points = new Array(); /- /创建线 opertype=2 /- function CreatePolyline() opertype = 2; tWindow.SetInputMode(1, , false); points = new Array(); /- /创建多边形 opertype=3 /- function CreatePolygon() opertype = 3; tWindow.SetInputMode(1, , false); points = new Array(); /- /记录鼠标左键 /- function OnLButtonUp(flags, x, y) if (opertype 0) var worldPointInfo = tWindow.PixelToWorld(x, y, -1); var position = worldPointInfo.Position; points.push(position.X); points.push(position.Y); points.push(position.Altitude); switch (opertype) case 1: var labelStyle = tCreator.CreateLabelStyle(0); tCreator.CreateTextLabel(position, 标签, labelStyle, 0, 标签); opertype = 0; tWindow.SetInputMode(0, , false); break; case 2: case 3: bMove = true; break; return false; /- /鼠标移动 /- function OnFrame() if (bMove) var mouseInfo=tWindow.GetMouseInfo(); var worldPointInfo=tWindow.PixelToWorld(mouseInfo.X,mouseInfo.Y,-1); var position=worldPointInfo.Position; var tempPoint=new Array(); tempPoint0=position.X; tempPoint1=position.Y; tempPoint2=position.Altitude; va
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB 3609.1-2025眼面部防护焊接防护第1部分:焊接防护具
- YY/T 1488-2025中医器械舌象信息采集设备
- 应用HPS教学模式培养学生生物学学科核心素养
- 2025年中国腻子粉项目投资计划书
- 中国氧芴项目商业计划书
- 晋城市人民医院感染科医院感染控制考核
- 齐齐哈尔市中医院放射科主治医师晋升考核
- 晋城市人民医院骨移植技术操作考核
- 唐山市中医院肌肉骨骼超声操作与评估资格认证考核
- 巴彦淖尔市人民医院护理病例教学考核
- JGT 352-2017 现浇混凝土空心结构成孔芯模
- Turning Red《青春变形记(2022)》完整中英文对照剧本
- 2024年泰州市现代农业发展集团有限公司招聘笔试冲刺题(带答案解析)
- 公开课氯气的性质课件省公开课金奖全国赛课一等奖微课获奖课件
- 幼儿园花样跳绳培训
- (正式版)SHT 3224-2024 石油化工雨水监控及事故排水储存设施设计规范
- 护理制度与职责
- 基本公共卫生服务居民健康档案课件
- 十大医药代表成功经验分享
- 以工代赈项目技能培训方案
- 精益改善套路
评论
0/150
提交评论