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);