ArcGIS for WPF 访问外部资源

本文详细介绍了使用 ArcGIS API for Silverlight 访问外部资源的方法,通过修改 TiledMapServiceLayer 类实现与 Google Map 的集成。示例包括指定地图区域、导航、缩放等功能,并提供了完整地图 UserControl 代码及使用教程,最终展示了一个集成 Google 地图的示例应用。

  应用背景:

  因项目需要尝试了解了ArcGIS、Bing Map、Google Map等开发技术,最终是使用ArcGIS写了个Demo。

  ArcGIS现提供了一套控件库ArcGIS  API  for WPF供Silverlight开发使用,其中也包括WPF可以使用的控件。

  对比Sample Demo以及自己动手实践,还是比较快的就熟悉控件结构,不过对于已经使用过一年多WPF的我来说,感觉控件库开发者还是Winform那套思想,没有发挥出WPF数据绑定、模板等的优势来,用起来不是特别顺手。

  ArcGIS网上提供的地图都相对简单,乍看上去与我们平时使用的Google地图、百度地图什么的有很大差别(可能是我没掌握到精髓吧),寻寻觅觅之后进行了以下尝试,也就是这篇文章的主题——ArcGIS 访问外部资源。

  

参考文章:

  ArcGIS API for Silverlight开发入门(7):使用非AGS数据源的图层

  文章后边留言中反映出现404错误等,我刚开尝试做的时候也得不到数据,猜想是不是像作者说的那样数据Url应经过时了,后来在研究GMap源代码的时候,发现它也同样使用了Google Map数据源,经过调试跟踪得到了大致的路径,替换baseUrl,终于让我看到地图图像了。下边是经过修改后的TiledMapServiceLayer:

ContractedBlock.gif ExpandedBlockStart.gif GoogleMapTileLayer
    public   class  GoogleMapTileLayer : TiledMapServiceLayer
    {
        
public   override   void  Initialize()
        {
            
this .FullExtent  =   new  Envelope( - 20037508.342787 - 20037508.342787 20037508.342787 20037508.342787 );
            {
                SpatialReference 
=   new  SpatialReference( 102113 );
            };
            
this .SpatialReference  =   new  SpatialReference( 102113 );
            
             this .TileInfo  =   new  TileInfo()
            {
                Height 
=   256 ,
                Width 
=   256 ,

                Origin 
=   new  MapPoint( - 20037508.342787 20037508.342787 )
                {
                    SpatialReference 
=   new  SpatialReference( 102113 )
                },
                Lods 
=   new  Lod[ 20 ]
            };

            
double  resolution  =   156543.033928 ;
            
for  ( int  i  =   0 ; i  <  TileInfo.Lods.Length; i ++ )
            {
                TileInfo.Lods[i] 
=   new  Lod() { Resolution  =  resolution };
                resolution 
/=   2 ;
            }

            
base .Initialize();
        }

        
public   override   string  GetTileUrl( int  level,  int  row,  int  col)
        {
             string  baseUrl  =   " http://mt3.google.cn/vt/lyrs=m@156000000&hl=zh-CN&x= " ;
            
string  url  =  baseUrl  +  col.ToString()  +   " &y= "   +  row.ToString()  +   " &z= "   +  level.ToString()  +   " &s= " ;
            
return  url;
        }
    }

  在xaml中的使用该图层:

  < esri:Map.Layers >
    < WPFControlLibary:GoogleMapTileLayer  />
  </ esri:Map.Layers >

  因为地图初始就显示重庆地区,就需要指定Envelope,再加上导航、缩放等现成的工具,最终整个地图UserControl代码如下:

ContractedBlock.gif ExpandedBlockStart.gif Map Control
< UserControl  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:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:esri
="http://schemas.esri.com/arcgis/client/2009"
             xmlns:i
="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:local
="clr-namespace:NPView.View.WPFControl"
            
x:Class ="GISBrowserCtl" >

    
< Grid  x:Name ="LayoutRoot" >
        
< esri:Map  x:Name ="MyMap"
                  MouseDown
="MyMap_MouseDown" >
            
< esri:Map.Extent >
                
< esri:Envelope  XMin ="11841331.013437796"
                               YMin
="3434962.1416729852"
                               XMax
="11872920.415001778"
                               YMax
="3453477.0409229854" >
                    
< esri:Envelope.SpatialReference >
                        
< esri:SpatialReference  WKID ="102113"   />
                    
</ esri:Envelope.SpatialReference >
                
</ esri:Envelope >
            
</ esri:Map.Extent >
            
< esri:Map.Layers >
                
< WPFControlLibary:GoogleMapTileLayer  />
            
</ esri:Map.Layers >
            
< i:Interaction.Behaviors >
                
< esri:MaintainExtentBehavior  />
            
</ i:Interaction.Behaviors >
        
</ esri:Map >
     </ Grid >
</ UserControl >

  附效果图一张

   

  ArcGIS API for Silverlight开发入门(8):在程序中使用Virtual Earth的服务

  同样我们还可以按此使Virtual Earth的服务,不过过程要复杂点不过也好合法点,在ArcGIS中使用Bing Map也很容易啦!

转载于:https://www.cnblogs.com/wdysunflower/archive/2011/07/14/2105584.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值