Overlays in GMap.Net Wpf

I am creating an application that needs a tool for rendering a geographical map, in addition, the application needs this tool to provide a way to add custom overlays.

I found GMap.Net a great tool to work with.

I found many examples WinFormon the Internet that create custom overlays, for example:

GMapOverlay markersOverlay = new GMapOverlay("markers");
GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(-25.966688, 32.580528), GMarkerGoogleType.green);
markersOverlay.Markers.Add(marker);
gmap.Overlays.Add(markersOverlay);

But when I approached the version of GMap.Net in the version WPF, I noticed that the overlays disappeared, and I was forced to add markers directly to the marker collection ( mymap.Markers.Add(new Marker())) without the ability to combine markers in a separate overlay.

How to use overlays in the version of GMap.Net Wpf?

+4
source share
2 answers

, . , ZIndex , .

, WinFrom.

+5

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

ComboBox SelectedIndex, ZIndex . , (ObservableCollection) MainMap.Markers. / , . , , (UIElement) Shape , . , .

( ) Visibility Shape s 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;
    }
}

, .

0

All Articles