同時支援google地圖和衛星圖

來源:互聯網
上載者:User

網上很多擷取google衛星圖的url地址都已經過時,在這裡為各位使用arcgis api 的朋友們提供一個可用的url。綜合,以前分享的“自己寫圖層載入google線上地圖”。所以把兩種常用的道路地圖與衛星圖集合在一起,供大家學習交流。

   public class GoogleTileMap : TiledMapServiceLayer
    {
        private const string TilePathBase = @"http://mt{0}.google.com/vt/lyrs={1}&z={2}&x={3}&y={4}";
        private int server_rr = 0;
        private const string charStreet = "m";
        private const string charSatellite = "s";
        private bool _IsTileDownloadStarted;
        private GoogleMapModes _MapMode;

        //預設是街道地圖
        public GoogleTileMap()
        {
            MapMode = GoogleMapModes.Street;
        }

        public GoogleTileMap(GoogleMapModes mode)
        {
            MapMode = mode;
        }

        public GoogleMapModes MapMode
        {
            get { return _MapMode; }
            set
            {
                if (_IsTileDownloadStarted)
                {
                    throw new InvalidOperationException();
                }
                _MapMode = value;
            }
        }

        public override string GetTileUrl(int level, int row, int col)
        {
            _IsTileDownloadStarted = true;
            server_rr = (server_rr + 1) % 4;
            string url = string.Empty;
            switch (MapMode)
            {
                case GoogleMapModes.Street:
                    url = string.Format(TilePathBase, server_rr, charStreet, level, col, row);
                    break;
                case GoogleMapModes.Satellite:
                    url = string.Format(TilePathBase, server_rr, charSatellite, level, col, row);
                    break;
                default:
                    break;
            }
           
            return url;
        }

        public override void Initialize()
        {
            double resolution = 156543.033928;
            this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787);//(-180,-85.0511287798066,180, 85.0511287798066)
            {
                SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102113);
            };
            this.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102113);
            this.TileInfo = new TileInfo()
            {
                Height = 256,
                Width = 256,
                Origin = new ESRI.ArcGIS.Client.Geometry.MapPoint(-20037508.342787,20037508.342787)
                {
                    SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102113)
                },
                Lods = new Lod[20]
            };
            for (int i = 0; i < TileInfo.Lods.Length; i++)
            {
                TileInfo.Lods[i] = new Lod() { Resolution = resolution };
                resolution /= 2;
            }
            base.Initialize();
        }

    }

 

使用就很簡單:

 <mapsvc:GoogleTileMap ID="MyLayer" MapMode="Street"  ></mapsvc:GoogleTileMap>

源碼可以在這下載:http://download.csdn.net/detail/leesmn/4381592

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.