To better understand the (GMapMarker) marker, let's have a look at how they're
added.
The (UIElement) Shape of the marker is set, passing
- the
MainWindow instance
- coordinates (a.o.)
- ToolTipText
to the (UserControl) CustomMarkerDemo's constructor
// 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);
}
In the demo I used a ComboBox's SelectedIndex to set the ZIndex of new markers. As you can see markers are added to the (ObservableCollection) MainMap.Markers. It's tempting to remove / filter the markers in the collection when we don't need 'em. Problem with this approach is that when the (UIElement) Shapes are removed from the view, they're disposed and need to be reconstructed. This results in undesired behaviour, especially if you want to be able to show all overlays at once.
Instead I chose to only add markers to the collection (by user interaction) and set the Visibility of the Shapes, based on current combobox.SelectedIndex.
// 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;
}
}
I linked a set up with only the bare bones, note there's a lot more functionality in these libraries.