1
我對Windows 10 UWP中的新地圖控件有疑問。我需要添加一個包含一組多邊形的地圖圖層,每個多邊形都必須保存一些綁定的數據,並且我想知道如何處理多邊形上的輕擊事件以顯示與其相關的詳細信息。但是沒有屬性DataContext,並且沒有事件在MapPolygon類中被Tapped。我們如何實現它?新的地圖控制中沒有DataContext和Tapped屬性 - Windows 10
我對Windows 10 UWP中的新地圖控件有疑問。我需要添加一個包含一組多邊形的地圖圖層,每個多邊形都必須保存一些綁定的數據,並且我想知道如何處理多邊形上的輕擊事件以顯示與其相關的詳細信息。但是沒有屬性DataContext,並且沒有事件在MapPolygon類中被Tapped。我們如何實現它?新的地圖控制中沒有DataContext和Tapped屬性 - Windows 10
您可以在數據模板中定義多邊形,並且可以將多邊形的路徑綁定到BasicGeoposition的列表。對於點擊事件,當用戶點擊多邊形時,可以從mapElementClick事件中獲取地理位置。
我嘗試下面的代碼從一個多邊形水龍頭事件,似乎工作
1)創建設置路徑多邊形多邊形
var polygon = new MapPolygon();
polygon.FillColor = Color.FromArgb(80, 255, 0, 0);
polygon.StrokeColor = Colors.Red;
polygon.StrokeThickness = 15;
2)
List<BasicGeoposition> positions = new List<BasicGeoposition>();
positions.Add(new BasicGeoposition { Latitude = 25.251231, Longitude = 55.305957 });
positions.Add(new BasicGeoposition { Latitude = 25.251105, Longitude = 55.306445 });
positions.Add(new BasicGeoposition { Latitude = 25.249977, Longitude = 55.306091 });
positions.Add(new BasicGeoposition { Latitude = 25.250392, Longitude = 55.304441 });
positions.Add(new BasicGeoposition { Latitude = 25.250748, Longitude = 55.304661 });
positions.Add(new BasicGeoposition { Latitude = 25.250481, Longitude = 55.305726 });
polygon.Path = new Geopath(positions);
3)將多邊形添加到MapElemetns中
myMap.MapElements.Add(polygon);
4)設置地圖中心和縮放級別
myMap.Center = new Geopoint((new BasicGeoposition { Latitude =
25.251231, Longitude = 55.305957 }));
myMap.ZoomLevel = 18;
5)添加MapElementClick事件多邊形
myMap.MapElementClick += MyMap_MapElementClick;
private void MyMap_MapElementClick(MapControl sender, MapElementClickEventArgs args)
{
// add your code to position the canvas (pop up) and display it here
}
難道處理自來水,你已經嘗試以此爲榜樣? http://dotnetbyexample.blogspot.be/2015/08/windows-10-maps-part-3-querying-map.html – Depechie