2014-10-27 111 views
1

我正在構建一個windows phone 8.1應用程序,該應用程序讀取一個文件(其中包含GPS點,每個點包含例如緯度和經度字段)。對於每一個點我都有,所以它在地圖控件上顯示一個小圖釘圖標,基於它從上面的文件進行協調。有什麼方法可以在推針元素上實現點擊事件並將其用於例如顯示另一個窗口,用戶可以更改/顯示特定點/圖釘信息(經度或緯度)?這是我使用讀取地圖上我的文件,並顯示什麼,以及它工作得很好:地圖圖釘點擊事件

信息:notespublic ObservableCollection<Point> notes;

protected async override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     bool exist; // used to check if JSON file exists 

     // get current position and set the map to point at it 
     Geoposition position = await App.DataModel.GetCurrentPosition(); 

     await MyMap.TrySetViewAsync(position.Coordinate.Point, 16D); 

     mySlider.Value = MyMap.ZoomLevel; // set it to 16D from previous line 

     exist = await App.DataModel.FileExistsAsync(); 

     if (exist == true) 
     { 
      // read the file and load points into a list 
      await App.DataModel.ReadFile(); 

      // put points on the map - little map icon 
      foreach (var point in App.DataModel.notes) 
      { 

       MapIcon myMapIcon = new MapIcon(); 
       myMapIcon.Location = new Geopoint(new BasicGeoposition() 
       { 
        Latitude = point.Latitude, 
        Longitude = point.Longitude, 
       }); 
       myMapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0); 
       MyMap.MapElements.Add(myMapIcon); 
      } 
     } 
    } 

回答

3

不是因爲你已經實現了,沒有。如果您需要任何類型的最終用戶事件,則需要使用MyMap.Children.Add(myXamlControl)而不是使用MyMap.MapElements.Add(myMapIcon)將基於XAML的圖釘添加到地圖。 MapIcons被集成到地圖「圖像」中,而不是浮在頂部,並且不能對任何東西做出反應。

編輯:這是你如何設置一個XAML控制點和錨:

MyMap.SetLocation(myXamlControl, myPoint); 
MyMap.SetNormalizedAnchorPoint(myXamlControl, new Point(0.5, 0.5)); 
+0

感謝我指出了正確的方向。現在我有一個自定義的xaml控件,可以響應用戶輸入 – Dodi 2014-10-27 19:01:55