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);
        }
    }
}
时间: 2024-12-09 19:50:29

ArcGIS API for Silverlight加载google地图(后续篇)的相关文章

ArcGIS API for Silverlight 加载google地图

原文:ArcGIS API for Silverlight 加载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 Syst

解决ArcGIS API for Silverlight 加载地图的内外网访问问题

原文:解决ArcGIS API for Silverlight 加载地图的内外网访问问题 先上一个类,如下: public class BaseClass { public static string getFullUri(string oldUriString) { string newUriString = oldUriString; //处理相对地址============================================================ if (newUri

中科燕园webgis外包 讲解2----使用geoserver+openLayers加载google地图

1. 准备工作 安装java环境即JDK 下载geoserver  官网:http://geoserver.org/display/GEOS/Welcome 我的描述使用的是geoserver1.7版本,2.0版本类似,只是1.7是中文的,2.0版本可以再使用过1.7版本后自己摸索,大同小异. 下载openLayers 官网:http://www.openlayers.org/ 配置好JAVA_HOME 下载地图(shp格式) 可到此网站:http://nfgis.nsdi.gov.cn/asp

arcgis api for javascipt 加载天地图、百度地图

写在前面的话: 1.百度地图是自己定义的坐标系统,wkid=102100.百度地图数据是加密的产物.下文将附上百度坐标与WGS84,谷歌等坐标系统转换方法(地理-地理),此方法并未亲测,据说准 2.百度地图可以直接加载经纬度坐标 3.百度地图如果加载的arcgis api中会出现坐标偏移,1.中已经解决了地理坐标转换,那么找到百度投影-地理坐标的转换方式,则arcgis就可以直接无偏加载了,网上很多方法,但是亲测不行. 4.天地图不是涉密数据,根据本文提供的类库,arcgis api for j

ArcGIS api for javascript——加载查询结果,悬停显示信息窗口

描述 本例在开始和地图交互前执行一个查询任务并加在查询结果.这允许用户鼠标悬停在任意郡县时立即见到InfoWindow.本例改变了信息窗口的默认行为,仅在鼠标单击时显示信息窗口. QueryTask构造函数接受被查询的图层,即ESRI sample server上ESRI_Census_USA服务的郡县图层(索引号是3). 注意这和地图使用的不是一个服务.地图使用来自ArcGIS Online的ESRI_StreetMap_World_2D服务. 通过这种方式能够使用在视觉上匹配的不同服务作为地

ArcGIS api for javascript——加载查询结果,单击显示信息窗口

描述 本例在开始和地图交互前执行一个查询并加载结果.这允许用户点击任意郡县立即看到一个InfoWindow. QueryTask构造函数接受被查询的图层,即ESRI sample server上ESRI_Census_USA服务的郡县图层(索引号是3). 注意这和地图使用的不是一个服务.地图使用来自ArcGIS Online的ESRI_StreetMap_World_2D服务. 通过这种方式能够使用在视觉上匹配的不同服务作为地图和查询任务的服务. 注意本例中,街道地图被显示在没有郡县可见的比例,

ArcGIS API for JavaScript 加载独立GeoWebCache发布的Wmts服务

其实ArcGIS API for JavaScript 也已经有两个例子了,不过就是在一些参数方面,没有解释清楚.Arcgis的例子是以Geoserver发布的服务作为举例的,而这里是用独立的GeoWebCache服务WMTS服务的,地址是http://localhost:8080/geowebcache/service/wmts,按照ArcGIS给出的例子调了两天也没调出来,例子如下(这已经是我改过的): <script> var map, wmtsLayer; require([ &quo

[转]worldwind在线加载google地图,或者基于墨卡托投影的切片地图

package gis1; import java.net.MalformedURLException; import java.net.URL; import gov.nasa.worldwind.avlist.AVKey; import gov.nasa.worldwind.avlist.AVList; import gov.nasa.worldwind.avlist.AVListImpl; import gov.nasa.worldwind.geom.Angle; import gov.n

Arcgis for js加载百度地图

概述: 在前面的文章里提到了Arcgis for js加载天地图,在本节,继续讲解如何在Arcgis for js中加载百度地图. 效果: 地图 影像-无标注 影像-有标注 实现: 第一,在此感谢http://www.cnblogs.com/chenyuming507950417/p/3343729.html这篇文章的主人,给了我很大的启发与帮助,因为一直在找相关的参数,都不对,只有这个参数是没有问题的. 第二,百度地图可调用的有地图切片,影像切片,以及道路等POI切片,我将之用TiledMap