public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; IGraphicsContainer gc = app.Current2DMapControl.Map as IGraphicsContainer; if (app == null || app.Current2DMapControl == null) { return; } m_pActiveView = app.Current2DMapControl.ActiveView; m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; IFeatureCursor pFeaCur; IFeature pFeature; string classify = ""; string xCoor = ""; string yCoor = ""; string detectNo = ""; string fusu = ""; string standard = ""; string road = ""; bool have = false; m_LabelPoints = new List <LabelPoint>(); try { if (button == 1) { IRubberBand band = new RubberRectangularPolygonClass(); m_pGeoTrack = band.TrackNew(m_Display, null); if (m_pGeoTrack.IsEmpty) { IPoint searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); m_pGeoTrack = DF2DPipe.Class.PublicFunction.DoBuffer(searchPoint, DF2DPipe.Class.PublicFunction.ConvertPixelsToMapUnits(m_pActiveView, GlobalValue.System_Selection_Option().Tolerate)); //m_ActiveView.FocusMap.SelectByShape(geo, s, false); } WaitForm.Start("正在查询...", "请稍后"); foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass()) { if (have) { break; } string[] arrFc2DId = mc.Fc2D.Split(';');//将二级大类所对应的要素类ID转换为数组 if (arrFc2DId == null) { continue; } foreach (SubClass sc in mc.SubClasses) { if (have) { break; } if (!sc.Visible2D) { continue; } foreach (string fc2DId in arrFc2DId) //遍历二级子类所对应的要素类ID { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); //根据要素类ID得到DF2DFC if (dffc == null) { continue; } FacilityClass fcc = dffc.GetFacilityClass(); if (fcc.Name != "PipeNode") { continue; } IFeatureLayer fl = dffc.GetFeatureLayer(); IFeatureClass fc = dffc.GetFeatureClass(); ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = m_pGeoTrack; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; pSpatialFilter.WhereClause = "SMSCODE = '" + sc.Name + "'"; pFeaCur = fc.Search(pSpatialFilter, false); while ((pFeature = pFeaCur.NextFeature()) != null) { if (have) { break; } foreach (string field in sysFields) { DFDataConfig.Class.FieldInfo fi = fcc.GetFieldInfoBySystemName(field); if (fi == null) { continue; } int index = fc.Fields.FindField(fi.Name); object obj = pFeature.get_Value(index); switch (field) { case "Classify": classify = obj.ToString(); break; case "x": xCoor = obj.ToString(); break; case "y": yCoor = obj.ToString(); break; case "Detectid": detectNo = obj.ToString(); break; case "Additional": fusu = obj.ToString(); break; case "Standard": standard = obj.ToString(); break; case "Road": road = obj.ToString(); break; //case "Classify": // classify = obj.ToString(); // break; //case "x": // xCoor = obj.ToString(); // break; //case "y": // yCoor = obj.ToString(); // break; //case "DetectNo": // detectNo = obj.ToString(); // break; //case "Additional": // fusu = obj.ToString(); // break; //case "Standard": // standard = obj.ToString(); // break; //case "proad": // road = obj.ToString(); // break; } } LabelPoint lp = new LabelPoint(pFeature, fl, classify, xCoor, yCoor, detectNo, fusu, standard, road); m_LabelPoints.Add(lp); have = true; } } } } if (m_LabelPoints.Count != 1) { XtraMessageBox.Show("请重新获取单个管线"); WaitForm.Stop(); } foreach (LabelPoint lp in m_LabelPoints) { WaitForm.SetCaption("正在输出属性,请稍后..."); DrawNodeLabels(lp.Feature, lp); } WaitForm.Stop(); } } catch (System.Exception ex) { } }
private void DrawNodeInfo(IPoint point, LabelPoint lp) { IGraphicsContainer pGraContainer = m_pMapControl.Map as IGraphicsContainer; ITextElement pTextElement; IElement pElement; IPoint pAnnoPnt = new PointClass(); ITextSymbol sym = new TextSymbolClass(); stdole.IFontDisp myfont = (stdole.IFontDisp) new stdole.StdFontClass(); myfont.Name = "华文细黑"; sym.Font = myfont; myfont.Bold = true; sym.Size = 8;//SystemInfo.Instance.TextSize; Color color = ColorTranslator.FromHtml(SystemInfo.Instance.TextColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; sym.Color = pColor; double xoffset = 4; double yoffset = 1.5; int i = 0; foreach (string fi in fields) { sym.Text = fi; pAnnoPnt.PutCoords(point.X + xoffset, point.Y - yoffset - i * nHeight); pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); switch (fi) { case "类别": sym.Text = lp.Classify; break; case "x坐标": sym.Text = lp.X; break; case "y坐标": sym.Text = lp.Y; break; case "探查号": sym.Text = lp.DetectNo; break; case "附属物": sym.Text = lp.Fusu; break; case "规格": sym.Text = lp.Standard; break; case "所在道路": sym.Text = lp.Road; break; } pAnnoPnt.PutCoords(point.X + xoffset + nWidth, point.Y - yoffset - i * nHeight); pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); i++; (m_pMapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pMapControl.Extent); } }