WPF地图应用开发-----BingMap系列2

此文介绍 图钉的使用

在开发应用中 ,经常会使用图钉(在地图没坐标上标记一下),如图:

应用1

需求 在地图上 标记 一些 点。显示一些信息。(我的做法 通过 xml 记录 这些 坐标经纬度。。)

如图:

1 <?xml version="1.0" encoding="utf-8"?>
2 <Data>
3   <Point Guid="CE928B26-AA2B-4DCC-96E8-D650186FBAAA" 
4          ID="001" lat="36.7199961312977" lng="119.100299383698">
5     <Name>公司</Name>
6     <Description>不能有吃的广告</Description>
7     <Adress>北宫街路南</Adress>
8   </Point>
。。。。。。很多这种 元素 9 </Data>

再次 吐槽下: 有linq to xml 操纵 xml 方便好多。。。感觉 比Linq to Entity 好用多了

ok。下面介绍 一下 图钉的用法:

通过 给地图添加 图层。。。在图层上 设置 图钉的方式 :

代码:

 1       ///通过 鼠标点击事件,获取鼠标点击位置然后转化为地图经纬度  注:此事件请自己在xaml 中订阅
 2        private void map_MouseDown(object sender, MouseButtonEventArgs e)
 3         {           
 4             mousedownpoint = map.ViewportPointToLocation(e.GetPosition(sender as IInputElement));
 5         }
 6 
 7         MapLayer maplayer = new MapLayer();
 8         private void AddP()
 9         {            
10             Pushpin p = new Pushpin();
11             maplayer.AddChild(p, mousedownpoint);
12         }

在构造 函数中给地图添加这个“图钉层”

public MainWindow()
{
  InitializeComponent();
  AddTileOverlay(); //这是处理 中文地图方法  详情见 第一篇文章
  map.map.Children.Add(maplayer); //添加 图钉层 

}

 

posted @ 2013-04-18 09:15  沐松  阅读(667)  评论(0编辑  收藏  举报