C#的WPF下在GMap.NET中添加自定义Marker的点击响应
Point clickPoint = e.GetPosition(mapControl); PointLatLng point = mapControl.FromLocalToLatLng((int)clickPoint.X, (int)clickPoint.Y); foreach(GMapMarker marker in mapControl.Markers) { GPoint markerPoint = mapControl.FromLatLngToLocal(marker.Position); double deltaX = 0, deltaY = 0; if(marker.Shape != null) { if(marker.Shape is Ellipse) { Ellipse ee = (Ellipse)marker.Shape; deltaX = ee.Width; deltaY = ee.Height; } else if (marker.Shape is Image) { Image ee = (Image)marker.Shape; deltaX = ee.Width; deltaY = ee.Height; } } if(clickPoint.X - markerPoint.X > 0 && clickPoint.X - markerPoint.X < deltaX) { if (clickPoint.Y - markerPoint.Y > 0 && clickPoint.Y - markerPoint.Y < deltaY) { MessageBoxResult result = MessageBox.Show("确认删除,请选确认\n\r取消删除,请选取消", "是否删除标记吗?", MessageBoxButton.YesNo, MessageBoxImage.Question); if(result == MessageBoxResult.Yes) { marker.Shape = null; } break; } } }