如何使用Image作为Map PushPin

时间:2013-12-25 01:57:18

标签: c# xaml windows-phone-7 windows-phone-8

我正在尝试使用自定义图像作为WP8地图控件上的地图图钉。我没有得到任何调试错误,但我在地图上看不到任何东西。我不确定错误是什么,或者我是否正确这样做。

XAML

<Controls:Map x:Name="Map"
                      Pitch="55"
                      ZoomLevel="13"
                      LandmarksEnabled="True"
                      PedestrianFeaturesEnabled="True">

        </Controls:Map>

XAML.CS

private void InitializePushPin()
    {
        // Create a small circle to mark the current location.
        //myCircle = new Ellipse();
        //myCircle.Fill = new SolidColorBrush(Colors.Green);
        //myCircle.Height = 20;
        //myCircle.Width = 20;
        //myCircle.Opacity = 50;
        myImage = new BitmapImage(new Uri("/Assets/Tiles/Launch/map.location.png", UriKind.RelativeOrAbsolute));

        // Create a MapOverlay to contain the circle.
        myLocationOverlay = new MapOverlay();
        //myLocationOverlay.Content = myCircle;
        myLocationOverlay.Content = myImage;
        myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);


        // Create a MapLayer to contain the MapOverlay.
        myLocationLayer = new MapLayer();
        myLocationLayer.Add(myLocationOverlay);

        // Add the MapLayer to the Map.
        this.Map.Layers.Add(myLocationLayer);
    }

正如您所看到的,原始实现是一个圆圈,它正常工作。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

尝试使用Image控件作为MapOverlay的内容,而不是BitmapImage。图像控件用于显示图像,将其用作内容并将Source属性设置为BitmapImage。

// Create a small circle to mark the current location.
myImage = new BitmapImage(new Uri("/Assets/Tiles/Launch/map.location.png", UriKind.RelativeOrAbsolute));
var image = new Image();
image.Width = 20;
image.Height = 20;
image.Opacity = 50;
image.Source = myImage;

// Create a MapOverlay to contain the circle.
myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = image;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);