首页 新闻 赞助 找找看

在winform里面开发地图,在地图上任意设置两个点,起点和终点,希望通过contextMenuStrip建个菜单,显示设为起点和终点,最后怎么实现选中起点或终点,分别写一个事件还是怎么样?请教

0
悬赏园豆:5 [已解决问题] 解决于 2013-11-05 12:37

在winform里面开发地图,在地图上任意设置两个点,起点和终点,希望通过contextMenuStrip建个菜单,显示设为起点和终点,最后怎么实现选中起点或终点,分别写一个事件还是怎么样?请教

Danny@yang的主页 Danny@yang | 初学一级 | 园豆:145
提问于:2013-10-31 12:48
< >
分享
最佳答案
0

这样,你先通过按钮来实现已知起点、途经点、终点,然后生成线路。
然后再考虑,如何通过鼠标事件来获取地理位置。

把整个过程拆分为两个步骤来做。

收获园豆:5
飞扬的尘埃 | 小虾三级 |园豆:1318 | 2013-10-31 18:03

当你触发鼠标事件后,地图上只存在一个默认点,起点和终点的位置也是根据它来设置,根据它设置的话,我的起点设置时会出现一下,当设置终点是它就会消失,很不爽。。。我给你看下代码这是根据默认点获取坐标

void MainMap_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = true;

if (currentMarker.IsVisible)
{
currentMarker.Position = MainMap.FromLocalToLatLng(e.X, e.Y);

var px = MainMap.MapProvider.Projection.FromLatLngToPixel(currentMarker.Position.Lat, currentMarker.Position.Lng, (int)MainMap.Zoom);
var tile = MainMap.MapProvider.Projection.FromPixelToTileXY(px);

Debug.WriteLine("MouseDown: geo: " + currentMarker.Position + " | px: " + px + " | tile: " + tile);
}
}
}这个是鼠标事件

int index = 0;
private void gMapControl2_MouseClick(object sender, MouseEventArgs e)
{

if (index == 0)
{
start = currentMarker.Position;
currentMarker = new GMarkerGoogle(start, GMarkerGoogleType.red);
currentMarker.IsHitTestVisible = true;
top.Markers.Add(currentMarker);
currentMarker.ToolTipMode = MarkerTooltipMode.Always;
currentMarker.ToolTipText = "起点";
index++;
return;
}
if (index == 1)
{
end = currentMarker.Position;
currentMarker = new GMarkerGoogle(end, GMarkerGoogleType.red);
currentMarker.IsHitTestVisible = true;
top.Markers.Add(currentMarker);
currentMarker.ToolTipMode = MarkerTooltipMode.Always;
currentMarker.ToolTipText = "终点";
index = 0;
}
}

Danny@yang | 园豆:145 (初学一级) | 2013-10-31 18:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册