爲了更好地理解(GMapMarker) marker
,讓我們來看看它們是如何被添加的 。
的標記被設置的(UIElement) Shape
,傳遞
- 的
MainWindow
實例
- 座標(A.O。)
- 的ToolTipText
到(UserControl) CustomMarkerDemo
的構造
// add marker
private void addMarker_Click(object sender, RoutedEventArgs e)
{
GMapMarker marker = new GMapMarker(currentMarker.Position);
{
... // ToolTipText fetching logic
marker.Shape = new CustomMarkerDemo(this, marker, ToolTipText);
marker.ZIndex = combobox.SelectedIndex;
}
MainMap.Markers.Add(marker);
}
the demo我用ComboBox
的SelectedIndex
來設置新標記的ZIndex
。正如你可以看到標記被添加到(ObservableCollection) MainMap.Markers
。當我們不需要時,很容易刪除/過濾集合中的標記。這種方法的問題是,當從視圖中刪除(UIElement) Shape
時,它們被丟棄並需要重建。這會導致不受歡迎的行爲,特別是如果您希望能夠一次顯示所有疊加層。
取而代之,我選擇僅向集合添加標記(通過用戶交互),並基於當前的combobox.SelectedIndex
設置Shape
的Visibility
。
// change overlays
private void combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox combobox = sender as ComboBox;
if (combobox != null && MainMap != null)
{
// show all overlays
if (combobox.SelectedIndex == combobox.Items.Count - 1)
{
foreach (GMapMarker marker in MainMap.Markers)
marker.Shape.Visibility = Visibility.Visible;
}
// show only selected overlay
else
{
foreach (GMapMarker marker in MainMap.Markers)
{
if (marker.ZIndex == combobox.SelectedIndex)
marker.Shape.Visibility = Visibility.Visible;
else
marker.Shape.Visibility = Visibility.Collapsed;
}
}
currentMarker.Shape.Visibility = Visibility.Visible;
}
}
我鏈接了一個只有裸露的骨骼的設置,請注意這些庫中有更多的功能。
您應該在[討論頁](https://greatmaps.codeplex.com/discussions/topics/4903/wpf)上提問。 – Clemens
這是相應的[線程](https://greatmaps.codeplex.com/discussions/640141) – rdoubleui
是的,這就是我 – Matan