微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ArcGIS API for Silverlight 加载BingMap,GoogleMap,WorldImageryMap,OpenStreetMap,BaiduMap方法

1.首先Silverlight前台加载esri:Map,示例代码如下:

//添加引用
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"<pre name="code" class="html">
//添加esri:Map
<esri:Map x:Name="TestMap"  IslogoVisible="False"  MinimumResolution="0.01"  MouseMove="Subway_MouseMove"></span>
            <esri:Map.Layers>
                <esri:ArcGISDynamicMapServiceLayer ID="···" displayName="···" Initialized="···" Url="····" ></esri:ArcGISDynamicMapServiceLayer>
                <esri:Graphicslayer ID="MyGraphicslayer"  Opacity="1"/>
            </esri:Map.Layers>
        </esri:Map>

2.后台添加地图

Map MyMap = this.LayoutRoot.FindName("TestMap") as Map;

A.BingMap

ESRI.ArcGIS.Client.Bing.TileLayer bingLayer = new TileLayer();
bingLayer.ID = "BingMapLayer";
bingLayer.displayName = "BingMap";
bingLayer.LayerStyle = TileLayer.LayerType.AerialWithLabels;
bingLayer.Visible = true;
bingLayer.ServerType = ServerType.Production;
bingLayer.Token = "AjXYD5KFgNM650vi1Q9VKNWFBORxoux7Y_UFrmuwqs0RvXSkVyfaNueRlPkLctKN";
MyMap.Layers.Insert(0,bingLayer);

B.WordImagerMap

ArcGISTiledMapServiceLayer worldImageryLayer = new ArcGISTiledMapServiceLayer();
worldImageryLayer.ID = "WorldImageryLayer";
worldImageryLayer.displayName = "WorldImageryLayer";
worldImageryLayer.Visible = true;
worldImageryLayer.Url = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer";
worldImageryLayer.Visible = false;
MyMap.Layers.Insert(0,worldImageryLayer);
C.OpenStreetMap

OpenStreetMapLayer osLayer = new OpenStreetMapLayer();
osLayer.ID = "OpenStreetLayer";
osLayer.displayName = "OpenStreetLayer";
osLayer.Style = OpenStreetMapLayer.MapStyle.Mapnik;
osLayer.Visible = true;
osLayer.Opacity = 1;
MyMap.Layers.Insert(0,osLayer);
D.GoogleMap

首先添加一个类,命名为GoogletopographicLayer,类的代码如下:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;

namespace GoogleMap
{
    public class GoogletopographicLayer: TiledMapServiceLayer  
    {
        private const double cornerCoordinate = 20037508.3427892;
        private string _baseURL = "m@161000000"; //google街道图

        public override void Initialize()
        {
            ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
            this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892)
            {
                SpatialReference = new SpatialReference(102100)
            };
            //图层的空间坐标系  
            this.SpatialReference = new SpatialReference(102100);
            // 建立切片信息,每个切片大小256*256px,共16级.  
            this.TileInfo = new TileInfo()
            {
                Height = 256,Width = 256,Origin = new MapPoint(-cornerCoordinate,cornerCoordinate) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102100) },Lods = new Lod[16]
            };
            //为每级建立方案,每一级是前一级别的一半.  
            double resolution = cornerCoordinate * 2 / 256;
            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 url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=" + _baseURL + "&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=galil";
            if (_baseURL == "s@92")
            {
                url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=" + _baseURL + "&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=galil"; //加载Google遥感图  
            }
            if (_baseURL == "t@128")
            {
                url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=" + _baseURL + ",r@169000000&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=galil";//加载Google地形图  
            }
            if (_baseURL == "m@161000000")
            {
                url = "http://mt" + (col % 4) + ".google.cn/vt/lyrs=" + _baseURL + "&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=galil"; //加载Google街道图  
            }
            return string.Format(url);

            //调用加载初始的Google街道地图  
            //string baseUrl = "http://mt2.google.cn/vt/v=w2.116&hl=zh-CN&gl=cn&x={0}&y={1}&z={2}&s=G";  
            //return string.Format(baseUrl,col,row,level);  
        }  

    }
}
        /// <summary>
        /// Initialization BaiduMap
        /// </summary>
        public void InitGoogleMap()
        {
            GoogletopographicLayer GoogleMaplayer = new GoogletopographicLayer();
            GoogleMaplayer.ID = "GoogleMapLayer";
            GoogleMaplayer.displayName = "GoogleMap";
            GoogleMaplayer.Visible = ture;
            MyMap.Layers.Insert(0,GoogleMaplayer);
        }

E.BaiduMap

首先添加一个类,命名为BaidutopographicLayer,类的代码如下:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;

namespace BaiduMap
{
    public class BaiduMapLayer : TiledMapServiceLayer  
    {
        private const double cornerCoordinate = 20037508.3427892;
        private string _baseURL = "POI"; //Baidu地形图  

        public override void Initialize()
        {
            ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
            this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(5916776.8,1877209.3,19242502.6,7620381.8)
            {
                SpatialReference = new SpatialReference(102100)
            };
            //图层的空间坐标系  
            this.SpatialReference = new SpatialReference(102100);
            // 建立切片信息,每个切片大小256*256px,共16级.  
            this.TileInfo = new TileInfo()
            {
                Height = 256,int col)
        {
            int zoom = level - 1;
            int offsetX =Convert.ToInt16(Math.Pow(2,zoom));
            int offsetY = offsetX - 1;
            int numX = col - offsetX;
            int numY = (-row) + offsetX;
            zoom = level + 1;
            int num = (col + row) % 8 + 1;


            string url = "";
            if (_baseURL == "Vector")
            {
                url = "http://q" + num + ".baidu.com/it/u=x=" + numX + ";y=" + numY + ";z=" + zoom + ";v=013;type=web&fm=44"; //加载Baidu遥感图  
            }
            if (_baseURL == "Image")
            {
                url = "http://q" + num + ".baidu.com/it/u=x=" + numX + ";y=" + numY + ";z=" + zoom + ";v=009;type=sate&fm=46";//加载Baidu地形图  
            }
            if (_baseURL == "POI")
            {
                url = "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x=" + numX + "&y=" + numY + "&z=" + zoom + "&styles=pl&udt=20140819";  //加载Baidu街道图  
            }
            return string.Format(url);

        }  

    }
}
/// <summary>
        /// Initialization BaiduMap
        /// </summary>
        public void InitBaiduMap()
        {
            BaiduMapLayer Baidulayer = new BaiduMapLayer();
            Baidulayer.ID = "BaiduMapLayer";
            Baidulayer.displayName = "Baidu";
            Baidulayer.Visible = true;
            MyMap.Layers.Insert(0,Baidulayer);
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐