
1.首先Silverlight前台加载esri:Map,示例代码如下:
//添加引用xmlns:esri="http://schemas.esri.com/arcgis/clIEnt/2009"<pre name="code" >
//添加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); } 总结 以上是内存溢出为你收集整理的ArcGIS API for Silverlight 加载BingMap,GoogleMap,WorldImageryMap,OpenStreetMap,BaiduMap方法全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 加载BingMap,GoogleMap,WorldImageryMap,OpenStreetMap,BaiduMap方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)