『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

ArcGIS 10.1 for Server入门(5-4)使用Web APIs创建web应用之搭建 web 应用

ArcGIS 10.1 for Server入门(5-4)使用Web APIs创建web应用之搭建 web 应用
ArcGIS 10.1 for Server入门(5-4)使用Web APIs创建web应用之搭建 web 应用

       1、启动 Visual Studio 2010,新建一个项目,如下图,选择 Silverlight Application

 

 

 

       2、点击 OK 后将弹出 Web 网站配置页面,这里接受默认参数。

 

 

 

       点击 OK 后,新建的 Silverlight 应用程序如下图所示,工作区的上半部分是页面设计视图,下半部分是页面标记代码视图,右侧解决方案目录中有两个工程,一个是 Silverlight 工程,另一个是 ASP.NET 网站包含的 aspxhtml 网页和 web.config 配置文件) ,而创建的 Silverlight 应用程序,将依托这个网站来运行。

 

 

 

       3、在 Silverlight 工程引用中添加对 ArcGIS Silverlight API 类库的引用。

 

 

 

       4 在标记代码中( .xaml 文件)添加对“命名空间”的引用。

 

<UserControl x:Class="HelloWorld.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:esri="http://schemas.esri.com/arcgis/client/2009"

mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400">

  <Grid x:Name="LayoutRoot" Background="White">

  </Grid>

</UserControl>

       5、添加地图控件

 

<UserControl x:Class="HelloWorld.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:esri="http://schemas.esri.com/arcgis/client/2009"

mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400">

  <Grid x:Name="LayoutRoot" Background="White">

  </Grid>

</UserControl>

        6、添加服务图层(XAML 代码)

 

<Grid x:Name="LayoutRoot" Background="White">

  <esri:Map x:Name="myMap">

    <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"

    Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"

    InitializationFailed="Layer_InitializationFailed"/>

    </esri:Map>

</Grid>

       7、添加后台代码(使用 C#

 

using System;

using System.Windows;

using System.Windows.Input;

using System.Windows.Controls;

using ESRI.ArcGIS.Client;

namespace HelloWorld

{

  public partial class MainPage : UserControl

  {

    public MainPage()

    {

      InitializeComponent();

    }

    private void Layer_InitializationFailed(object sender, EventArgs e)

    {

      //获取图层对象

      Layer layer = sender as Layer;

      //显示图层加载失败原因的提示

      MessageBox.Show("加载图层失败: " + layer.InitializationFailure.Message);

    }

  }

}

       8、编译运行,效果如下(因为上面使用的是在线地图服务,因此需要连接 Internet)。

 

 

 

       9、拔掉网线再试将提示加载图层失败,如下图所示:

 

 

 

       10、如果看不见地图可能是因为没有跨域访问策略文件。

 

       文件名:clientaccesspolicy.xml

 

       文 ArcGIS Server 站点所在机器的 wwwroot 目录下,例如:C:\inetpub\wwwroot

 

       文件内容:

 

<access-policy>

  <cross-domain-access>

    <policy>

      <allow-from http-request-headers="*">

        <domain uri="*"/>

        <domain uri="http://*"/>

      </allow-from>

      <grant-to>

        <resource path="/" include-subpaths="true"/>

      </grant-to>

    </policy>

  </cross-domain-access>

</access-policy>

       至此,一个简单的 ArcGIS Silverlight API 应用就搭建好了。

      京ICP备2025132830号-1 京公网安备 号