wpf GMap
安装nuget
【GMap.NET.Core】、【GMap.NET.WinPresentation】
AMapProviderBase
public abstract class AMapProviderBase : GMapProvider
{
public AMapProviderBase()
{
MaxZoom = null;
RefererUrl = "http://www.amap.com/";
//Copyright = string.Format("©{0} 高德 Corporation, ©{0} NAVTEQ, ©{0} Image courtesy of NASA", DateTime.Today.Year);
}
public override PureProjection Projection
{
get { return MercatorProjection.Instance; }
}
GMapProvider[] overlays;
public override GMapProvider[] Overlays
{
get
{
if (overlays == null)
{
overlays = new GMapProvider[] { this };
}
return overlays;
}
}
}
public class AMapProvider : AMapProviderBase
{
public static readonly AMapProvider Instance;
readonly Guid id = new Guid("EF3DD303-3F74-4938-BF40-232D0595EE88");
public override Guid Id
{
get { return id; }
}
readonly string name = "AMap";
public override string Name
{
get
{
return name;
}
}
static AMapProvider()
{
Instance = new AMapProvider();
}
public override PureImage GetTileImage(GPoint pos, int zoom)
{
try
{
string url = MakeTileImageUrl(pos, zoom, LanguageStr);
return GetTileImageUsingHttp(url);
}
catch (Exception ex)
{
return null;
}
}
string MakeTileImageUrl(GPoint pos, int zoom, string language)
{
var num = (pos.X + pos.Y) % 4 + 1;
//string url = string.Format(UrlFormat, num, pos.X, pos.Y, zoom);
string url = string.Format(UrlFormat, pos.X, pos.Y, zoom);
return url;
}
//static readonly string UrlFormat = "http://webrd04.is.autonavi.com/appmaptile?x={0}&y={1}&z={2}&lang=zh_cn&size=1&scale=1&style=7";
static readonly string UrlFormat = "http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={0}&y={1}&z={2}";
}
界面上添加控件
<usercontrol:MapControl
x:Name="mapControl"
Panel.ZIndex="100"
MaxZoom="24"
MinZoom="1"
Zoom="13" />
在界面的Loaded中添加
mapControl.CacheLocation = Environment.CurrentDirectory + "\\GMapCache\\"; //缓存位置
//mapControl.MapProvider = GMapProviders.GoogleChinaMap; // 这里需要填写地图提供商,官方默认包含Google地图
//mapControl.MapProvider = GaoDeimgProvider.Instance; // 这里需要填写地图提供商,官方默认包含Google地图
mapControl.MapProvider = AMapProvider.Instance; // 这里需要填写地图提供商,官方默认包含Google地图
mapControl.MinZoom = 2; //最小缩放
mapControl.MaxZoom = 17; //最大缩放
mapControl.Zoom = 5; //当前缩放
mapControl.ShowCenter = true; //不显示中心十字点
mapControl.DragButton = MouseButton.Left; //左键拖拽地图
mapControl.Position = new PointLatLng(32.064, 118.704); //地图中心位置:珠 海
留待后查,同时方便他人
联系我:renhanlinbsl@163.com
联系我:renhanlinbsl@163.com