我尝试实现可通过使用ThinkGeo绘制地图的鼠标单击事件。当我开始运行代码时,此功能才处于活动状态。我想在地图上应用一个按钮,以便可以启用和禁用地图上的鼠标单击事件。有人可以显示一个示例或示例,我认为它需要布尔类型变量对吗?
private void map_Loaded(object sender, RoutedEventArgs e)
{
Map1.MapUnit = GeographyUnit.Meter;
LayerOverlay myOverlay = new LayerOverlay();
Map1.Overlays.Add(myOverlay);
myOverlay.TileCache = new FileBitmapTileCache(@"..\..\Cache\");
string[] files = System.IO.Directory.GetFiles(@"C:\Users\User\Desktop\DSI REFERENCE\Map Data\Raster");
foreach (string file in files)
{
GeoTiffRasterLayer tiffLayer = new GeoTiffRasterLayer(file);
myOverlay.Layers.Add(tiffLayer);
}
myOverlay.Open();
Map1.CurrentExtent = myOverlay.GetBoundingBox();
InMemoryFeatureLayer inmemoryFeatureLayer = new InMemoryFeatureLayer();
inmemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(new GeoImage(@"C:\Users\User\Downloads\15floors\Icon\Point.png"));
inmemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay markerOverlay = new LayerOverlay();
markerOverlay.Layers.Add(inmemoryFeatureLayer);
Map1.Overlays.Add("MarkerOverlay", markerOverlay);
Map1.Refresh();
}
private void Map1_MapClick(object sender, MapClickWpfMapEventArgs e)
{
LayerOverlay markerOverlay = (LayerOverlay)Map1.Overlays["MarkerOverlay"];
InMemoryFeatureLayer inmemoryFeatureLayer = markerOverlay.Layers[0] as InMemoryFeatureLayer;
MultipolygonShape buffer = e.WorldLocation.Buffer(350, GeographyUnit.Meter, DistanceUnit.Kilometer);
inmemoryFeatureLayer.InternalFeatures.Add(new Feature(e.WorldLocation));
Map1.Refresh();
}
private void Plot_ButtonClick(object sender, RoutedEventArgs e)
{
InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)Map1.FindFeatureLayer("InMemoryFeatureLayer");
inMemoryLayer.Open();
inMemoryLayer.EditTools.BeginTransaction();
inMemoryLayer.EditTools.Delete("MarkerOverlay");
inMemoryLayer.EditTools.CommitTransaction();
inMemoryLayer.Close();
Map1.Refresh(Map1.Overlays["InmemoryOverlay"]);
}
}
答案 0 :(得分:1)
无需创建按钮,如果您不希望地图控件生成鼠标单击事件,则只需关闭点击测试:
Map1.IsHitTestVisible = false;