using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Views;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using KUI.Windows;
using stdole;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
namespace Kingo.Plugin.General.View
{
///
/// UCWYInfo.xaml 的交互逻辑
///
public partial class UCWYSketch : UserControl, IElementInfo
{
private IProofManager ProofMgr = null;
private IHookHelper hookHelper { get; set; }
private NYYSInfo OldData { get; set; }
private NYYSInfo NYYSInfo { get; set; }
private ProjectInfo projectInfo { get; set; }
private TaskPackage taskPackage { get; set; }
///
/// 数据源集合
///
private DataTable Data { get; set; }
public UCWYSketch()
{
InitializeComponent();
Title = "外业草图";
DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray);
NYYSInfo = new NYYSInfo();
this.DataContext = NYYSInfo;
this.Loaded += (s, e) =>
{
hookHelper = new HookHelperClass();
hookHelper.Hook = MapsManager.Instance.MapService.getAxMapControl().Object;
};
}
public bool IsShow { get; set; }
public int ShowIndex { get; set; }
public bool ResetSize { get; set; }
public bool AllowEdit { get; set; }
public Guid ID { get; set; }
public DockStyle DockAreas { get; set; }
public System.Drawing.Size FloatSize { get; set; }
public int DockWidth { get; set; }
public int DockHeight { get; set; }
public DockStyle DefaultArea { get; set; }
public bool ShowCloseButton { get; set; }
public bool ShowAutoHideButton { get; set; }
public string Title { get; set; }
private void LoadData(IWorkspace workspace, string tableName)
{
ICursor cursor = null;
ITable table = null;
try
{
table = (workspace as IFeatureWorkspace).OpenTable(tableName);
if (Data == null)
{
Data = new DataTable();
ConstructColumn(table.Fields);
}
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"TBBSM='{this.NYYSInfo.WYRWTB.TBBSM }' and BID='{this.taskPackage.BID}'"
};
cursor = table.Search(queryFilter, true);
IRow row = null;
while ((row = cursor.NextRow()) != null)
{
DataRow dr = Data.NewRow();
for (int i = 0; i < Data.Columns.Count; i++)
{
object obj = row.get_Value((int)Data.Columns[i].ExtendedProperties["index"]);
if (obj == null)
{
continue;
}
else
{
if ((obj.ToString()).Contains("1899/12/30 0:00:00"))
{
obj = System.DBNull.Value;
}
}
if (obj is string)
obj = obj.ToString().Trim();
dr[i] = obj;
}
Data.Rows.Add(dr);
System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
}
}
catch (Exception ex)
{
LogAPI.Debug("加载" + tableName + "数据异常:" + ex.Message);
MessageHelper.ShowError("加载" + tableName + "数据异常:" + ex.Message);
}
finally
{
if (cursor != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
}
}
}
private void ConstructColumn(IFields fields)
{
if (fields != null)
{
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.get_Field(i);
if (field.Name.ToUpper().EndsWith("SHAPE"))
continue;
DataColumn col = new DataColumn();
col.ExtendedProperties.Add("index", i);
col.ColumnName = field.Name;
col.Caption = field.AliasName;
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
col.DataType = typeof(short);
break;
case esriFieldType.esriFieldTypeInteger:
col.DataType = typeof(int);
break;
case esriFieldType.esriFieldTypeSingle:
break;
case esriFieldType.esriFieldTypeDouble:
col.DataType = typeof(double);
break;
case esriFieldType.esriFieldTypeString:
col.DataType = typeof(string);
break;
case esriFieldType.esriFieldTypeDate:
col.DataType = typeof(DateTime);
break;
case esriFieldType.esriFieldTypeOID:
col.DataType = typeof(Int32);
break;
case esriFieldType.esriFieldTypeGeometry:
break;
case esriFieldType.esriFieldTypeBlob:
break;
case esriFieldType.esriFieldTypeRaster:
break;
case esriFieldType.esriFieldTypeGUID:
break;
case esriFieldType.esriFieldTypeGlobalID:
break;
case esriFieldType.esriFieldTypeXML:
break;
default:
break;
}
col.ReadOnly = !field.Editable;//编辑状态启用默认是否可以编辑
Data.Columns.Add(col);
System.Runtime.InteropServices.Marshal.ReleaseComObject(field);
}
}
}
public void BindData(object obj)
{
IWorkspaceAPI workspaceAPI = null;
IRDBHelper rdbHelper = null;
try
{
NYYSInfo nYYSInfo = obj as NYYSInfo;
if (nYYSInfo == null) return;
this.NYYSInfo = nYYSInfo;
if (listDdeleteWYSketck == null)
{
listDdeleteWYSketck = new List();
}
listDdeleteWYSketck.Clear();
taskPackage = nYYSInfo.TaskPackages;
if (taskPackage == null || taskPackage.PackageTempPath == null || !System.IO.File.Exists(taskPackage.PackageTempPath)) return;
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (NYYSInfo.WYRWTB == null || string.IsNullOrWhiteSpace(NYYSInfo.WYRWTB.TBBSM))
{
btnAddData.IsEnabled = false;
btnClearData.IsEnabled = false;
this.DataContext = this.NYYSInfo;
return;
}
btnAddData.IsEnabled = true;
btnClearData.IsEnabled = true;
//this.btnOk.IsEnabled = true;
//外业任务图斑信息
DataTable dataTable = rdbHelper.ExecuteDatatable("WYRW", $"select * from WYRW WHERE TBBSM='{NYYSInfo.WYRWTB.TBBSM}'", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
return;
//throw new Exception("任务DB中未找到WYRW(外业任务图斑)=" + NYYSInfo.WYRWTB.TBBSM + "的图斑信息!");
}
if (dataTable.Rows.Count > 1)
{
throw new Exception("WYRW(外业任务图斑)表中存在" + dataTable.Rows.Count + "条图斑标识码为" + NYYSInfo.WYRWTB.TBBSM + "信息!");
}
this.NYYSInfo.WYRWTB = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity(dataTable.Rows[0]);
List listTable = new List() { "MarkPoint", "MarkPolygon", "MarkLine" };
Data = null;
workspaceAPI = new WorkspaceAPI(taskPackage.SchemeGDBPath, WorkspaceTypeEnum.GDBFile, true);
foreach (var item in listTable)
{
LoadData(workspaceAPI.CurrentWorkspace, item);
}
if (Data == null || Data.Rows.Count == 0)
{
this.NYYSInfo.WYSketch = new List();
}
else
{
this.NYYSInfo.WYSketch = KGIS.Framework.Utils.Utility.TBToList.ToList(Data);
}
this.DataContext = this.NYYSInfo;
this.OldData = PluginServiceInterface.CommonHelper.DeepCopyByBin(this.NYYSInfo);
}
catch (Exception ex)
{
LogAPI.Debug("外业标注绑定数据异常:" + ex.Message);
LogAPI.Debug("外业标注绑定数据异常:" + ex);
LogAPI.Debug("外业标注绑定数据异常:" + ex.StackTrace);
throw ex;
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
if (workspaceAPI != null)
{
workspaceAPI.CloseWorkspace();
}
}
}
public void SaveEdit()
{
IWorkspaceAPI workspaceAPI = null;
IRDBHelper rdbHelper = null;
try
{
if (this.NYYSInfo.WYSketch == null) return;
if (taskPackage.PackageTempPath == null || !System.IO.File.Exists(taskPackage.PackageTempPath)) return;
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
workspaceAPI = new WorkspaceAPI(taskPackage.SchemeGDBPath, WorkspaceTypeEnum.GDBFile, true);
//标注信息保存到DB
rdbHelper.ExecuteNonQueryWithException($"delete from WYSketch where TBBSM='{ NYYSInfo.WYRWTB.TBBSM }'", CommandType.Text);
foreach (var item in this.NYYSInfo.WYSketch)
{
rdbHelper.ExecuteNonQueryWithException(string.Format("INSERT INTO WYSketch (TBBSM, BZLX, BZMS, Geometry) VALUES('{0}', '{1}', '{2}', '{3}');", this.NYYSInfo.WYRWTB.TBBSM, item.BZLX, item.BZMS, item.Geometry), CommandType.Text);
}
//标注保存到矢量化图层中
List listTable = new List() { "MarkPoint", "MarkPolygon", "MarkLine" };
foreach (var tableName in listTable)
{
IFeatureClassAPI tableAPI = null;
try
{
if (!workspaceAPI.ExistFeatureClass(tableName))
{
continue;
}
if (listDdeleteWYSketck != null && listDdeleteWYSketck.Count > 0)
{
foreach (var item in listDdeleteWYSketck)
{
switch (tableName)
{
case "MarkPoint":
if (!item.BZLX.Equals("点"))
{
continue;
}
break;
case "MarkPolygon":
if (!item.BZLX.Equals("面"))
{
continue;
}
break;
case "MarkLine":
if (!item.BZLX.Equals("线"))
{
continue;
}
break;
}
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("delete from {0} where TBBSM='{1}' and objectid={2} and bid='{3}'", tableName, NYYSInfo.WYRWTB.TBBSM, item.ObjectID, taskPackage.BID));
}
}
List list = new List();
switch (tableName)
{
case "MarkPoint":
list = this.NYYSInfo.WYSketch.Where(x => x.BZLX.Equals("点") && !string.IsNullOrWhiteSpace(x.Geometry)).ToList();
break;
case "MarkLine":
list = this.NYYSInfo.WYSketch.Where(x => x.BZLX.Equals("线") && !string.IsNullOrWhiteSpace(x.Geometry)).ToList();
break;
case "MarkPolygon":
list = this.NYYSInfo.WYSketch.Where(x => x.BZLX.Equals("面") && !string.IsNullOrWhiteSpace(x.Geometry)).ToList();
break;
}
if (list.Count <= 0)
{
continue;
}
tableAPI = workspaceAPI.OpenFeatureClass(tableName);
int indexGeometry = tableAPI.FeatureClass.Fields.FindField("geometry");
foreach (var item in list)
{
if (item.ObjectID <= 0)
{
IGeometry geometry = null;
switch (tableName)
{
case "MarkPoint":
geometry = ConverJsonToIGeoemtry(item.Geometry, ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint);
break;
case "MarkLine":
geometry = ConverJsonToIGeoemtry(item.Geometry, ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline);
break;
case "MarkPolygon":
geometry = ConverJsonToIGeoemtry(item.Geometry);
break;
}
if (geometry.SpatialReference != null)
{
geometry.Project((tableAPI.FeatureClass as IGeoDataset).SpatialReference);
}
IFeature feature = tableAPI.FeatureClass.CreateFeature();
feature.Shape = geometry;
if (indexGeometry > -1)
{
feature.set_Value(indexGeometry, ConverIGometryToJson(geometry));
}
feature.Store();
item.ObjectID = feature.OID;
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("update {0} set bsm='{5}',bzlx='{1}',bzms='{2}',TBBSM='{3}',bid='{4}' where objectid={5}", tableName, item.BZLX, item.BZMS, this.NYYSInfo.WYRWTB.TBBSM, taskPackage.BID, item.ObjectID));
System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
System.Runtime.InteropServices.Marshal.ReleaseComObject(geometry);
}
else
{
if (indexGeometry > -1)
{
IFeature feature = tableAPI.FeatureClass.GetFeature(item.ObjectID);
feature.set_Value(indexGeometry, ConverIGometryToJson(feature.ShapeCopy));
feature.Store();
}
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("update {0} set bsm='{5}',bzlx='{1}',bzms='{2}',TBBSM='{3}',bid='{4}' where objectid={5}", tableName, item.BZLX, item.BZMS, this.NYYSInfo.WYRWTB.TBBSM, taskPackage.BID, item.ObjectID));
}
}
}
catch (Exception ex)
{
throw new Exception("标注保存失败:" + ex.Message);
}
finally
{
if (tableAPI != null)
{
tableAPI.CloseFeatureClass();
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("外业标注绑定数据保存异常:" + ex.Message);
LogAPI.Debug("外业标注绑定数据保存异常:" + ex);
LogAPI.Debug("外业标注绑定数据保存异常:" + ex.StackTrace);
throw;
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
if (workspaceAPI != null)
workspaceAPI.CloseWorkspace();
}
}
private void BtnAddData_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
BZToolSelected();
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void BZToolSelected()
{
switch (this.bzType.SelectedIndex)
{
case 0:
Tool.DrawPointTool drawPolygonTool = new Tool.DrawPointTool();
drawPolygonTool.DrawCompleted += DrawCompleted;
drawPolygonTool.OnCreate(this.hookHelper.Hook);
drawPolygonTool.OnClick();
(this.hookHelper.Hook as IMapControl3).CurrentTool = drawPolygonTool;
break;
case 1:
Tool.DrawPolylineTool drawPolygonTool2 = new Tool.DrawPolylineTool();
drawPolygonTool2.DrawCompleted += DrawCompleted;
drawPolygonTool2.OnCreate(this.hookHelper.Hook);
drawPolygonTool2.OnClick();
(this.hookHelper.Hook as IMapControl3).CurrentTool = drawPolygonTool2;
break;
case 2:
Tool.DrawPolygonTool drawPolygonTool3 = new Tool.DrawPolygonTool();
drawPolygonTool3.DrawCompleted += DrawCompleted;
drawPolygonTool3.OnCreate(this.hookHelper.Hook);
drawPolygonTool3.OnClick();
(this.hookHelper.Hook as IMapControl3).CurrentTool = drawPolygonTool3;
break;
}
}
private void DrawCompleted(ESRI.ArcGIS.Geometry.IGeometry geo)
{
try
{
this.ShowLoading("正在更新标注......", 0, 0);
//KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar("正在更新标注......");
if (geo.SpatialReference == null)
{
geo.SpatialReference = this.hookHelper.FocusMap.SpatialReference;
}
else
{
geo.Project(this.hookHelper.FocusMap.SpatialReference);
}
WYSketch wYSketch = new WYSketch()
{
BSM = this.NYYSInfo.WYRWTB.ObjectID,
TBBSM = this.NYYSInfo.WYRWTB.TBBSM,
BID = taskPackage.BID.ToString(),
};
switch (geo.GeometryType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
this.hookHelper.ActiveView.GraphicsContainer.AddElement(PointElement(geo), 0);
wYSketch.BZLX = "点";
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
this.hookHelper.ActiveView.GraphicsContainer.AddElement(PolylineElement(geo), 0);
wYSketch.BZLX = "线";
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
this.hookHelper.ActiveView.GraphicsContainer.AddElement(PolygonElement(geo), 0);
wYSketch.BZLX = "面";
break;
}
wYSketch.Geometry = ConverIGometryToJson(geo);
this.NYYSInfo.WYSketch.Add(wYSketch);
this.Dispatcher.Invoke(new Action(() =>
{
this.DataContext = null;
this.DataContext = this.NYYSInfo;
}));
this.hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
this.CloseLoading();
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar();
MessageHelper.ShowError(ex.Message);
}
finally
{
this.CloseLoading();
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar();
}
}
///
/// IGeometry转JSON字符串
///
/// 待转换图形
/// 坐标参考wkid,4490:CGCS2000球面坐标参考,默认输出CGCS2000球面坐标参考的json图形
/// 是地理坐标参考
///
public static string ConverIGometryToJson(IGeometry geometry, int wkid = 4490, bool isGeograhicCoordinateSystem = true)
{
try
{
if (geometry == null || geometry.IsEmpty || geometry.SpatialReference == null)
{
throw new Exception("图形或坐标参考为空,无法转换!");
}
if (wkid > 0)
{
if (isGeograhicCoordinateSystem)
{
geometry.Project(GeoDBAPI.CreateGeographicCoordinateSystem(wkid));
}
else
{
geometry.Project(GeoDBAPI.CreteSpatialReference(wkid));
}
}
#pragma warning disable CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
#pragma warning disable CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
using (ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser())
#pragma warning restore CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
#pragma warning restore CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
{
ESRI.ArcGIS.Geometry.JSONConverterGeometryClass jsonConverter = new JSONConverterGeometryClass();
comReleaser.ManageLifetime(jsonConverter);
ESRI.ArcGIS.esriSystem.IJSONWriter jsonWriter = new ESRI.ArcGIS.esriSystem.JSONWriterClass();
jsonWriter.WriteToString();
comReleaser.ManageLifetime(jsonWriter);
jsonConverter.WriteGeometry(jsonWriter, null, geometry, false);
return Encoding.UTF8.GetString(jsonWriter.GetStringBuffer());
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// JSON图图形转IGeometry
///
/// 图形串
/// 图形类型:点,线、面
/// 输出图形坐标参考wkid,4490:CGCS2000球面坐标参考,默认输出CGCS2000球面坐标参考的json图形
/// 是地理坐标参考
///
public static IGeometry ConverJsonToIGeoemtry(string jsonGeometry, esriGeometryType geometryType = esriGeometryType.esriGeometryPolygon, int wkid = 4490, bool isGeograhicCoordinateSystem = true)
{
try
{
#pragma warning disable CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
#pragma warning disable CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
using (ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser())
#pragma warning restore CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
#pragma warning restore CS0618 // “ComReleaser”已过时:“The assembly containing this class is obsolete. Reference the ESRI.ArcGIS.ADF.Connection.Local assembly instead.”
{
ESRI.ArcGIS.esriSystem.IJSONReader reader = new ESRI.ArcGIS.esriSystem.JSONReaderClass();
comReleaser.ManageLifetime(reader);
reader.ReadFromString(jsonGeometry);
ESRI.ArcGIS.Geometry.JSONConverterGeometryClass jsonConverter = new JSONConverterGeometryClass();
comReleaser.ManageLifetime(jsonConverter);
IGeometry geometry = jsonConverter.ReadGeometry(reader, geometryType, false, false);
if (geometry == null || geometry.IsEmpty)
{
throw new Exception("转换后图形为空!");
}
//此处发现湖南抽取过来的图形Simplify之后图形变化较大,会删除节点,所以湖南暂时不执行图形简化操作
if (!KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43"))
{
ESRI.ArcGIS.Geometry.ITopologicalOperator topological = geometry as ESRI.ArcGIS.Geometry.ITopologicalOperator;
if (!topological.IsSimple)
{
topological.Simplify();
}
}
ISpatialReference spatialReference = null;
if (isGeograhicCoordinateSystem)
{
spatialReference = GeoDBAPI.CreateGeographicCoordinateSystem(wkid);
}
else
{
spatialReference = GeoDBAPI.CreteSpatialReference(wkid);
}
if (wkid > 0)
{
if (geometry.SpatialReference == null)
{
geometry.SpatialReference = spatialReference;
}
else if (wkid != geometry.SpatialReference.FactoryCode)
{
geometry.Project(spatialReference);
}
}
return geometry;
}
}
catch (Exception ex)
{
throw ex;
}
}
public static IElement TextElement(IGeometry pGeometry, string textLabel)
{
IRgbColor pColor = new RgbColorClass()
{
Red = 0,
Blue = 255,
Green = 0
};
IFontDisp pFont = new StdFont()
{
Name = "宋体",
Size = 12
} as IFontDisp;
ITextSymbol pTextSymbol = new TextSymbolClass()
{
Color = pColor,
Font = pFont,
Size = 12
};
IGeometry geometry = pGeometry;
switch (geometry.GeometryType)
{
case esriGeometryType.esriGeometryPolygon:
geometry = (pGeometry as IArea).Centroid;
break;
}
IElement pTextElment = new TextElementClass()
{
Symbol = pTextSymbol,
ScaleText = true,
Text = textLabel,
Geometry = geometry
};
return pTextElment;
}
public static IElement PointElement(IGeometry pGeometry)
{
IElement pElement = new MarkerElementClass();
IMarkerElement pMarkerElement = (IMarkerElement)pElement;
ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Red = 255;
pSimpleMarkerSymbol.Color = pRgbColor;
pSimpleMarkerSymbol.Size = 10;
pMarkerElement.Symbol = pSimpleMarkerSymbol;
pElement.Geometry = pGeometry;
return pElement;
}
///
/// 创建线元素
///
/// 线几何图形
/// 线元素
public static IElement PolylineElement(IGeometry pGeometry)
{
IElement pElement = new LineElementClass();
ILineElement pLineElement = (ILineElement)pElement;
ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Red = 0;
pRgbColor.Green = 0;
pRgbColor.Blue = 0;
pSimpleLineSymbol.Color = pRgbColor;
pSimpleLineSymbol.Width = 5;
pLineElement.Symbol = pSimpleLineSymbol;
pElement.Geometry = pGeometry;
return pElement;
}
///
/// 创建面元素
///
/// 面几何对象
/// 面元素
public static IElement PolygonElement(IGeometry pGeometry)
{
IElement pElement = new PolygonElementClass();
//填充符号设置
ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
//填充符号的边框设置
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
IRgbColor pRgbColol = new RgbColorClass();
pRgbColol.Red = 0;
pRgbColol.Green = 0;
pRgbColol.Blue = 110;
pLineSymbol.Color = pRgbColol;
pLineSymbol.Width = 1;
pSimpleFillSymbol.Outline = pLineSymbol;
//填充符号颜色
pRgbColol = new RgbColorClass();
pRgbColol.Red = 229;
pRgbColol.Green = 103;
pRgbColol.Blue = 102;
pSimpleFillSymbol.Color = pRgbColol;
pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; //.esriSFSBackwardDiagonal;
//面元素设置
IFillShapeElement pFillShapeElement = (IFillShapeElement)pElement;
pFillShapeElement.Symbol = pSimpleFillSymbol;
pElement.Geometry = pGeometry;
return pElement;
}
private int SelectIndex = -1;
private void DgWYSketch_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
try
{
if (e.Key != Key.Enter)
{
return;
}
SelectIndex = this.dgWYSketch.SelectedIndex;
}
catch
{
SelectIndex = -1;
}
}
private void DgWYSketch_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
try
{
if (SelectIndex < 0)
{
return;
}
List listNew = this.dgWYSketch.ItemsSource as List;
WYSketch wySketch = listNew[SelectIndex] as WYSketch;
SelectIndex = -1;
if (wySketch != null)
{
RefreshBZ(wySketch);
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError("绘制标注描述异常:" + ex.Message);
}
}
private void RefreshBZ(WYSketch wYSketch)
{
try
{
this.hookHelper.ActiveView.GraphicsContainer.DeleteAllElements();
foreach (var item in this.NYYSInfo.WYSketch)
{
if (wYSketch != null && wYSketch.Geometry.Equals(item.Geometry))
{
LocationBZ(item);
}
else
{
LocationBZ(item, false);
}
}
this.hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
}
catch (Exception ex)
{
throw ex;
}
}
private void LocationBZ(WYSketch wySketch, bool isLocation = true)
{
try
{
if (wySketch.ObjectID > 0)
{
ILayer layer = null;
switch (wySketch.BZLX)
{
case "点":
layer = MapsManager.Instance.MapService.GetFeatureLayerByName("MarkPoint");
break;
case "线":
layer = MapsManager.Instance.MapService.GetFeatureLayerByName("MarkLine");
break;
case "面":
layer = MapsManager.Instance.MapService.GetFeatureLayerByName("MarkPolygon");
break;
}
if (layer != null)
{
IFeature feature = (layer as IFeatureLayer).FeatureClass.GetFeature(wySketch.ObjectID);
if (isLocation)
{
MapsManager.Instance.MapService.Zoom(feature.ShapeCopy);
}
return;
}
}
ESRI.ArcGIS.Geometry.IGeometry geometry = null;
//IElement element = null;
switch (wySketch.BZLX)
{
case "点":
geometry = ConverJsonToIGeoemtry(wySketch.Geometry, ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint);
geometry.Project(this.hookHelper.FocusMap.SpatialReference);
break;
case "线":
geometry = ConverJsonToIGeoemtry(wySketch.Geometry, ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline);
geometry.Project(this.hookHelper.FocusMap.SpatialReference);
break;
case "面":
geometry = ConverJsonToIGeoemtry(wySketch.Geometry);
geometry.Project(this.hookHelper.FocusMap.SpatialReference);
break;
}
MapsManager.Instance.MapService.DrawGraph(geometry);
if (!string.IsNullOrWhiteSpace(wySketch.BZMS))
this.hookHelper.ActiveView.GraphicsContainer.AddElement(TextElement(geometry, wySketch.BZMS), 1);
if (isLocation)
MapsManager.Instance.MapService.Zoom(geometry);
}
catch (Exception ex)
{
throw ex;
}
}
public List listDdeleteWYSketck { get; set; }
private void BtnClearData_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
if (MessageHelper.ShowYesNoAndTips("是否确定删除当前图斑所有标注?") != System.Windows.Forms.DialogResult.Yes)
{
return;
}
foreach (var item in this.NYYSInfo.WYSketch)
{
if (item.ObjectID > 0)
{
if (listDdeleteWYSketck == null)
{
listDdeleteWYSketck = new List();
}
listDdeleteWYSketck.Add(item);
}
}
this.NYYSInfo.WYSketch.Clear();
this.DataContext = null;
this.DataContext = this.NYYSInfo;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError("清空标注异常:" + ex.Message);
}
}
private void BzType_SelectedIndexChanged(object sender, System.Windows.RoutedEventArgs e)
{
try
{
BZToolSelected();
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void TxtYPSM_GotFocus(object sender, System.Windows.RoutedEventArgs e)
{
if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null)
{
(MapsManager.Instance.CurrProjectInfo as ProjectInfo).EnableShortcut = false;
}
}
private void TxtYPSM_LostFocus(object sender, System.Windows.RoutedEventArgs e)
{
if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null)
{
(MapsManager.Instance.CurrProjectInfo as ProjectInfo).EnableShortcut = true;
}
}
private void Txt_delete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
if ((sender as TextBlock) == null || (sender as TextBlock).Tag == null || (WYSketch)((sender as TextBlock).Tag) == null)
{
return;
}
WYSketch dr = ((WYSketch)((sender as TextBlock).Tag));
this.NYYSInfo.WYSketch.Remove(dr);
if (dr.ObjectID > 0)
{
if (listDdeleteWYSketck == null)
{
listDdeleteWYSketck = new List();
}
listDdeleteWYSketck.Add(dr);
}
this.DataContext = null;
this.DataContext = this.NYYSInfo;
RefreshBZ(null);
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void Txt_info_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
if ((sender as TextBlock) == null || (sender as TextBlock).Tag == null || (WYSketch)((sender as TextBlock).Tag) == null)
{
return;
}
WYSketch wySketch = ((WYSketch)((sender as TextBlock).Tag));
LocationBZ(wySketch);
}
catch (Exception ex)
{
MessageHelper.ShowError("定位失败:" + ex.Message);
}
}
}
}