Graphic edit and Spatial Analyst

This commit is contained in:
PeterZhong 2024-12-04 23:17:14 +08:00
parent f735e0f239
commit 59f3c97c1e
3 changed files with 884 additions and 41 deletions

View File

@ -6,15 +6,16 @@
xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
xmlns:local="clr-namespace:GisDevelop_Exp"
mc:Ignorable="d"
Title="GIS开发实验" Height="450" Width="800">
Title="GIS开发实验" Height="450" Width="800"
MouseLeftButtonDown="LayerListBox_OnPreviewMouseLeftButtonDown">
<Window.Resources>
<local:MapViewModel x:Key="MapViewModel" />
</Window.Resources>
<Grid>
<Menu x:Name="MenuContainer" Margin="0,0,0,0">
<MenuItem x:Name="Menu_File" Header="文件">
<MenuItem x:Name="Menu_OpenShp" Header="打开Shp" Click="Menu_OpenShp_Click"/>
<MenuItem x:Name="Menu_OpenGeodatabase" Header="打开Geodatabase" Click="Menu_OpenGeodatabase_Click"/>
<MenuItem x:Name="Menu_OpenShp" Header="打开Shp" Click="Menu_OpenShp_Click" />
<MenuItem x:Name="Menu_OpenGeodatabase" Header="打开Geodatabase" Click="Menu_OpenGeodatabase_Click" />
<MenuItem x:Name="Menu_OpenOnlineMap" Header="打开在线地图" Click="Menu_OpenOnlineMap_OnClick"></MenuItem>
<MenuItem x:Name="Menu_OpenRaster" Header="打开栅格数据" Click="Menu_OpenRaster_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Exit" Header="退出程序" Click="Menu_Exit_OnClick"></MenuItem>
@ -30,37 +31,111 @@
<MenuItem x:Name="Menu_Click_Indentify" Header="点击查询" Click="Menu_Click_Indentify_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Identify_Indentify" Header="Indentify查询" Click="Menu_Identify_Indentify_OnClick"></MenuItem>
</MenuItem>
<MenuItem x:Name="Menu_Symbology" Header="符号系统">
<MenuItem x:Name="Menu_Symbology" Header="符号设计">
<MenuItem x:Name="Menu_Point_Add_Layer" Header="添加图层" Click="Menu_OpenShp_Click"></MenuItem>
<MenuItem x:Name="Menu_Point_Draw_Point" Header="画点" Click="Menu_Point_Symbol_Click"></MenuItem>
<MenuItem x:Name="Menu_Point_Draw_Line" Header="画线" Click="Menu_Point_Draw_Line_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Point_Draw_Polygon" Header="画面" Click="Menu_Point_Draw_Polygon_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Layers_Options" Header="符号系统" Click="Menu_Layers_Options_OnClick"></MenuItem>
</MenuItem>
<MenuItem x:Name="Menu_Thematic_Map" Header="专题地图">
<MenuItem x:Name="Menu_Simple_Color" Header="简单着色" Click="Menu_Simple_Color_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Unique_Color" Header="唯一值着色" Click="Menu_Unique_Color_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Level_Color" Header="分级着色" Click="Menu_Level_Color_OnClick"></MenuItem>
</MenuItem>
<MenuItem x:Name="Menu_Spatial_Analyst" Header="空间分析">
<MenuItem x:Name="Menu_Clip" Header="裁剪" Click="Menu_Clip_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Cut" Header="剪切" Click="Menu_Cut_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Union" Header="联合" Click="Menu_Union_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Intersect" Header="求交" Click="Menu_Intersect_OnClick"></MenuItem>
<Separator></Separator>
<MenuItem x:Name="Menu_Topology" Header="拓扑纠正" Click="Menu_Topology_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Simplify" Header="简化" Click="Menu_Simplify_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Buffer" Header="缓冲" Click="Menu_Buffer_OnClick"></MenuItem>
<MenuItem x:Name="Menu_Intersection_Point" Header="求交点" Click="Menu_Intersection_Point_OnClick"></MenuItem>
</MenuItem>
</Menu>
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged" GeoViewTapped="MainMapView_OnGeoViewTapped" MouseLeftButtonDown="MainMapView_OnMouseLeftButtonDown" MouseRightButtonDown="MainMapView_OnMouseRightButtonDown"/>
<ListBox x:Name="LayerListBox" Width="143" SelectedIndex="0" RenderTransformOrigin="0.451,1.105" Margin="0,37,0,13" HorizontalAlignment="Left" PreviewMouseMove="LayerListBox_OnPreviewMouseMove" Drop="LayerListBox_OnDrop" ItemStringFormat="删除">
<ListBox.ContextMenu>
<ContextMenu/>
</ListBox.ContextMenu>
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0"
ViewpointChanged="MainMapView_OnViewpointChanged" GeoViewTapped="MainMapView_OnGeoViewTapped"
MouseLeftButtonDown="MainMapView_OnMouseLeftButtonDown"
MouseRightButtonDown="MainMapView_OnMouseRightButtonDown" />
<ListBox x:Name="LayerListBox" Width="143" SelectedIndex="0" RenderTransformOrigin="0.451,1.105"
Margin="0,56,0,13" HorizontalAlignment="Left" PreviewMouseMove="LayerListBox_OnPreviewMouseMove"
Drop="LayerListBox_OnDrop" PreviewMouseRightButtonDown="LayerListBox_OnPreviewMouseRightButtonDown"
PreviewMouseLeftButtonDown="LayerListBox_OnPreviewMouseLeftButtonDown">
<!-- <ListBox.ContextMenu> -->
<!-- <ContextMenu> -->
<!-- <MenuItem Header="删除" x:Name="Context_Menu_Delete" Click="Context_Menu_Delete_OnClick"/> -->
<!-- <MenuItem Header="缩放至图层" x:Name="Context_Menu_Fit" Click="Context_Menu_Fit_OnClick"/> -->
<!-- <MenuItem Header="图层符号化" x:Name="Context_Menu_Symbology" Click="Context_Menu_Symbology_OnClick"/> -->
<!-- </ContextMenu> -->
<!-- </ListBox.ContextMenu> -->
</ListBox>
<Border BorderBrush="#FF8B1D76" BorderThickness="2,2,2,2" HorizontalAlignment="Right" Height="180" Width="202" VerticalAlignment="Top" IsEnabled="False">
<esri:MapView x:Name="EagleMapView"/>
<Popup x:Name="Layer_Popup" Placement="MousePoint" StaysOpen="True">
<Border Background="White" BorderBrush="Gray" BorderThickness="0.5">
<StackPanel>
<MenuItem Header="删除" x:Name="Context_Menu_Delete" Click="Context_Menu_Delete_OnClick" />
<MenuItem Header="缩放至图层" x:Name="Context_Menu_Fit" Click="Context_Menu_Fit_OnClick" />
<MenuItem Header="图层符号化" x:Name="Context_Menu_Symbology" Click="Context_Menu_Symbology_OnClick" />
</StackPanel>
</Border>
</Popup>
<Border BorderBrush="#FF8B1D76" BorderThickness="2,2,2,2" HorizontalAlignment="Right" Height="180" Width="202"
VerticalAlignment="Top" IsEnabled="False">
<esri:MapView x:Name="EagleMapView" />
</Border>
<Border BorderBrush="#000000" BorderThickness="1" HorizontalAlignment="Right" Height="24" Width="202" VerticalAlignment="Top" IsEnabled="True" Margin="580,210,0,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<ComboBox x:Name="BasemapChooser" HorizontalAlignment="Left" Height="24" Margin="9,-1,0,-1" VerticalAlignment="Top" Width="182" SelectionChanged="BasemapChooser_OnSelectionChanged" IsEnabled="True"/>
<Border BorderBrush="#000000" BorderThickness="1" HorizontalAlignment="Right" Height="24" Width="202"
VerticalAlignment="Top" IsEnabled="True" Margin="580,210,0,0"
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<ComboBox x:Name="BasemapChooser" HorizontalAlignment="Left" Height="24" Margin="9,-1,0,-1"
VerticalAlignment="Top" Width="182" SelectionChanged="BasemapChooser_OnSelectionChanged"
IsEnabled="True" />
</Border>
<!-- <ToolBar HorizontalAlignment="Left" Height="29" Margin="0,20,0,0" VerticalAlignment="Top" Width="361"> -->
<!-- <Button x:Name="Btn_Add_Shp" Height="32" Width="32" Click="Menu_OpenShp_Click"> -->
<!-- <Button.Background> -->
<!-- <ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\add.png"/> -->
<!-- </Button.Background> -->
<!-- </Button> -->
<!-- <Button x:Name="Btn_Add_Online" Height="32" Width="32" Click="Btn_Add_Online_OnClick"> -->
<!-- <Button.Background> -->
<!-- <ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\online.png"/> -->
<!-- </Button.Background> -->
<!-- </Button> -->
<!-- </ToolBar> -->
<Grid Margin="0,18,0,350" Background="White">
<Button x:Name="BtnDraw" Content="开始绘制" HorizontalAlignment="Left" Height="26"
Margin="169,4,0,0" VerticalAlignment="Top" Width="68" Click="BtnDraw_Click" IsEnabled="False" />
<Label Content="类型" HorizontalAlignment="Left" Margin="51,4,0,0"
VerticalAlignment="Top" RenderTransformOrigin="1.618,0.654" />
<ComboBox x:Name="SketchModeComboBox" HorizontalAlignment="Left" Margin="90,4,0,0"
VerticalAlignment="Top" Width="62" IsEnabled="False" />
<Button x:Name="BtnEdit" Content="编辑 " HorizontalAlignment="Left" Height="26"
Margin="257,4,0,0" VerticalAlignment="Top" Width="68" IsEnabled="False" Click="BtnEdit_Click" />
<Button x:Name="BtnUndo" Content="撤销 " HorizontalAlignment="Left" Height="26"
Margin="349,4,0,0" VerticalAlignment="Top" Width="68" Command="{Binding UndoCommand}"
IsEnabled="False" />
<Button x:Name="BtnRedo" Content="恢复" HorizontalAlignment="Left" Height="26"
Margin="440,4,0,0" VerticalAlignment="Top" Width="68" Command="{Binding RedoCommand}"
IsEnabled="False" />
<Button x:Name="BtnComplete" Content="完成" HorizontalAlignment="Left" Height="26"
Margin="525,4,0,0" VerticalAlignment="Top" Width="68" RenderTransformOrigin="1.412,0.308"
Command="{Binding CompleteCommand}" IsEnabled="False" />
<Button x:Name="BtnCancel" Content="取消" HorizontalAlignment="Left" Height="26"
Margin="610,4,0,0" VerticalAlignment="Top" Width="68" RenderTransformOrigin="1.412,0.308"
Command="{Binding CancelCommand}" IsEnabled="False" />
<Button x:Name="BtnClear" Content="清空" HorizontalAlignment="Left" Height="26"
Margin="695,4,0,0" VerticalAlignment="Top" Width="68" RenderTransformOrigin="1.412,0.308"
IsEnabled="False" Click="BtnClear_Click" />
<CheckBox x:Name="CBEditBegin" Content="开始" HorizontalAlignment="Left"
Margin="5,9,0,0" VerticalAlignment="Top" RenderTransformOrigin="1.073,1.812"
Checked="CBEditBegin_Checked" />
</Grid>
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom">
<ToolBar HorizontalAlignment="Left" Height="32" VerticalAlignment="Top" Width="150" Margin="0,0,10,10"
x:Name="MovableToolbar">
<Button x:Name="Btn_Add_Shp" Height="32" Width="32" Click="Menu_OpenShp_Click">
<Button.Background>
<ImageBrush
ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\add.png" />
</Button.Background>
</Button>
<Button x:Name="Btn_Add_Online" Height="32" Width="32" Click="Btn_Add_Online_OnClick">
<Button.Background>
<ImageBrush
ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\online.png" />
</Button.Background>
</Button>
</ToolBar>
</Border>
</Grid>
</Window>
</Window>

View File

@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
@ -35,6 +36,15 @@ enum CURRENTOPERATION
DrawPoint,
DrawLine,
DrawPolygon,
Cal_Clip,
Cal_Cut,
Cal_Union,
Cal_IntersectPoint,
Cal_Simplify,
Cal_Intersect,
Cal_Intersection,
Cal_Gene,
Cal_Buff
}
namespace GisDevelop_Exp
@ -53,12 +63,21 @@ namespace GisDevelop_Exp
private List<MapPoint> linePoints;
private List<Graphic> linesList;
private SimpleMarkerSymbol pointSymbol;
private SimpleLineSymbol lineSymbol;
private SimpleFillSymbol fillSymbol;
private SimpleLineSymbol outlineSymbol;
private Symbol pSymbol;
private ListBoxItem cur_LayerItem;
private GraphicsOverlay _pGraphicsOverLay;
private Point _startPoint;
private List<Graphic> listOfClipGraphics; //几何操作时选择的图形
private readonly Dictionary<string, Basemap> _basemapOptions = new Dictionary<string, Basemap>()
{
{ "Streets (Raster)", new Basemap(BasemapStyle.OSMStreets) },
@ -76,23 +95,34 @@ namespace GisDevelop_Exp
private CURRENTOPERATION m_CurOper;
List<System.Drawing.Color> ColorArray = new List<Color>
{
Color.AliceBlue, Color.AntiqueWhite, Color.Aqua, Color.Aquamarine, Color.Azure,
Color.Beige, Color.Bisque, Color.Black, Color.BlanchedAlmond, Color.Blue, Color.Brown,
Color.BurlyWood, Color.CadetBlue, Color.Chocolate, Color.Coral, Color.CornflowerBlue,
Color.Cornsilk, Color.Crimson, Color.Cyan, Color.FloralWhite, Color.Green, Color.GreenYellow,
Color.HotPink, Color.LawnGreen, Color.Magenta
};
public MainWindow()
{
InitializeComponent();
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));
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<MapPoint>();
linesList = new List<Graphic>();
m_CurOper = CURRENTOPERATION.NullOpe;
Initialize();
EagleMapView.Map = new Map(BasemapStyle.ArcGISImageryStandard);
GraphicsOverlay graphicLayer = new GraphicsOverlay();
MainMapView.GraphicsOverlays.Add(graphicLayer);
listOfClipGraphics = new List<Graphic>();
}
private void Initialize()
@ -134,6 +164,7 @@ namespace GisDevelop_Exp
await MainMapView.SetViewpointGeometryAsync(openedFeature.Extent);
}
}
AddLayerNameToList();
}
@ -169,6 +200,7 @@ namespace GisDevelop_Exp
MainMapView.Map.InitialViewpoint = geodatabaseViewPoint;
// MainMapView.Map = geodatabaseMap;
}
AddLayerNameToList();
}
@ -317,7 +349,7 @@ namespace GisDevelop_Exp
{
AddPrivateOnlineMap();
}
private async void AddPrivateOnlineMap()
{
Map map = new Map(BasemapStyle.ArcGISTopographic);
@ -331,7 +363,7 @@ namespace GisDevelop_Exp
AddLayerNameToList();
}
private void MainMapView_OnGeoViewTapped(object? sender, GeoViewInputEventArgs e)
private async void MainMapView_OnGeoViewTapped(object? sender, GeoViewInputEventArgs e)
{
MainMapView.DismissCallout();
if (m_CurOper == CURRENTOPERATION.NullOpe)
@ -354,7 +386,8 @@ namespace GisDevelop_Exp
FunClickQuery(e.Location, _featureLayer);
}
}
}else if (m_CurOper == CURRENTOPERATION.IdentifyQuery)
}
else if (m_CurOper == CURRENTOPERATION.IdentifyQuery)
{
if (MainMapView.Map.OperationalLayers.Count > 0)
{
@ -365,6 +398,249 @@ namespace GisDevelop_Exp
}
}
}
else if (m_CurOper == CURRENTOPERATION.Cal_Buff)
{
IdentifyGraphicsOverlayResult gResult_Buff =
await MainMapView.IdentifyGraphicsOverlayAsync(_pGraphicsOverLay, e.Position, 5, false);
if (gResult_Buff.Graphics.Count < 1)
{
return;
}
Graphic selGraphic_Buff = gResult_Buff.Graphics.First();
selGraphic_Buff.IsSelected = true;
listOfClipGraphics.Add(selGraphic_Buff); //记录所选图形
if (listOfClipGraphics.Count == 1) //图形数目为1时进行缓冲计算
{
Graphic g1 = listOfClipGraphics[0];
Esri.ArcGISRuntime.Geometry.Geometry resultGeometry =
GeometryEngine.Buffer(g1.Geometry, 500000.0); //执行缓冲操作
if (resultGeometry != null) //处理结果
{
_pGraphicsOverLay.Graphics.Remove(g1); //从图形层中移除原图形
Graphic clipedGraphic = new Graphic(resultGeometry, new
SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.FromArgb(125, 255, 250, 0), new
SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.FromArgb(0, 0, 0),
4.0))); //利用剪切结果构造新的图形
_pGraphicsOverLay.Graphics.Add(clipedGraphic);
m_CurOper = CURRENTOPERATION.NullOpe;
}
listOfClipGraphics.Clear(); //清空图形选择集合
_pGraphicsOverLay.ClearSelection(); //清空图形层所选
}
}
else if (m_CurOper == CURRENTOPERATION.Cal_Union)
{
Console.WriteLine("Inside the if condition");
IdentifyGraphicsOverlayResult gResultUnion = await
MainMapView.IdentifyGraphicsOverlayAsync(_pGraphicsOverLay, e.Position, 5, false);
if (gResultUnion.Graphics.Count < 1)
{
return;
}
Graphic selGraphicUnion = gResultUnion.Graphics.First(); //每次选中的Graphic取出来
selGraphicUnion.IsSelected = true;
listOfClipGraphics.Add(selGraphicUnion); //记录所选图形
if (listOfClipGraphics.Count == 2) //图形数目为2时进行剪切计算
{
Graphic g1 = listOfClipGraphics[0];
Graphic g2 = listOfClipGraphics[1];
if (g1.Geometry.GeometryType != GeometryType.Polygon ||
g2.Geometry.GeometryType != GeometryType.Polygon) //如果所选图形不是多边形,则退出
{
MessageBox.Show("请选择两个多边形图形!");
listOfClipGraphics.Clear();
_pGraphicsOverLay.ClearSelection();
return;
}
Esri.ArcGISRuntime.Geometry.Geometry resultGeometry =
GeometryEngine.Union(g1.Geometry, g2.Geometry); //执行联合操作
if (resultGeometry != null) //处理结果
{
_pGraphicsOverLay.Graphics.Remove(g1); //从图形层中移除原图形
_pGraphicsOverLay.Graphics.Remove(g2);
Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol); //利用联合结果构建新的图形
_pGraphicsOverLay.Graphics.Add(clipedGraphic);
m_CurOper = CURRENTOPERATION.NullOpe;
}
listOfClipGraphics.Clear(); //清空图形选择集合
_pGraphicsOverLay.ClearSelection(); //清空图形层所选
}
}
else if (m_CurOper == CURRENTOPERATION.Cal_Cut)
{
IdentifyGraphicsOverlayResult gResult_Cut = await
MainMapView.IdentifyGraphicsOverlayAsync(_pGraphicsOverLay, e.Position, 5, false);
if (gResult_Cut.Graphics.Count < 1)
{
return;
}
Graphic selGraphic_Cut = gResult_Cut.Graphics.First();
selGraphic_Cut.IsSelected = true;
listOfClipGraphics.Add(selGraphic_Cut); //记录所选图形
if (listOfClipGraphics.Count == 2) //图形数目为1时进行剪切计算
{
Graphic g1 = listOfClipGraphics[0];
Graphic g2 = listOfClipGraphics[1];
if (g1.Geometry.GeometryType != GeometryType.Polygon ||
g2.Geometry.GeometryType != GeometryType.Polyline) //如果所选图形不是多边形,则退出
{
MessageBox.Show("请先选择一个面要素后再选择一个线要素.");
listOfClipGraphics.Clear();
_pGraphicsOverLay.ClearSelection();
return;
}
Esri.ArcGISRuntime.Geometry.Polyline polyLine =
(Esri.ArcGISRuntime.Geometry.Polyline)g2.Geometry;
Esri.ArcGISRuntime.Geometry.Geometry[] resultGeometry =
GeometryEngine.Cut(g1.Geometry, polyLine); //执行剪切操作
if (resultGeometry != null) //处理结果
{
_pGraphicsOverLay.Graphics.Remove(g1);
_pGraphicsOverLay.Graphics.Remove(g2);
for (int z = 0; z < resultGeometry.Length; z++)
{
Graphic clipedGraphic = new Graphic(resultGeometry[z],
fillSymbol); //利 用剪切结果构建新的图形
_pGraphicsOverLay.Graphics.Add(clipedGraphic);
}
m_CurOper = CURRENTOPERATION.NullOpe;
}
listOfClipGraphics.Clear(); //清空图形选择集合
_pGraphicsOverLay.ClearSelection(); //清空图形层所选
}
}else if (m_CurOper == CURRENTOPERATION.Cal_Intersection)
{
IdentifyGraphicsOverlayResult gResult_Intersect = await MainMapView.IdentifyGraphicsOverlayAsync(_pGraphicsOverLay, e.Position, 5, false);
if (gResult_Intersect.Graphics.Count < 1)
return;
Graphic selGraphic_Intersect = gResult_Intersect.Graphics.First();
selGraphic_Intersect.IsSelected = true;
listOfClipGraphics.Add(selGraphic_Intersect); //记录所选图形
if (listOfClipGraphics.Count == 2) //图形数目为2时进行求交计算
{
Graphic g1 = listOfClipGraphics[0];
Graphic g2 = listOfClipGraphics[1];
IReadOnlyList<Geometry> resultGeometry = GeometryEngine.Intersections(g1.Geometry, g2.Geometry); //执行求交点操作
// Geometry resultGeometry = GeometryEngine.Intersection(g1.Geometry, g2.Geometry); //执行求交操作
if (resultGeometry != null) //处理结果
{
_pGraphicsOverLay.Graphics.Remove(g1);
_pGraphicsOverLay.Graphics.Remove(g2);
foreach (var pointGeometry in resultGeometry)
{
Graphic clipedGraphic = new Graphic(pointGeometry, pointSymbol); //利用求交结果构建新的图形
_pGraphicsOverLay.Graphics.Add(clipedGraphic);
}
m_CurOper = CURRENTOPERATION.NullOpe;
}
listOfClipGraphics.Clear();//清空图形选择集合
_pGraphicsOverLay.ClearSelection();//清空图形层所选
}
}else if (m_CurOper == CURRENTOPERATION.Cal_Intersect)
{
IdentifyGraphicsOverlayResult gResult_Intersect = await MainMapView.IdentifyGraphicsOverlayAsync(_pGraphicsOverLay, e.Position, 5, false);
if (gResult_Intersect.Graphics.Count < 1)
return;
Graphic selGraphic_Intersect = gResult_Intersect.Graphics.First();
selGraphic_Intersect.IsSelected = true;
listOfClipGraphics.Add(selGraphic_Intersect); //记录所选图形
if (listOfClipGraphics.Count == 2) //图形数目为2时进行求交计算
{
Graphic g1 = listOfClipGraphics[0];
Graphic g2 = listOfClipGraphics[1];
// IReadOnlyList<Geometry> resultGeometry = GeometryEngine.Intersections(g1.Geometry, g2.Geometry); //执行求交点操作
Geometry resultGeometry = GeometryEngine.Intersection(g1.Geometry, g2.Geometry); //执行求交操作
if (resultGeometry != null) //处理结果
{
_pGraphicsOverLay.Graphics.Remove(g1);
_pGraphicsOverLay.Graphics.Remove(g2);
Graphic clipedGraphic = new Graphic(resultGeometry, pointSymbol); //利用求交结果构建新的图形
_pGraphicsOverLay.Graphics.Add(clipedGraphic);
m_CurOper = CURRENTOPERATION.NullOpe;
}
listOfClipGraphics.Clear();//清空图形选择集合
_pGraphicsOverLay.ClearSelection();//清空图形层所选
}
}else if (m_CurOper == CURRENTOPERATION.Cal_Clip)
{
IdentifyGraphicsOverlayResult gResult_Intersect = await MainMapView.IdentifyGraphicsOverlayAsync(_pGraphicsOverLay, e.Position, 5, false);
if (gResult_Intersect.Graphics.Count < 1)
return;
Graphic selGraphic_Intersect = gResult_Intersect.Graphics.First();
selGraphic_Intersect.IsSelected = true;
listOfClipGraphics.Add(selGraphic_Intersect); //记录所选图形
if (listOfClipGraphics.Count == 2) //图形数目为2时进行求交计算
{
Graphic g1 = listOfClipGraphics[0];
Graphic g2 = listOfClipGraphics[1];
Geometry resultGeometry = GeometryEngine.Clip(g1.Geometry, g2.Geometry.Extent); //执行求交操作
if (resultGeometry != null) //处理结果
{
_pGraphicsOverLay.Graphics.Remove(g1);
_pGraphicsOverLay.Graphics.Remove(g2);
Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol); //利用求交结果构建新的图形
_pGraphicsOverLay.Graphics.Add(clipedGraphic);
m_CurOper = CURRENTOPERATION.NullOpe;
}
listOfClipGraphics.Clear();//清空图形选择集合
_pGraphicsOverLay.ClearSelection();//清空图形层所选
}
}else if (m_CurOper == CURRENTOPERATION.Cal_Simplify)
{
IdentifyGraphicsOverlayResult gResult_Buff =
await MainMapView.IdentifyGraphicsOverlayAsync(_pGraphicsOverLay, e.Position, 5, false);
if (gResult_Buff.Graphics.Count < 1)
{
return;
}
Graphic selGraphic_Buff = gResult_Buff.Graphics.First();
selGraphic_Buff.IsSelected = true;
listOfClipGraphics.Add(selGraphic_Buff); //记录所选图形
if (listOfClipGraphics.Count == 1) //图形数目为1时进行缓冲计算
{
Graphic g1 = listOfClipGraphics[0];
Esri.ArcGISRuntime.Geometry.Geometry resultGeometry =
GeometryEngine.Simplify(g1.Geometry); //执行缓冲操作
if (resultGeometry != null) //处理结果
{
_pGraphicsOverLay.Graphics.Remove(g1); //从图形层中移除原图形
if(resultGeometry.GeometryType == GeometryType.Point || resultGeometry.GeometryType == GeometryType.Multipoint){
Graphic simplifiedGraphic = new Graphic(resultGeometry, pointSymbol); //利用剪切结果构造新的图形
_pGraphicsOverLay.Graphics.Add(simplifiedGraphic);
}else if (resultGeometry.GeometryType == GeometryType.Polyline)
{
Graphic simplifiedGraphic = new Graphic(resultGeometry, lineSymbol); //利用剪切结果构造新的图形
_pGraphicsOverLay.Graphics.Add(simplifiedGraphic);
}else if (resultGeometry.GeometryType == GeometryType.Polygon)
{
Graphic simplifiedGraphic = new Graphic(resultGeometry, fillSymbol); //利用剪切结果构造新的图形
_pGraphicsOverLay.Graphics.Add(simplifiedGraphic);
}
m_CurOper = CURRENTOPERATION.NullOpe;
}
listOfClipGraphics.Clear(); //清空图形选择集合
_pGraphicsOverLay.ClearSelection(); //清空图形层所选
}
}
}
private void Menu_Simple_Identify_OnClick(object sender, RoutedEventArgs e)
@ -418,18 +694,20 @@ namespace GisDevelop_Exp
pQueryPara.Geometry = selEnv;
pQueryPara.SpatialRelationship = SpatialRelationship.Intersects;
await _featureLayer.SelectFeaturesAsync(pQueryPara, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
FeatureQueryResult pQueryResult = await _featureLayer.GetSelectedFeaturesAsync();
List<Feature> pListFeatures = pQueryResult.ToList();
if (pListFeatures.Count <= 0)
{
return;
}
EnvelopeBuilder pEnvBuilder = new EnvelopeBuilder(_featureLayer.SpatialReference);
for (int i = 0; i < pListFeatures.Count; i++)
{
pEnvBuilder.UnionOf(pListFeatures[i].Geometry.Extent);
}
await MainMapView.SetViewpointGeometryAsync(pEnvBuilder.ToGeometry(), 50);
Feature pFeature;
string sInfo = "";
@ -437,7 +715,7 @@ namespace GisDevelop_Exp
for (int i = 0; i < pListFeatures.Count; i++)
{
pFeature = pListFeatures[i];
IDictionary<string,object> FeatureAttri = pFeature.Attributes;
IDictionary<string, object> FeatureAttri = pFeature.Attributes;
string str;
object obj;
sInfo += "选中的第" + i.ToString() + "个要素的属性\n\r";
@ -447,19 +725,21 @@ namespace GisDevelop_Exp
obj = FeatureAttri.Values.ElementAt(j);
sInfo += str + ":" + obj.ToString() + "\r\n";
}
MessageBox.Show(sInfo);
}
}
private async void FunIndentifyQuery(System.Windows.Point pPoint, FeatureLayer pFLayer)
{
IdentifyLayerResult identifyLayerResult = await MainMapView.IdentifyLayerAsync(pFLayer,pPoint,20,false);
IdentifyLayerResult identifyLayerResult = await MainMapView.IdentifyLayerAsync(pFLayer, pPoint, 20, false);
if (!identifyLayerResult.GeoElements.Any())
{
return;
}
Feature identifyFeature = (Feature)identifyLayerResult.GeoElements.First();
IDictionary<string,object> FeatureAttri = identifyFeature.Attributes;
IDictionary<string, object> FeatureAttri = identifyFeature.Attributes;
string str;
string tempStr = "";
object obj;
@ -469,6 +749,7 @@ namespace GisDevelop_Exp
obj = FeatureAttri.Values.ElementAt(i);
tempStr += str + ":" + obj.ToString() + "\r\n";
}
System.Windows.MessageBox.Show(tempStr);
}
@ -505,11 +786,12 @@ namespace GisDevelop_Exp
RasterLayer rasterLayer = new RasterLayer(raster);
aMap.OperationalLayers.Add(rasterLayer);
await rasterLayer.LoadAsync();
Viewpoint geodatabaseViewPoint = new Viewpoint(rasterLayer.FullExtent);
aMap.InitialViewpoint = geodatabaseViewPoint;
MainMapView.Map = aMap;
}
AddLayerNameToList();
}
@ -551,7 +833,7 @@ namespace GisDevelop_Exp
{
return;
}
var targetPerson = listBoxItem.Content as CheckBox;
if (ReferenceEquals(listBoxItem, sourceItem))
{
@ -562,7 +844,7 @@ namespace GisDevelop_Exp
int sourceIndex = LayerListBox.Items.IndexOf(sourceItem);
LayerListBox.Items.Remove(sourceItem);
LayerListBox.Items.Insert(targetIndex, sourceItem);
MoveLayer(sourceItem.ToolTip as string,listBoxItem.ToolTip as string);
MoveLayer(sourceItem.ToolTip as string, listBoxItem.ToolTip as string);
}
private void AddLayerNameToList()
@ -625,6 +907,7 @@ namespace GisDevelop_Exp
return obj as T;
obj = System.Windows.Media.VisualTreeHelper.GetParent(obj);
}
return null;
}
}
@ -692,6 +975,7 @@ namespace GisDevelop_Exp
MainMapView.GraphicsOverlays[0].Graphics.Remove(curGraphic);
linesList.Remove(curGraphic);
}
Polyline line = new Polyline(linePoints);
Graphic lineGraphic = new Graphic(line, lineSymbol);
MainMapView.GraphicsOverlays[0].Graphics.Add(lineGraphic);
@ -709,6 +993,7 @@ namespace GisDevelop_Exp
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);
@ -748,5 +1033,484 @@ namespace GisDevelop_Exp
{
m_CurOper = CURRENTOPERATION.NullOpe;
}
private void SetSimpleRender(FeatureLayer pLayer, Symbol pSymbol)
{
if (pSymbol == null)
{
pSymbol = this.pSymbol;
}
Random r = new Random();
int num = r.Next(0, 20);
Color pColor = ColorArray[num];
OptionsWindow op = new OptionsWindow();
if (pSymbol == null)
{
if (pLayer.FeatureTable.GeometryType == GeometryType.Point ||
pLayer.FeatureTable.GeometryType == GeometryType.Multipoint)
{
pSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, pColor, 5);
op.PointSymbol = (SimpleMarkerSymbol)pSymbol;
}
else if (pLayer.FeatureTable.GeometryType == GeometryType.Polyline)
{
pSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, pColor, 1);
op.LineSymbol = (SimpleLineSymbol)pSymbol;
}
else if (pLayer.FeatureTable.GeometryType == GeometryType.Polygon)
{
SimpleLineSymbol pOutlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Gray, 1);
pSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, pColor, pOutlineSymbol);
op.FillSymbol = (SimpleFillSymbol)pSymbol;
}
}
else
{
if (pLayer.FeatureTable.GeometryType == GeometryType.Point ||
pLayer.FeatureTable.GeometryType == GeometryType.Multipoint)
{
op.PointSymbol = (SimpleMarkerSymbol)pSymbol;
}
else if (pLayer.FeatureTable.GeometryType == GeometryType.Polyline)
{
op.LineSymbol = (SimpleLineSymbol)pSymbol;
}
else if (pLayer.FeatureTable.GeometryType == GeometryType.Polygon)
{
op.FillSymbol = (SimpleFillSymbol)pSymbol;
}
}
SimpleRenderer sRenderer = new SimpleRenderer(pSymbol);
pLayer.Renderer = sRenderer;
op.GeometryType = pLayer.FeatureTable.GeometryType;
op.ShowDialog();
}
private void Menu_Simple_Color_OnClick(object sender, RoutedEventArgs e)
{
FeatureLayer _featureLayer = MainMapView.Map.OperationalLayers[0] as FeatureLayer;
SetSimpleRender(_featureLayer, pSymbol);
}
private async void SetUniqueRender(FeatureLayer pLayer, string sFieldName, List<Symbol> pSymbolList = null)
{
UniqueValueRenderer regionRenderer = new UniqueValueRenderer();
regionRenderer.FieldNames.Add(sFieldName);
QueryParameters pQueryPara = new QueryParameters();
pQueryPara.WhereClause = "1=1";
FeatureQueryResult queryResult = await pLayer.FeatureTable.QueryFeaturesAsync(pQueryPara);
IEnumerator<Feature> queryFeatures = queryResult.GetEnumerator();
object featureValue;
int i = 0;
while (queryFeatures.MoveNext())
{
featureValue = queryFeatures.Current.GetAttributeValue(sFieldName);
Symbol tempSymbol = null;
if (pSymbolList == null)
{
if (i >= ColorArray.Count)
i = 0;
Color pColor = ColorArray[i];
if (pLayer.FeatureTable.GeometryType == GeometryType.Point ||
pLayer.FeatureTable.GeometryType == GeometryType.Multipoint)
{
tempSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, pColor, 5);
}
else if (pLayer.FeatureTable.GeometryType == GeometryType.Polyline)
{
tempSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, pColor, 1);
}
else if (pLayer.FeatureTable.GeometryType == GeometryType.Polygon)
{
SimpleLineSymbol tempSymbol2 = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid,
Color.Gray, 1);
tempSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, pColor, tempSymbol2);
}
}
else
{
tempSymbol = pSymbolList[i];
}
i++;
UniqueValue pUniqueValue = new UniqueValue("null", "null", tempSymbol, featureValue);
regionRenderer.UniqueValues.Add(pUniqueValue);
}
SimpleFillSymbol defaultFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, Color.Gray,
null);
regionRenderer.DefaultSymbol = defaultFillSymbol;
regionRenderer.DefaultLabel = "Other";
pLayer.Renderer = regionRenderer;
}
private void Menu_Unique_Color_OnClick(object sender, RoutedEventArgs e)
{
if (MainMapView.Map.OperationalLayers.Count > 0)
{
FeatureLayer _featureLayer = MainMapView.Map.OperationalLayers[0] as FeatureLayer;
string sQueryFieldName = "XZQMC";
SetUniqueRender(_featureLayer, sQueryFieldName);
}
}
private async void SetClassBreaksRender(FeatureLayer pLayer, string sFieldName, int ClassifyCount = 5,
List<Symbol> pSymbolList = null)
{
//ClassBreaksRenderer
ClassBreaksRenderer pCBRenderer = new ClassBreaksRenderer();
//设置字段名
pCBRenderer.FieldName = sFieldName;
//设置统计查询条件,
StatisticDefinition statDefinitionMin = new StatisticDefinition(sFieldName, StatisticType.Minimum, "");
StatisticDefinition statDefinitionMax = new StatisticDefinition(sFieldName, StatisticType.Maximum, "");
List<StatisticDefinition> statDefinitions = new List<StatisticDefinition>
{
statDefinitionMin,
statDefinitionMax,
};
StatisticsQueryParameters pQueryPara = new StatisticsQueryParameters(statDefinitions);
//执行统计查询
StatisticsQueryResult queryResult = await pLayer.FeatureTable.QueryStatisticsAsync(pQueryPara);
//从统计结果中获取最大值,获取最小值
string str;
object max = null, min = null;
double dMax, dMin;
//获取该字段的最大值,最小值,为后续分级做准备
IReadOnlyDictionary<string, object> sResult = queryResult.First().Statistics;
for (int i = 0; i < sResult.Count; i++)
{
str = sResult.Keys.ElementAt(i);
if (str.Contains("MAX"))
max = sResult.Values.ElementAt(i);
if (str.Contains("MIN"))
min = sResult.Values.ElementAt(i);
}
dMax = (double)(max);
dMin = (double)(min);
//计算并设置分级中每一级别的范围,以及符号
for (int i = 0; i < ClassifyCount; i++)
{
ClassBreak pClassBreak = new ClassBreak();
//每一级别范围的最大值、最小值
if (i == 0)
pClassBreak.MinValue = dMin;
else
pClassBreak.MinValue = dMin + (dMax - dMin) * (i - 1) / ClassifyCount;
;
pClassBreak.MaxValue = dMin + (dMax - dMin) * (i + 1) / ClassifyCount;
Color tempColor = Color.FromArgb(i * 50 + 10, 255, 255);
//创建符号,这里图层为面层,直接创建面符号,注意若图层为 点层、线层,需创建对应的点符号、线符号
SimpleLineSymbol tempSymbol2 = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Gray,
1);
Symbol pSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, tempColor, tempSymbol2);
pClassBreak.Symbol = pSymbol;
//将设置好的ClassBreak放入ClassBreaksRenderer中。
pCBRenderer.ClassBreaks.Add(pClassBreak);
}
//将创建好的ClassBreaksRenderer 赋值给图层
pLayer.Renderer = pCBRenderer;
}
private void Menu_Level_Color_OnClick(object sender, RoutedEventArgs e)
{
if (MainMapView.Map.OperationalLayers.Count > 0)
{
FeatureLayer _featureLayer = MainMapView.Map.OperationalLayers[0] as FeatureLayer;
string sQueryFieldName = "FID";
SetClassBreaksRender(_featureLayer, sQueryFieldName);
}
}
private void Context_Menu_Delete_OnClick(object sender, RoutedEventArgs e)
{
Layer_Popup.IsOpen = false;
LayerListBox.Items.Remove(cur_LayerItem);
LayerCollection pLayers = MainMapView.Map.OperationalLayers;
Layer delLayer = GetLayer(cur_LayerItem.ToolTip as string);
pLayers.Remove(delLayer);
e.Handled = true;
}
private void LayerListBox_OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
Layer_Popup.IsOpen = false;
var pos = e.GetPosition(LayerListBox);
System.Windows.Media.HitTestResult
result = System.Windows.Media.VisualTreeHelper.HitTest(LayerListBox, pos);
if (result == null)
{
Layer_Popup.IsOpen = false;
return;
}
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
if (listBoxItem == null)
{
Layer_Popup.IsOpen = false;
return;
}
cur_LayerItem = listBoxItem;
Layer_Popup.HorizontalOffset = pos.X;
Layer_Popup.VerticalOffset = pos.Y;
Layer_Popup.IsOpen = true;
e.Handled = true;
}
private void Context_Menu_Fit_OnClick(object sender, RoutedEventArgs e)
{
Layer_Popup.IsOpen = false;
Layer fitLayer = GetLayer(cur_LayerItem.ToolTip as string);
MainMapView.SetViewpointGeometryAsync(fitLayer.FullExtent);
e.Handled = true;
}
private void Context_Menu_Symbology_OnClick(object sender, RoutedEventArgs e)
{
Layer_Popup.IsOpen = false;
Layer symbologyLayer = GetLayer(cur_LayerItem.ToolTip as string);
FeatureLayer _featureLayer = (FeatureLayer)symbologyLayer;
if (_featureLayer != null && _featureLayer.Renderer is SimpleRenderer simpleRenderer)
{
var symbol = simpleRenderer.Symbol;
SetSimpleRender((FeatureLayer)symbologyLayer, symbol);
}
else
{
pSymbol = null;
SetSimpleRender((FeatureLayer)symbologyLayer, null);
}
e.Handled = true;
}
private void LayerListBox_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var pos = e.GetPosition(Layer_Popup);
System.Windows.Media.HitTestResult
result = System.Windows.Media.VisualTreeHelper.HitTest(Layer_Popup, pos);
if (result == null)
{
Layer_Popup.IsOpen = false;
return;
}
var menuItem = Utils.FindVisualParent<MenuItem>(result.VisualHit);
if (menuItem == null)
{
Layer_Popup.IsOpen = false;
return;
}
// Layer_Popup.IsOpen = false;
e.Handled = false;
}
private void CBEditBegin_Checked(object sender, RoutedEventArgs e)
{
//设置部分按钮可以操作。
SketchModeComboBox.IsEnabled = true;
BtnDraw.IsEnabled = true;
// 获取_ pGraphicsOverLay ,用于放置图形元素
// Window w = Window.GetWindow(this);
// MyMapView = (MapView)w.FindName("MyMapView");
_pGraphicsOverLay = new GraphicsOverlay();
MainMapView.GraphicsOverlays.Add(_pGraphicsOverLay);
SketchModeComboBox.ItemsSource =
System.Enum.GetValues(typeof(SketchCreationMode));
SketchModeComboBox.SelectedIndex = 0;
//设置图形元素编辑的相关属性
SketchEditConfiguration config = MainMapView.SketchEditor.EditConfiguration;
if (config != null)
{
config.AllowVertexEditing = true;
config.ResizeMode = SketchResizeMode.Uniform;
config.AllowMove = true;
}
//设置 页面的DataContext为 SketchEditor
DataContext = MainMapView.SketchEditor;
}
private async void BtnDraw_Click(object sender, RoutedEventArgs e)
{
try
{
BtnCancel.IsEnabled = true;
BtnRedo.IsEnabled = true;
BtnUndo.IsEnabled = true;
BtnComplete.IsEnabled = true;
SketchCreationMode creationMode =
(SketchCreationMode)SketchModeComboBox.SelectedItem;
Esri.ArcGISRuntime.Geometry.Geometry geometry = await
MainMapView.SketchEditor.StartAsync(creationMode, true);
// Create and add a graphic from the geometry the user drew
// Graphic graphic = new Graphic (geometry);
Graphic graphic = CreateGraphic(geometry);
_pGraphicsOverLay.Graphics.Add(graphic);
BtnClear.IsEnabled = _pGraphicsOverLay.Graphics.Count > 0;
BtnEdit.IsEnabled = _pGraphicsOverLay.Graphics.Count > 0;
}
catch (TaskCanceledException) //当 点击 取消后,抛出代码运行异常 ,需要添加该行
{
// Ignore ... let the user cancel drawing
}
catch (Exception ex)
{
// Report exceptions
MessageBox.Show("Error drawing graphic shape: " + ex.Message);
}
}
private Graphic CreateGraphic(Esri.ArcGISRuntime.Geometry.Geometry geometry)
{
// Create a graphic to display the specified geometry
//若不设置符号,图形元素不显示。
Symbol symbol = null;
switch (geometry.GeometryType)
{
// Symbolize with a fill symbol
case GeometryType.Envelope:
case GeometryType.Polygon:
{
symbol = new SimpleFillSymbol()
{
Color = System.Drawing.Color.Red,
Style = SimpleFillSymbolStyle.Solid
};
break;
}
// Symbolize with a line symbol
case GeometryType.Polyline:
{
symbol = new SimpleLineSymbol()
{
Color = System.Drawing.Color.Red,
Style = SimpleLineSymbolStyle.Solid,
Width = 5d
};
break;
}
// Symbolize with a marker symbol
case GeometryType.Point:
case GeometryType.Multipoint:
{
symbol = new SimpleMarkerSymbol()
{
Color = System.Drawing.Color.Red,
Style = SimpleMarkerSymbolStyle.Circle,
Size = 15d
};
break;
}
}
// pass back a new graphic with the appropriate symbol
return new Graphic(geometry, symbol);
}
private async void BtnEdit_Click(object sender, RoutedEventArgs e)
{
try
{
Graphic editGraphic = await GetGraphicAsync();
if (editGraphic == null)
{
return;
}
// Let the user make changes to the graphic's geometry, await the result (updated geometry)
Esri.ArcGISRuntime.Geometry.Geometry newGeometry =
await MainMapView.SketchEditor.StartAsync(editGraphic.Geometry);
// Display the updated geometry in the graphic
editGraphic.Geometry = newGeometry;
}
catch (TaskCanceledException) //当 点击 取消后,抛出代码运行异常 ,需要添加该行
{
// Ignore ... let the user cancel drawing
}
catch (Exception ex)
{
// Report exceptions
MessageBox.Show("Error drawing graphic shape: " + ex.Message);
}
}
private async Task<Graphic> GetGraphicAsync()
{
//鼠标点击,获取点坐标对象
Geometry pMapPoint = await
MainMapView.SketchEditor.StartAsync(SketchCreationMode.Point, false);
//将点对象由地图坐标转换为屏幕坐标
Point scrPoint = MainMapView.LocationToScreen((MapPoint)pMapPoint);
//利用Indendify识别该点选中的图形元素
IReadOnlyList<IdentifyGraphicsOverlayResult> results = await
MainMapView.IdentifyGraphicsOverlaysAsync(scrPoint, 2, false);
//获取选中的第一个元素
Graphic graphic = null;
IdentifyGraphicsOverlayResult idResult = results.FirstOrDefault();
if (idResult != null && idResult.Graphics.Count > 0)
{
graphic = idResult.Graphics.FirstOrDefault();
}
return graphic;
}
private void BtnClear_Click(object sender, RoutedEventArgs e)
{
_pGraphicsOverLay.Graphics.Clear();
BtnClear.IsEnabled = false;
BtnEdit.IsEnabled = false;
}
private void Menu_Buffer_OnClick(object sender, RoutedEventArgs e)
{
m_CurOper = CURRENTOPERATION.Cal_Buff;
}
private void Menu_Union_OnClick(object sender, RoutedEventArgs e)
{
m_CurOper = CURRENTOPERATION.Cal_Union;
}
private void Menu_Cut_OnClick(object sender, RoutedEventArgs e)
{
m_CurOper = CURRENTOPERATION.Cal_Cut;
}
private void Menu_Intersection_Point_OnClick(object sender, RoutedEventArgs e)
{
m_CurOper = CURRENTOPERATION.Cal_Intersection;
}
private void Menu_Intersect_OnClick(object sender, RoutedEventArgs e)
{
m_CurOper = CURRENTOPERATION.Cal_Intersect;
}
private void Menu_Simplify_OnClick(object sender, RoutedEventArgs e)
{
m_CurOper = CURRENTOPERATION.Cal_Simplify;
}
private void Menu_Clip_OnClick(object sender, RoutedEventArgs e)
{
m_CurOper = CURRENTOPERATION.Cal_Clip;
}
private void Menu_Topology_OnClick(object sender, RoutedEventArgs e)
{
MessageBox.Show("此功能暂未实现");
}
}
}

View File

@ -250,6 +250,10 @@ namespace GisDevelop_Exp
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
{
if (GeometryType != GeometryType.Polyline)
{
return;
}
System.Windows.Media.Color color = System.Windows.Media.Color.FromArgb(lineColor.A, lineColor.R, lineColor.G, lineColor.B);
Label_Line_Color.Background = new SolidColorBrush(color);
Slider_Line_Width.Value = Convert.ToInt32(lineSymbol.Width);