zoukankan      html  css  js  c++  java
  • ArcGIS for WPF 访问外部资源

      应用背景:

      因项目需要尝试了解了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:

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

                    Origin 
    = new MapPoint(-20037508.34278720037508.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代码如下:

    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也很容易啦!

  • 相关阅读:
    155. 最小栈
    160. 相交链表
    PAT 1057 Stack
    PAT 1026 Table Tennis
    PAT 1017 Queueing at Bank
    PAT 1014 Waiting in Line
    PAT 1029 Median
    PAT 1016 Phone Bills
    PAT 1010 Radix
    PAT 1122 Hamiltonian Cycle
  • 原文地址:https://www.cnblogs.com/wdysunflower/p/2105584.html
Copyright © 2011-2022 走看看