WPF & ArcGIS Engine三维开发入门攻略

    技术2022-05-20  70

    WPF & ArcGIS Engine三维开发入门攻略

    前些日子在做ESRI的开发大赛,从刚开始接触ArcGIS Engine(以下称AE)那会儿“摸着石头过河”那个阶段一路走下来,有了不少心得体会,在此给大家分享下。

    做得是一个三维的校园地下管线系统,使用的AE的SceneControl组件。传说Scene适合小场景精细模型展示,Globe适合大场景海量数据展示,所以选的前者。界面用的是Dotnetbar for WinForm,但其实WPF更好些,这里我也以WPF为例。

     

    我的系统环境:Windows 7 专业版,Visual Studio 2010,ArcGIS Engine 9.3

     

    1.创建项目

    创建一个WPF的项目,必须选择.Net framework 3.5AE9.3不支持.Net4.0),添加引用:

    ESRI.ArcGIS.3DAnalyst ESRI.ArcGIS.AxControls ESRI.ArcGIS.Carto ESRI.ArcGIS.Controls ESRI.ArcGIS.Display ESRI.ArcGIS.Geometry ESRI.ArcGIS.GlobeCore ESRI.ArcGIS.Output ESRI.ArcGIS.System ESRI.ArcGIS.SystemUI

    VS08可以在.Net选项卡下面找到所有引用,但10则只能去ESRI安装目录下找

     

    2.界面

    把缺省标题MainWindow改掉,分割主窗体中的Grid为左右两部分,两边各放置一个WindowsFormsHost,用于承载AE的控件。

    打开XAML视图, 在顶部引入AE控件的命名空间,名字随意

    xmlns:esri="clr-namespace:ESRI.ArcGIS.Controls;assembly=ESRI.ArcGIS.AxControls"

    编辑两个WindowsFormsHost,添加两个控件

    <WindowsFormsHost Margin="10" >     <esri:AxTOCControl x:Name="toc" Dock="Fill" /> </WindowsFormsHost>

    <WindowsFormsHost Grid.Column="1" Margin="10" >     <esri:AxSceneControl x:Name="scene" Dock="Fill" /> </WindowsFormsHost>

     

    3.代码 AE的程序需要Liscene才能启动,通常的办法是在窗体上放置一个LicenseControl。但对于WPF,这个办法行不通。 在App.xaml.cs,App类下建一个构造方法

    public App() {    AoInitialize aoi = new AoInitializeClass ();    //Additional license choices can be included here.    esriLicenseProductCode productCode =        esriLicenseProductCode .esriLicenseProductCodeEngine;    if (aoi.IsProductCodeAvailable(productCode) ==        esriLicenseStatus .esriLicenseAvailable)    {         aoi.Initialize(productCode);    } }

    程序启动后,绑定TOC到Scene,并加载地图

    private void Window_Loaded( object sender, RoutedEventArgs e) {    this .toc.SetBuddyControl( this .scene); // 绑定 Toc Scene    this .scene.LoadSxFile( "******" ); // 加载场景    this .scene.Navigate = true ; // 启用 Navigate    this .scene.Update(); }

     

    OK,F5启动看下效果

     

     

    最后,请同样装了64位Windows的朋友们,再做下面一个步骤:项目->WpfScene属性->生成,把目标平台设置成x86。只因为AE还没有支持64位,令人失望的是,最新的ArcGIS 10依然没有。

     

     

    参考:

    WPF 与ArcEngine 也挺有情调的么

    如何在WPF项目中使用ArcEngine的控件做开发

    ArcGIS Blog:Can you use Visual Studio 2010 to develop against ArcGIS 10

    ESRI资源中心:How to host an ArcGIS Engine map control in a WPF application


    最新回复(0)