locked
Bing maps silverlight control pushpin scaling problems. RRS feed

  • Question


  • 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:

     

    //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
    }, newLocation(-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!

    • Edited by Team Flux Tuesday, April 6, 2010 1:25 PM
    Tuesday, April 6, 2010 12:40 PM

Answers

  • Figured it out. It is just a matter of adding the image direclty, 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;

     

    Tuesday, April 6, 2010 2:18 PM

All replies