views:

397

answers:

3

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!

A: 

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

Yep, worked, sorry for the previous post. It was just a matter of setting a FIXED size for the transformation and settinf the centerx and centery properties accordingly. Thanks earthware :)
Rares Musina
A: 

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;
Rares Musina
+1  A: 

Here's an example that shows how to Auto Scale Pushpins with the Map's ZoomLevel using the Pushpin object (instead of an Image object) and keeps them in the correct location. All with a little help from a custom IValueConverter, ScaleTransform and a little Data Binding.

http://pietschsoft.com/post/2010/06/04/Resizing-and-Auto-Scaling-Pushpin-in-Bing-Maps-Silverlight.aspx

Chris Pietschmann