views:

741

answers:

1

I'm trying to use the microsoft_maps_mapcontrol. I see how one could create a pushpin and the lat long location... but i can't figure out how to instead use an image in place of that pushpin. doesn't look like pushpin will allow using a different image. So, that being the case how do you create an image and then wire it to the proper spot. Once wired can will i be able to use an event for when that image is clicked on.

thanks shannon


added 3/2/2010

I've looked at the example given at http://www.microsoft.com/maps/isdk/silverlightbeta/#MapControlInteractiveSdk.Tutorials.UIElements.Media.TutorialPositionPointMedia

and i must not be converting something correctly to vb.

Here is there code

 Image image = new Image();
  image.Source = new BitmapImage(new Uri(ImageUriValue.Text, UriKind.RelativeOrAbsolute));
        double opacity;
        if (double.TryParse(OpacityText.Text, out opacity))
        {
            image.Opacity = opacity;
        }
        image.ImageFailed += MediaFailed;

  Point point = GetPoint();
  Canvas.SetLeft(image, point.X);
  Canvas.SetTop(image, point.Y);
  myCanvas.Children.Add(image);

  element = image;

and what i converted it to

        Dim image As New Image()
    image.Source = New BitmapImage(New Uri("\Images\1.png", UriKind.RelativeOrAbsolute))

    Canvas.SetLeft(image, 100)
    Canvas.SetTop(image, 100)
    myCanvas.Children.Add(image)

    element = image

Hopefully that helps in spotting what i'm not doing correctly. thanks shannon

+1  A: 

Hey Shannon,

Here's a code snippet that should show you how to add an image.

public void addImageToMap()
{
    MapLayer imageLayer = new MapLayer();

    Image image = new Image();
    //Define the URI location of the image
    image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("myimage.png", UriKind.Relative));
    //Define the image display properties
    image.Opacity = 0.8;
    image.Stretch = System.Windows.Media.Stretch.None;
    //The map location to place the image at
    Location location = new Location() { Latitude = -45, Longitude = 122 };
    //Center the image around the location specified
    PositionOrigin position = PositionOrigin.Center;

    //Add the image to the defined map layer
    imageLayer.AddChild(image, location, position);
    //Add the image layer to the map
    TestMap.Children.Add(imageLayer);
}

http://msdn.microsoft.com/en-us/library/ee681895.aspx

Joe McBride
thanks.. of done my best to convert it to vb.. was wondering.. do i have my path correct... for the image.. it is in an Image folder off the root. image.Source = New BitmapImage(New Uri("C:\Dev\Sandbox\silverlight\Map\BingMaps\BingMaps\Images\1.png", UriKind.Relative))nothing is displaing when i run it.. so i'm wondering if my path is incorrect
jvcoach23
Yes that path would be incorrect. The path needs to be relative to the Silverlight XAP. For instance if your XAP is in the ClientBin folder of your website, move your images folder to the ClientBin folder. Then your URI would be Uri("/Images/1.png", UriKind.Relative). Note that you need to use the web slash syntax "/" instead of the desktop slash syntax "\".
Joe McBride