Guys,
Looks like the GeoCollection.Remove(string) API does not work. I modified your sample AddSimpleMarkers class to be able to remove a marker as follows:
using
System;
using
System.Linq;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Media.Imaging;
using
ThinkGeo.MapSuite.Core;
using
ThinkGeo.MapSuite.WpfDesktopEdition;
namespace
CSHowDoISamples
{
public
partial
class
AddSimpleMarkers : UserControl
{
public
AddSimpleMarkers()
{
InitializeComponent();
}
private
void
WpfMap_Loaded(
object
sender, RoutedEventArgs e)
{
wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
wpfMap1.CurrentExtent =
new
RectangleShape(-155.733, 95.60, 104.42, -81.9);
WorldMapKitWmsWpfOverlay worldMapKitOverlay =
new
WorldMapKitWmsWpfOverlay();
wpfMap1.Overlays.Add(worldMapKitOverlay);
SimpleMarkerOverlay markerOverlay =
new
SimpleMarkerOverlay();
wpfMap1.Overlays.Add(
"MarkerOverlay"
, markerOverlay);
wpfMap1.Refresh();
}
private
void
wpfMap1_MapClick(
object
sender, MapClickWpfMapEventArgs e)
{
if
(e.MouseButton != MapMouseButton.Left)
return
;
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)wpfMap1.Overlays[
"MarkerOverlay"
];
Marker marker =
new
Marker(e.WorldLocation);
marker.ImageSource =
new
BitmapImage(
new
Uri(
"/Resources/AQUA.png"
, UriKind.RelativeOrAbsolute));
marker.Width = 20;
marker.Height = 34;
marker.YOffset = -17;
var contextMenu =
new
ContextMenu();
var menuItem =
new
MenuItem();
menuItem.Header =
"Remove"
;
menuItem.Name =
"Marker"
+ marker.GetHashCode().ToString();
menuItem.Click += OnRemoveMarkerRequested;
contextMenu.Items.Add(menuItem);
marker.ContextMenu = contextMenu;
marker.Name = menuItem.Name;
markerOverlay.Markers.Add(marker);
markerOverlay.Refresh();
}
private
void
OnRemoveMarkerRequested(
object
sender, RoutedEventArgs e)
{
var markerOverlay = (SimpleMarkerOverlay)wpfMap1.Overlays[
"MarkerOverlay"
];
var markerName = ((MenuItem) e.Source).Name;
// does not work?
markerOverlay.Markers.Remove(markerName);
var marker = markerOverlay.Markers.First(m =>
string
.Compare(m.Name, markerName, StringComparison.OrdinalIgnoreCase) == 0);
markerOverlay.Markers.Remove(marker);
// remember to unhook MenuItem from OnRemoveMarkerRequested
markerOverlay.Refresh();
}
}
}
If you run the sample, an exception is not thrown by the LINQ statement indicating that the marker was not removed. However, grabbing the marker instance and remove it works correctly. Any ideas or a better recommendation on how to remove markers?
TIA.
W