2012-07-23 4 views
0

나는 사용자에게 wp7 앱의 빙지도에서 여러 개의 압핀을보고 싶습니다. maplayer를 사용하여 압핀 클러스터를 만들었지 만 cs 파일 자체에서 해당 압핀에 이미지를 동적으로 추가 할 수 없었습니다. 그건 그렇고, xaml에서 압정 컨트롤을 사용하지 않았습니다. 루프를 반복하는 동안 압핀 개체를 추가하는 것뿐입니다. 나는 또한 이미지 소스를 제공하기 위해 이미지 브러시 속성을 사용하여 시도동적으로 고정 핀에 이미지를 제공하는 방법 #

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 쪽에서 압핀에 datatemplate을 변경/추가하지 않고이 작업이 필요합니다.

답변

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); 

     } 
    } 
} 
관련 문제