Silverlight - Adding Text to Pushpin in Bing Maps via C#
Posted
by Morano88
on Stack Overflow
See other posts from Stack Overflow
or by Morano88
Published on 2010-05-10T18:29:44Z
Indexed on
2010/05/10
18:34 UTC
Read the original article
Hit count: 2132
I was able to make my silverlight Bing map accepts Mousclicks and converts them to Pushpins in C#. Now I want to show a text next to the PushPin as a description that appears when the mouse goes over the pin , I have no clue how to do that. What are the methods that enable me to do this thing?
This is the C# code :
public partial class MainPage : UserControl
{ private MapLayer m_PushpinLayer;
public MainPage()
{
InitializeComponent();
base.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
base.Loaded -= OnLoaded;
m_PushpinLayer = new MapLayer();
x_Map.Children.Add(m_PushpinLayer);
x_Map.MouseClick += OnMouseClick;
}
private void AddPushpin(double latitude, double longitude)
{
Pushpin pushpin = new Pushpin();
pushpin.MouseEnter += OnMouseEnter;
pushpin.MouseLeave += OnMouseLeave;
m_PushpinLayer.AddChild(pushpin, new Location(latitude, longitude), PositionOrigin.BottomCenter);
}
private void OnMouseClick(object sender, MapMouseEventArgs e)
{
Point clickLocation = e.ViewportPoint;
Location location = x_Map.ViewportPointToLocation(clickLocation);
AddPushpin(location.Latitude, location.Longitude);
}
private void OnMouseLeave(object sender, MouseEventArgs e)
{
Pushpin pushpin = sender as Pushpin;
// remove the pushpin transform when mouse leaves
pushpin.RenderTransform = null;
}
private void OnMouseEnter(object sender, MouseEventArgs e)
{
Pushpin pushpin = sender as Pushpin;
// scaling will shrink (less than 1) or enlarge (greater than 1) source element
ScaleTransform st = new ScaleTransform();
st.ScaleX = 1.4;
st.ScaleY = 1.4;
// set center of scaling to center of pushpin
st.CenterX = (pushpin as FrameworkElement).Height / 2;
st.CenterY = (pushpin as FrameworkElement).Height / 2;
pushpin.RenderTransform = st;
}
}
© Stack Overflow or respective owner