Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bing maps silverlight control pushpin scaling problems

Basically my problem is that i've adapted a piece of code found here

http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1

which does exactly what I want it to do, that is scale some pushpin images according to the map's zoom level. The only problem is that I've adapted this code to run with the bing maps silverlight control (not virtual earth like in the original example) and now the images scale correclty, but they are repositioned and only reach the desired position when my zoom level is maximum. Any idea why? Help will be greatly appreciated :)

Modified code below:

var layer = new MapLayer();
map.AddChild(layer);

//Sydney
layer.AddChild(new Pin
{
    ImageSource = new BitmapImage(new Uri("pin.png", UriKind.Relative)),
    MapInstance = map
}, new Location(-33.86643, 151.2062), PositionMethod.Center);

becomes something like

layer.AddChild(new Pin
{
    ImageSource = new BitmapImage(new Uri("pin.png", UriKind.Relative)),
    MapInstance = map
}, new Location(-33.92485, 18.43883), PositionOrigin.BottomCenter);

I am assuming it has something to do with a different way in which bing maps anchors its UIelements. Details on that are also very userful. Thank you!

like image 408
Rares Musina Avatar asked Dec 06 '25 04:12

Rares Musina


2 Answers

try adding your own fixed size bitmapimage to the map rather than using the pushpin class

like image 61
7 revs Avatar answered Dec 08 '25 18:12

7 revs


Thanks to earthware's response I managed to solve my problem. It is just a matter of adding the image direclty (no pushpin class involved), adding a fixed size to it and setting the CenterX and CenterY properties of the scaling accordingly. Code sample follows:

image.Source = new BitmapImage(new Uri("pin.png", UriKind.Relative));
image.Stretch = System.Windows.Media.Stretch.None;
image.Height = 152;
image.Width = 116;

layer.AddChild(image, new Location(-33.86643, 151.2062), PositionOrigin.BottomCenter);
image.RenderTransform = scaleTr;

scaleTr.CenterX = image.Width / 2; //image is alligned bottom center (see above)
scaleTr.CenterY = image.Height;
like image 28
Rares Musina Avatar answered Dec 08 '25 18:12

Rares Musina