ArcGIS API for Silverlight加载google地图(后续篇)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArcGIS API for Silverlight加载google地图(后续篇)相关的知识,希望对你有一定的参考价值。

原文: 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 = "[email protected]"; //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 + ",[email protected]&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga";
            if (_baseURL == "[email protected]")
            {
                //地形图
                url = "http://mt1.google.cn/vt/lyrs=" + _baseURL + ",[email protected]&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga";
            }
            if (_baseURL == "[email protected]")
            {
                //卫星图
                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 == "[email protected]")
            {
                //街道图
                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 = "[email protected]"; //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 + ",[email protected]&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga";
            if (_baseURL == "[email protected]")
            {
                //地形图
                url = "http://mt1.google.cn/vt/lyrs=" + _baseURL + ",[email protected]&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga";
            }
            if (_baseURL == "[email protected]")
            {
                //卫星图
                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 == "[email protected]")
            {
                //街道图
                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 = "[email protected]"; //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 + ",[email protected]&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga";
            if (_baseURL == "[email protected]")
            {
                //地形图
                url = "http://mt1.google.cn/vt/lyrs=" + _baseURL + ",[email protected]&&hl=zh-CN&gl=CN&src=app&" + "x=" + col + "&" + "y=" + row + "&" + "z=" + level + "&s=Ga";
            }
            if (_baseURL == "[email protected]")
            {
                //卫星图
                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 == "[email protected]")
            {
                //街道图
                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 Python 检索 ArcGIS 角色

arcgis api for javascript怎么加载天地图的影像图

arcgis api for javascript中怎么获取当前地图的大小

ArcGIS API For Android Errors汇总

arcgis api for javascript 4.10版本的本地部署

如何利用arcgis api for javascript在graphicslayer绘制点线面