ArcGIS API for Silverlight載入google地圖(後續篇)
之前在部落格中(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, -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[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, 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 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, -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[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, 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);
}
}
}
相關文章
- ArcGIS API for Silverlight 載入google地圖APIGo地圖
- ArcGIS API for Silverlight中載入Google地形圖(瓦片圖)APIGo
- ArcGIS API for Silverlight載入BingMap遙感地圖API地圖
- ArcGIS API for Silverlight 地圖載入進度條類之MapProgressBarAPI地圖APP
- ArcGis api配合vue開發入門系列(一)引入arcgis api以及載入地圖APIVue地圖
- 解決ArcGIS API for Silverlight 載入地圖的內外網訪問問題API地圖
- ArcGIS API for Silverlight實現地圖測距功能API地圖
- ArcGIS API for Silverlight 呼叫GP服務載入等值線圖層API
- ArcGIS API for Silverlight地圖載入眾多點時,使用Clusterer解決重疊問題API地圖
- ArcGIS API for Silverlight 點選地圖彈出自定義窗體API地圖
- ArcGIS API for Silverlight開發入門準備API
- ArcGIS API for Silverlight 中根據座標點在地圖上打標記API地圖
- ArcGIS API for Silverlight 地圖中解決點眾多的簇解決方法API地圖
- ArcGIS API for Silverlight 滑鼠移入移出地圖要素彈出視窗(優化處理)API地圖優化
- vue地圖視覺化 ArcGIS篇(3)Vue地圖視覺化
- ArcGIS API for Silverlight 地圖元素點閃爍,線流動顯示的處理方式API地圖
- ArcGIS API for Silverlight 點選地圖上的要素,彈出視窗(使用Telerik RadWindow)API地圖
- 基於ArcGIS API for Javascript的地圖編輯工具APIJavaScript地圖
- ArcGIS API for Silverlight 學習筆記API筆記
- ArcGIS API for Silverlight 實現修改地圖上的工程點位置API地圖
- ArcGIS API for Silverlight之ElementLayer使用注意點API
- ArcGIS API for Silverlight之配準JPG圖片地圖文字傾斜解決方案API地圖
- ArcGIS API for Silverlight 繪製降雨路徑動畫API動畫
- ArcGIS API for Silverlight程式碼中使用Template模板API
- 建立第一個ArcGIS API for Silverlight應用API
- ArcGIS載入高德、OSM和谷歌等地圖谷歌地圖
- ArcGIS API for Silverlight 動態圖層(ArcGISDynamicMapServiceLayer)的顯示與隱藏API
- ArcGIS API for Silverlight 查詢點閃爍顯示API
- ArcGIS API for Silverlight動態標繪的實現API
- ArcGIS API for Silverlight 當DataGrid選中項時,地圖聚焦彈出視窗,並可以播放音訊檔案API地圖音訊
- SuperMap iClient for Silverlight 載入天地圖client地圖
- ArcGIS API for Silverlight 呼叫GP服務繪製等值面API
- ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用APISymbol
- ArcGIS API for Silverlight開發中常用問題彙總API
- ArcGIS API for Silverlight 滑鼠移動顯示地理座標API
- 【Google官方教程】第一課:高效地載入大Bitmap(點陣圖)Go
- ArcGIS API for JavaScript根據兩個點座標在地圖上畫線APIJavaScript地圖
- 百度地圖API入門——(5)百度地圖API的簡介地圖API