[翻译]
Andrea_86著 a little Virtual Earth Control
[简介]
本文的目的是想在Windows Form中加载 虚拟地球的 地图。因为,你可以轻易地在HTML页面上加载这些地图,所以我会使用WebBrowser 控件。不过另一个问题也随之而来,如何捕获到HTML页面的事件?
[背景]
如果你将这些地图使用在 商业用途上,请阅读微软许可( ¥¥¥)
在保存和拷贝图片时,我使用了SharpDevelop 上的一个类(Juergen Thomas, Berlin (Germany) - http://www.codeproject.com/csharp/FormPrintPackage.asp)
[代码使用]
控件的使用是非常简单的。
创建一个新的WinForm项目,包含Dll组件。
调用下面的方法,插入控件:
Code:
vEarthControl1.ShowInitialMap();
下面两个方法初始化地图:
Code:
//
To Show the initial map
public void ShowInitialMap()
public void ShowInitialMap()
//
and to close the map
public void unInit()
public void unInit()
这个方法用于改变地图类型,显示或隐藏操作界面,以及改变风格:
Code:
public
enum
DashboardStyleEnum {
Small,
Normal,
Tiny
}
public void DashBoardShow()
public void DashBoardHide()
public void DashBoardSet(DashboardStyleEnum dStyle)
public enum MapStyleEnum {
Road ,
Aerial ,
Hybrid ,
BirdsEye
}
public void SetMapStyle(MapStyleEnum mStyle)
Small,
Normal,
Tiny
}
public void DashBoardShow()
public void DashBoardHide()
public void DashBoardSet(DashboardStyleEnum dStyle)
public enum MapStyleEnum {
Road ,
Aerial ,
Hybrid ,
BirdsEye
}
public void SetMapStyle(MapStyleEnum mStyle)
调整比例尺,缩放地图:
Code:
public
void
GoToCoordinates(
double
Latit,
double
Longit)
public void SetZoomLevel(Int16 zLevel)
public void ZoomOut()
public void ZoomIn()
public void ZoomWorld()
public void ZoomBest()
public void SetZoomLevel(Int16 zLevel)
public void ZoomOut()
public void ZoomIn()
public void ZoomWorld()
public void ZoomBest()
在地图上添加移去pushpin(可能是标签的意思:)
Code:
public
void
AddPushpin(Int32 IDPush, Double lat, Double lon, String Descrizione)
public void AddPushpin(Int32 IDPush, Double lat, Double lon, String Descrizione, String iconAddress)
public void RemovePushpin(Int32 IDPush)
public void RemoveAllPushpins()
public void AddPushpin(Int32 IDPush, Double lat, Double lon, String Descrizione, String iconAddress)
public void RemovePushpin(Int32 IDPush)
public void RemoveAllPushpins()
保存地图,并打印
Code:
public
Bitmap GetMapImage()
public Boolean SaveMapAsBitmap(String FileName)
public Boolean SaveMapAsBitmap()
public void PrintMapDefaultSettings()
public void PrintMapPreview()
public void PrintOptions()
public Boolean SaveMapAsBitmap(String FileName)
public Boolean SaveMapAsBitmap()
public void PrintMapDefaultSettings()
public void PrintMapPreview()
public void PrintOptions()
下面是些 高级函数,如果你不知道怎么给它传递参数的话,不要随便使用!!
Code:
public
void
ExecuteCommandOnMap(String commandText)
public void ExecuteCommandOnMap(String commandText, String commandParameters)
public void ExecuteCommand(String commandText)
public void ExecuteCommand(String commandText, String commandParameters)
public void ExecuteCommandOnMap(String commandText, String commandParameters)
public void ExecuteCommand(String commandText)
public void ExecuteCommand(String commandText, String commandParameters)
两个事件,避免当鼠标在地图上时,发出声音:
public
class
OnMoveOnMapEventArgs : EventArgs
{
public Double Lat;
public Double Lon;
public DateTime ora;
}
private void OnClickOnMap( object sender, VEarth.OnClickOnMapEventArgs e)
private void OnMoveOnMap( object sender, VEarth.OnMoveOnMapEventArgs e)
{
public Double Lat;
public Double Lon;
public DateTime ora;
}
private void OnClickOnMap( object sender, VEarth.OnClickOnMapEventArgs e)
private void OnMoveOnMap( object sender, VEarth.OnMoveOnMapEventArgs e)
[关注]
Virtual Earth SDK: http://msdn2.microsoft.com/en-us/library/bb429619.aspx