diff --git a/GisDevelop_Exp/MainWindow.xaml b/GisDevelop_Exp/MainWindow.xaml
index be4eeb8..db3102e 100644
--- a/GisDevelop_Exp/MainWindow.xaml
+++ b/GisDevelop_Exp/MainWindow.xaml
@@ -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">
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/GisDevelop_Exp/MainWindow.xaml.cs b/GisDevelop_Exp/MainWindow.xaml.cs
index df055c2..159f2da 100644
--- a/GisDevelop_Exp/MainWindow.xaml.cs
+++ b/GisDevelop_Exp/MainWindow.xaml.cs
@@ -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 linePoints;
private List 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 listOfClipGraphics; //几何操作时选择的图形
+
private readonly Dictionary _basemapOptions = new Dictionary()
{
{ "Streets (Raster)", new Basemap(BasemapStyle.OSMStreets) },
@@ -76,23 +95,34 @@ namespace GisDevelop_Exp
private CURRENTOPERATION m_CurOper;
+ List ColorArray = new List
+ {
+ 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();
linesList = new List();
-
+
m_CurOper = CURRENTOPERATION.NullOpe;
Initialize();
EagleMapView.Map = new Map(BasemapStyle.ArcGISImageryStandard);
GraphicsOverlay graphicLayer = new GraphicsOverlay();
MainMapView.GraphicsOverlays.Add(graphicLayer);
+ listOfClipGraphics = new List();
}
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 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 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 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 FeatureAttri = pFeature.Attributes;
+ IDictionary 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 FeatureAttri = identifyFeature.Attributes;
+ IDictionary 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 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 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 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 statDefinitions = new List
+ {
+ 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 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(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