ArcGIS for WPF下的Google图层
来源:互联网 发布:知君本无邪txt 编辑:程序博客网 时间:2024/06/10 04:09
试了一下原来SilverLight下的方法,发现直接继承TiledMapServiceLayer然后覆盖GetTileUrl方法是不行的,没办法,只好再向上继承自TiledLayer了,需要覆盖GetTileSource方法,也就意味着要自己做下载图片的实现,其中有个关键的地方:
var web = new WebClient {Credentials = CredentialCache.DefaultCredentials};//要设置证书web.Headers.Add(HttpRequestHeader.UserAgent, "Microsoft Internet Explorer");//要设置UserAgent
好了,下面附上cs文件源码:
using System;using System.IO;using System.Net;using System.Windows.Media;using System.Windows.Media.Imaging;using ESRI.ArcGIS.Client;using ESRI.ArcGIS.Client.Geometry;namespace WPF.Map{ public class GoogleMapTileLayer : TiledLayer { /// <summary> /// 切片源点的坐标常量 /// </summary> private const double OriginX = -20037508.342787; private const double OriginY = 20037508.342787; private int _mapType = 0; private int WKID = 102100; private string _languageCode = "zh-CN"; private string _countryCode = "cn"; /// <summary> /// 地图类型 0:地形图 1:卫星图 2:街道图 /// </summary> public int MapType { get { return _mapType; } set { _mapType = value; } } public string LanguageCode { get { return _languageCode; } set { _languageCode = value; } } public string CountryCode { get { return _countryCode; } set { _countryCode = value; } } protected override void GetTileSource(int level, int row, int col, Action<ImageSource> onComplete) { string url, BaseUrl; switch (_mapType) { case 0: //地形图 BaseUrl = "m@210000000"; url = string.Format("http://mt{0}.google.cn/vt/lyrs={1}&v=w2.114&hl={2}&gl={3}&src=app&x={4}&y={5}&z={6}&s={7}", col % 4, BaseUrl, LanguageCode, CountryCode, col, row, level, "Galileo".Substring(0, (col * 3 + row) % 8)); break; case 1: //卫星图 BaseUrl = "s@126"; url = string.Format("http://mt{0}.google.cn/vt/lyrs={1}&v=w2.114&hl={2}&gl={3}&src=app&x={4}&y={5}&z={6}&s={7}", col % 4, BaseUrl, LanguageCode, CountryCode, col, row, level, "Galileo".Substring(0, (col * 3 + row) % 8)); break; case 2: //街道图 BaseUrl = "h@210000000"; url = string.Format("http://mt{0}.google.cn/vt/imgtp=png32&lyrs={1}&v=w2.114&hl={2}&gl={3}&src=app&x={4}&y={5}&z={6}&s={7}", col % 4, BaseUrl, LanguageCode, CountryCode, col, row, level, "Galileo".Substring(0, (col * 3 + row) % 8)); break; default: //地形图 BaseUrl = "m@210000000"; url = string.Format("http://mt{0}.google.cn/vt/lyrs={1}&v=w2.114&hl={2}&gl={3}&src=app&x={4}&y={5}&z={6}&s={7}", col % 4, BaseUrl, LanguageCode, CountryCode, col, row, level, "Galileo".Substring(0, (col * 3 + row) % 8)); break; } var web = new WebClient {Credentials = CredentialCache.DefaultCredentials}; web.Headers.Add(HttpRequestHeader.UserAgent, "Microsoft Internet Explorer"); web.DownloadDataCompleted += (sender, args) => { if (args.Error == null && onComplete != null) { var ms2 = new MemoryStream(args.Result, 0, args.Result.Length); ms2.Seek(0, SeekOrigin.Begin); var image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.None; image.CreateOptions = BitmapCreateOptions.None; image.StreamSource = ms2; image.EndInit(); onComplete(image); } }; web.DownloadDataAsync(new Uri(url, UriKind.RelativeOrAbsolute)); } public override void Initialize() { this.FullExtent = new Envelope(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787); { SpatialReference = new SpatialReference(WKID); }; this.SpatialReference = new SpatialReference(WKID); this.TileInfo = new TileInfo() { Height = 256, Width = 256, Origin = new MapPoint(-20037508.342787, 20037508.342787) { SpatialReference = new SpatialReference(WKID) }, 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(); } }}
1 0
- ArcGIS for WPF下的Google图层
- arcgis api for javascript graphiclayer dojo框架下画图图层的显示与清除
- Arcgis for flex 给Google卫星地图加上地点名(道路图层)
- arcgis for javascript之ArcGISDynamicMapServiceLayer图层控制的实现
- arcgis for android 学习 - (3) 图层的可见性
- arcgis for ios 类和图层的对应说明
- arcgis api for javascript 图层控制
- ArcGIS api for javascript-图层控制
- Arcgis for Android---图层控制
- ArcGis for WPF 符号渲染
- arcgis图层的分类
- ArcGIS API for Silverlight开发入门(7):使用非AGS数据源的图层
- ArcGIS API for Silverlight开发入门(7):使用非AGS数据源的图层
- ArcGIS API for Silverlight开发入门(7):使用非AGS数据源的图层
- ArcGIS API for Silverlight 动态图层(ArcGISDynamicMapServiceLayer)的显示与隐藏
- ArcGIS API for Silverlight开发入门(7):使用非AGS数据源的图层
- 使用ArcGIS API for JavaScript实现类似ArcMap的图层控制面板Tab of Contents
- ArcGIS for iOS地图上添加测距功能,及显示相应的路径图层
- EmguCV学习-摄像头采集
- OJ_1075
- 动态添加jquery Moblie元素
- 查询Oracle数据库中各对象占用空间情况
- 题目1050:完数
- ArcGIS for WPF下的Google图层
- VoltDB Truncate Table优化,性能提高加速N倍,是不是史上最快呢?
- SharedPreferences
- Apache Log4j 2.0-rc1 发布
- android webview js交互, 响应webview中的图片点击事件
- Mega48/88/128中内部EEPROM的读写
- Jenkins server Installation
- python学习笔记(django入门02)
- Error: Failed to send data by channels – post message failed