Development and application of "Silverlight" Bing Maps: Map Management and coordinate control (Coordcontrol)
Using the Bing Maps Silverlight control Development, there are many times when you need a real-world mapping feature, which is to add a callout (such as a Pushpin) to the click Point on the current map via a mouse click event, mainly using The Viewportpointtolocation method coordinates the transformation and transforms the physical coordinates of the clicked point of the mouse into geographical coordinates (longitude, latitude), which is defined as follows:
[ScriptableMemberAttribute]
public override Location ViewportPointToLocation (Point viewportPoint)
{}
Clicking on the map will trigger a series of Map mouse events (Mapmouseeventargs), through which event arguments can be directly or get to the physical coordinates of the mouse's current click Point, which is defined as follows:
namespace Microsoft.Maps.MapControl
{
public class MapMouseEventArgs : MapEventArgs
{
public MapMouseEventArgs(Point viewportPoint);
[ScriptableMember]
public Point ViewportPoint { get; }
}
}
Understand the above two key points can be achieved on the map to manage functions, such as we through the mouse click event to handle, when the mouse clicked on the map to achieve the dot, the code is as follows:
protected void map_MouseClick(object sender, MapMouseEventArgs e)
{
//初始化一个图标
Pushpin pushpin = new Pushpin();
//设置图钉对象的定位坐标
pushpin.Location = map.ViewportPointToLocation(e.ViewportPoint);
//添加图钉到地图上
map.Children.Add(pushpin);
}