ArcGIS API for Silverlight中加载Google地形图(瓦片图)
原文:ArcGIS API for Silverlight中加载Google地形图(瓦片图)
在做水利、气象、土地等行业中,若能使用到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 System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry; namespace GoogleMap.CommonClass
{
public class GoogleTopographicLayer: TiledMapServiceLayer
{
private const double cornerCoordinate = 20037508.3427892;
private string _baseURL = "t@128"; //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[16]
};
//为每级建立方案,每一级是前一级别的一半.
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的初始值即可。
<UserControl x:Class="GoogleMap.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:layer="clr-namespace:GoogleMap.CommonClass"
d:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded"> <Grid x:Name="LayoutRoot" Background="White">
<esri:Map x:Name="myMap" IsLogoVisible="False" ZoomDuration="0:00:02" PanDuration="0:00:02">
</esri:Map>
</Grid>
</UserControl>
3、Silverlight项目中的MainPage.xaml.cs文件内容如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TestDZX.CommonClass;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client; namespace GoogleMap
{
public partial class MainPage: UserControl
{
ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); public MainPage()
{
InitializeComponent();
} private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
GoogleTopographicLayerlayer = new GoogleTopographicLayer();
myMap.Layers.Add(layer);
}
}
}
4、完成以上步骤后,运行,可以看见Google地形图了,just try it,have fun!

5、补充:这里使用的是墨卡托坐标,而我们经常使用的是经纬度坐标,这就需要做转换,下面提供一个类,WKIDConvert.cs,内容
如下:
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.Geometry; namespace GoogleMap.CommonClass
{
public static class WKIDConvert
{
//经纬度转墨卡托
public static MapPoint lonlat2mercator(MapPoint lonlat)
{
MapPoint mercator = new MapPoint();
double X = lonlat.X * 20037508.34 / 180;
double Y = Math.Log(Math.Tan((90 + lonlat.Y) * Math.PI / 360)) / (Math.PI / 180);
Y = Y * 20037508.34 / 180;
mercator.X = X;
mercator.Y = Y;
return mercator;
} //墨卡托转经纬度
public static MapPoint mercator2lonlat(MapPoint mercator)
{
MapPoint lonlat = new MapPoint();
double X = mercator.X / 20037508.34 * 180;
double Y = mercator.Y / 20037508.34 * 180;
Y = 180 / Math.PI * (2 * Math.Atan(Math.Exp(Y * Math.PI / 180)) - Math.PI / 2);
lonlat.X = X;
lonlat.Y = Y;
return lonlat;
}
}
}
然后我们如果要定位到某个城市的话,比如黄山市,其Extent为:117.647738815324,29.4704217183843,118.446182957997,30.4124245048916
我们这里为MainPage.xaml.cs中添加一行代码即可定位到黄山市范围
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
GoogleTopographicLayer layer = new GoogleTopographicLayer();
myMap.Layers.Add(layer);
myMap.Extent = new Envelope(WKIDConvert.lonlat2mercator(new MapPoint(117.647738815324, 29.4704217183843)), WKIDConvert.lonlat2mercator(new MapPoint(118.446182957997, 30.4124245048916)));
}
6、再次补充:在之前的Google地形图上叠加自定义ArcMap地图,可以是动态图也可以是静态图,只要加上发布的地图,即可显示,在MainPage.xaml.cs中添加如下几行代码即可。
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
//叠加Google地形图瓦片
GoogleTopographicLayer layer = new GoogleTopographicLayer();
myMap.Layers.Add(layer);
layer.Opacity = 1;
//加载动态图
ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dLayer = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer();
myMap.Layers.LayersInitialized += (evtsender, args) =>
{
myMap.ZoomTo(dLayer.InitialExtent);
};
dLayer.Url = "http://localhost/arcgis/rest/services/HS/MapServer/";
myMap.Layers.Add(dLayer);
dLayer.Opacity = 1;
myMap.Extent = new Envelope(WKIDConvert.lonlat2mercator(new MapPoint(117.647738815324, 29.4704217183843)), WKIDConvert.lonlat2mercator(new MapPoint(118.446182957997, 30.4124245048916)));
}
效果图如下,这里只是做了黄山市的市界边线,主要作用就是在Google地形图上明显看出黄山市的范围:

===========================================================================
如果觉得对您有帮助,微信扫一扫支持一下:
ArcGIS API for Silverlight中加载Google地形图(瓦片图)的更多相关文章
- ArcGIS API for Silverlight地图加载众多点时,使用Clusterer解决重叠问题
原文:ArcGIS API for Silverlight地图加载众多点时,使用Clusterer解决重叠问题 问题:如果在地图上加载成百上千工程点时,会密密麻麻,外观不是很好看,怎么破? 解决方法: ...
- arcgis api for JavaScript _加载三维图层(scene layer)
arcgis api for JavaScript _加载三维图层(scene layer) arcgis api for JavaScript 4.x 版本增加对三维的支持. 关于三维图层(sce ...
- ArcGis API for JavaScript学习——加载地图
ArcGis API for JavaScript开发笔记——加载地图 在这个例子中使用的离线部署的API(请参见 http://note.youdao.com/noteshare?id=f42865 ...
- ArcGIS API for Silverlight中专题地图的实现浅析
原文http://www.gisall.com/html/32/7232-2418.html 专题地图是突出表现特定主题或者属性的地图.常见专题地图类型有唯一值渲染,分类渲染,柱状图,饼状图,点密度图 ...
- ArcGIS API for JS4.7加载FeatureLayer,点击弹出信息并高亮显示
我加载的是ArcGIS Server本地发布的FeatureService,ArcGIS API for JS4.7记载FeatureLayer时,在二维需要通过代码启用WebGL渲染,在三维模式下, ...
- arcgis中加载google在线地图
打开arcmap——文件——arcgis online ——搜索china maps 选择china
- ArcGIS API For Silverlight使用在线地图的多种方法总结
引自:http://www.cnblogs.com/meimao5211/p/3283969.html ArcGIS API For Silverlight使用在线地图的多种方法总结 本人也正在学习A ...
- ArcGIS API for Silverlight学习笔记
ArcGIS API for Silverlight学习笔记(一):为什么要用Silverlight API(转) 你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我都 ...
- Silverlight客户端加载DWG图纸方案
前段时间一直再研究怎么才能在Silverlight客户端加载 DWG图纸,ArcGIS API For Silverlight中可以加载Shp文件,但是不能加载DWG,最后想出了一个方法步骤如下: 1 ...
随机推荐
- POJ1511 Invitation Cards(多源单汇最短路)
边取反,从汇点跑单源最短路即可. #include<cstdio> #include<cstring> #include<queue> #include<al ...
- 小明A+B[HDU2096]
小明A+B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4856 (状态压缩DP+TSP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4856 题目大意:有一个迷宫.迷宫里有些隧道,每个隧道有起点和终点,在隧道里不耗时.出隧道就耗时,你的 ...
- phonegap+html5开发app的一些总结
1.Css3圆角白边:使用css3圆角效果时,在android某些机器上会产生白边,所以应该在圆角的div外套一个div(背景色和外部相同),然后有圆角效果的div 内部使用自己的背景色 border ...
- python 获取类的属性
如果不清楚一个对象是否拥有某个属性,可以使用内置函数hasattr 访问一个对象的属性的方法是通过特别属性__dict__,它是一个映射,将属性名称映射到属性值 为了调试方便,可以添加下面这个函数 d ...
- oracle系列--第一篇 数据库基础
第一章 数据库基础 1.1 数据管理概述 1.1.1 什么是数据管理 与我们人类相比,计算机的最大优势就是能够高速.精准地运行,其运行的过程就是执行程序代码和操作指令.处理数据的过程.可以说,数据处理 ...
- SSH框架优缺点
SSH框架优缺点 开源是3个框架共有的优点 Struts2框架(MVC框架)的优点如下: 1) 实现了MVC模式,层次结构清晰,使程序员只需关注业务逻辑的实现: 2) 丰富的标签库,大大提高了开发 ...
- C#并行库(TaskParallelLibrary)用法小结
今天有空,总结一下.NET 4.5并行库(TaskParallelLibrary)用法. 也许C和C++的程序员刚刚开始写C#还习惯于new Thread来新建一个线程,但新建线程需要内存和CPU上下 ...
- String数组转List,List转String数组
引入自: http://blog.csdn.net/aaronuu/article/details/7055650 List 转换为 String数组 List<String> list ...
- Javascript 笔记与总结(2-14)事件
常用事件: ● onclick 元素点击时 ● onfocus 元素获得焦点时 ● onblur 元素失去焦点时 ● onmouseover 鼠标经过时 ● onsubmit 表单提交时(<fo ...