博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcGIS API for Silverlight开发入门(8):在程序中使用Virtual Earth的服务
阅读量:6939 次
发布时间:2019-06-27

本文共 3300 字,大约阅读时间需要 11 分钟。

SilverlightAPI中还包括了一个ESRI.ArcGIS.VirtualEarth.dll类库,让我们可以方便的访问到老东家的VirtualEarth服务。目前SilverlightAPI中提供的VirtualEarth服务有三种:Map,Geocode和Routing,不过一看就知道后两种服务对于国内的数据来说又无缘了。

        直接看如何使用它的Map服务获取地图数据吧。同前,新建一个Silverlight工程,添加ESRI.ArcGIS.dll和ESRI.ArcGIS.VirtualEarth.dll的引用,引入xml命名空间,在xaml里面这样写:

  1. <esri:Map x:Name="Map1" Loaded="Map1_Loaded">
  2.             <esri:Map.Layers>
  3.                 <esriVE:TileLayer ID="VELayer" LayerStyle="AerialWithLabels" ServerType="Staging"/>
  4.             </esri:Map.Layers>
  5.         </esri:Map>
复制代码
可以看出,和添加其他图层基本是一样的。SIlverlightAPI中针对VE地图的图层类型是TileLayer,LayerStyle有三种:Road,Aerial和AerialWithLabels,分别对应矢量图,影像图和带街道标注的影像图。ServerType就比较特殊了,有两种:Staging和Production,分别对应访问VE服务的账户类别,前者是免费的,后者是收费的。如果你此时运行程序的话,那是看不到地图的,因为TileLayer还有个关键的token属性没有设置。
        VE的服务那是相当安全,每次访问VE的服务,都要提供一个token(一个加密字符串)来进行身份验证,而这个token又是根据TokenService自动生成的,要通过TokenService生成一个token,又需要一个合法的Microsoft Virtual Earth Platformdeveloper account……明白了这个过程,就来做我们的工作吧。
        首先, ,当然之前你还得有一个Windows Live账号。申请的这个账号是Evaluation版的,所以决定了以后我们只能使用Staging的服务,如果要把它变成Production版本,可以通过邮件联系微软,然后缴费;
        之后到注册时所填的邮箱去激活申请的Microsoft Virtual Earth Platform developeraccount账号,然后为其设置密码(必须是8-14为之间,包括大、小写字母,数字,且还要有非字母数字的字符,和windows server2008是一样的),我们平常肯定不会这样设置密码,为了以防万一,建议赶紧把设置好的密码记录下来,
没准哪天就忘了。现在就可以用这个账户和密码来访问TokenService,通过它生成token,交给TileLayer的token属性。
        为了安全目的考虑,token是不建议也不能直接在Silverlight程序中进行设置的。那么怎么办呢?这样办:1、通过装载Silverlight的aspx页面的Page_Load方法,来申请我们的token,并把它添加到Silverlight的初始参数中,2、然后当Silverlight插件载入的时候,把token读出来,3、在Map_Loaded事件中,赋给TileLayer。
1、通过TokenService申请token:
在webapp中add webreference,url用 ,起个名字叫VirtualEarthService.TokenService。
  1. <script language="C#" runat="Server">
  2.     private string VEAccountID = "你的ID(注意只是AccountID)";
  3.     private string VEAccountPassword="你的密码";
  4.    
  5.     protected void Page_Load(object sender,EventArgs e)
  6.     {
  7. _08_virtual_earth.Web.VirtualEarthService.TokenService.CommonService
  8. commenservice = new
  9. _08_virtual_earth.Web.VirtualEarthService.TokenService.CommonService();
  10.         
  11.         commenservice.Credentials = new System.Net.NetworkCredential(VEAccountID, VEAccountPassword);
  12. _08_virtual_earth.Web.VirtualEarthService.TokenService.TokenSpecification
  13. tokenSpec=new
  14. _08_virtual_earth.Web.VirtualEarthService.TokenService.TokenSpecification();
  15.         tokenSpec.TokenValidityDurationMinutes=480;
  16.         if (HttpContext.Current!=null && !HttpContext.Current.Request.IsLocal)
  17.         {
  18.             tokenSpec.ClientIPAddress=HttpContext.Current.Request.UserHostAddress;
  19.         }
  20.         else
  21.         {
  22.             tokenSpec.ClientIPAddress="127.0.0.1";
  23.         }
  24.         
  25.         string token = "";
  26.         token = commenservice.GetClientToken(tokenSpec);
  27.         Xaml1.InitParameters = string.Format("token={0}", token);
  28.     }
  29. </script>
复制代码
其中Xaml1是Silverlight插件的ID:<asp:Silverlight ID="Xaml1" runat="server"...
2、Silverlight插件载入时读出这个token。在App.xaml.cs中:
  1. private void Application_Startup(object sender, StartupEventArgs e)
  2.         {
  3.             VEtoken = e.InitParams["token"];
  4.             this.RootVisual = new Page();
  5.         }
复制代码
3、最后在加载地图控件后,交付token:
  1. private void Map1_Loaded(object sender, RoutedEventArgs e)
  2.         {
  3.             foreach (Layer layer in Map1.Layers)
  4.                 if (layer is TileLayer)
  5.                     (layer as TileLayer).Token = (Application.Current as App).VEtoken;
  6.         }
复制代码
终于能看见VE的图了。当然,我们的开发账户是免费的,所以地图上有很多“Staging”麻点(每个tile一个):

08_ve.jpg

(89.16 KB)
2009-5-6 18:16

 

        至此,ArcGIS API for Silverlight的开发入门已经讲完了,我和大家一样也是边学边写的,刚好这两天SIlverlightAPI又升级了第二个Beta版。其实Silverlight和Flex一样,能使传统的WebGIS散发出全新的魅力,从而使我们的程序在RIA的道路上大踏步前进,能够做出什么样的效果也基本只受想象力的制约了。随着Silverlight3的推出,我们也有理由相信Silverlight的明天会更好。

原文地址:

转载地址:http://masnl.baihongyu.com/

你可能感兴趣的文章
Myeclipse 启动tomcat项目报Out of memory: java heap space
查看>>
easyui-笔记
查看>>
php include 绝对路径 dirname(__FILE__)
查看>>
软考倒计时19天:招投标法、合同法、采购法
查看>>
通过style控制圆形imageView显示
查看>>
K - 4 Values whose Sum is 0(中途相遇法)
查看>>
实验五 Servlet过滤器
查看>>
GIT版本控制系统(二)
查看>>
关于一些测绘软件的评价
查看>>
UISearchBar--改变内部输入框的背景颜色
查看>>
使用redis-cli --pipe快速插入数据
查看>>
数据结构----队列:顺序队列&顺序循环队列、链式队列、顺序优先队列
查看>>
福大软工1816 · 第三次作业 - 结对项目1(原型设计)
查看>>
三国杀的10个人生感悟
查看>>
nginx错误:unknown directive "锘? in F:\nginx/conf/nginx.conf:3
查看>>
【数据结构-文都】第二章 线性表(1)
查看>>
Ubuntu快捷键
查看>>
mycp
查看>>
python连续爬取多个网页的图片分别保存到不同的文件夹
查看>>
linux之SQL语句简明教程---UNION ALL
查看>>