2012-07-23 44 views
0

我有一個場景,我希望用戶在wp7應用程序中查看Bing地圖中的多個圖釘。我使用maplayer來製作圖釘集羣,但我無法在cs文件本身中動態地將圖像添加到該圖釘。順便說一下,我沒有使用xaml中的圖釘控件。我只是在循環播放時將圖釘對象添加到maplayer。如何在c中動態顯示圖像圖像#

這裏是我的代碼:

maplayer layer = new maplayer(); 

watcher.start(); 

for (int i = 0; i < lst.count; i++) 

      {     
        Pushpin mypin = new Pushpin(); 
        watcher.Position.Location.Latitude = Convert.ToDouble(lst[i].Latitude); 
        watcher.Position.Location.Longitude=Convert.ToDouble(lst[i].Longitude); 

       } 


       GeoCoordinate geo = new GeoCoordinate(watcher.Position.Location.Latitude, watcher.Position.Location.Longitude); 
       mypin.Location = geo; 

       mypin.Background = new SolidColorBrush(Colors.Gray); 
       mypin.Foreground = new SolidColorBrush(Colors.White); 
       mypin.Content = "My location"; 
       layer.AddChild(mypin, mypin.Location); 
      } 
      map1.SetView(watcher.Position.Location, Status == true ? 5.0 : 3.0); 
      map1.Children.Add(layer); 


watcher.stop(); 

我也使用圖像畫筆屬性來提供圖像源試圖圖釘但圖釘本身變爲不可見。

這樣的:

ImageBrush ib = new ImageBrush(); 

ib.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"Images/push.png", UriKind.Relative)); 

mypin.Background = ib; 

請幫我在這。我需要在不更改/添加數據模板的情況下完成xaml側的圖釘。

回答

1

此問題在MSDN中的Working With Pushpins的頁面中進行了介紹。以下是給出的示例,其中圖像直接添加到地圖上的圖層:

namespace WindowsPhoneApplication1 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     MapLayer imageLayer; 


     public MainPage() 
     { 
      InitializeComponent(); 

      //Create a layer to contain the pushpin images. 
      imageLayer = new MapLayer(); 
      map1.Children.Add(imageLayer); 
     } 


     private GeoCoordinate mapCenter; 

     private void button1_Click(object sender, RoutedEventArgs e) 
     { 

      // Retrieve the center of the current map view. 
      mapCenter = map1.Center; 

      // Define the image to use as the pushpin icon. 
      Image pinImage = new Image(); 

      //Define the URI location of the image. 
      pinImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("bluepushpin.png", UriKind.Relative)); 

      //Define the image display properties. 
      pinImage.Opacity = 0.8; 
      pinImage.Stretch = System.Windows.Media.Stretch.None; 

      // Put the image at the center of the view. 
      PositionOrigin position = PositionOrigin.Center; 
      imageLayer.AddChild(pinImage, mapCenter, position); 

     } 
    } 
}