之前在博客中(http://blog.csdn.net/taomanman/article/details/8019687)提到的加载Google地图方案,因为Google地址问题,看不到图了,发现是URL地址变换造成的。
现将如下三个类公布出来,源码如下:
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 MapClIEnt.CommonClass{ public class GoogleMapLayer : TiledMapServiceLayer { private const double cornerCoordinate = 20037508.3427892; public string _baseURL = "t@131"; //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[18] }; //为每级建立方案,每一级是前一级别的一半. 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://mt1.Google.cn/vt/lyrs=" + _baseURL + ",r@225000000&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; if (_baseURL == "t@131") { //地形图 url = "http://mt1.Google.cn/vt/lyrs=" + _baseURL + ",r@225000000&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; } if (_baseURL == "s@132") { //卫星图 url = "http://mt3.Google.cn/vt/lyrs=" + _baseURL + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=G"; } if (_baseURL == "m@225000000") { //街道图 url = "http://mt1.Google.cn/vt/lyrs=" + _baseURL + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; } return string.Format(url); } }}
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 MapClIEnt.CommonClass{ public class GoogleMapRoadLayer : TiledMapServiceLayer { private const double cornerCoordinate = 20037508.3427892; private string _baseURL = "m@225000000"; //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,Lods = new Lod[19] }; //为每级建立方案,每一级是前一级别的一半. 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,r@225000000&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; } if (_baseURL == "s@132") { //卫星图 url = "http://mt3.Google.cn/vt/lyrs=" + _baseURL + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=G"; } if (_baseURL == "m@225000000") { //街道图 url = "http://mt1.Google.cn/vt/lyrs=" + _baseURL + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; } return string.Format(url); } }}
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 MapClIEnt.CommonClass{ public class GoogleMapSateliateLayer : TiledMapServiceLayer { private const double cornerCoordinate = 20037508.3427892; private string _baseURL = "s@132"; //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,Lods = new Lod[20] }; //为每级建立方案,每一级是前一级别的一半. 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,r@225000000&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; } if (_baseURL == "s@132") { //卫星图 url = "http://mt3.Google.cn/vt/lyrs=" + _baseURL + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=G"; } if (_baseURL == "m@225000000") { //街道图 url = "http://mt1.Google.cn/vt/lyrs=" + _baseURL + "&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga"; } return string.Format(url); } }}总结
以上是内存溢出为你收集整理的ArcGIS API for Silverlight加载google地图(后续篇)全部内容,希望文章能够帮你解决ArcGIS API for Silverlight加载google地图(后续篇)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)