ArcGIS for Silverlight API google地圖操作

1.地圖圖層
  <esri:Map x:Name="mymap"  WrapAround="True" SnapToLevels="True" Extent="13026373.9205,4389217.2155,13039428.4582,4395595.7317" >
            <esri:Map.Layers >
                <GoogDitu:GoogleTopographicLayer >
                </GoogDitu:GoogleTopographicLayer>
                <esri:GraphicsLayer ID="MyGraphicsLayer"/>
            </esri:Map.Layers>
        </esri:Map>
   Extent表示地圖的範圍大小,數值是墨卡託數

2.google服務圖層
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;
 
 public class GoogleTopographicLayer: TiledMapServiceLayer 
    { 
        private const double cornerCoordinate = 20037508.3427892;
        private string _baseURL = "m@161000000";
 
        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://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);
           //以上顯示的Google地圖類型,有三種,根據需要,可以修改變量_baseURL的初始值即可。
        } 

    }

3.地圖的放大縮小
 mymap.Zoom(1.5)其中數值大於1是放大
 mymap.Zoom(0.5)數值小於1是縮小

3.地圖的中心點改變
mymap.PanTo()這個方法裏放的是墨卡託經緯度

4.改變地圖點的圖標
 Symbol = new PictureMarkerSymbol() { Source = new BitmapImage(new Uri("../Images/pr.png", UriKind.Relative)), Width = 20, Height = 17 }

5.給地圖添加圖標
  GraphicsLayer graphicsLayer = mymap.Layers["MyGraphicsLayer"] as GraphicsLayer;
  MyGraphic graphic = new MyGraphic()
                        {
                            Geometry = mercator.FromGeographic(new MapPoint(Convert.ToDouble(item.Longitude), Convert.ToDouble(item.Latitude))),
                            Symbol = new PictureMarkerSymbol() { Source = new BitmapImage(new Uri("../Images/pr.png", UriKind.Relative)), Width = 20, Height = 17 },
                                                };
  graphicsLayer.Graphics.Add(graphic);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章