FormIdentifyBySpatial.cs 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. //======================================================================
  2. //
  3. //
  4. //
  5. // CLR 版本: 4.0.30319.1
  6. // 命名空间: Tofly.SearchUI.Win
  7. // 类 名: FormIdentifyBySpatial
  8. // 创 建 人: 汤云伟
  9. // 创建时间: 2016/11/08 9:32:00
  10. // 修 改 人:
  11. // 修改时间:
  12. //
  13. //======================================================================
  14. using System;
  15. using System.Collections.Generic;
  16. using System.ComponentModel;
  17. using System.Drawing;
  18. using System.Data;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Windows.Forms;
  22. using Tofly.Core.Stereotype;
  23. using Tofly.Core.ServiceLocator;
  24. using Tofly.CoreUI.Control;
  25. using Tofly.CoreUI.Message;
  26. using Tofly.CoreUI.Plot;
  27. using Tofly.Data.General;
  28. using Tofly.GIS;
  29. using Tofly.GIS.Carto;
  30. using Tofly.GIS.Geometry;
  31. using Tofly.GIS.Util;
  32. using Tofly.GIS.SpatialDatabase;
  33. using Tofly.GISUI.Controls;
  34. using Tofly.GISUI.Utils;
  35. using Tofly.GIS.Display;
  36. using Tofly.Core.Context.Support;
  37. namespace Tofly.SearchUI.Win
  38. {
  39. /// <summary>
  40. /// 以空间查询实现图形识别类(查询图形的属性数据)
  41. /// </summary>
  42. [Component(IsSingleton = "false", Name = "Tofly.SearchUI.Win.FormIdentifyBySpatial")]
  43. public partial class FormIdentifyBySpatial : Tofly.CoreUI.Win.Form.Forms.FormClass, Tofly.SearchUI.Query.IFormIdentifyBySpatial
  44. {
  45. #region ----- 模块级变量 -----
  46. private const string TopMostLayer = "<最顶图层>";
  47. private const string SelectableLayers = "<可选图层>";
  48. private const string VisibleLayers = "<可见图层>";
  49. private const string AllLayers = "<所有图层>";
  50. /// <summary>
  51. /// 系统主接口
  52. /// </summary>
  53. private IPluginContent _mainContent;
  54. /// <summary>
  55. ///
  56. /// </summary>
  57. private IMap _cmap;
  58. /// <summary>
  59. /// 识别范围“图层”集合
  60. /// </summary>
  61. private List<CustomMapLayer> _lstIdentifyRange = new List<CustomMapLayer>();
  62. /// <summary>
  63. /// 参与识别工具的图层
  64. /// </summary>
  65. private List<IFeatureLayer> _lstIdentifyLayer = new List<IFeatureLayer>();
  66. /// <summary>
  67. /// 用于保存空间查询结果的字典
  68. /// </summary>
  69. private Dictionary<IFeatureLayer, List<IFeature>> _dicIdentifyResults = new Dictionary<IFeatureLayer, List<IFeature>>();
  70. /// <summary>
  71. /// 当前选择要素的数据对象
  72. /// </summary>
  73. private IFeatureLayer _layerSelected;
  74. /// <summary>
  75. /// 当前选择的要素
  76. /// </summary>
  77. private IFeature _ftrSelected;
  78. /// <summary>
  79. /// 是否正在查询附件
  80. /// </summary>
  81. private bool _bQueryingAttachments = false;
  82. #endregion
  83. #region ----- IFormIdentifyBySpatial 接口实现 -----
  84. /// <summary>
  85. /// 执行识别操作
  86. /// </summary>
  87. /// <param name="geomIdentify">进行失败操作的图形</param>
  88. public Dictionary<IFeatureLayer, List<IFeature>> DoIdentify(IGeometry geomIdentify)
  89. {
  90. //try
  91. //{
  92. if (this.IsDisposed) //确保窗口有效
  93. {
  94. return null;
  95. }
  96. this._layerSelected = null;
  97. this._ftrSelected = null;
  98. this.tvIdentifyResult.Nodes.Clear();
  99. this._dicIdentifyResults.Clear();
  100. this.ShowClickedNodeInfo(null, false); //清除表格数据
  101. Application.DoEvents();
  102. List<IFeatureLayer> __lstIdentifyLayers = this._lstIdentifyLayer;//this.GetIdentifyLayers(); //获取查询图层
  103. if (geomIdentify == null || __lstIdentifyLayers.Count == 0) //没有图层时不进行任何操作返回
  104. {
  105. return null;
  106. }
  107. this.lblFeatureCount.Text = "正在查询...";
  108. Application.DoEvents();
  109. Dictionary<IFeatureLayer, List<IFeature>> __dicIdentifyResult = this.ExecuteIdentify(__lstIdentifyLayers, geomIdentify); //对需查询的图层执行查询操作
  110. #region ----- 显示识别结果 -----
  111. if (this.identifyRange.IfTopLayers) //在识别结果中分析顶层图层
  112. {
  113. if (this._dicIdentifyResults.Count > 0) //通过图层树分析顶图层
  114. {
  115. List<ILayer> __lstIdentifiedLayers = this._dicIdentifyResults.Keys.Select(flyrItem => flyrItem as ILayer).ToList();
  116. ILayer __lyrTopLayer = this.GetTopMostLayer(__lstIdentifiedLayers);
  117. this._dicIdentifyResults = this._dicIdentifyResults.Where(kvItem => kvItem.Key == __lyrTopLayer).ToDictionary(kvItem => kvItem.Key, kvItem => kvItem.Value);
  118. }
  119. }
  120. int __iCount = this._dicIdentifyResults.Sum(kvLayerFeature => kvLayerFeature.Value.Count);
  121. if (__iCount > 1000)
  122. {
  123. throw new System.Exception("查看范围过大,结果超过1000个,请缩小查看范围。");
  124. }
  125. this.tvIdentifyResult.Nodes.Clear(); //快速连续点击时,可能出现并发处理的必要已有结果清除
  126. #region 选择要素的符号缩略图集合
  127. IBaseSymbolHelper __symolHelper = ContextRegistry.GetContext().GetObject("Tofly.GIS.ArcGIS.Util.BaseSymbolHelper") as IBaseSymbolHelper;
  128. ImageList __imgList = __symolHelper.GetSelectedFeaturesSymbol(this._dicIdentifyResults);
  129. //移除非设计时加载的图片(动态生成的要素符号缩略图)
  130. while (this.imgListTV.Images.Count > 6)
  131. {
  132. this.imgListTV.Images.RemoveAt(6);
  133. }
  134. for (int __iKey = 0; __iKey < __imgList.Images.Keys.Count; __iKey++)
  135. {
  136. this.imgListTV.Images.Add(__imgList.Images.Keys[__iKey], __imgList.Images[__imgList.Images.Keys[__iKey]]);
  137. }
  138. #endregion
  139. foreach (var __identifyResultItem in this._dicIdentifyResults)
  140. {
  141. TreeNode __tnLayer = this.tvIdentifyResult.Nodes.Add(__identifyResultItem.Key.Name); //图层节点
  142. string __strClassPrefix = __identifyResultItem.Key.FeatureClass.ObjectClassID.ToString();
  143. foreach (var __identifyObj in __identifyResultItem.Value)
  144. {
  145. //__tnLayer.Nodes.Add(__identifyObj.OID.ToString()); //要素节点
  146. __tnLayer.Nodes.Add(new TreeNode()
  147. {
  148. Text = __identifyObj.OID.ToString(),
  149. ImageKey = string.Format("{0}_{1}", __strClassPrefix, __identifyObj.OID)
  150. }); //要素节点
  151. }
  152. }
  153. this.tvIdentifyResult.ExpandAll(); //展开所有节点
  154. if (this.tvIdentifyResult.Nodes.Count > 0)
  155. {
  156. this.tvIdentifyResult.TopNode = tvIdentifyResult.Nodes[0]; //显示第一节点
  157. this.tvIdentifyResult.SelectedNode = tvIdentifyResult.Nodes[0]; //默认选中首节点
  158. }
  159. #endregion
  160. return __dicIdentifyResult;
  161. //}
  162. //catch (System.Exception ex)
  163. //{
  164. // if ((ex is System.NullReferenceException) == false)
  165. // {
  166. // MessageManager.Show(ex.Message, "执行查询");
  167. // }
  168. //}
  169. //return null;
  170. }
  171. /// <summary>
  172. /// 显示鼠标当前位置
  173. /// </summary>
  174. /// <param name="mapX"></param>
  175. /// <param name="mapY"></param>
  176. public void DisplayCoordinates(double mapX, double mapY)
  177. {
  178. if (this.IsDisposed)
  179. {
  180. return;
  181. }
  182. //鼠标在按下移动时显示当时坐标
  183. this.txtCoordinate.Text = string.Format("{0}, {1}", mapX.ToString("########.########"), mapY.ToString("########.########")) + " " + this.MapUnitChinese(this._cmap.MapUnits);
  184. }
  185. #endregion
  186. /// <summary>
  187. ///
  188. /// </summary>
  189. private FormIdentifyBySpatial()
  190. {
  191. InitializeComponent();
  192. tsbtnAttachFile.Visible = false;//隐藏“查看附件”
  193. this.identifyRange.DropHeight = this.Height * 2 / 3;
  194. this.identifyRange.LayerSelectedChanged += this.IdentifyRange_LayerSelectedChanged;
  195. this.ucsFeatureViewer.IsViewer = true; //设置属性控件模式
  196. }
  197. /// <summary>
  198. ///
  199. /// </summary>
  200. /// <param name="content">系统主接口</param>
  201. public FormIdentifyBySpatial(IPluginContent content)
  202. : this()
  203. {
  204. this._mainContent = content;
  205. }
  206. #region ----- 实现Singleton模式(单例) -----
  207. /// <summary>
  208. /// 获取唯一的识别结果窗口对象
  209. /// </summary>
  210. /// <param name="content"></param>
  211. /// <returns></returns>
  212. public static FormIdentifyBySpatial GetInstance(IPluginContent content)
  213. {
  214. return Nested.GetIdentifyForm(content);
  215. }
  216. /// <summary>
  217. /// 内嵌类,提供惟一的识别结果窗口对象
  218. /// </summary>
  219. private class Nested
  220. {
  221. private static FormIdentifyBySpatial _frmIndentify;
  222. /// <summary>
  223. /// 获取识别结果窗口对象实例
  224. /// </summary>
  225. /// <param name="content"></param>
  226. /// <returns></returns>
  227. internal static FormIdentifyBySpatial GetIdentifyForm(IPluginContent content)
  228. {
  229. if (Nested._frmIndentify == null || Nested._frmIndentify.IsDisposed)
  230. {
  231. Nested._frmIndentify = new FormIdentifyBySpatial(content);
  232. }
  233. return Nested._frmIndentify;
  234. }
  235. }
  236. #endregion
  237. /// <summary>
  238. /// 窗体初始化时加载图层过滤器
  239. /// </summary>
  240. /// <param name="sender"></param>
  241. /// <param name="e"></param>
  242. private void FormIdentifyBySpatial_Load(object sender, EventArgs e)
  243. {
  244. try
  245. {
  246. IMapControl __cmapControl = ServiceLocatorFactory.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl;
  247. this._cmap = __cmapControl.Map;
  248. this._mainContent.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
  249. this.pbarIdentify.Visible = false; //隐藏进度条
  250. this.identifyRange.InitLayer(); //初始化图层树
  251. this.IdentifyRange_LayerSelectedChanged(null); //初始化识别图层集合
  252. this.ucsFeatureViewer.CMap = this._cmap; //设置属性浏览控件的地图引起
  253. }
  254. catch { }
  255. }
  256. /// <summary>
  257. ///
  258. /// </summary>
  259. /// <param name="sender"></param>
  260. /// <param name="e"></param>
  261. private void FormIdentifyBySpatial_Deactivate(object sender, EventArgs e)
  262. {
  263. //this.tvIdentifyRange_Leave(null, null);
  264. }
  265. /// <summary>
  266. ///
  267. /// </summary>
  268. /// <param name="sender"></param>
  269. /// <param name="e"></param>
  270. private void FormIdentifyBySpatial_FormClosed(object sender, FormClosedEventArgs e)
  271. {
  272. //清空列表
  273. this._lstIdentifyRange.Clear();
  274. this._dicIdentifyResults.Clear();
  275. this.identifyRange.LayerSelectedChanged -= this.IdentifyRange_LayerSelectedChanged;
  276. }
  277. private void tvIdentifyResult_AfterSelect(object sender, TreeViewEventArgs e)
  278. {
  279. try
  280. {
  281. if (e != null)
  282. {
  283. this.ShowClickedNodeInfo(e.Node, true); //显示选中要素的数据
  284. }
  285. }
  286. catch (System.Exception ex)
  287. {
  288. MessageManager.Show(ex.Message, "查看台帐");
  289. }
  290. }
  291. private void tvIdentifyRange_Leave(object sender, EventArgs e)
  292. {
  293. //this.tvIdentifyRange.Visible = false;
  294. }
  295. private void tvIdentifyRange_AfterSelect(object sender, TreeViewEventArgs e)
  296. {
  297. //try
  298. //{
  299. // if (e != null)
  300. // {
  301. // this.cmbIdentifyType.Items.Clear();
  302. // this.cmbIdentifyType.Items.Add(e.Node.Text);
  303. // this.cmbIdentifyType.SelectedIndex = 0;
  304. // this.cmbIdentifyType.Focus();
  305. // }
  306. //}
  307. //catch(System.Exception ex)
  308. //{
  309. // MessageManager.Show("设置识别范围失败:" + ex.Message);
  310. //}
  311. }
  312. private void cmbLayerFilter_Click(object sender, EventArgs e)
  313. {
  314. //if (this.tvIdentifyRange.Nodes.Count > 0)
  315. //{
  316. // if (!this.tvIdentifyRange.Visible)
  317. // {
  318. // if (this.tvIdentifyRange.SelectedNode == null)
  319. // {
  320. // string __strIdentifyRange = this.cmbIdentifyType.Text;
  321. // TreeNode[] __arrNodeMatched = this.tvIdentifyRange.Nodes.Find(__strIdentifyRange, true);
  322. // if (__arrNodeMatched.Length > 0)
  323. // {
  324. // this.tvIdentifyRange.SelectedNode = __arrNodeMatched[0];
  325. // }
  326. // this.tvIdentifyRange.TopNode = this.tvIdentifyRange.Nodes[0];
  327. // }
  328. // this.tvIdentifyRange.Width = this.cmbIdentifyType.Width;
  329. // this.tvIdentifyRange.Height = 200;
  330. // this.tvIdentifyRange.Left = this.cmbIdentifyType.Left;
  331. // this.tvIdentifyRange.Top = this.cmbIdentifyType.Top + this.cmbIdentifyType.Height;
  332. // this.tvIdentifyRange.Visible = true;
  333. // this.tvIdentifyRange.Focus();
  334. // }
  335. // else
  336. // {
  337. // this.tvIdentifyRange.Visible = false;
  338. // }
  339. //}
  340. }
  341. /// <summary>
  342. /// 查看设备要素附件
  343. /// </summary>
  344. /// <param name="sender"></param>
  345. /// <param name="e"></param>
  346. private void tsbtnAttachFile_Click(object sender, EventArgs e)
  347. {
  348. try
  349. {
  350. if (this._ftrSelected == null || this._bQueryingAttachments)
  351. {
  352. return;
  353. }
  354. #region ------------ 查询/查看附件 ------------
  355. Tofly.CoreUI.Control.IForm pForm = Tofly.Core.Context.Support.ContextRegistry.GetContext().GetObject("FormFTPManager", new object[] { this._ftrSelected,false }) as Tofly.CoreUI.Control.IForm;
  356. pForm.ShowDialog();
  357. #endregion
  358. }
  359. catch (System.Exception ex)
  360. {
  361. MessageManager.Show(string.Format("获取失败:{0}", ex.Message), "查看要素附件");
  362. }
  363. }
  364. private void tsbtnCreateSelectionset_Click(object sender, EventArgs e)
  365. {
  366. try
  367. {
  368. this._cmap.ClearSelection();
  369. this._cmap.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, this._cmap.Extent);
  370. List<int> __lstFeatureOIDs = new List<int>();
  371. foreach (var __identifyResult in this._dicIdentifyResults)
  372. {
  373. __lstFeatureOIDs.Clear();
  374. __lstFeatureOIDs.AddRange(__identifyResult.Value.Select(feat => feat.OID));
  375. __identifyResult.Key.AddSelectFeatureList(__lstFeatureOIDs); //图层选择集更新
  376. }
  377. this._cmap.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, this._cmap.Extent);
  378. MessageManager.Show(string.Format("生成选择集成功."));
  379. }
  380. catch(System.Exception ex)
  381. {
  382. MessageManager.Show(string.Format("生成失败:{0}", ex.Message), "生成选择集");
  383. }
  384. }
  385. private void tsbtnFlashSelected_Click(object sender, EventArgs e)
  386. {
  387. try
  388. {
  389. if (this.tvIdentifyResult.SelectedNode != null)
  390. {
  391. IGeometry[] __arrShineGeoms = new IGeometry[0];
  392. if (this.tvIdentifyResult.SelectedNode.Nodes.Count == 0) //选择要素节点
  393. {
  394. __arrShineGeoms = new IGeometry[] { this._ftrSelected.ShapeCopy };
  395. }
  396. else //图层节点
  397. {
  398. var __kvSelectedFeatureByLayer = this._dicIdentifyResults.First(kvItem => kvItem.Key.Name == this.tvIdentifyResult.SelectedNode.Text);
  399. __arrShineGeoms = __kvSelectedFeatureByLayer.Value.Select(feat => feat.ShapeCopy as IGeometry).ToArray();
  400. }
  401. this._cmap.FlashGeometry(this._cmap.ActiveView, __arrShineGeoms, 1, 200); //闪烁选择要素
  402. }
  403. }
  404. catch { }
  405. }
  406. private void FormIdentifyBySpatial_MouseEnter(object sender, EventArgs e)
  407. {
  408. if (!this.Focused)
  409. {
  410. this.Focus();
  411. }
  412. }
  413. private void tvIdentifyResult_MouseUp(object sender,System.Windows.Forms.MouseEventArgs e)
  414. {
  415. try
  416. {
  417. var __nodeMouseDown = this.tvIdentifyResult.GetNodeAt(e.Location);
  418. if (e.Button == System.Windows.Forms.MouseButtons.Right)
  419. {
  420. //var __nodeMouseDown = this.tvIdentifyResult.GetNodeAt(e.Location);
  421. if (__nodeMouseDown != null)
  422. {
  423. if (__nodeMouseDown != this.tvIdentifyResult.SelectedNode)
  424. {
  425. this.tvIdentifyResult.SelectedNode = __nodeMouseDown; //更新选中的节点
  426. }
  427. this.contextMenuTree.Show(this.tvIdentifyResult, e.Location);
  428. }
  429. }
  430. else if (e.Button == System.Windows.Forms.MouseButtons.Left)
  431. {
  432. if (this.tvIdentifyResult.SelectedNode != null && __nodeMouseDown == this.tvIdentifyResult.SelectedNode) //只在当前节点重复点击时,触发
  433. {
  434. this.tsbtnFlashSelected.PerformClick(); //触发要素闪烁
  435. }
  436. }
  437. }
  438. catch { }
  439. }
  440. /// <summary>
  441. /// 弹出菜单点击事件处理
  442. /// </summary>
  443. /// <param name="sender"></param>
  444. /// <param name="e"></param>
  445. private void contextMenuTree_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  446. {
  447. try
  448. {
  449. if (e == null)
  450. {
  451. return;
  452. }
  453. List<IFeature> __lstFeatureSelected = new List<IFeature>();
  454. KeyValuePair<IFeatureLayer, List<IFeature>> __kvSelectedFeatureByLayer = new KeyValuePair<IFeatureLayer, List<IFeature>>();
  455. if (this.tvIdentifyResult.SelectedNode.Nodes.Count == 0) //要素节点
  456. {
  457. __kvSelectedFeatureByLayer = this._dicIdentifyResults.First(kvItem => kvItem.Key.Name == this.tvIdentifyResult.SelectedNode.Parent.Text);
  458. __lstFeatureSelected.Add(__kvSelectedFeatureByLayer.Value.Find(ftrItem => ftrItem.OID == Convert.ToInt32(this.tvIdentifyResult.SelectedNode.Text)));
  459. }
  460. else //图层节点
  461. {
  462. __kvSelectedFeatureByLayer = this._dicIdentifyResults.First(kvItem => kvItem.Key.Name == this.tvIdentifyResult.SelectedNode.Text);
  463. __lstFeatureSelected.AddRange(__kvSelectedFeatureByLayer.Value);
  464. }
  465. if (e.ClickedItem == this.miFlashFeature)
  466. {
  467. List<IGeometry> __lstFeatureGeoms = new List<IGeometry>();
  468. foreach (var __ftrSel in __lstFeatureSelected)
  469. {
  470. __lstFeatureGeoms.Add(__ftrSel.ShapeCopy);
  471. }
  472. this._cmap.FlashGeometry(this._cmap.ActiveView, __lstFeatureGeoms.ToArray(), 1, 200); //闪烁选择要素
  473. }
  474. else if (e.ClickedItem == this.miZoomTo)
  475. {
  476. IEnvelope __gEnv = MapSelectionHelper.GetFeaturesEnvelope(__lstFeatureSelected);
  477. this._cmap.ActiveView.Extent = __gEnv;
  478. this._cmap.PartialRefresh(ViewDrawPhase.ViewGeography | ViewDrawPhase.ViewGeoSelection, null, null);
  479. }
  480. else if (e.ClickedItem == this.miPanTo)
  481. {
  482. IEnvelope __gEnvNew = MapSelectionHelper.GetFeaturesEnvelope(__lstFeatureSelected);
  483. IEnvelope __gEnvCurrent = this._cmap.Extent;
  484. __gEnvCurrent.CenterAt(__gEnvNew.GetCentroid());
  485. this._cmap.ActiveView.Extent = __gEnvCurrent;
  486. this._cmap.PartialRefresh(ViewDrawPhase.ViewGeography | ViewDrawPhase.ViewGeoSelection, null, null);
  487. }
  488. Application.DoEvents();
  489. }
  490. catch(System.Exception ex)
  491. {
  492. MessageManager.Show(ex.Message, "要素识别");
  493. }
  494. }
  495. #region ----- 事件处理 -----
  496. /// <summary>
  497. ///
  498. /// </summary>
  499. /// <param name="sender"></param>
  500. private void IdentifyRange_LayerSelectedChanged(object sender)
  501. {
  502. List<ILayer> __lstSelectLayer = this.identifyRange.SelectNodeLayers();
  503. this._lstIdentifyLayer.Clear();
  504. foreach (var __layer in __lstSelectLayer)
  505. {
  506. if (__layer is IFeatureLayer)
  507. {
  508. this._lstIdentifyLayer.Add(__layer as IFeatureLayer);
  509. }
  510. }
  511. }
  512. /// <summary>
  513. ///
  514. /// </summary>
  515. /// <param name="key"></param>
  516. /// <param name="value"></param>
  517. private void ServiceLocator_ServiceValueChange(string key, object value)
  518. {
  519. try
  520. {
  521. if (key.Equals(ServiceLocatorKeys.MapDocument))
  522. {
  523. this.DoIdentify(null); //执行空识别
  524. }
  525. }
  526. catch { }
  527. }
  528. ///// <summary>
  529. ///// 地图切换(更改)事件
  530. ///// </summary>
  531. ///// <param name="sender"></param>
  532. ///// <param name="e"></param>
  533. //private void Map_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
  534. //{
  535. // this.OnIdentifyRangeChanged(null); //加载过滤器列表
  536. // this.DoIdentify(null); //执行空识别
  537. //}
  538. /// <summary>
  539. /// 识别范围改变事件处理
  540. /// </summary>
  541. private void OnIdentifyRangeChanged(object item)
  542. {
  543. this._lstIdentifyRange.Clear();
  544. #region ----- 装载逻辑图层 -----
  545. CustomMapLayer topMostLayerProperty = new CustomMapLayer() //最顶图层
  546. {
  547. Category = TopMostLayer,
  548. FeatureType = tfLayerFeatureType.LayerFeatureLogic,
  549. LayerAliasName = TopMostLayer,
  550. SourceLayer = null,
  551. Valid = true
  552. };
  553. CustomMapLayer visibleLayerProperty = new CustomMapLayer() //可见图层
  554. {
  555. Category = VisibleLayers,
  556. FeatureType = tfLayerFeatureType.LayerFeatureLogic,
  557. LayerAliasName = VisibleLayers,
  558. SourceLayer = null,
  559. Valid = true
  560. };
  561. CustomMapLayer selectableLayerProperty = new CustomMapLayer() //可选图层
  562. {
  563. Category = SelectableLayers,
  564. FeatureType = tfLayerFeatureType.LayerFeatureLogic,
  565. LayerAliasName = SelectableLayers,
  566. SourceLayer = null,
  567. Valid = true
  568. };
  569. CustomMapLayer allLayerProperty = new CustomMapLayer() //所有图层
  570. {
  571. Category = AllLayers,
  572. FeatureType = tfLayerFeatureType.LayerFeatureLogic,
  573. LayerAliasName = AllLayers,
  574. SourceLayer = null,
  575. Valid = true
  576. };
  577. this._lstIdentifyRange.Add(topMostLayerProperty);
  578. this._lstIdentifyRange.Add(visibleLayerProperty);
  579. this._lstIdentifyRange.Add(selectableLayerProperty);
  580. this._lstIdentifyRange.Add(allLayerProperty);
  581. #endregion
  582. //List<CustomMapLayer> __lstTreeLayer = FeatureLayerHelper.GetTreeCustomLayer(this._arcHelper.FocusMap); //获取地图中树状图层集合
  583. //this._lstIdentifyRange.AddRange(__lstTreeLayer);
  584. #region ------- 呈现识别范围 -------
  585. //List<tfLayerFeatureType> __lstExceptedLayerType = new List<tfLayerFeatureType>() //排除识别的图层类型
  586. //{
  587. // tfLayerFeatureType.LayerFeatureUnknown,
  588. // tfLayerFeatureType.LayerFeatureRaster,
  589. //};
  590. //this.cmbIdentifyType.Items.Add(FormIdentifyBySpatial.SelectableLayers);
  591. //this.cmbIdentifyType.SelectedIndex = 0;
  592. //foreach (CustomMapLayer __custMapLayerItem in _lstIdentifyRange)
  593. //{
  594. // if (__custMapLayerItem.Valid && !__lstExceptedLayerType.Contains(__custMapLayerItem.FeatureType))
  595. // {
  596. // TreeNode __tnRootItem = new TreeNode(__custMapLayerItem.LayerAliasName)
  597. // {
  598. // Name = __custMapLayerItem.LayerAliasName,
  599. // Tag = __custMapLayerItem
  600. // };
  601. // switch (__custMapLayerItem.FeatureType)
  602. // {
  603. // case tfLayerFeatureType.LayerFeatureGroupLayer:
  604. // __tnRootItem.ImageKey = "LayerGroup";
  605. // __tnRootItem.SelectedImageKey = "LayerGroup";
  606. // break;
  607. // case tfLayerFeatureType.LayerFeatureLogic:
  608. // __tnRootItem.ImageKey = "LayerLogic";
  609. // __tnRootItem.SelectedImageKey = "LayerLogic";
  610. // break;
  611. // case tfLayerFeatureType.LayerFeaturePoint:
  612. // __tnRootItem.ImageKey = "LayerPoint";
  613. // __tnRootItem.SelectedImageKey = "LayerPoint";
  614. // break;
  615. // case tfLayerFeatureType.LayerFeaturePolyline:
  616. // __tnRootItem.ImageKey = "LayerLine";
  617. // __tnRootItem.SelectedImageKey = "LayerLine";
  618. // break;
  619. // case tfLayerFeatureType.LayerFeaturePolygon:
  620. // __tnRootItem.ImageKey = "LayerPolygon";
  621. // __tnRootItem.SelectedImageKey = "LayerPolygon";
  622. // break;
  623. // }
  624. // if (__custMapLayerItem.FeatureType == tfLayerFeatureType.LayerFeatureGroupLayer)
  625. // {
  626. // List<TreeNode> __lstSubLayerNodes = this.GetSubLayerNodes(__custMapLayerItem);
  627. // __tnRootItem.Nodes.AddRange(__lstSubLayerNodes.ToArray());
  628. // }
  629. // this.tvIdentifyRange.Nodes.Add(__tnRootItem);
  630. // }
  631. //}
  632. //this.tvIdentifyRange.ExpandAll();
  633. #endregion
  634. }
  635. #endregion
  636. #region ----- < 指定图层过滤器的获取方法 > -----
  637. /// <summary>
  638. /// 获取所有图层
  639. /// </summary>
  640. private List<ILayer> getAllLayers
  641. {
  642. get
  643. {
  644. List<ILayer> __lstSourceLayer = new List<ILayer>();
  645. List<tfLayerFeatureType> __lstExceptedLayerType = new List<tfLayerFeatureType>() //排除识别的图层类型
  646. {
  647. tfLayerFeatureType.LayerFeatureLogic,
  648. tfLayerFeatureType.LayerFeatureUnknown,
  649. tfLayerFeatureType.LayerFeatureRaster
  650. };
  651. foreach (CustomMapLayer __custMapLayerItem in this._lstIdentifyRange)
  652. {
  653. if (__custMapLayerItem.Valid && !__lstExceptedLayerType.Contains(__custMapLayerItem.FeatureType))
  654. {
  655. if (__custMapLayerItem.FeatureType == tfLayerFeatureType.LayerFeatureGroupLayer)
  656. {
  657. List<ILayer> __lstSubLayerSource = this.GetSubLayerSource(__custMapLayerItem);
  658. __lstSourceLayer.AddRange(__lstSubLayerSource);
  659. }
  660. else
  661. {
  662. __lstSourceLayer.Add(__custMapLayerItem.SourceLayer);
  663. }
  664. }
  665. }
  666. return __lstSourceLayer;
  667. }
  668. }
  669. /// <summary>
  670. /// 获取所有可选图层
  671. /// </summary>
  672. private List<ILayer> getSelectableLayers
  673. {
  674. get
  675. {
  676. List<ILayer> __lstSourceLayers = this.getAllLayers;
  677. __lstSourceLayers.RemoveAll(layerItem => !((IFeatureLayer)layerItem).Selectable);
  678. __lstSourceLayers.RemoveAll(layerItem => !layerItem.Visible);
  679. return __lstSourceLayers;
  680. }
  681. }
  682. /// <summary>
  683. /// 获取所有可见图层
  684. /// </summary>
  685. private List<ILayer> getVisibleLayers
  686. {
  687. get
  688. {
  689. //List<ILayer> __lstSourceLayers = this.getAllLayers;
  690. //__lstSourceLayers.RemoveAll(layerItem => !layerItem.Visible);
  691. List<ILayer> __lstSourceLayers = new List<ILayer>();
  692. List<tfLayerFeatureType> __lstExceptedLayerType = new List<tfLayerFeatureType>() //排除识别的图层类型
  693. {
  694. tfLayerFeatureType.LayerFeatureLogic,
  695. tfLayerFeatureType.LayerFeatureUnknown,
  696. tfLayerFeatureType.LayerFeatureRaster
  697. };
  698. foreach (CustomMapLayer __custMapLayerItem in this._lstIdentifyRange)
  699. {
  700. if (__custMapLayerItem.Valid && !__lstExceptedLayerType.Contains(__custMapLayerItem.FeatureType) && __custMapLayerItem.SourceLayer.Visible)
  701. {
  702. if (__custMapLayerItem.FeatureType == tfLayerFeatureType.LayerFeatureGroupLayer)
  703. {
  704. List<ILayer> __lstSubLayerSource = this.GetSubLayerSource(__custMapLayerItem);
  705. __lstSourceLayers.AddRange(__lstSubLayerSource);
  706. }
  707. else
  708. {
  709. __lstSourceLayers.Add(__custMapLayerItem.SourceLayer);
  710. }
  711. }
  712. }
  713. __lstSourceLayers.RemoveAll(lyrItem => !lyrItem.Visible); //排除可能的图层组中的不可见子图层
  714. return __lstSourceLayers;
  715. }
  716. }
  717. ///// <summary>
  718. ///// 获取图层过滤器中的图层
  719. ///// </summary>
  720. //private CustomMapLayer getTargetLayer
  721. //{
  722. // get
  723. // {
  724. // int selectedIndex = cmbIdentifyType.SelectedIndex;
  725. // return _lstIdentifyRange[selectedIndex];
  726. // }
  727. //}
  728. /// <summary>
  729. /// 获取最顶图层
  730. /// </summary>
  731. private CustomMapLayer getTopmostLayer
  732. {
  733. //必须保证index为0的图层不是GroupLayer或CompositeLayer
  734. get
  735. {
  736. CustomMapLayer layer = null;
  737. int layerCount = _lstIdentifyRange.Count;
  738. for (int i = 4; i < layerCount; i++)
  739. {
  740. CustomMapLayer layerProp = _lstIdentifyRange[i];
  741. ILayer esriLayer = layerProp.SourceLayer;
  742. if (!(esriLayer is IGroupLayer) &&
  743. !(esriLayer is ICompositeLayer))
  744. {
  745. layer = layerProp;
  746. break;
  747. }
  748. }
  749. return layer;
  750. }
  751. }
  752. #endregion
  753. #region ----- 其他私有方法 -----
  754. /// <summary>
  755. /// 显示中文地图单位
  756. /// </summary>
  757. /// <param name="mapUnit"></param>
  758. /// <returns></returns>
  759. private string MapUnitChinese(Units mapUnit)
  760. {
  761. string mapUnitChinese = "未知单位";
  762. switch (mapUnit)
  763. {
  764. case Units.Centimeters:
  765. mapUnitChinese = "厘米";
  766. break;
  767. case Units.DecimalDegrees:
  768. mapUnitChinese = "分米";
  769. break;
  770. case Units.Decimeters:
  771. mapUnitChinese = "";
  772. break;
  773. //case Units.Feet:
  774. // mapUnitChinese = "";
  775. // break;
  776. //case Units.Inches:
  777. // mapUnitChinese = "";
  778. // break;
  779. case Units.Kilometers:
  780. mapUnitChinese = "千米";
  781. break;
  782. case Units.Meters:
  783. mapUnitChinese = "米";
  784. break;
  785. case Units.Miles:
  786. mapUnitChinese = "英里";
  787. break;
  788. case Units.Millimeters:
  789. mapUnitChinese = "毫米";
  790. break;
  791. //case Units.Yards:
  792. // mapUnitChinese = "";
  793. // break;
  794. }
  795. return mapUnitChinese;
  796. }
  797. /// <summary>
  798. /// 获取组图层中子图层集合的树节点集合
  799. /// </summary>
  800. /// <param name="groupLayer"></param>
  801. /// <returns></returns>
  802. private List<TreeNode> GetSubLayerNodes(CustomMapLayer groupLayer)
  803. {
  804. List<TreeNode> __lstLayerNodes = new List<TreeNode>();
  805. List<tfLayerFeatureType> __lstExceptedLayerType = new List<tfLayerFeatureType>() //排除识别的图层类型
  806. {
  807. tfLayerFeatureType.LayerFeatureLogic,
  808. tfLayerFeatureType.LayerFeatureUnknown,
  809. tfLayerFeatureType.LayerFeatureRaster
  810. };
  811. foreach (CustomMapLayer __custMapLayerItem in groupLayer.SubLayers)
  812. {
  813. if (__custMapLayerItem.Valid && !__lstExceptedLayerType.Contains(__custMapLayerItem.FeatureType))
  814. {
  815. TreeNode __tnRootItem = new TreeNode(__custMapLayerItem.LayerAliasName)
  816. {
  817. Name = __custMapLayerItem.LayerAliasName,
  818. Tag = __custMapLayerItem
  819. };
  820. switch (__custMapLayerItem.FeatureType)
  821. {
  822. case tfLayerFeatureType.LayerFeatureGroupLayer:
  823. __tnRootItem.ImageKey = "LayerGroup";
  824. __tnRootItem.SelectedImageKey = "LayerGroup";
  825. break;
  826. case tfLayerFeatureType.LayerFeatureLogic:
  827. __tnRootItem.ImageKey = "LayerLogic";
  828. __tnRootItem.SelectedImageKey = "LayerLogic";
  829. break;
  830. case tfLayerFeatureType.LayerFeaturePoint:
  831. __tnRootItem.ImageKey = "LayerPoint";
  832. __tnRootItem.SelectedImageKey = "LayerPoint";
  833. break;
  834. case tfLayerFeatureType.LayerFeaturePolyline:
  835. __tnRootItem.ImageKey = "LayerLine";
  836. __tnRootItem.SelectedImageKey = "LayerLine";
  837. break;
  838. case tfLayerFeatureType.LayerFeaturePolygon:
  839. __tnRootItem.ImageKey = "LayerPolygon";
  840. __tnRootItem.SelectedImageKey = "LayerPolygon";
  841. break;
  842. }
  843. if (__custMapLayerItem.FeatureType == tfLayerFeatureType.LayerFeatureGroupLayer)
  844. {
  845. List<TreeNode> __lstSubLayerNodes = this.GetSubLayerNodes(__custMapLayerItem);
  846. __tnRootItem.Nodes.AddRange(__lstSubLayerNodes.ToArray());
  847. }
  848. __lstLayerNodes.Add(__tnRootItem);
  849. }
  850. }
  851. return __lstLayerNodes;
  852. }
  853. /// <summary>
  854. /// 获取组图层中子图层的源图层对象集合
  855. /// </summary>
  856. /// <param name="groupLayer"></param>
  857. /// <returns></returns>
  858. private List<ILayer> GetSubLayerSource(CustomMapLayer groupLayer)
  859. {
  860. List<ILayer> __lstSourceLayer = new List<ILayer>();
  861. List<tfLayerFeatureType> __lstExceptedLayerType = new List<tfLayerFeatureType>() //排除识别的图层类型
  862. {
  863. tfLayerFeatureType.LayerFeatureLogic,
  864. tfLayerFeatureType.LayerFeatureUnknown,
  865. tfLayerFeatureType.LayerFeatureRaster
  866. };
  867. foreach (CustomMapLayer __custMapLayerItem in groupLayer.SubLayers)
  868. {
  869. if (__custMapLayerItem.Valid && !__lstExceptedLayerType.Contains(__custMapLayerItem.FeatureType))
  870. {
  871. if (__custMapLayerItem.FeatureType == tfLayerFeatureType.LayerFeatureGroupLayer)
  872. {
  873. List<ILayer> __lstSubLayerSource = this.GetSubLayerSource(__custMapLayerItem);
  874. __lstSourceLayer.AddRange(__lstSubLayerSource);
  875. }
  876. else
  877. {
  878. __lstSourceLayer.Add(__custMapLayerItem.SourceLayer);
  879. }
  880. }
  881. }
  882. return __lstSourceLayer;
  883. }
  884. /// <summary>
  885. /// 获取需要进识别的图层集合
  886. /// </summary>
  887. /// <returns></returns>
  888. private List<ILayer> GetIdentifyLayers()
  889. {
  890. List<ILayer> __lstIdentifyLayers = new List<ILayer>();
  891. //string __identifyType = this.cmbIdentifyType.Text.Trim(); //获取过滤文本
  892. //switch (__identifyType)
  893. //{
  894. // case AllLayers:
  895. // __lstIdentifyLayers = this.getAllLayers;
  896. // break;
  897. // case SelectableLayers:
  898. // __lstIdentifyLayers = this.getSelectableLayers;
  899. // break;
  900. // case VisibleLayers:
  901. // __lstIdentifyLayers = this.getVisibleLayers;
  902. // break;
  903. // case TopMostLayer:
  904. // __lstIdentifyLayers = this.getSelectableLayers; //模拟先对所有可选图层进行识别
  905. // break;
  906. // default:
  907. // TreeNode[] __arrNodeSelected = this.tvIdentifyRange.Nodes.Find(__identifyType, true);
  908. // CustomMapLayer __custLayerSelected = __arrNodeSelected[0].Tag as CustomMapLayer;
  909. // if (__custLayerSelected.FeatureType == tfLayerFeatureType.LayerFeatureGroupLayer)
  910. // {
  911. // __lstIdentifyLayers.AddRange(this.GetSubLayerSource(__custLayerSelected));
  912. // }
  913. // else
  914. // {
  915. // __lstIdentifyLayers.Add(__custLayerSelected.SourceLayer);
  916. // }
  917. // break;
  918. //}
  919. return __lstIdentifyLayers;
  920. }
  921. /// <summary>
  922. /// 执行识别查询
  923. /// </summary>
  924. /// <param name="identifyLayers">进行识别的图层集合</param>
  925. /// <param name="geomIdentify">识别范围图形</param>
  926. private Dictionary<IFeatureLayer, List<IFeature>> ExecuteIdentify(List<IFeatureLayer> identifyLayers, IGeometry geomIdentify)
  927. {
  928. //Dictionary<IFeatureLayer, List<IFeature>> __dicSelectedFeatureByLayer = new Dictionary<IFeatureLayer, List<IFeature>>();
  929. #region ----- 显示处理进度 -----
  930. this.pbarIdentify.Visible = true;
  931. this.pbarIdentify.Maximum = 10;
  932. this.pbarIdentify.Minimum = 0;
  933. this.pbarIdentify.Value = 0;
  934. #endregion
  935. Dictionary<object, List<object>> __dicFeaturesByLayer = new Dictionary<object, List<object>>();
  936. List<ILayer> __lstIdenLayer = identifyLayers.Select(flayer => flayer as ILayer).ToList();
  937. Dictionary<object, List<object>> __dicTempLayerRow = this._cmap.GetSelectedFeaturesByGeometry(__lstIdenLayer, geomIdentify);
  938. if (this.identifyRange.IfTopLayers)
  939. {
  940. if (__dicTempLayerRow != null && __dicTempLayerRow.Count != 0)
  941. {
  942. foreach (KeyValuePair<object, List<object>> __kvLayerRow in __dicTempLayerRow)
  943. {
  944. __dicFeaturesByLayer.Add(__kvLayerRow.Key, __kvLayerRow.Value);
  945. break;
  946. }
  947. }
  948. }
  949. else
  950. {
  951. __dicFeaturesByLayer = __dicTempLayerRow;
  952. }
  953. this.pbarIdentify.Maximum = __dicFeaturesByLayer.Count; //更新进度条最大值
  954. IFeatureLayer __flayer = null;
  955. foreach (var __kvFeatureByLayer in __dicFeaturesByLayer)
  956. {
  957. __flayer = __kvFeatureByLayer.Key as IFeatureLayer;
  958. if (this._dicIdentifyResults.ContainsKey(__flayer) == false)
  959. {
  960. this._dicIdentifyResults.Add(__kvFeatureByLayer.Key as IFeatureLayer, __kvFeatureByLayer.Value.Select(objSel => objSel as IFeature).ToList()); //追加识别结果
  961. }
  962. else
  963. {
  964. }
  965. #region ----- 显示处理进度 -----
  966. if ((this.pbarIdentify.Value + 1) > this.pbarIdentify.Maximum)
  967. {
  968. this.pbarIdentify.Value = 0;
  969. }
  970. this.pbarIdentify.Value += 1;
  971. Application.DoEvents();
  972. #endregion
  973. }
  974. this.pbarIdentify.Value = this.pbarIdentify.Maximum;
  975. int __identifiedObjCount = 0; //查询得到的要素的数量
  976. if (this._dicIdentifyResults.Count > 0)
  977. {
  978. __identifiedObjCount = this._dicIdentifyResults.Sum(kvSelFeaturesByLayer => kvSelFeaturesByLayer.Value.Count);
  979. }
  980. this.pbarIdentify.Visible = false; //隐藏进度条
  981. this.lblFeatureCount.Text = "查询到 " + __identifiedObjCount + " 条记录"; //显示查询到的要素数量
  982. return this._dicIdentifyResults;
  983. }
  984. /// <summary>
  985. /// 显示选择节点的信息
  986. /// </summary>
  987. /// <param name="nodeClicked">被点击节点</param>
  988. /// <param name="doFlash">是否闪烁</param>
  989. private void ShowClickedNodeInfo(TreeNode nodeClicked, bool doFlash)
  990. {
  991. try
  992. {
  993. if (nodeClicked == null)
  994. {
  995. this.ShowFeatureAttributes(null, null); //清空显示表格数据
  996. }
  997. else
  998. {
  999. KeyValuePair<IFeatureLayer, List<IFeature>> __kvSelectedFeatureByLayer = new KeyValuePair<IFeatureLayer, List<IFeature>>();
  1000. int __iFeatureIndex = -1;
  1001. if (nodeClicked.Nodes.Count == 0) //要素节点
  1002. {
  1003. __iFeatureIndex = nodeClicked.Index;
  1004. __kvSelectedFeatureByLayer = this._dicIdentifyResults.First(kvItem => kvItem.Key.Name == nodeClicked.Parent.Text);
  1005. }
  1006. else //图层节点
  1007. {
  1008. __kvSelectedFeatureByLayer = this._dicIdentifyResults.First(kvItem => kvItem.Key.Name == nodeClicked.Text);
  1009. }
  1010. this._layerSelected = __kvSelectedFeatureByLayer.Key; //设置当前选择图层
  1011. if (__iFeatureIndex > -1) //点击了图层下的要素
  1012. {
  1013. this._ftrSelected = __kvSelectedFeatureByLayer.Value.Find(ftrItem => ftrItem.OID == Convert.ToInt32(nodeClicked.Text));
  1014. this.ShowFeatureAttributes(__kvSelectedFeatureByLayer.Key, this._ftrSelected);
  1015. //判断是否闪烁要素
  1016. if (doFlash)
  1017. {
  1018. IGeometry[] __arrGeoms = new IGeometry[] { this._ftrSelected.ShapeCopy };
  1019. this._cmap.FlashGeometry(this._cmap.ActiveView, __arrGeoms, 1, 200); //图层选择要素闪烁
  1020. //DisplayHelper.FlashGeometry(this._arcHelper.ActiveView, new IGeometry[1] { __featureSelected.ShapeCopy }, 1, 300); //存在延迟,切换过快后,立即关闭窗口,出现资源访问错误
  1021. //if (this._hookAction == null)
  1022. //{
  1023. // this._hookAction = new HookHelperClass() { Hook = this._arcHelper.Application };
  1024. //}
  1025. //this._hookAction.DoAction(__featureSelected.ShapeCopy, esriHookActions.esriHookActionsFlash);
  1026. //Application.DoEvents(); //快速操作时,不能立即提交消息,否则可能
  1027. }
  1028. }
  1029. else //点击了图层,同时闪烁图层下的所有要素图形
  1030. {
  1031. if (nodeClicked.Nodes.Count > 0 && this.ucsFeatureViewer.ProcessingFeature == null) //识别(空间)查询后的首要素数据显示
  1032. {
  1033. int __iFeatOID = Convert.ToInt32(nodeClicked.Nodes[0].Text);
  1034. this._ftrSelected = __kvSelectedFeatureByLayer.Value.Find(ftrItem => ftrItem.OID == __iFeatOID);
  1035. this.ShowClickedNodeInfo(nodeClicked.Nodes[0], false);
  1036. }
  1037. Application.DoEvents();
  1038. IGeometry[] __arrGeoms = __kvSelectedFeatureByLayer.Value.Select(feat => feat.ShapeCopy as IGeometry).ToArray();
  1039. this._cmap.FlashGeometry(this._cmap.ActiveView, __arrGeoms, 1, 200); //图层选择要素闪烁
  1040. }
  1041. //this.tsbtnAttachFile.Enabled = false; //设置附件按钮初始值
  1042. //this.tsbtnAttachFile_Click(null, null); //判断是否有附件数据
  1043. }
  1044. }
  1045. catch (System.Exception ex)
  1046. {
  1047. MessageManager.Show("显示失败:" + ex.Message, "显示选择设备信息");
  1048. }
  1049. }
  1050. /// <summary>
  1051. /// 显示指定要素的属性
  1052. /// </summary>
  1053. /// <param name="fLayerSelected">源要素图层</param>
  1054. /// <param name="identifiedFeature">查看要素</param>
  1055. private void ShowFeatureAttributes(IFeatureLayer fLayerSelected, IFeature identifiedFeature)
  1056. {
  1057. this.ucsFeatureViewer.ResetUserControlState(null); //重置控件
  1058. if (identifiedFeature == null)
  1059. {
  1060. return;
  1061. }
  1062. this.ucsFeatureViewer.SetFeatureView(fLayerSelected, identifiedFeature); //设置浏览要素
  1063. }
  1064. /// <summary>
  1065. /// 分析图层集合中的顶图层
  1066. /// </summary>
  1067. /// <param name="layers"></param>
  1068. /// <returns></returns>
  1069. private ILayer GetTopMostLayer(List<ILayer> layers)
  1070. {
  1071. ILayer __lyrTopLayer = null;
  1072. List<ILayer> __lstLayersAnalysting = new List<ILayer>(layers);
  1073. TreeNode __tnTopNode = null; //分析到的顶层图层节点
  1074. //while (__lstLayersAnalysting.Count > 1)
  1075. //{
  1076. // Dictionary<ILayer, int> __dicLayerIndex = new Dictionary<ILayer, int>();
  1077. // TreeNode __tnTopNodeNew = null;
  1078. // int __iMinIndex = -1;
  1079. // foreach (ILayer __lyrItem in __lstLayersAnalysting)
  1080. // {
  1081. // TreeNode __tnLayer = this.tvIdentifyRange.Nodes.Find(__lyrItem.Name, true)[0];
  1082. // while (__tnLayer.Parent != null && __tnLayer.Parent != __tnTopNode)
  1083. // {
  1084. // __tnLayer = __tnLayer.Parent;
  1085. // }
  1086. // __dicLayerIndex.Add(__lyrItem, __tnLayer.Index);
  1087. // if ((__iMinIndex == -1) || (__iMinIndex > __tnLayer.Index))
  1088. // {
  1089. // __iMinIndex = __tnLayer.Index;
  1090. // __tnTopNodeNew = __tnLayer;
  1091. // }
  1092. // }
  1093. // __lstLayersAnalysting.Clear();
  1094. // foreach (KeyValuePair<ILayer, int> __kvItem in __dicLayerIndex)
  1095. // {
  1096. // if (__kvItem.Value == __iMinIndex)
  1097. // {
  1098. // __lstLayersAnalysting.Add(__kvItem.Key);
  1099. // }
  1100. // }
  1101. // __tnTopNode = __tnTopNodeNew; //更新顶层节点
  1102. //}
  1103. //if (__lstLayersAnalysting.Count > 0)
  1104. //{
  1105. __lyrTopLayer = __lstLayersAnalysting[0];
  1106. //}
  1107. return __lyrTopLayer;
  1108. }
  1109. /// <summary>
  1110. /// 处理附件结果
  1111. /// </summary>
  1112. /// <param name="showForm"></param>
  1113. private void ProcessAttachmentsResult(bool showForm)
  1114. {
  1115. //this.tsbtnAttachFile.Enabled = (this._feEquipmentSelected.Attachments.Count > 0);
  1116. //if (showForm)
  1117. //{
  1118. // string __strMapRegion = ToflyGIS.BaseUtility.AppConfig.g_CurrentMapName;
  1119. // List<FeatureAttachment> __lstAttachment = new List<FeatureAttachment>();
  1120. // __lstAttachment.AddRange(this._feEquipmentSelected.Attachments);
  1121. // SDE_DAL.UI.FormAttachmentManage __frmAttachment = new SDE_DAL.UI.FormAttachmentManage(__strMapRegion, this._feEquipmentSelected.LayerCLSShortName, this._feEquipmentSelected.OID, __lstAttachment)
  1122. // {
  1123. // Owner = this,
  1124. // StartPosition = FormStartPosition.CenterParent
  1125. // };
  1126. // __frmAttachment.ShowDialog();
  1127. // __frmAttachment.Dispose();
  1128. // __frmAttachment = null;
  1129. //}
  1130. }
  1131. #endregion
  1132. }
  1133. }