From f7125ef57d69c329b38d53410102f59b964cc67c Mon Sep 17 00:00:00 2001 From: PeterZhong Date: Mon, 2 Dec 2024 11:52:00 +0800 Subject: [PATCH] Draw graphics and set symbol --- GisDevelop_Exp/MainWindow.xaml.cs | 49 ++++- GisDevelop_Exp/OptionsWindow.xaml | 32 ++-- GisDevelop_Exp/OptionsWindow.xaml.cs | 257 ++++++++++++++++++++++++++- 3 files changed, 312 insertions(+), 26 deletions(-) diff --git a/GisDevelop_Exp/MainWindow.xaml.cs b/GisDevelop_Exp/MainWindow.xaml.cs index 66c1c8b..7570643 100644 --- a/GisDevelop_Exp/MainWindow.xaml.cs +++ b/GisDevelop_Exp/MainWindow.xaml.cs @@ -57,6 +57,7 @@ namespace GisDevelop_Exp private SimpleMarkerSymbol pointSymbol; private SimpleLineSymbol lineSymbol; private SimpleFillSymbol fillSymbol; + private SimpleLineSymbol outlineSymbol; private readonly Dictionary _basemapOptions = new Dictionary() { @@ -82,6 +83,7 @@ namespace GisDevelop_Exp pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Blue, 3); lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Blue, 1); fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Blue,new SimpleLineSymbol(SimpleLineSymbolStyle.Solid,System.Drawing.Color.Pink,1)); + outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Blue, 1); linePoints = new List(); linesList = new List(); @@ -331,14 +333,18 @@ namespace GisDevelop_Exp private void MainMapView_OnGeoViewTapped(object? sender, GeoViewInputEventArgs e) { - MapPoint mapLocation = e.Location; - Geometry myGeometry = mapLocation.Project(SpatialReferences.Wgs84); - MapPoint projectedLocation = (MapPoint)myGeometry; - string mapLocationDescription = - string.Format("纬度: {0:F3} 经度:{1:F3}", projectedLocation.Y, projectedLocation.X); - CalloutDefinition myCalloutDefinition = new CalloutDefinition("当前位置:", mapLocationDescription); - MainMapView.ShowCalloutAt(mapLocation, myCalloutDefinition); - if (m_CurOper == CURRENTOPERATION.SelectQuery) + MainMapView.DismissCallout(); + if (m_CurOper == CURRENTOPERATION.NullOpe) + { + MapPoint mapLocation = e.Location; + Geometry myGeometry = mapLocation.Project(SpatialReferences.Wgs84); + MapPoint projectedLocation = (MapPoint)myGeometry; + string mapLocationDescription = + string.Format("纬度: {0:F3} 经度:{1:F3}", projectedLocation.Y, projectedLocation.X); + CalloutDefinition myCalloutDefinition = new CalloutDefinition("当前位置:", mapLocationDescription); + MainMapView.ShowCalloutAt(mapLocation, myCalloutDefinition); + } + else if (m_CurOper == CURRENTOPERATION.SelectQuery) { if (MainMapView.Map.OperationalLayers.Count > 0) { @@ -564,6 +570,7 @@ namespace GisDevelop_Exp LayerListBox.AllowDrop = true; LayerCollection pLayers = MainMapView.Map.OperationalLayers; if (pLayers.Count <= 0) return; + List checkBoxes = new List(); for (int i = pLayers.Count - 1; i >= 0; i--) { CheckBox cb = new CheckBox() @@ -584,6 +591,7 @@ namespace GisDevelop_Exp cb.Focusable = false; cb.Checked += new RoutedEventHandler(Checked_Layers_CheckBox); cb.Unchecked += new RoutedEventHandler(UnChecked_Layers_CheckBox); + ListBoxItem listBoxItem = new ListBoxItem(); LayerListBox.Items.Add(cb); } } @@ -656,6 +664,7 @@ namespace GisDevelop_Exp private void Menu_Point_Symbol_Click(object sender, RoutedEventArgs e) { + MainMapView.GraphicsOverlays[0].Graphics.Clear(); m_CurOper = CURRENTOPERATION.DrawPoint; } @@ -686,6 +695,26 @@ namespace GisDevelop_Exp linesList.Add(lineGraphic); } } + else if (m_CurOper == CURRENTOPERATION.DrawPolygon) + { + linePoints.Add(location); + if (linePoints.Count > 1) + { + if (linesList.Count > 0) + { + Graphic curGraphic = linesList[linesList.Count - 1]; + MainMapView.GraphicsOverlays[0].Graphics.Remove(curGraphic); + linesList.Remove(curGraphic); + } + Polygon polygon = new Polygon(linePoints); + Graphic polygonGraphic = new Graphic(polygon, fillSymbol); + MainMapView.GraphicsOverlays[0].Graphics.Add(polygonGraphic); + Polyline line = new Polyline(linePoints); + Graphic lineGraphic = new Graphic(line, lineSymbol); + // MainMapView.GraphicsOverlays[0].Graphics.Add(lineGraphic); + linesList.Add(lineGraphic); + } + } } private void Menu_Layers_Options_OnClick(object sender, RoutedEventArgs e) @@ -694,18 +723,22 @@ namespace GisDevelop_Exp op.PointSymbol = pointSymbol; op.LineSymbol = lineSymbol; op.FillSymbol = fillSymbol; + op.GeometryType = MainMapView.GraphicsOverlays[0].Graphics[0].Geometry.GeometryType; op.ShowDialog(); } private void Menu_Point_Draw_Line_OnClick(object sender, RoutedEventArgs e) { + MainMapView.GraphicsOverlays[0].Graphics.Clear(); m_CurOper = CURRENTOPERATION.DrawLine; linePoints.Clear(); } private void Menu_Point_Draw_Polygon_OnClick(object sender, RoutedEventArgs e) { + MainMapView.GraphicsOverlays[0].Graphics.Clear(); m_CurOper = CURRENTOPERATION.DrawPolygon; + linePoints.Clear(); } private void MainMapView_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e) diff --git a/GisDevelop_Exp/OptionsWindow.xaml b/GisDevelop_Exp/OptionsWindow.xaml index b96e1a0..22e66ee 100644 --- a/GisDevelop_Exp/OptionsWindow.xaml +++ b/GisDevelop_Exp/OptionsWindow.xaml @@ -6,7 +6,8 @@ xmlns:local="clr-namespace:GisDevelop_Exp" mc:Ignorable="d" Title="符号系统" Height="453" Width="399" - Loaded="Window_Loaded"> + Loaded="Window_Loaded" + x:Name="Options_Window"> @@ -14,7 +15,7 @@ - + - + @@ -54,12 +55,12 @@