private void axSceneControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ISceneControlEvents_OnMouseDownEvent e) { IPoint pPoint = null; object objOwner = null; object objObject = null; axSceneControl1.SceneGraph.Locate(axSceneControl1.SceneViewer, e.x, e.y, esriScenePickMode.esriScenePickGeography, true, out pPoint, out objOwner, out objObject); ITextElement pTextElement = new TextElementClass(); pTextElement.Text = "dddddd"; IGraphicsContainer3D pGCon3D = axSceneControl1.Scene.BasicGraphicsLayer as IGraphicsContainer3D; IElement pElement = new MarkerElementClass(); IMarkerElement pPointElement = pElement as MarkerElementClass; ILineElement pLineElement = pElement as ILineElement; ISimpleLineSymbol pLSymbol = new SimpleLineSymbolClass(); ISimpleMarkerSymbol pMSym = new SimpleMarkerSymbolClass(); IColor pFromColor = new RgbColorClass(); IRgbColor pRgbColor = pFromColor as IRgbColor; pRgbColor.Red = 255; pRgbColor.Green = 0; pRgbColor.Blue = 0; pMSym.Size = 10; pMSym.Color = pFromColor; pMSym.Style = esriSimpleMarkerStyle.esriSMSDiamond; pPointElement.Symbol = pMSym; pLSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pElement.Geometry = pPoint; pGCon3D.AddElement(pElement as IElement ); axSceneControl1.Scene.SceneGraph.RefreshViewers(); IDisplay3D pIDisplay3D = axSceneControl1.Scene.SceneGraph as IDisplay3D ; pIDisplay3D.FlashLocation(pPoint); }
/// <summary> /// ����ע��ʵ�� /// </summary> /// <param name="pITable">���ݱ����</param> /// <param name="entinyNode">VCT�ռ�ʵ��ڵ�</param> public override void CreateFeature(ITable pITable, EntityNode entinyNode) { try { AnnotationNode pAnnotationNode = entinyNode as AnnotationNode; if (pAnnotationNode != null) { IFeatureClass pFeatureCls = pITable as IFeatureClass; this.Feature = pFeatureCls.CreateFeature(); ///��ʶ�븳ֵ int dBSMIndex = -1; dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled); if (dBSMIndex != -1) this.Feature.set_Value(dBSMIndex, pAnnotationNode.EntityID); ///Ҫ�ش��븳ֵ int dSYDMIndex = -1; dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField); if (dSYDMIndex != -1) this.Feature.set_Value(dSYDMIndex, pAnnotationNode.FeatureCode); IAnnotationFeature pAnnotationFeature = Feature as IAnnotationFeature; if (pAnnotationFeature != null) { /////ע�����ݸ�ֵ ITextElement pTextElement = new TextElementClass(); ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Angle = pAnnotationNode.Angle; pTextElement.Text = pAnnotationNode.Text; pTextElement.Symbol = pTextSymbol; pAnnotationFeature.Annotation = pTextElement as IElement; } IPoint pPoint = new PointClass(); pPoint.PutCoords(pAnnotationNode.PointLocation.X, pAnnotationNode.PointLocation.Y); (this.Feature as IFeature).Shape = pPoint; this.Feature.Store(); } } catch (Exception ex) { LogAPI.WriteErrorLog(ex); } }
public static void TextElementAdd(IPoint point, String content, System.Drawing.Font font, Color color, ref ITextElement textElementReturn) { ESRI.ArcGIS.Carto.ITextElement textElement = new TextElementClass(); textElement.Text = content; ESRI.ArcGIS.Display.IRgbColor rgbColor = ColorToRgbColor(color); ITextSymbol textSymbol = SetUpTextSymbol(font, rgbColor); textElement.Symbol = textSymbol; IElement element = textElement as IElement; element.Geometry = point; IGraphicsContainer graphicsContainer = g_axPageLayoutControl.PageLayout as IGraphicsContainer; graphicsContainer.AddElement(element, 0); g_axPageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); textElementReturn = textElement; }
/// <summary> /// Creates a Balloon Callout with the given text and background color for the given feature. /// </summary> /// <param name="feature">The feature for which to create the callout.</param> /// <param name="displayText">The text to display.</param> /// <param name="bgColor">The background color of the callout</param> /// <returns>Returns an element with a callout symbol.</returns> public static IElement CreateBalloonCalloutForFeature(IFeature feature, string displayText, string bgColor) { ITextElement element = new TextElementClass(); if (feature != null) { IPoint anchor = new PointClass(); try { if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) ((IPolyline)feature.ShapeCopy).QueryPoint(esriSegmentExtension.esriNoExtension, .5, true, anchor); else if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPoint) anchor.PutCoords(feature.ShapeCopy.Envelope.XMax, feature.ShapeCopy.Envelope.YMax); } catch (Exception ex) { // _logger.LogException(ex, "There was an error getting the shape from the feature."); anchor = null; } if (anchor != null || !anchor.IsEmpty) { IBalloonCallout balloon = new BalloonCalloutClass(); balloon.AnchorPoint = anchor; balloon.LeaderTolerance = .5; balloon.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle; balloon.Symbol = GenerateGenericFillSymbol(bgColor, esriSimpleFillStyle.esriSFSSolid); IFormattedTextSymbol txtSym = new TextSymbolClass(); txtSym.Background = balloon as ITextBackground; txtSym.Size = 10; if (string.IsNullOrEmpty(displayText)) displayText = feature.OID.ToString(); ((IElement)element).Geometry = feature.ShapeCopy;//offSet; element.Text = displayText; element.Symbol = txtSym; } } return element as IElement; }
private IElement GetElement(IGeometry geometry, string text, float size) { IElement element; ITextElement textElement = new TextElementClass(); element = textElement as IElement; ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Color = ColorSelection.GetColor(); textSymbol.Size = Convert.ToDouble(size); textSymbol.Font = GetIFontDisp(size); textSymbol.HorizontalAlignment = GetHorizontalAlignment(); textSymbol.VerticalAlignment = GetVerticalAlignment(); element.Geometry = geometry; textElement.Symbol = textSymbol; textElement.Text = text; return element; }
public static IElement AddTitle(IPageLayout pageLayout, String s, IColor color, double angle) { ITextElement pTextElement = new TextElementClass(); pTextElement.Text = s; ITextSymbol pTextSymbol = new TextSymbolClass(); //Text的符号样式 //pTextSymbol.Size = 30; pTextSymbol.Color = color; pTextSymbol.Angle = angle; pTextSymbol.RightToLeft = false; //文本由左向右排列 pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; //垂直方向基线对齐 pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //文本两端对齐 pTextElement.Symbol = pTextSymbol; //设置位置 IElement pElement = pTextElement as IElement; return(pElement); //pElement.Geometry = pageLayout.TrackRectangle(); //将元素添加到容器中 // pGraphicsContainer.AddElement(pElement, 0); }
private void DrawPipeInfo(IntersectPipe interPipe, int i) { try { IGraphicsContainer pGraContainer = m_pMapControl.Map as IGraphicsContainer; 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*/; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); IFeatureRenderer FeatureRenderer = new SimpleRendererClass(); IGeoFeatureLayer geolyr = interPipe.FeaLayer as IGeoFeatureLayer; if (geolyr == null) { return; } FeatureRenderer = geolyr.Renderer; //获取此图层的Symbol pSimpleLineSymbol = (ISimpleLineSymbol)FeatureRenderer.get_SymbolByFeature(interPipe.Feature); sym.Color = pSimpleLineSymbol.Color; //类别 sym.Text = interPipe.Classify; if (sym.Text == null) { return; } pAnnoPnt.PutCoords(dblStartX + nWidth, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 ITextElement pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; IElement pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //起点点号 sym.Text = interPipe.StartNo; if (sym.Text == null) { return; } pAnnoPnt.PutCoords(dblStartX + nWidth * 2, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //终点点号 sym.Text = interPipe.EndNo; if (sym.Text == null) { return; } pAnnoPnt.PutCoords(dblStartX + nWidth * 3, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //材质 sym.Text = interPipe.Material; if (sym.Text == null) { return; } pAnnoPnt.PutCoords(dblStartX + nWidth * 4, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //埋设方式 sym.Text = interPipe.Coverstyle; if (sym.Text == null) { return; } pAnnoPnt.PutCoords(dblStartX + nWidth * 5, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //管径 sym.Text = interPipe.Diameter; if (sym.Text == null) { return; } pAnnoPnt.PutCoords(dblStartX + nWidth * 6, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //所在道路 sym.Text = interPipe.Road; if (sym.Text == null) { return; } pAnnoPnt.PutCoords(dblStartX + nWidth * 7, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); } catch (System.Exception ex) { } }
//添加标注 void itemaddlable_Click(object sender, EventArgs e) { // //使用TextElment绘制标注, fieldName为要绘制的属性 //public static void AddLable(AxMapControl axMapControl, ILayer layer, string fieldName) //{ ILayer layer = Global.mainmap.Map.get_Layer(0); IRgbColor pColor = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; IFontDisp pFont = new StdFont() { Name = "宋体", Size = 5 } as IFontDisp; ITextSymbol pTextSymbol = new TextSymbolClass() { Color = pColor, Font = pFont, Size = 11 }; IGraphicsContainer pGraContainer = Global.mainmap.Map as IGraphicsContainer; //遍历要标注的要素 IFeatureLayer pFeaLayer = layer as IFeatureLayer; IFeatureClass pFeaClass = pFeaLayer.FeatureClass; IFeatureCursor pFeatCur = pFeaClass.Search(null, false); IFeature pFeature = pFeatCur.NextFeature(); int index = pFeature.Fields.FindField("NAME");//要标注的字段的索引 IEnvelope pEnv = null; ITextElement pTextElment = null; IElement pEle = null; while (pFeature != null) { //使用地理对象的中心作为标注的位置 pEnv = pFeature.Extent; IPoint pPoint = new PointClass(); pPoint.PutCoords(pEnv.XMin + pEnv.Width * 0.5, pEnv.YMin + pEnv.Height * 0.5); pTextElment = new TextElementClass() { Symbol = pTextSymbol, ScaleText = true, Text = pFeature.get_Value(index).ToString() }; pEle = pTextElment as IElement; pEle.Geometry = pPoint; //添加标注 pGraContainer.AddElement(pEle, 0); pFeature = pFeatCur.NextFeature(); } (Global.mainmap.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, Global.mainmap.Extent); }
//坐标画点 public static void CreatPoint(AxMapControl axMapControl,double x,double y,int m) { //首先要实现容器接口 IGraphicsContainer pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer; //pGraphicsContainer.DeleteAllElements();//清空容器里面所有的元素 //设置点的坐标 IPoint pPoint = new PointClass(); pPoint.PutCoords(x, y); //IMarkerElement用来获得symbol属性 IMarkerElement pMarkerElement = new MarkerElementClass(); //用ISimpleMarkerSymbol来设置点的属性 ISimpleMarkerSymbol pSymbol = new SimpleMarkerSymbolClass(); IRgbColor pRGBcolor = new RgbColorClass(); pRGBcolor.Red = 0; pRGBcolor.Green =220; pRGBcolor.Blue = 0; // pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSymbol.Size = 5; pSymbol.Color = pRGBcolor;//绿色 pSymbol.Style = esriSimpleMarkerStyle.esriSMSCross; pSymbol.Outline = false; pMarkerElement.Symbol = pSymbol; //IEnvelope envelop=new EnvelopeClass(); pPoint.Envelope.SetEmpty(); //IElement用来获得Geometry属性 IElement pElement = pMarkerElement as IElement; //把IPoint转换为为IGeoMetry也能实现 //IGeometry pGeometry = pPoint as IGeometry; //pElement.Geometry = pGeometry; //设置点的标签; ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Size = 10; pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ITextElement texElement = new TextElementClass(); texElement.Symbol = pTextSymbol; texElement.Text = m.ToString(); IElement tElement = texElement as IElement; texElement.ScaleText = true; pElement.Geometry = pPoint; tElement.Geometry = pPoint; //在容器里添加元素 pGraphicsContainer.AddElement(pElement, 0); pGraphicsContainer.AddElement(tElement, 0); pElement.Activate(axMapControl.ActiveView.ScreenDisplay); //tElement.Activate(axMapControl.ActiveView.ScreenDisplay); axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null); // axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, tElement, null); }
public static ITextElement make_Dxf_Text(string fName, string sText, double dAngle, double dH, double dX, double dY) { string newText; newText = sText.Replace(@"\P", "\n"); ITextElement pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = newText; IFormattedTextSymbol myTextSym = new TextSymbolClass(); stdole.IFontDisp myFont = (stdole.IFontDisp) new stdole.StdFontClass(); myFont.Name = fName; myFont.Size = decimal.Parse(dH.ToString()); myTextSym.Font = myFont; myTextSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; myTextSym.Angle = dAngle; System.Text.RegularExpressions.Regex objNumberPattern = new System.Text.RegularExpressions.Regex(@"[^a-zA-Z0-9.-]"); //2008.2.2 TianK 添加 使数字和字母的宽度为75 if (!(newText == "") && !objNumberPattern.IsMatch(newText[0].ToString()) && !objNumberPattern.IsMatch(newText[newText.Length - 1].ToString())) { myTextSym.CharacterWidth = 75; } pTextElement.Symbol = myTextSym; IElement pElement; pElement = (IElement)pTextElement; IPoint pPoint = new PointClass(); pPoint.PutCoords(dX, dY); pElement.Geometry = pPoint; return(pTextElement); // ts.Text =newText; // ts.Font=myfont; //// if(dAngle!=0) //// ts.Angle=dAngle*(Math.PI/180); //// ts.Size=dH; // pTextElement.Symbol=ts; // pTextElement.ScaleText=false; // // IElement pElement; // pElement=(IElement)pTextElement; // // IPoint pPoint=new PointClass(); // pPoint.PutCoords(dX,dY); // pElement.Geometry=pPoint; // // IGroupSymbolElement pGroupSymbolElement; // pGroupSymbolElement=(IGroupSymbolElement)pTextElement; // pGroupSymbolElement.SymbolID=0; // if(dAngle!=0) // { // ITransform2D pTransform2D; // pTransform2D =(ITransform2D) pTextElement; // pTransform2D.Rotate (pPoint,dAngle*(Math.PI/180)); // } // // return pTextElement; }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add CmdAddText.OnClick implementation IPageLayoutControl3 pPageLayoutControl = ClsGlobal.GetPageLayoutControl(m_hookHelper); if (pPageLayoutControl == null) { return; } //if (m_hookHelper.Hook is IToolbarControl) //{ // if (((IToolbarControl)m_hookHelper.Hook).Buddy is IPageLayoutControl3) // { // pPageLayoutControl = (IPageLayoutControl3)((IToolbarControl)m_hookHelper.Hook).Buddy; // } //} ////In case the container is MapControl //else if (m_hookHelper.Hook is IPageLayoutControl3) //{ // pPageLayoutControl = (IPageLayoutControl3)m_hookHelper.Hook; //} //else //{ // MessageBox.Show("当前界面必须是PageLayoutControl界面!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // return; //} try { ITextElement pTextElement = new TextElementClass(); IElement pElement = (IElement)pTextElement; //添加文本 pTextElement.Text = "Text"; pTextElement.ScaleText = false; ITextSymbol pTextSymbol = pTextElement.Symbol; pTextSymbol.Size = 48; pTextElement.Symbol = pTextSymbol; IGraphicsContainer pGraphicContainer = m_hookHelper.ActiveView.GraphicsContainer; IActiveView pActiveView = m_hookHelper.ActiveView; IPageLayout pPageLayout = (IPageLayout)pActiveView; IPage pPage = pPageLayout.Page; IEnvelope pPrintPageEnvolope = pPage.PrintableBounds; double dbCenterX = (pPrintPageEnvolope.XMax + pPrintPageEnvolope.XMin) / 2; double dbCenterY = (pPrintPageEnvolope.YMax + pPrintPageEnvolope.YMin) / 2; double pWidth = 20; double pHeigth = 20; double dbXmin = dbCenterX - pWidth / 2; double dbYmin = dbCenterY - pHeigth / 2; double dbXmax = dbCenterX + pWidth / 2; double dbYmax = dbCenterY + pHeigth / 2; IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(dbXmin, dbYmin, dbXmax, dbYmax); pElement.Geometry = pEnvelope as IGeometry; pGraphicContainer.AddElement(pElement, 0); //刷新 m_hookHelper.ActiveView.Refresh(); //LibCerMap.FrmAddText FrmAddtext = new LibCerMap.FrmAddText(null); //if (FrmAddtext.ShowDialog() == DialogResult.OK) //{ //} } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void AddElement(IPolyline polyline) { try { ArcGIS.Common.Editor.Editor.StartEditOperation(); string strLineInfo = CommonHelper.GetIntersectInformationFlagLineOnlyOne(polyline, _cheQiConfig, _feature); if (string.IsNullOrWhiteSpace(strLineInfo)) { MessageBox.Show(@"扯旗字段为空,请重新设置扯旗字段", @"扯旗", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } IPoint referPoint = new PointClass(); referPoint.X = _polyline.ToPoint.X; referPoint.Y = _polyline.ToPoint.Y; stdole.IFontDisp fontDisp = new StdFontClass() as IFontDisp; fontDisp.Name = _cheQiConfig.FontName; fontDisp.Size = _cheQiConfig.FontSize; fontDisp.Italic = _cheQiConfig.Italic; fontDisp.Underline = _cheQiConfig.Underline; fontDisp.Bold = _cheQiConfig.Bold; fontDisp.Strikethrough = _cheQiConfig.Strikethrough; ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Size = (double)_cheQiConfig.FontSize; textSymbol.Font = fontDisp; textSymbol.Color = _cheQiConfig.FontColor; textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ITextElement textElement = new TextElementClass(); textElement.Text = strLineInfo; textElement.Symbol = textSymbol; textElement.ScaleText = true; IPoint textPoint = new PointClass(); textPoint.X = referPoint.X; textPoint.Y = referPoint.Y + 1; IElement element = textElement as IElement; element.Geometry = textPoint; IFeature annoFeature = _cheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature(); IAnnotationClassExtension annotationClassExtension = _cheQiConfig.FlagAnnoLayer.FeatureClass.Extension as IAnnotationClassExtension; IAnnotationFeature annotationFeature = new AnnotationFeatureClass(); annotationFeature = annoFeature as IAnnotationFeature; annotationFeature.Annotation = element; annotationFeature.LinkedFeatureID = _feature.OID; annoFeature.Store(); _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, 0); annotationClassExtension.Draw(annotationFeature, _context.ActiveView.ScreenDisplay, null); _context.ActiveView.ScreenDisplay.FinishDrawing(); double maxLength = annoFeature.Shape.Envelope.Width; IFeatureClass flagLineFeatureClass = _cheQiConfig.FlagLineLayer.FeatureClass; IFeature feature = flagLineFeatureClass.CreateFeature(); IPointCollection pointCollection = _polyline as IPointCollection; IPoint point = new PointClass(); point.Y = referPoint.Y; point.X = referPoint.X + maxLength; pointCollection.AddPoint(point); feature.Shape = pointCollection as IPolyline; feature.Store(); _context.ActiveView.Refresh(); } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { ArcGIS.Common.Editor.Editor.StartEditOperation(); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { //Get the active view IActiveView activeView = m_hookHelper.ActiveView; //Create a new text element ITextElement textElement = new TextElementClass(); //Create a text symbol ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Size = 25; //Set the text element properties textElement.Symbol = textSymbol; textElement.Text = DateTime.Now.ToShortDateString(); //QI for IElement IElement element = (IElement) textElement; //Create a point IPoint point = new PointClass(); point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y); //Set the elements geometry element.Geometry = point; //Add the element to the graphics container activeView.GraphicsContainer.AddElement(element, 0); //Refresh the graphics activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e) { if (e.button != 2) return; //Create a new point IPoint pPoint = new PointClass(); pPoint.PutCoords(e.pageX, e.pageY); //Create a new text element ITextElement textElement = new TextElementClass(); //Set the text to display today's date textElement.Text = DateTime.Now.ToShortDateString(); //Add element to graphics container using the CommandsEnvironment default text symbol axPageLayoutControl1.AddElement((IElement) textElement, pPoint, m_graphicProperties.TextSymbol, "", 0); //Refresh the graphics axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void SetMapFrame()//设置地图基本信息,如比例尺,图例等: { IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)this.axPageLayoutControl1.ActiveView; pGraphicsContainer.Reset(); IElementProperties pElementProperties = (IElementProperties)pGraphicsContainer.Next(); while (pElementProperties != null) { if (pElementProperties is ITextElement) //设置文本 { ITextElement ptextElement = new TextElementClass(); ptextElement = (ITextElement)pElementProperties; if (ptextElement.Text.Trim() == "双击添加标题" || ptextElement.Symbol.Size > 25) { ptextElement.Text = m_textTitle; } if (ptextElement.Text.Trim().Contains("坐标系")) { ptextElement.Text = "坐标系:" + m_textProject + "\r" + "高程系:" + m_textElevation; } if (ptextElement.Text.Trim().Contains("制作者")) { ptextElement.Text = "制图人:" + m_textName + "\r" + "制作时间:" + m_textDate; } } if (pElementProperties.Type == "Map Surround Frame") { IMapSurroundFrame pMapSurrounFrame = pElementProperties as IMapSurroundFrame; IElement pElement = (IElement)pElementProperties; if (pMapSurrounFrame.MapSurround.Name.Trim() == "Legend") { ILegend pLegend = pMapSurrounFrame.MapSurround as ILegend; pLegend.Map = m_Map; // IMapSurround pMapSurround = pMapSurrounFrame.MapSurround; //pElement = pMapSurrounFrame.MapSurround as IElement; // pMapSurround.Map = m_Map; // m_Map.AddMapSurround(pMapSurround); } if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line" || pMapSurrounFrame.MapSurround.Name == "Scale Line" || pMapSurrounFrame.MapSurround.Name == "Hollow Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Single Division Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Double Alternating Scale Bar") { // m_Map.MapScale = 5000; IScaleBar pScaleBar = pMapSurrounFrame.MapSurround as IScaleBar; pScaleBar.Map = m_Map; pScaleBar.Units = m_Map.MapUnits; pScaleBar.UseMapSettings(); pElement = pMapSurrounFrame.MapSurround as IElement; } if (pMapSurrounFrame.MapSurround.Name == "Scale Text") { IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText; pScaleText.Map = m_Map; } if (pMapSurrounFrame.MapSurround.Name == "North Arrow") { INorthArrow pNorthArrow = pMapSurrounFrame.MapSurround as INorthArrow; pNorthArrow.Map = m_Map; } } if (pElementProperties.Type == "Data Frame") { IFrameElement pFrameElement = pElementProperties as IFrameElement; IMapFrame pMapframe = pFrameElement as IMapFrame; // pMapframe.ExtentType = esriExtentTypeEnum.esriExtentBounds; IMapGrids pmapGrids = pMapframe as IMapGrids; IMapGrid pMapGrid = null; for (int i = 0; i < pmapGrids.MapGridCount; i++) { pMapGrid = pmapGrids.get_MapGrid(i); //用户要求显示与否 pMapGrid.Visible = true; } } pElementProperties = (IElementProperties)pGraphicsContainer.Next(); } if (axPageLayoutControl1.Page.Orientation == 2) { IPaper paper; paper = new PaperClass(); //create a paper object IPrinter printer; printer = new EmfPrinterClass(); //create a printer object paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32()); paper.Orientation = 2; printer.Paper = paper; axPageLayoutControl1.Printer = printer; pageSetupDialog1.PageSettings.Landscape = true; pageSetupDialog1.AllowOrientation = true; } if (axPageLayoutControl1.Page.Orientation == 1 && axPageLayoutControl1.Printer.Paper.Orientation == 2) { IPaper paper; paper = new PaperClass(); //create a paper object IPrinter printer; printer = new EmfPrinterClass(); //create a printer object paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32()); paper.Orientation = 1; printer.Paper = paper; axPageLayoutControl1.Printer = printer; pageSetupDialog1.PageSettings.Landscape = false; pageSetupDialog1.AllowOrientation = true; } }
//点击地图框事件 private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e) { if (e.button == 1) { IPageLayout pPageLayout = axPageLayoutControl1.PageLayout;; IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer; IActiveView pActiveView = pPageLayout as IActiveView; IMapFrame pMapFrame; IMapSurroundFrame pMapSurroundFrame; IElement pElement; switch (tag) { #region 添加标题 case 1: ITextElement pTextElement = new TextElementClass(); pTextElement.Text = title; pTextElement.Symbol = pTextSymbol; pElement = pTextElement as IElement; try { pElement.Geometry = axPageLayoutControl1.TrackRectangle(); } catch { MessageBox.Show("请拉框选择范围!", "提示"); return; } pGraphicsContainer.AddElement(pElement, 0); axPageLayoutControl1.Refresh(); tag = 0; break; #endregion #region 添加图例 case 2: pLegend2 = new LegendClass_2(); pElement = axPageLayoutControl1.FindElementByName("legend"); if (pElement != null) { pGraphicsContainer.DeleteElement(pElement); } pElementTypeName = "lenend"; pUid = new UIDClass(); pUid.Value = "esriCato.Legend"; if (pGraphicsContainer == null) { return; } pMapSurround = pLegend2 as IMapSurround; pMapSurround.Map = pActiveView.FocusMap; pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame; if (pMapFrame == null) { return; } pMapSurroundFrame = new MapSurroundFrameClass(); pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUid, null); pMapSurroundFrame.MapSurround = pMapSurround; pMapSurroundFrame.MapSurround.Name = pElementTypeName; pMapSurroundFrame.MapFrame = pMapFrame; pElement = pMapSurroundFrame as IElement; try { pElement.Geometry = axPageLayoutControl1.TrackRectangle(); } catch { MessageBox.Show("请拉框选择范围!", "提示"); return; } pElement.Activate(pActiveView.ScreenDisplay); pElement.Draw(pActiveView.ScreenDisplay, null); pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); //图例标题字体样式 pLegend2.Title = "图例"; pTitltFont.Name = "黑体"; pTitltFont.Bold = true; pTitltFont.Size = 16; pTitltTextSymbol.Color = ColorToIColor(Color.Black); pTitltTextSymbol.Font = pTitltFont; pLenendFormat.TitleSymbol = pTitltTextSymbol; //图例图层名字体样式 pLayerFont.Name = "仿宋_GB2312"; pLayerFont.Size = 13; pLayerTextSymbol.Font = pLayerFont; //图例标签字体样式 pLabelFont.Name = "仿宋_GB2312"; pLabelFont.Size = 13; pLabelTextSymbol.Font = pLayerFont; for (int i = 0; i < pLenendItemsString.Count; i++) { for (int j = 0; j < pLegend2.ItemCount; j++) { if (pLenendItemsString[i].ToString() == pLegend2.get_Item(j).Layer.Name) { pLegend2.RemoveItem(j); } } } pLegend2.AdjustColumns(pColumnCount); pLegend2.Refresh(); tag = 0; break; #endregion #region 添加指北针 case 3: if (pGraphicsContainer == null) { return; } pElement = axPageLayoutControl1.FindElementByName("northarrow"); if (pElement != null) { pGraphicsContainer.DeleteElement(pElement); } pElementTypeName = "northarrow"; pUid = new UIDClass(); pUid.Value = "esriCato.MarkerNorthArrow"; pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame; pMapSurroundFrame = new MapSurroundFrameClass(); pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUid, null); pMapSurroundFrame.MapSurround = pNorthArrowStyleGalleryItem.Item as IMapSurround; pElement = pMapSurroundFrame as IElement; try { pElement.Geometry = axPageLayoutControl1.TrackRectangle(); } catch { MessageBox.Show("请拉框选择范围!", "提示"); return; } pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); tag = 0; break; #endregion #region 添加比例尺 case 4: if (pGraphicsContainer == null) { return; } pElement = axPageLayoutControl1.FindElementByName("scalebar"); if (pElement != null) { pGraphicsContainer.DeleteElement(pElement); } IScaleBar pScaleBar; pScaleBar = pScaleStyleGalleryItem.Item as IScaleBar; pScaleBar.Units = esriUnits.esriKilometers; pScaleBar.UnitLabel = " KM"; pElementTypeName = "scalebar"; pUid = new UIDClass(); pUid.Value = "esriCato.AlternatingScaleBar"; pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame; pMapSurroundFrame = new MapSurroundFrameClass(); pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUid, null); pMapSurroundFrame.MapSurround = pScaleStyleGalleryItem.Item as IMapSurround; pElement = pMapSurroundFrame as IElement; try { pElement.Geometry = axPageLayoutControl1.TrackRectangle(); } catch { MessageBox.Show("请拉框选择范围!", "提示"); } pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); tag = 0; break; #endregion } } }
//���õ�ͼ������Ϣ��������ߣ�ͼ���ȣ� private void SetMapFrame() { IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)this.axPageLayoutControl1.ActiveView; pGraphicsContainer.Reset(); IElementProperties pElementProperties = (IElementProperties)pGraphicsContainer.Next(); while (pElementProperties != null) { if (pElementProperties is ITextElement) //�����ı� { ITextElement ptextElement = new TextElementClass(); ptextElement = (ITextElement)pElementProperties; if (ptextElement.Text.Trim() == "˫����ӱ���" ||ptextElement .Symbol.Size >25) { ptextElement.Text = m_textTitle; } if (ptextElement.Text.Trim().Contains("����ϵ")) { ptextElement.Text = "����ϵ��" + m_textProject + "\r" + "�߳�ϵ��" + m_textElevation; } if (ptextElement.Text.Trim().Contains("������")) { ptextElement.Text = "��ͼ�ˣ�"+m_textName+"\r"+"����ʱ�䣺"+m_textDate; } } if (pElementProperties.Type == "Map Surround Frame") { IMapSurroundFrame pMapSurrounFrame = pElementProperties as IMapSurroundFrame; IElement pElement = (IElement)pElementProperties; if (pMapSurrounFrame.MapSurround.Name.Trim() == "Legend") { ILegend pLegend = pMapSurrounFrame.MapSurround as ILegend; pLegend.Map = m_Map; // IMapSurround pMapSurround = pMapSurrounFrame.MapSurround; //pElement = pMapSurrounFrame.MapSurround as IElement; // pMapSurround.Map = m_Map; // m_Map.AddMapSurround(pMapSurround); } if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" ||pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line"||pMapSurrounFrame.MapSurround .Name =="Scale Line"|| pMapSurrounFrame .MapSurround .Name =="Hollow Scale Bar"||pMapSurrounFrame .MapSurround .Name =="Single Division Scale Bar"|| pMapSurrounFrame .MapSurround.Name =="Double Alternating Scale Bar") { // m_Map.MapScale = 5000; IScaleBar pScaleBar = pMapSurrounFrame.MapSurround as IScaleBar; pScaleBar.Map = m_Map; pScaleBar.Units = m_Map.MapUnits; pScaleBar.UseMapSettings(); pElement = pMapSurrounFrame.MapSurround as IElement; } if (pMapSurrounFrame.MapSurround.Name == "Scale Text") { IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText; pScaleText.Map = m_Map; } if (pMapSurrounFrame.MapSurround.Name == "North Arrow") { INorthArrow pNorthArrow = pMapSurrounFrame.MapSurround as INorthArrow; pNorthArrow.Map = m_Map; } } if (pElementProperties.Type == "Data Frame") { IFrameElement pFrameElement = pElementProperties as IFrameElement; IMapFrame pMapframe = pFrameElement as IMapFrame; // pMapframe.ExtentType = esriExtentTypeEnum.esriExtentBounds; IMapGrids pmapGrids = pMapframe as IMapGrids; IMapGrid pMapGrid = null; for(int i =0;i<pmapGrids.MapGridCount ;i++) { pMapGrid = pmapGrids.get_MapGrid(i); //�û�Ҫ����ʾ��� pMapGrid.Visible = true; } } pElementProperties = (IElementProperties)pGraphicsContainer.Next(); } if (axPageLayoutControl1.Page.Orientation == 2) { IPaper paper; paper = new PaperClass(); //create a paper object IPrinter printer; printer = new EmfPrinterClass(); //create a printer object paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32()); paper.Orientation = 2; printer.Paper = paper; axPageLayoutControl1.Printer = printer; pageSetupDialog1.PageSettings.Landscape = true; pageSetupDialog1.AllowOrientation = true; } if (axPageLayoutControl1.Page.Orientation == 1&&axPageLayoutControl1 .Printer .Paper .Orientation ==2) { IPaper paper; paper = new PaperClass(); //create a paper object IPrinter printer; printer = new EmfPrinterClass(); //create a printer object paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32()); paper.Orientation = 1; printer.Paper = paper; axPageLayoutControl1.Printer = printer; pageSetupDialog1.PageSettings.Landscape = false; pageSetupDialog1.AllowOrientation = true; } }
private void GeneratePageLayout() { IPageLayout pageLayout = axPageLayoutControl1.PageLayout; IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer; pGraphicsContainer.DeleteAllElements(); IPage pPage = new PageClass(); pPage = pageLayout.Page; pPage.PutCustomSize(36, 24); IActiveView pActiveView = pageLayout as IActiveView; IMap pMap = pActiveView.FocusMap; IMapFrame mapFrame1 = pGraphicsContainer.FindFrame(pMap) as IMapFrame; IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(1.5, 3, 17.5, 20); IElement pElement = mapFrame1 as IElement; pElement.Geometry = pEnvelope; //Map frame 2 IMap mapDF1 = new MapClass(); IMapFrame mapFrame2 = new MapFrameClass(); mapFrame2.Map = mapDF1; IElement element1 = mapFrame2 as IElement; IEnvelope envelope1 = new EnvelopeClass(); envelope1.PutCoords(18.5, 3, 34.5, 20); element1.Geometry = envelope1; //?????element 1 or bot map always hide??? pGraphicsContainer.AddElement(element1, 0); //# //////add map---problem shot //mapFrame1.Map = m_MapControltop.ActiveView.FocusMap; //mapFrame2.Map = m_MapControlbase.ActiveView.FocusMap; //# //TRY to use ObjectCopy //copy map to top mapframe of pagelayoutcontrol IObjectCopy objectCopy1 = new ObjectCopyClass(); object toCopyMap1 = m_MapControltop.ActiveView.FocusMap; //IMap map1 = toCopyMap1 as IMap; //map1.IsFramed = true; object copiedMap1 = objectCopy1.Copy(toCopyMap1); object toOverwriteMap1 = mapFrame1.Map; objectCopy1.Overwrite(copiedMap1, ref toOverwriteMap1); //SetMapExtent1(); //copy map to bot mapframe of pagelayoutcontrol IObjectCopy objectCopy2 = new ObjectCopyClass(); object toCopyMap2 = m_MapControlbase.ActiveView.FocusMap; object copiedMap2 = objectCopy2.Copy(toCopyMap2); object toOverwriteMap2 = mapFrame2.Map; objectCopy2.Overwrite(copiedMap2, ref toOverwriteMap2); mapFrame1.Map.Name = "MapTop"; mapFrame2.Map.Name = "MapBot"; //try to change scale IGraphicsContainer container = this.axPageLayoutControl1.GraphicsContainer; container.Reset(); IElement element = container.Next(); int index = 0; while (element != null) { if (element is IMapFrame) { IMapFrame mapFrame = (IMapFrame)element; string sMapName = mapFrame.Map.Name; IElementProperties elementProperties = (IElementProperties)element; string slementName = elementProperties.Name; index += 1; } element = container.Next(); } //add title ITextElement teTitle = new TextElementClass(); IPoint ptTitle = new PointClass(); ptTitle.PutCoords(18, 22.5); IElement eleTitle = teTitle as IElement; eleTitle = MakeATextElement(ptTitle, tbStNum.Text + " " + tbStNa.Text + " Historical Aerial Comparison", 80); pGraphicsContainer.AddElement(eleTitle, 0); string topYear = cboTopYear.Text; string botYear = cboBotYear.Text; //Add subtitle ITextElement teSubTitle1 = new TextElementClass(); IPoint ptSubTitle1 = new PointClass(); ptSubTitle1.PutCoords(9.5, 21); IElement eleSubTitle1 = teSubTitle1 as IElement; eleSubTitle1 = MakeATextElement(ptSubTitle1, topYear, 45); pGraphicsContainer.AddElement(eleSubTitle1, 0); //Add Subtitle2 ITextElement teSubTitle2 = new TextElementClass(); IPoint ptSubTitle2 = new PointClass(); ptSubTitle2.PutCoords(26.5, 21); IElement eleSubTitle2 = teSubTitle2 as IElement; eleSubTitle2 = MakeATextElement(ptSubTitle2, botYear, 45); pGraphicsContainer.AddElement(eleSubTitle2, 0); //Add Scale Bar AddScaleBar(mapFrame1.Map); //Add North Arrow AddNorthArrow(axPageLayoutControl1.PageLayout, mapFrame1.Map); axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); MessageBox.Show("Done!"); }
private IElement MakeATextElement(IPoint pPoint, string strText, double fontsize) { IRgbColor pRGBColor; ITextElement pTextElement; ITextSymbol pTextSymbol; IElement pElement; pRGBColor = new RgbColorClass(); pRGBColor.Blue = 0; pRGBColor.Red = 0; pRGBColor.Green = 0; pTextElement = new TextElementClass(); pElement = pTextElement as IElement; pElement.Geometry = pPoint; IFontDisp pFontDisp = new StdFontClass() as IFontDisp; pFontDisp.Name = "Time NewRoman"; pFontDisp.Bold = true; pTextSymbol = new TextSymbolClass(); pTextSymbol.Font = pFontDisp; pTextSymbol.Color = pRGBColor; pTextSymbol.Size = fontsize; pTextElement.Symbol = pTextSymbol; pTextElement.Text = strText; return pElement; }
/// <summary> /// ����һ��TextElement /// </summary> /// <params name="text"></params> /// <returns></returns> ITextElement CreateTextElement(string text) { //����һ��TextSymbol ITextSymbol txtSymbol = new TextSymbolClass(); //�������� Font dispFont = new Font("Arial", 10, FontStyle.Regular); txtSymbol.Font = (stdole.IFontDisp)ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(dispFont); //�������� txtSymbol.Color = TransColorToAEColor(Color.Red); //��ɫ //����һ��TextElement ITextElement txtElement = new TextElementClass(); txtElement.Symbol = txtSymbol; txtElement.Text = text; return txtElement; }
private void AxMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { //屏幕坐标点转化为地图坐标点 pPointPt = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { IActiveView pActiveView = axMapControl1.ActiveView; IEnvelope pEnvelope = new EnvelopeClass(); switch (pMouseOperate) { #region 拉框放大 case "ZoomIn": pEnvelope = axMapControl1.TrackRectangle(); //如果拉框范围为空则返回 if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) { return; } //如果有拉框范围,则放大到拉框范围 pActiveView.Extent = pEnvelope; pActiveView.Refresh(); break; #endregion #region 拉框缩小 case "ZoomOut": pEnvelope = axMapControl1.TrackRectangle(); //如果拉框范围为空则退出 if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) { return; } //如果有拉框范围,则以拉框范围为中心,缩小倍数为:当前视图范围/拉框范围 else { double dWidth = pActiveView.Extent.Width * pActiveView.Extent.Width / pEnvelope.Width; double dHeight = pActiveView.Extent.Height * pActiveView.Extent.Height / pEnvelope.Height; double dXmin = pActiveView.Extent.XMin - ((pEnvelope.XMin - pActiveView.Extent.XMin) * pActiveView.Extent.Width / pEnvelope.Width); double dYmin = pActiveView.Extent.YMin - ((pEnvelope.YMin - pActiveView.Extent.YMin) * pActiveView.Extent.Height / pEnvelope.Height); double dXmax = dXmin + dWidth; double dYmax = dYmin + dHeight; pEnvelope.PutCoords(dXmin, dYmin, dXmax, dYmax); } pActiveView.Extent = pEnvelope; pActiveView.Refresh(); break; #endregion #region 漫游 case "Pan": axMapControl1.Pan(); break; #endregion #region 择要素 case "SelFeature": IEnvelope pEnv = axMapControl1.TrackRectangle(); IGeometry pGeo = pEnv as IGeometry; //矩形框若为空,即为点选时,对点范围进行扩展 if (pEnv.IsEmpty == true) { tagRECT r; r.left = e.x - 5; r.top = e.y - 5; r.right = e.x + 5; r.bottom = e.y + 5; pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4); pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference; } pGeo = pEnv as IGeometry; axMapControl1.Map.SelectByShape(pGeo, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); break; #endregion #region 要素选择 case "SelectFeature": IPoint point = new PointClass(); IGeometry pGeometry = point as IGeometry; axMapControl1.Map.SelectByShape(pGeometry, null, false); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); break; #endregion #region 距离量算 case "MeasureLength": //判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点 if (pNewLineFeedback == null) { //实例化追踪线对象 pNewLineFeedback = new NewLineFeedbackClass(); pNewLineFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay; //设置起点,开始动态线绘制 pNewLineFeedback.Start(pPointPt); dToltalLength = 0; } else //如果追踪线对象不为空,则添加当前鼠标点 { pNewLineFeedback.AddPoint(pPointPt); } //pGeometry = m_PointPt; if (dSegmentLength != 0) { dToltalLength = dToltalLength + dSegmentLength; } break; #endregion #region 面积量算 case "MeasureArea": if (pNewPolygonFeedback == null) { //实例化追踪面对象 pNewPolygonFeedback = new NewPolygonFeedback(); pNewPolygonFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay; ; pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //开始绘制多边形 pNewPolygonFeedback.Start(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } else { pNewPolygonFeedback.AddPoint(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } break; #endregion #region 添加文字 case "AddCharacters": { //本例的实现类似于前面测量工具的实现 //在工具条添加自定义的工具之后,在其Click事件中用m_flag变量记录操作 //然后在MapControl的OnMouseDown事件的适当位置添加如下代码: IFontDisp font = new StdFontClass() as IFontDisp; font.Bold = true; font.Name = "Arial"; font.Size = 20; IColor pColor = new RgbColorClass(); pColor.RGB = 0; ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Size = 200; pTextSymbol.Font = font; pTextSymbol.Color = pColor; IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); ITextElement pTextElement = new TextElementClass(); pTextElement.Symbol = pTextSymbol; pTextElement.Text = toolStripTextBox1.Text; IElement pElement = pTextElement as IElement; pElement.Geometry = pPoint as IGeometry; axMapControl1.ActiveView.GraphicsContainer.AddElement(pElement, 3); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } break; #endregion #region 添加线型元素 case "AddLine": IGraphicsContainer pGra = axMapControl1.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; IGeometry pgeo = axMapControl1.TrackLine(); AddLineElement(pgeo, pGra); break; #endregion #region 缓冲区闪烁 case "Buffer": //IMap pMap = axMapControl1.Map; IPoint pt = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); ITopologicalOperator pTopo = pt as ITopologicalOperator; IGeometry pGeo1 = pTopo.Buffer(50); IColor pColor1 = new RgbColorClass(); pColor1.RGB = 2556; SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = pColor1; ISymbol symbol = simpleFillSymbol as ISymbol; pActiveView.ScreenDisplay.SetSymbol(symbol); pActiveView.ScreenDisplay.DrawPolygon(pGeo1); //pMap.SelectByShape(pGeo1, null, false); //闪动 axMapControl1.FlashShape(pGeo1, 26, 200, symbol); //ThreadInfo threadInfo = new ThreadInfo(); //threadInfo.pActiveView = pActiveView; //GPU并行 //threadInfo.e = e; //ThreadPool.QueueUserWorkItem(new WaitCallback(processfile), threadInfo); axMapControl1.ActiveView.Refresh(); break; #endregion default: break; } } }
private void method_0(IPoint ipoint_4, double double_5, double double_6, double double_7, double double_8) { object missing = System.Type.Missing; IPolyline polyline = new PolylineClass(); IPolyline polyline2 = new PolylineClass(); IPolyline polyline3 = new PolylineClass(); IElement item = new LineElementClass(); IElement element2 = new LineElementClass(); IElement element3 = new LineElementClass(); ILineElement element4 = null; IPoint inPoint = new PointClass(); IPoint point2 = new PointClass(); IPointCollection points = polyline as IPointCollection; IPoint point3 = new PointClass(); IPoint point4 = new PointClass(); IPoint point5 = new PointClass(); IPoint point6 = new PointClass(); IPoint point7 = new PointClass(); IPoint point8 = new PointClass(); IElement element5 = new TextElementClass(); switch (this.int_0) { case 0: inPoint.PutCoords(ipoint_4.X, base.RightUp.Y); point2.PutCoords(base.RightUp.X, base.RightUp.Y - double_6); point3.PutCoords(ipoint_4.X - double_7, base.RightUp.Y); point4.PutCoords(ipoint_4.X - double_7, ipoint_4.Y - double_7); point5.PutCoords(base.RightUp.X, (base.RightUp.Y - double_6) - double_7); point6.PutCoords(base.RightUp.X, base.RightUp.Y - double_8); point7.PutCoords(base.RightUp.X - double_5, base.RightUp.Y - double_8); point8.PutCoords(base.RightUp.X - (double_5 / 2.0), base.RightUp.Y - (double_8 / 2.0)); break; case 1: inPoint.PutCoords(ipoint_4.X, base.RightLow.Y); point2.PutCoords(base.RightLow.X, base.RightLow.Y + double_6); point3.PutCoords(ipoint_4.X - double_7, base.RightLow.Y); point4.PutCoords(ipoint_4.X - double_7, ipoint_4.Y + double_7); point5.PutCoords(base.RightLow.X, (base.RightLow.Y + double_6) + double_7); point6.PutCoords(base.RightLow.X, (base.RightLow.Y + double_6) - double_8); point7.PutCoords(base.RightLow.X - double_5, (base.RightLow.Y + double_6) - double_8); point8.PutCoords(base.RightLow.X - (double_5 / 2.0), (base.RightLow.Y + double_6) - (double_8 / 2.0)); break; case 2: inPoint.PutCoords(ipoint_4.X, base.LeftLow.Y); point2.PutCoords(base.LeftLow.X, base.LeftLow.Y + double_6); point3.PutCoords(ipoint_4.X + double_7, base.LeftLow.Y); point4.PutCoords(ipoint_4.X + double_7, ipoint_4.Y + double_7); point5.PutCoords(base.LeftLow.X, (base.LeftLow.Y + double_6) + double_7); point6.PutCoords(base.LeftLow.X, (base.LeftLow.Y + double_6) - double_8); point7.PutCoords(base.LeftLow.X + double_5, (base.LeftLow.Y + double_6) - double_8); point8.PutCoords(base.LeftLow.X + (double_5 / 2.0), (base.LeftLow.Y + double_6) - (double_8 / 2.0)); break; case 3: inPoint.PutCoords(ipoint_4.X, base.LeftUp.Y); point2.PutCoords(base.LeftUp.X, base.LeftUp.Y - double_6); point3.PutCoords(ipoint_4.X + double_7, base.LeftUp.Y); point4.PutCoords(ipoint_4.X + double_7, ipoint_4.Y - double_7); point5.PutCoords(base.LeftUp.X, (base.LeftUp.Y - double_6) - double_7); point6.PutCoords(base.LeftUp.X, base.RightUp.Y - double_8); point7.PutCoords(base.LeftUp.X + double_5, base.LeftUp.Y - double_8); point8.PutCoords(base.LeftUp.X + (double_5 / 2.0), base.LeftUp.Y - (double_8 / 2.0)); break; } points.AddPoint(inPoint, ref missing, ref missing); points.AddPoint(ipoint_4, ref missing, ref missing); points.AddPoint(point2, ref missing, ref missing); item.Geometry = polyline; element4 = item as ILineElement; element4.Symbol = this.method_5(1); this.ilist_0.Add(item); points = polyline2 as IPointCollection; points.AddPoint(point3, ref missing, ref missing); points.AddPoint(point4, ref missing, ref missing); points.AddPoint(point5, ref missing, ref missing); element2.Geometry = polyline2; element4 = element2 as ILineElement; element4.Symbol = this.method_5(2); this.ilist_0.Add(element2); points = polyline3 as IPointCollection; points.AddPoint(point6, ref missing, ref missing); points.AddPoint(point7, ref missing, ref missing); element3.Geometry = polyline3; element4 = element3 as ILineElement; element4.Symbol = this.method_5(1); this.ilist_0.Add(element3); element5.Geometry = point8; ITextElement element6 = element5 as ITextElement; element6.Text = "图 例"; element6.Symbol = base.FontStyle(20.0, esriTextHorizontalAlignment.esriTHACenter, esriTextVerticalAlignment.esriTVACenter); this.ilist_0.Add(element5); }
//生成点注记 public ITextElement MakeTextElement(ITextElement pTextElement, double ptX, double ptY, int intCharacterWidthIndexValue) { ITextElement pMyTextElement = new TextElementClass(); pMyTextElement.Text = pTextElement.Text; ITextSymbol pTextSymbol = new TextSymbolClass(); Console.WriteLine(pMyTextElement.Text); //若果要旋转注记 if (CommonFunction.MatchNumber(pMyTextElement.Text))//如果数字 { if (m_IsRotationNumAnno) { pTextSymbol.Angle = pTextElement.Symbol.Angle + Math.Atan(m_A1 / m_A2) * 180 / Math.PI - 90; } else { pTextSymbol.Angle = pTextElement.Symbol.Angle; } } else//若果文字 { string str = pMyTextElement.Text; if (IsChina(str)) { if (m_IsRotationTextAnno) { pTextSymbol.Angle = pTextElement.Symbol.Angle + Math.Atan(m_A1 / m_A2) * 180 / Math.PI - 90; } else { pTextSymbol.Angle = pTextElement.Symbol.Angle; } } else { if (Char.IsLetter(str[0])) //若果为点号(D12345)或 规格注记(DL2或 DN 12345 { if (str.Contains(" ") || Char.IsLetter(str[1])) //规格注记====则必须旋转! { pTextSymbol.Angle = pTextElement.Symbol.Angle + Math.Atan(m_A1 / m_A2) * 180 / Math.PI - 90; } else//点号=根据设置来确定是否旋转 { if (m_IsRotationNumAnno) { pTextSymbol.Angle = pTextElement.Symbol.Angle + Math.Atan(m_A1 / m_A2) * 180 / Math.PI - 90; } else { pTextSymbol.Angle = pTextElement.Symbol.Angle; } } } } } pTextSymbol.Color = pTextElement.Symbol.Color; pTextSymbol.Font = pTextElement.Symbol.Font; pTextSymbol.HorizontalAlignment = pTextElement.Symbol.HorizontalAlignment; pTextSymbol.RightToLeft = pTextElement.Symbol.RightToLeft; pTextSymbol.Size = pTextElement.Symbol.Size; pTextSymbol.Text = pTextElement.Symbol.Text; pTextSymbol.VerticalAlignment = pTextElement.Symbol.VerticalAlignment; IFormattedTextSymbol pFormattedTextSymbol = pTextSymbol as IFormattedTextSymbol; pFormattedTextSymbol.CharacterWidth = intCharacterWidthIndexValue; pMyTextElement.Symbol = pTextSymbol; IElement pElement; pElement = (IElement)pMyTextElement; IPoint pPoint = new PointClass(); pPoint.PutCoords(ptX, ptY); pElement.Geometry = pPoint; return(pMyTextElement); }
public BetterMarker(ESRI.ArcGIS.Geometry.IPoint mapPoint, string Text, double MapScale) { _Callout = new BalloonCallout(); _Callout.AnchorPoint = mapPoint; ITextElement pTextElement = new TextElementClass(); IElement pElement; IFillSymbol pFill = new SimpleFillSymbolClass(); ILineSymbol pLine = new SimpleLineSymbolClass(); IFormattedTextSymbol pLabelSymbol = new TextSymbolClass(); IRgbColor c = new RgbColorClass(); c.Red = 0; c.Green = 0; c.Blue = 0; IRgbColor d = new RgbColorClass(); d.Red = 255; d.Green = 255; d.Blue = 255; IRgbColor e = new RgbColorClass(); e.Red = 205; e.Green = 192; e.Blue = 176; pLine.Color = c; pFill.Color = d; pFill.Outline = pLine; this._Callout.Symbol = pFill; this._Callout.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle; pLabelSymbol.Background = this._Callout as ITextBackground; pLabelSymbol.Size = 10.5d; pLabelSymbol.ShadowColor = e; pLabelSymbol.ShadowXOffset = 1.0d; pLabelSymbol.ShadowYOffset = 1.0d; pTextElement.Text = Text; pTextElement.Symbol = pLabelSymbol as ITextSymbol; pElement = pTextElement as IElement; double delta = (.1 * MapScale) / 2; //switch (mMap.MapScale) //{ // case //} ESRI.ArcGIS.Geometry.IPoint p1 = new ESRI.ArcGIS.Geometry.PointClass(); p1.X = mapPoint.X + delta; p1.Y = mapPoint.Y + delta; pElement.Geometry = p1; this._Element = pElement; }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { m_command.OnClick(); m_hookHelper.ActiveView.Refresh(); IPoint pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint); IFeatureLayer featureLayer = GIS.Common.DataEditCommon.copypasteLayer; if (featureLayer == null) { return; } IFeatureSelection m_featureSelection = featureLayer as IFeatureSelection; ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = m_featureSelection.SelectionSet; if (m_selectionSet.Count == 0) { return; } IFeatureClass pFeatureClass = featureLayer.FeatureClass; ICursor pCursor = null; m_selectionSet.Search(null, false, out pCursor); IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor; IFeature m_pFeature = pFeatureCursor.NextFeature(); double dx = 0; double dy = 0; if (m_pFeature == null) { return; } DataEditCommon.InitEditEnvironment(); DataEditCommon.CheckEditState(); while (m_pFeature != null) { ITransform2D pTrans2D = m_pFeature.ShapeCopy as ITransform2D; if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry0Dimension) { IPoint pt = m_pFeature.Shape as IPoint; if (dx == 0) { dx = pPoint.X - pt.X; } if (dy == 0) { dy = pPoint.Y - pt.Y; } pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry1Dimension) { IPolyline lPolyline = m_pFeature.Shape as IPolyline; if (dx == 0) { dx = pPoint.X - lPolyline.FromPoint.X; } if (dy == 0) { dy = pPoint.Y - lPolyline.FromPoint.Y; } pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry2Dimension) { if (m_pFeature.FeatureType == esriFeatureType.esriFTAnnotation) { IAnnotationFeature annoFeature = m_pFeature as IAnnotationFeature; IElement element = (IElement)annoFeature.Annotation; ITextElement textElement = new TextElementClass(); IPoint mPoint = element.Geometry as IPoint; pTrans2D = mPoint as ITransform2D; if (dx == 0) { dx = pPoint.X - mPoint.X; } if (dy == 0) { dy = pPoint.Y - mPoint.Y; } pTrans2D.Move(dx, dy); element.Geometry = pTrans2D as IGeometry; annoFeature.Annotation = element; m_pFeature.Store(); } else { IPolygon lPolyline = m_pFeature.Shape as IPolygon; if (dx == 0) { dx = pPoint.X - lPolyline.FromPoint.X; } if (dy == 0) { dy = pPoint.Y - lPolyline.FromPoint.Y; } pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } } else { } m_pFeature = pFeatureCursor.NextFeature(); } DataEditCommon.g_engineEditor.StopOperation("editpaste"); GIS.Common.DataEditCommon.copypaste = 0; DataEditCommon.copypasteLayer = null; m_hookHelper.ActiveView.Refresh(); //IPoint pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint); //IFeatureLayer featureLayer = DataEditCommon.g_pLayer as IFeatureLayer; //if (featureLayer == null) return; //if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == featureLayer.FeatureClass.ShapeType && DataEditCommon.MyCopy.m_featureLayer.FeatureClass.FeatureType == featureLayer.FeatureClass.FeatureType) //{ // ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = DataEditCommon.MyCopy.m_selectionSet; // for (int i = 0; i < m_selectionSet.Count; i++) // { // } //} //else if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && featureLayer.FeatureClass.FeatureType != esriFeatureType.esriFTAnnotation) //{ //} //else if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && DataEditCommon.MyCopy.m_featureLayer.FeatureClass.FeatureType!=esriFeatureType.esriFTAnnotation&& featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //{ //} //DataEditCommon.InitEditEnvironment(); //DataEditCommon.CheckEditState(); }
private void button_dress_Click(object sender, EventArgs e) { //获取axPageLayoutControl1的图形容器 IGraphicsContainer graphicsContainer = axPageLayoutControl1.GraphicsContainer; //获取axPageLayoutControl1空间里面显示的地图图层 IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap); if (mapFrame == null) { return; } //--------------创建图例------------ UID uID = new UIDClass(); //创建UID作为该图例的唯一标识符,方便创建之后进行删除、移动等操作 uID.Value = "esriCarto.Legend"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null); if (mapSurroundFrame == null) { return; } if (mapSurroundFrame.MapSurround == null) { return; } mapSurroundFrame.MapSurround.Name = "图例"; IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(16, 2, 18, 7);//设置图例摆放位置(原点在axPageLayoutControl左下角) IElement element = (IElement)mapSurroundFrame; element.Geometry = envelope; //将图例转化为几何要素添加到axPageLayoutControl1,并刷新页面显示 axPageLayoutControl1.AddElement(element, Type.Missing, Type.Missing, "Legend", 0); axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //-----------设置指北针-------- IMapSurround pMapSurround; INorthArrow pNorthArrow; pNorthArrow = new MarkerNorthArrowClass();//创建指北针的实例 pMapSurround = pNorthArrow; pMapSurround.Name = "NorthArrow"; //定义UID UID uid = new UIDClass(); uid.Value = "esriCarto.MarkerNorthArrow"; //定义MapSurroundFrame对象 IMapSurroundFrame pMapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); pMapSurroundFrame.MapSurround = pMapSurround; IElement pDeletElement = axPageLayoutControl1.FindElementByName("NorthArrow");//获取PageLayout中的图例元素 if (pDeletElement != null) { graphicsContainer.DeleteElement(pDeletElement); //如果已经存在指北针,删除已经存在的指北针 } //定义Envelope设置Element摆放的位置 IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(16, 24, 21, 32); IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = pEnvelope; graphicsContainer.AddElement(pElement, 0); //刷新axPageLayoutControl1的内容 axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //-----------设置比例尺------------ IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; IMap pMap = pActiveView.FocusMap as IMap; IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; //IMapSurround pMapSurround; //设置比例尺样式 IScaleBar pScaleBar = new ScaleLineClass(); pScaleBar.Units = esriUnits.esriKilometers; pScaleBar.Divisions = 4; pScaleBar.Subdivisions = 3; pScaleBar.DivisionsBeforeZero = 0; pScaleBar.UnitLabel = "km"; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; pScaleBar.LabelGap = 3.6; pScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; ITextSymbol pTextsymbol = new TextSymbolClass(); pTextsymbol.Size = 1; stdole.StdFont pFont = new stdole.StdFont(); pFont.Size = 3; pFont.Name = "Arial"; pTextsymbol.Font = pFont as stdole.IFontDisp; pTextsymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pScaleBar.UnitLabelSymbol = pTextsymbol; pScaleBar.LabelSymbol = pTextsymbol; INumericFormat pNumericFormat = new NumericFormatClass(); pNumericFormat.AlignmentWidth = 0; pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits; pNumericFormat.RoundingValue = 0; pNumericFormat.UseSeparator = true; pNumericFormat.ShowPlusSign = false; //定义UID pMapSurround = pScaleBar; pMapSurround.Name = "ScaleBar"; // UID uid = new UIDClass(); uid.Value = "esriCarto.ScaleLine"; //定义MapSurroundFrame对象IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null); pMapSurroundFrame.MapSurround = pMapSurround; //定义Envelope设置Element摆放的位置 //IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(8, 2, 14, 4); //IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = pEnvelope; //IElement pDeletElement = axPageLayoutControl1.FindElementByName("ScaleBar"); //获取PageLayout中的比例尺元素 if (pDeletElement != null) { pGraphicsContainer.DeleteElement(pDeletElement); //如果已经存在比例尺,删除已经存在的比例尺 } pGraphicsContainer.AddElement(pElement, 0); //刷新axPageLayoutControl1的内容 axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //---------------添加标题------------- //IGraphicsContainer graphicsContainer = axPageStation.PageLayout as IGraphicsContainer; //IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(-14, 26, 35, 26); IRgbColor pColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; pFont.Name = "宋体"; pFont.Bold = true; ITextSymbol pTextSymbol = new TextSymbolClass() { Color = pColor, //Font = pFont, Size = 30 }; ITextElement pTextElement = new TextElementClass() { Symbol = pTextSymbol, ScaleText = true, Text = "盗墓难度专题图" }; element = pTextElement as ESRI.ArcGIS.Carto.IElement; element.Geometry = envelope; graphicsContainer.AddElement(element, 0); axPageLayoutControl1.Refresh(); }
public static void setAllElements(Dictionary <string, string> dict) { IPageLayout pLayout = _pMxDoc.PageLayout; IGraphicsContainer pGraphics = pLayout as IGraphicsContainer; pGraphics.Reset(); IElement element = new TextElementClass(); IElementProperties2 pElementProp; ITextElement pTextElement; try { element = (IElement)pGraphics.Next(); while (element != null) { if (element is ITextElement) { pTextElement = element as ITextElement; pElementProp = element as IElementProperties2; if (pElementProp.Name == "title") { pTextElement.Text = dict["title"]; } else if (pElementProp.Name == "summary") { pTextElement.Text = dict["summary"]; } else if (pElementProp.Name == "mxd_name") { pTextElement.Text = dict["mxd_name"]; } else if (pElementProp.Name == "map_no") { pTextElement.Text = dict["map_no"]; } else if (pElementProp.Name == "scale") { pTextElement.Text = dict["scale"]; } else if (pElementProp.Name == "spatial_reference") { pTextElement.Text = dict["spatial_reference"]; } else if (pElementProp.Name == "glide_no") { pTextElement.Text = dict["glide_no"]; } } element = (IElement)pGraphics.Next(); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error updating layout elements"); System.Diagnostics.Debug.WriteLine(e); } IActiveView activeView = _pMxDoc.ActivatedView as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void AddCallOutElement(IPolyline pPolyline) { IGraphicsContainer pGraphicCtn = m_pActiveView.GraphicsContainer; try { frmEdit frmCallOut = new frmEdit(true); PublicClass.POINTAPI pos = new PublicClass.POINTAPI(); PublicClass.GetCursorPos(ref pos); frmCallOut.Location = new System.Drawing.Point(pos.x, pos.y); // * pScreen.BitsPerPixel int scrW = Screen.PrimaryScreen.WorkingArea.Width; //主显示宽度 int scrH = Screen.PrimaryScreen.WorkingArea.Height; //主显示高度 frmCallOut.Location = new System.Drawing.Point(pos.x, pos.y); // * pScreen.BitsPerPixel if (pos.x + frmCallOut.Width > scrW && pos.y + frmCallOut.Height > scrH) //超出显示器边界宽和高,则迂回 { frmCallOut.Location = new System.Drawing.Point(scrW - frmCallOut.Width, scrH - frmCallOut.Height); } if (pos.x + frmCallOut.Width > scrW && pos.y + frmCallOut.Height < scrH) //超出显示器边界宽,则迂回 { frmCallOut.Location = new System.Drawing.Point(scrW - frmCallOut.Width, pos.y); } if (pos.x + frmCallOut.Width < scrW && pos.y + frmCallOut.Height > scrH) //超出显示器边界高,则迂回 { frmCallOut.Location = new System.Drawing.Point(pos.x, scrH - frmCallOut.Height); } frmCallOut.ShowDialog(); if (frmCallOut.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return; } ITextElement pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = frmCallOut.AnnoText; IFormattedTextSymbol pTextSymbol = (IFormattedTextSymbol)frmCallOut.m_pTextSymbol; IBalloonCallout pCallout = new BalloonCalloutClass(); pCallout.Symbol = frmCallOut.m_pFillSymbol; pCallout.AnchorPoint = pPolyline.FromPoint; pTextSymbol.Background = (ITextBackground)pCallout; pTextElement.Symbol = pTextSymbol as ITextSymbol; IElement pElement = (IElement)pTextElement; pElement.Geometry = pPolyline.ToPoint; //刷新显示 frmCallOut.Dispose(); IGraphicsContainerSelect pGraphicsSel = pGraphicCtn as IGraphicsContainerSelect; pGraphicsSel.UnselectAllElements(); pGraphicsSel.SelectElement(pElement); pGraphicCtn.AddElement(pElement, 0); m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("添加文本注记失败:" + ex.Message, "提示"); return; } }
//拉框选择 private void mainMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (flag == 1) { baseOrder.box_select(e); } //屏幕坐标点转化为地图坐标点 pPointPt = (mainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { IActiveView pActiveView = mainMapControl.ActiveView; IEnvelope pEnvelope = new EnvelopeClass(); if (pMouseOperate == "MeasureLength") { //判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点 if (pNewLineFeedback == null) { //实例化追踪线对象 pNewLineFeedback = new NewLineFeedbackClass(); pNewLineFeedback.Display = (mainMapControl.Map as IActiveView).ScreenDisplay; //设置起点,开始动态线绘制 pNewLineFeedback.Start(pPointPt); dToltalLength = 0; } else //如果追踪线对象不为空,则添加当前鼠标点 { pNewLineFeedback.AddPoint(pPointPt); } //pGeometry = m_PointPt; if (dSegmentLength != 0) { dToltalLength = dToltalLength + dSegmentLength; } } else if (pMouseOperate == "MeasureArea") { if (pNewPolygonFeedback == null) { //实例化追踪面对象 pNewPolygonFeedback = new NewPolygonFeedback(); pNewPolygonFeedback.Display = (mainMapControl.Map as IActiveView).ScreenDisplay; ; pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //开始绘制多边形 pNewPolygonFeedback.Start(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } else { pNewPolygonFeedback.AddPoint(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } } } else if (e.button == 2) { pMouseOperate = ""; mainMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; } if (flag == 0) { mainMapControl.CurrentTool = null; if (e.button != 2) { flag = 999; return; } IPoint point = new PointClass(); point = mainMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); //设置文本格式 ITextSymbol textSymbol = new TextSymbolClass(); StdFont stdFont = new stdole.StdFontClass(); stdFont.Name = "宋体"; stdFont.Size = 24; textSymbol.Font = (IFontDisp)stdFont; textSymbol.Angle = 0; textSymbol.RightToLeft = false; //垂直方向基线对齐 textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline; //文本两端对齐 textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull; textSymbol.Text = C.Text; ITextElement textElement = new TextElementClass(); textElement.Symbol = textSymbol; textElement.Text = textSymbol.Text; //获取坐标,添加文本 IElement element = (IElement)textElement; element.Geometry = point; mainMapControl.ActiveView.GraphicsContainer.AddElement(element, 0); mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, null); } if (flag == 66) {//画线 IGeometry pGeom; pGeom = (IGeometry)mainMapControl.TrackLine(); IGraphicsContainer pGraphicsContainer = mainMapControl.Map as IGraphicsContainer; baseOrder.AddLineElement(pGeom, pGraphicsContainer); } if (flag == 77) {//闪 IMap pMap = mainMapControl.Map; IActiveView pActiveView = pMap as IActiveView; IPoint pt = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); ITopologicalOperator pTopo = pt as ITopologicalOperator; IGeometry pGeo = pTopo.Buffer(100); IColor pColor = new RgbColorClass(); pColor.RGB = 2556; SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = pColor; ISymbol symbol = simpleFillSymbol as ISymbol; pActiveView.ScreenDisplay.SetSymbol(symbol); pActiveView.ScreenDisplay.DrawPolygon(pGeo); pMap.SelectByShape(pGeo, null, false); mainMapControl.FlashShape(pGeo, 25, 200, symbol); mainMapControl.ActiveView.Refresh(); } }
private void MoveFeature() { ITransform2D pTrans2d; IWorkspaceEdit pWorkspaceEdit; //工作空间的编辑接口 pWorkspaceEdit = Class.Common.CurWspEdit; pWorkspaceEdit.StartEditOperation(); m_pEnvelope = ((IFeature)m_OriginFeatureArray.get_Element(0)).Extent; for (int i = 0; i < m_OriginFeatureArray.Count; i++) { IFeature pFeature = (IFeature)m_OriginFeatureArray.get_Element(i); if (pFeature.FeatureType == esriFeatureType.esriFTAnnotation) { IAnnotationFeature pAnnotationFeature = pFeature as IAnnotationFeature; IElement element = new TextElementClass(); element = pAnnotationFeature.Annotation; IPoint pPointOld = null; if (element.Geometry.GeometryType == esriGeometryType.esriGeometryPolyline) { IPolyline pPolyline = element.Geometry as IPolyline; pPointOld = pPolyline.FromPoint; } else if (element.Geometry.GeometryType == esriGeometryType.esriGeometryPoint) { pPointOld = element.Geometry as IPoint; } IPoint pPointNew = new PointClass(); pPointNew.PutCoords(pPointOld.X + (m_pPoint2.X - m_pPoint0.X), pPointOld.Y + (m_pPoint2.Y - m_pPoint0.Y)); element.Geometry = pPointNew; try { pAnnotationFeature.Annotation = element; ((IFeature)pAnnotationFeature).Store(); } catch { System.Windows.Forms.MessageBox.Show("当前操作不在有效坐标范围内,操作失败"); } m_pEnvelope.Union(pFeature.Shape.Envelope); } else { pTrans2d = (ITransform2D)pFeature.Shape; //接口的跳转 pTrans2d.Move(m_pPoint2.X - m_pPoint0.X, m_pPoint2.Y - m_pPoint0.Y); m_pEnvelope.Union(((IGeometry)pTrans2d).Envelope); pFeature.Shape = (IGeometry)pTrans2d; pFeature.Store(); } } pWorkspaceEdit.StopEditOperation(); m_App.Workbench.UpdateMenu(); //m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pEnvelope);//视图刷新 }
private void DrawNodeInfo(IPoint point, IntersectPipe ip) { 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 = ip.Classify; break; case "起点号": sym.Text = ip.StartNo; break; case "终点号": sym.Text = ip.EndNo; break; case "材质": sym.Text = ip.Material; break; case "埋设方式": sym.Text = ip.Coverstyle; break; case "管径": sym.Text = ip.Diameter; break; case "所在道路": sym.Text = ip.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); } }
public static void drawText(string text, IPoint pt, IRgbColor color, AxMapControl mapControl) { ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Size = 10; pTextSymbol.Color = color; ITextElement pTextElement = new TextElementClass(); pTextElement.Text = text; pTextElement.ScaleText = false; pTextElement.Symbol = pTextSymbol; IElement pElement = pTextElement as IElement; pElement.Geometry = pt; IGraphicsContainer pGraphicsContainer = mapControl.Map as IGraphicsContainer; IActiveView pActiveView = mapControl.ActiveView; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public static void AddTextElement(AxPageLayoutControl PageLayoutControl, double x, double y, string textName) { IPageLayout pPageLayout; IActiveView pAV; IGraphicsContainer pGraphicsContainer; IPoint pPoint; ITextElement pTextElement; IElement pElement; ITextSymbol pTextSymbol; IRgbColor pColor; pPageLayout = PageLayoutControl.PageLayout; pAV = (IActiveView)pPageLayout; pGraphicsContainer = (IGraphicsContainer)pPageLayout; pTextElement = new TextElementClass(); IFontDisp pFont = new StdFontClass() as IFontDisp; pFont.Bold = true; pFont.Name = "宋体"; pFont.Size = 26; pColor = new RgbColorClass(); pColor.Red = 255; pTextSymbol = new TextSymbolClass(); pTextSymbol.Color = (IColor)pColor; pTextSymbol.Font = pFont; pTextElement.Text = textName; pTextElement.Symbol = pTextSymbol; pPoint = new PointClass(); pPoint.X = x; pPoint.Y = y; pElement = (IElement)pTextElement; pElement.Geometry = (IGeometry)pPoint; pGraphicsContainer.AddElement(pElement, 0); pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void btnTextSymbol_Click(object sender, EventArgs e) { ITextElement textElement = new TextElementClass(); textElement.Symbol = pTextSymbol; textElement.Text = "图层名"; frmTextSymbol frmText = new frmTextSymbol(ref textElement); frmText.ShowDialog(); pTextSymbol = textElement.Symbol; //这里是设置标注的字体样式 }
/// <summary> /// 绘制文字到地图中 /// </summary> /// <params name="text"></params> /// <params name="pPoint"></params> /// <params name="drawFont"></params> void DrawTextToMap(string text, ESRI.ArcGIS.Geometry.IPoint pPoint) { IElement element; ITextElement textElement = new TextElementClass(); element = textElement as IElement; ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Color = m_color; if (m_pFont != null) { textSymbol.Font = (stdole.IFontDisp)ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(m_pFont); textSymbol.Size = Convert.ToDouble(m_pFont.Size); } element.Geometry = pPoint; textElement.Symbol = textSymbol; textElement.Text = text; IFeature pFeature = DataEditCommon.SaveAnno(element, text); GIS.Common.DataEditCommon.g_pMap.SelectFeature(GIS.Common.DataEditCommon.g_pLayer, pFeature); GIS.Common.DataEditCommon.g_pAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); }
/// <summary> /// �����ı���ʾ�� /// </summary> /// <param name="x">��ʾ���ʶ��λ��X����</param> /// <param name="y">��ʾ���ʶ��λ��Y����</param> public void CreateTextElment(AxMapControl axMapControl1, double x, double y, string strText) { IPoint pPoint = new PointClass(); IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IGraphicsContainer pGraphicsContainer; IElement pElement = new MarkerElementClass(); IElement pTElement = new TextElementClass(); pGraphicsContainer = (IGraphicsContainer)pActiveView; IFormattedTextSymbol pTextSymbol = new TextSymbolClass(); IBalloonCallout pBalloonCallout = CreateBalloonCallout(x, y); IRgbColor pColor = new RgbColorClass(); pColor.Red = 150; pColor.Green = 0; pColor.Blue = 0; pTextSymbol.Color = pColor; ITextBackground pTextBackground; pTextBackground = (ITextBackground)pBalloonCallout; pTextSymbol.Background = pTextBackground; ((ITextElement)pTElement).Symbol = pTextSymbol; ((ITextElement)pTElement).Text = strText; IPoint p = new PointClass(); //���õ������ p.PutCoords(x, y); IElementProperties ipElemProp; IMarkerElement ipMarkerElement = new MarkerElementClass(); IPictureMarkerSymbol ipPicMarker = new PictureMarkerSymbolClass(); ipPicMarker.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, "D:\\pro\\ArcGisView\\ArcGisView\\1.bmp"); ipPicMarker.Size = 24; IRgbColor ipRGBTrans = new RgbColorClass(); ipRGBTrans.RGB = 0xffffff; ipPicMarker.BitmapTransparencyColor = ipRGBTrans as IColor; ipMarkerElement.Symbol = ipPicMarker as IMarkerSymbol; IElement ipElement = ipMarkerElement as IElement; ipElement.Geometry = p as IGeometry; axMapControl1.ActiveView.GraphicsContainer.AddElement(ipElement, 0); pPoint.X = x + 42; pPoint.Y = y + 42; pTElement.Geometry = pPoint; pGraphicsContainer.AddElement(pTElement, 1); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private static void DrawLabel(IGroupElement3 group, string label, IPoint point) { var text = new TextElementClass { AnchorPoint = esriAnchorPointEnum.esriCenterPoint, Text = label, Geometry = point }; group.AddElement(text); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { IGeometry Geom = null; if (!m_bInUse) { downPoint = m_pAnchorPoint; m_pRecordPointArray.Add(downPoint); m_pCircleFeed = new NewCircleFeedbackClass(); m_bInUse = true; m_pCircleFeed.Display = m_pActiveView.ScreenDisplay; m_pLineFeed = new NewLineFeedbackClass(); m_pLineFeed.Start(downPoint); m_pCircleFeed.Start(downPoint); } else //如果命令正在使用 { if (pGraphicsContainer != null) { pGraphicsContainer.DeleteAllElements(); } movePoint = m_pAnchorPoint; //画半径线 m_pRecordPointArray.Add(movePoint); IPolyline pPolyline; pPolyline = (IPolyline)CommonFunction.MadeSegmentCollection(ref m_pRecordPointArray); Geom = (IGeometry)pPolyline; CommonFunction.AddElement(m_pMapControl, Geom); m_radius = CommonFunction.GetDistance_P12(downPoint, movePoint); //半径 //m_radius = Math.Round( m_radius,1,MidpointRounding.AwayFromZero);//保留一位小数 //缓冲半径文本 ITextElement iTextElement = new TextElementClass(); iTextElement.Text = m_radius.ToString(".##") + "米"; ITextSymbol sce = new TextSymbolClass(); sce.Size = 15 /*SystemInfo.Instance.TextSize*/; Color color = ColorTranslator.FromHtml(SystemInfo.Instance.TextColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; sce.Color = pColor; iTextElement.Symbol = sce; IElement iElement = (IElement)iTextElement; iElement.Geometry = Geom; this.m_pMapControl.ActiveView.GraphicsContainer.AddElement(iElement, 0); this.m_pMapControl.ActiveView.Refresh(); //画圆 pSegmentCollection = new PolygonClass(); pSegmentCollection.SetCircle(downPoint, m_radius); pGeom = pSegmentCollection as IGeometry; if (pGeom != null) { AddCreateCircleElement(pGeom, this.m_pMapControl.ActiveView); this.m_pMapControl.ActiveView.Refresh(); GetPipeInfo(); } if (m_pRecordPointArray.Count != 0) { m_pRecordPointArray.RemoveAll(); } m_bInUse = false; } }
private void DrawColName() { IGraphicsContainer pGraContainer = m_pMapControl.Map as IGraphicsContainer; 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 = 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; //类别 sym.Text = "类别"; pAnnoPnt.PutCoords(dblStartX + nWidth, dblStartY + nHeight * m_IntersectPipes.Count); ITextElement pTextElement = new TextElementClass(); pTextElement.ScaleText = true; pTextElement.Text = sym.Text; pTextElement.Symbol = sym; IElement pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //起点点号 sym.Text = "起点点号"; pAnnoPnt.PutCoords(dblStartX + nWidth * 2, dblStartY + nHeight * m_IntersectPipes.Count);//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //终点点号 sym.Text = "终点点号"; pAnnoPnt.PutCoords(dblStartX + nWidth * 3, dblStartY + nHeight * m_IntersectPipes.Count);//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //材质 sym.Text = "材质"; pAnnoPnt.PutCoords(dblStartX + nWidth * 4, dblStartY + nHeight * m_IntersectPipes.Count);//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //埋设方式 sym.Text = "埋设方式"; pAnnoPnt.PutCoords(dblStartX + nWidth * 5, dblStartY + nHeight * m_IntersectPipes.Count);//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //管径 sym.Text = "管径"; pAnnoPnt.PutCoords(dblStartX + nWidth * 6, dblStartY + nHeight * m_IntersectPipes.Count);//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); //所在道路 sym.Text = "所在道路"; pAnnoPnt.PutCoords(dblStartX + nWidth * 7, dblStartY + nHeight * m_IntersectPipes.Count);//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3 pTextElement = new TextElementClass(); pTextElement.Text = sym.Text; pTextElement.Symbol = sym; pElement = (IElement)pTextElement; pElement.Geometry = pAnnoPnt; pGraContainer.AddElement(pElement, 0); (m_pMapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pMapControl.Extent); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button == 1) { IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView as IGraphicsContainer; m_point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IEnumElement pEnumElement = pGraphicsContainer.LocateElements(m_point, 1); if (pEnumElement == null) return; m_element = pEnumElement.Next(); if (m_element is AnnotationElement) { ITextElement pTextElement = new TextElementClass { Text = ((ITextElement)m_element).Text, Symbol = ((ITextElement)m_element).Symbol, ScaleText = true }; m_viewElement = pTextElement as IElement; m_viewElement.Geometry = m_element.Geometry; m_hookHelper.ActiveView.GraphicsContainer.AddElement(m_viewElement, 0); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, m_viewElement, null); } // 移动状态信息 m_moving = true; } }
public void CreateTextElment(double x, double y) { IPoint pPoint = new PointClass(); IMap pMap = axMapControl.Map; IActiveView pActiveView = pMap as IActiveView; IGraphicsContainer pGraphicsContainer; IElement pElement = new MarkerElementClass(); IElement pTElement = new TextElementClass(); pGraphicsContainer = (IGraphicsContainer)pActiveView; IFormattedTextSymbol pTextSymbol = new TextSymbolClass(); IBalloonCallout pBalloonCallout = CreateBalloonCallout(x, y); IRgbColor pColor = new RgbColorClass(); pColor.Red = 150; pColor.Green = 0; pColor.Blue = 0; pTextSymbol.Color = pColor; ITextBackground pTextBackground; pTextBackground = (ITextBackground)pBalloonCallout; pTextSymbol.Background = pTextBackground; ((ITextElement)pTElement).Symbol = pTextSymbol; ((ITextElement)pTElement).Text = "测试"; pPoint.X = x + 42; pPoint.Y = y + 42; //axMapControl.CenterAt(pPoint); pTElement.Geometry = pPoint; pGraphicsContainer.AddElement(pTElement, 1); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void CalculateLength(int x, int y, int num) { string[] str; string str1 = String.Concat(" ", this.GetUnitDesc(_context.FocusMap.MapUnits)); ILine lineClass = new Line(); double length = 0; string str2 = ""; IPoint mapPoint = ((IActiveView)this._context.FocusMap).ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (mapPoint != null) { if (!(num != 1 ? true : this._lineFeedback != null)) { //第一个点 this._length = 0; this._lineFeedback = new NewLineFeedbackClass() { Display = ((IActiveView)this._context.FocusMap).ScreenDisplay }; _lineFeedback.Start(mapPoint); _iPoint0 = mapPoint; graphicsContainer.DeleteAllElements(); str2 = string.Concat("距离 = 0.0 ", str1, ", 总长度 = 0.0 ", str1); } else if (this._lineFeedback != null) { switch (num) { case 1: { lineClass.PutCoords(this._iPoint0, mapPoint); length = lineClass.Length; _length = _length + length; this._lineFeedback.AddPoint(mapPoint); str = new string[] { "距离 = ", length.ToString("0.####"), str1, ", 总长度 = ", _length.ToString("0.####"), str1 }; str2 = string.Concat(str); ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; IElement pElement = pLineElement as IElement; IPolyline pLine2 = new Polyline() as IPolyline; IPointCollection pCol = pLine2 as IPointCollection; pCol.AddPoint(_iPoint0); pCol.AddPoint(mapPoint); pElement.Geometry = (IGeometry)pLine2; graphicsContainer.AddElement(pElement, 0); double ang = GetAngle(lineClass); ITextElement pTextElement = new TextElementClass(); pTextElement.Symbol = pAngleSymbol; pTextElement.Text = ang.ToString("###.##"); IElement pTextElement2 = pTextElement as IElement; pTextElement2.Geometry = (IGeometry)pLine2; graphicsContainer.AddElement(pTextElement2, 0); ITextElement pTextElement3 = new TextElementClass(); pTextElement3.Symbol = pDistSymbol; pTextElement3.Text = string.Format("{0:###.##}({1:####.##}){2}", lineClass.Length, _length, str1); IElement pTextElement4 = pTextElement3 as IElement; pTextElement4.Geometry = (IGeometry)pLine2; graphicsContainer.AddElement(pTextElement4, 0); ((IActiveView)this._context.FocusMap).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); this._iPoint0 = mapPoint; break; } case 2: { lineClass.PutCoords(this._iPoint0, mapPoint); length = lineClass.Length; double num2 = this._length + length; str = new string[] { "距离 = ", length.ToString("0.####"), str1, ", 总长度 = ", num2.ToString("0.####"), str1 }; str2 = string.Concat(str); //this.m_HookHelper.SetStatus(str2); this._lineFeedback.MoveTo(mapPoint); this._iPoint1 = mapPoint; break; } case 3: { lineClass.PutCoords(this._iPoint0, this._iPoint1); length = 0; _length = _length + lineClass.Length; str = new string[] { "距离 = ", length.ToString("0.####"), str1, ", 总长度 = ", this._length.ToString("0.####"), str1 }; str2 = string.Concat(str); //this.m_HookHelper.SetStatus(str2); this._lineFeedback = null; ((IActiveView)this._context.FocusMap).Refresh(); break; } } } } }
private void AddBalloonCalloutLabel(string strName, string strText, IPoint pPointAnchor, IElementCollection pElementCollection) { ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; IRgbColor pRgbColorFillSymbol = new RgbColorClass(); pRgbColorFillSymbol.RGB = fColor; //pRgbColorFillSymbol.Red = Color.White.R; //pRgbColorFillSymbol.Green = Color.White.G; //pRgbColorFillSymbol.Blue = Color.White.B; //byte bt = 0; //pRgbColorFillSymbol.Transparency = bt; pSimpleFillSymbol.Color = pRgbColorFillSymbol; //IBalloonCallout 接口 IBalloonCallout pBalloonCallout = new BalloonCalloutClass();//弹出标签的背景 pBalloonCallout.Style = _style;//选择弹出标签样式,请尝试另外两种样式 pBalloonCallout.Symbol = pSimpleFillSymbol;//填充 pBalloonCallout.LeaderTolerance = 1; pBalloonCallout.AnchorPoint = pPointAnchor;//定位点 //创建点标注 ITextSymbol pTextSymbol = new TextSymbolClass(); IFormattedTextSymbol pFormattedTextSymbol = pTextSymbol as IFormattedTextSymbol; pFormattedTextSymbol.Background = pBalloonCallout as ITextBackground;//设置背景 //字体相关设置 IRgbColor pRgbColorTextSymbol = new RgbColorClass();//字体颜色 pRgbColorTextSymbol.RGB = tColor; //pRgbColorTextSymbol.Red = 0; //pRgbColorTextSymbol.Green = 0; //pRgbColorTextSymbol.Blue = 0; pFormattedTextSymbol.Color = pRgbColorTextSymbol; pFormattedTextSymbol.Font.Name = "宋体"; pFormattedTextSymbol.Size = _FontSize; pFormattedTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;//对齐方式 pFormattedTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; ISimpleTextSymbol pSimpleTextSymbol = pTextSymbol as ISimpleTextSymbol; pSimpleTextSymbol.XOffset = 15; pSimpleTextSymbol.YOffset = 0; //加点标签 ITextElement pTextElement = new TextElementClass(); pTextElement.Symbol = pFormattedTextSymbol as ITextSymbol; pTextElement.Text = strText;//显示的标注文本 IElement pElement = pTextElement as IElement; pElement.Geometry = pPointAnchor as IGeometry;//位置 pPointPosition IElementProperties pElementProperties = pElement as IElementProperties; pElementProperties.Name = strName;//IElement的名称 pElementCollection.Add(pElementProperties as IElement, -1); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { m_command.OnClick(); m_hookHelper.ActiveView.Refresh(); IPoint pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint); IFeatureLayer featureLayer = GIS.Common.DataEditCommon.copypasteLayer; if (featureLayer == null) return; IFeatureSelection m_featureSelection = featureLayer as IFeatureSelection; ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = m_featureSelection.SelectionSet; if (m_selectionSet.Count == 0) return; IFeatureClass pFeatureClass = featureLayer.FeatureClass; ICursor pCursor = null; m_selectionSet.Search(null, false, out pCursor); IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor; IFeature m_pFeature = pFeatureCursor.NextFeature(); double dx = 0; double dy = 0; if (m_pFeature == null) return; DataEditCommon.InitEditEnvironment(); DataEditCommon.CheckEditState(); while(m_pFeature!=null) { ITransform2D pTrans2D = m_pFeature.ShapeCopy as ITransform2D; if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry0Dimension) { IPoint pt = m_pFeature.Shape as IPoint; if (dx == 0) dx = pPoint.X - pt.X; if (dy == 0) dy = pPoint.Y - pt.Y; pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry1Dimension) { IPolyline lPolyline = m_pFeature.Shape as IPolyline; if (dx == 0) dx = pPoint.X - lPolyline.FromPoint.X; if(dy==0) dy=pPoint.Y - lPolyline.FromPoint.Y; pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry2Dimension) { if (m_pFeature.FeatureType == esriFeatureType.esriFTAnnotation) { IAnnotationFeature annoFeature = m_pFeature as IAnnotationFeature; IElement element = (IElement)annoFeature.Annotation; ITextElement textElement = new TextElementClass(); IPoint mPoint=element.Geometry as IPoint; pTrans2D = mPoint as ITransform2D; if (dx == 0) dx = pPoint.X - mPoint.X; if (dy == 0) dy = pPoint.Y - mPoint.Y; pTrans2D.Move(dx, dy); element.Geometry = pTrans2D as IGeometry; annoFeature.Annotation = element; m_pFeature.Store(); } else { IPolygon lPolyline = m_pFeature.Shape as IPolygon; if (dx == 0) dx = pPoint.X - lPolyline.FromPoint.X; if (dy == 0) dy = pPoint.Y - lPolyline.FromPoint.Y; pTrans2D.Move(dx, dy); m_pFeature.Shape = pTrans2D as IGeometry; m_pFeature.Store(); } } else { } m_pFeature = pFeatureCursor.NextFeature(); } DataEditCommon.g_engineEditor.StopOperation("editpaste"); GIS.Common.DataEditCommon.copypaste = 0; DataEditCommon.copypasteLayer = null; m_hookHelper.ActiveView.Refresh(); //IPoint pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint); //IFeatureLayer featureLayer = DataEditCommon.g_pLayer as IFeatureLayer; //if (featureLayer == null) return; //if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == featureLayer.FeatureClass.ShapeType && DataEditCommon.MyCopy.m_featureLayer.FeatureClass.FeatureType == featureLayer.FeatureClass.FeatureType) //{ // ESRI.ArcGIS.Geodatabase.ISelectionSet m_selectionSet = DataEditCommon.MyCopy.m_selectionSet; // for (int i = 0; i < m_selectionSet.Count; i++) // { // } //} //else if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && featureLayer.FeatureClass.FeatureType != esriFeatureType.esriFTAnnotation) //{ //} //else if (DataEditCommon.MyCopy.m_featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && DataEditCommon.MyCopy.m_featureLayer.FeatureClass.FeatureType!=esriFeatureType.esriFTAnnotation&& featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //{ //} //DataEditCommon.InitEditEnvironment(); //DataEditCommon.CheckEditState(); }
private ITextElement MakeTextElement(IPoint pPoint, string strText, string sFontName, bool Centered = false, long FontSize = 8) { // Setup a color IRgbColor pRGBColor = new RgbColorClass(); pRGBColor.Blue = 0; pRGBColor.Red = 0; pRGBColor.Green = 0; // Set text element at the right place ITextElement pTextElement = new TextElementClass(); IElement pElement = pTextElement as IElement; pElement.Geometry = pPoint; // Setup a Font IFontDisp pFontDisp = new stdole.StdFontClass() as IFontDisp; pFontDisp.Name = sFontName; // Setup a TextSymbol that the TextElement will draw with ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Font = pFontDisp; pTextSymbol.Color = pRGBColor; pTextSymbol.Size = FontSize; // Center if appropriate if (Centered == true) { pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } else { pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } // Give the TextSymbol and string to the TextElement pTextElement.Symbol = pTextSymbol; pTextElement.Text = strText; return pTextElement; }
private void txtNewText_Leave(object sender, EventArgs e) { ITextElement pTextElement = new TextElementClass(); pTextElement.Text = this.txtNewText.Text; IElement pElement = pTextElement as IElement; pElement.Geometry = this.mapTextPoint; IGraphicsContainer pGraphicsContainer = this.mainMapControl.Map as IGraphicsContainer; pGraphicsContainer.AddElement(pElement, 0); this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); this.txtNewText.Visible = false; }
/// <summary> /// 绘制小柱状 /// </summary> /// <param name="datasources">各地质层厚度(0.83,0.3,1.2,200)最后一个值为底板标高</param> /// <param name="pt">小柱状中心点</param> /// <param name="Angle">旋转角度</param> /// <param name="bili">比例</param> /// <param name="bid">BID</param> /// <param name="edit">函数外控制编辑状态为false,函数内自动控制编辑状态为true,当批量绘图时建议函数外控制编辑状态</param> public static bool drawXZZ(List <KeyValuePair <int, double> > datasources, IPoint pt, double Angle, string bid, double bili = 1, bool edit = true) { double angle = -Angle; Angle = -Angle * Math.PI / 180; DrawXZZMap draw = new DrawXZZMap(bili); var AnnoLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_AnnotationXZZ) as IFeatureLayer; //注记图层 var lineLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolylineXZZ) as IFeatureLayer; //线源图层 var topLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolygonXZZ) as IFeatureLayer; //外部图形图层 if (AnnoLayer == null || lineLayer == null || topLayer == null) { System.Windows.Forms.MessageBox.Show("小柱状图层缺失!"); return(false); } IWorkspaceEdit workspaceEdit = null; if (edit) { var dataset = lineLayer.FeatureClass as IDataset; workspaceEdit = dataset.Workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); } try { // 准备添加数据 var polygonTopCursor = topLayer.FeatureClass.Insert(true); var polylineCursor = lineLayer.FeatureClass.Insert(true); var AnnoCursor = AnnoLayer.FeatureClass.Insert(true); // 从数据源图层获得数据 var num1 = datasources[datasources.Count - 1].Value; // 最后一条横线数值 datasources.RemoveAt(datasources.Count - 1); if (datasources.Count > 1) { List <IPoint> txtPoints; List <IPoint> lineStartPoints; var polygons = new List <KeyValuePair <string, IPolygon> >(); // 构造图形 draw.ContructGeometry(pt, datasources, out polygons, out lineStartPoints, out txtPoints); ITransform2D pTrans2D; // 生成方框图形 foreach (var polygon in polygons) { var feature2 = topLayer.FeatureClass.CreateFeatureBuffer(); feature2.set_Value(feature2.Fields.FindField("BID"), bid); if (polygon.Key == "top") { feature2.set_Value(feature2.Fields.FindField("type"), 0); } else if (polygon.Key == "white") { feature2.set_Value(feature2.Fields.FindField("type"), 1); } else if (polygon.Key == "black") { feature2.set_Value(feature2.Fields.FindField("type"), 2); } pTrans2D = polygon.Value as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); IPolygon ppp = pTrans2D as IPolygon; GIS.Common.DataEditCommon.ZMValue(feature2, ppp); feature2.Shape = ppp; polygonTopCursor.InsertFeature(feature2); } // 生成注记 var enveloplist = new List <IEnvelope>(); for (int i = 0; i < txtPoints.Count; i++) { var featureAnno = AnnoLayer.FeatureClass.CreateFeatureBuffer(); IAnnotationFeature AnnoFeature = (IAnnotationFeature)featureAnno; pTrans2D = txtPoints[i] as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Angle = angle; var elementTxt = new TextElementClass { Geometry = pTrans2D as IGeometry, FontName = "微软雅黑", Size = 12 * bili, SymbolID = 0, Symbol = pTextSymbol }; if (i == txtPoints.Count - 1) { elementTxt.Text = num1.ToString(); // 最后一条横线的数值 elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; // 显示在线下边 featureAnno.set_Value(featureAnno.Fields.FindField("strType"), 2); } else { elementTxt.Text = datasources[i].Value.ToString(); elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; featureAnno.set_Value(featureAnno.Fields.FindField("strType"), datasources[i].Key); } AnnoFeature.Annotation = elementTxt; featureAnno.set_Value(featureAnno.Fields.FindField("strAngle"), -angle); featureAnno.set_Value(featureAnno.Fields.FindField("strX"), pt.X); featureAnno.set_Value(featureAnno.Fields.FindField("strY"), pt.Y); featureAnno.set_Value(featureAnno.Fields.FindField("strScale"), bili); featureAnno.set_Value(featureAnno.Fields.FindField("strIndex"), i + 1); featureAnno.set_Value(featureAnno.Fields.FindField("BID"), bid); pTrans2D = featureAnno.Shape as ITransform2D; pTrans2D.Rotate(pt, -Angle); enveloplist.Add(((IGeometry)pTrans2D).Envelope); AnnoCursor.InsertFeature(featureAnno); } // 生成线 var polyline = new PolylineClass(); for (int i = 0; i < enveloplist.Count; i++) { // 计算注记的终点 IPoint toPoint = new PointClass(); if (i % 2 == 0) { toPoint.X = enveloplist[i].XMax; } else { toPoint.X = enveloplist[i].XMin; } toPoint.Y = lineStartPoints[i].Y; var line = new PathClass { FromPoint = lineStartPoints[i], ToPoint = toPoint }; polyline.AddGeometry(line); } var featureLine = lineLayer.FeatureClass.CreateFeatureBuffer(); pTrans2D = polyline as ITransform2D; pTrans2D.Rotate(pt, Angle); IPolyline mline = pTrans2D as IPolyline; GIS.Common.DataEditCommon.ZMValue(featureLine, mline); featureLine.Shape = mline; featureLine.set_Value(featureLine.Fields.FindField("BID"), bid); polylineCursor.InsertFeature(featureLine); } AnnoCursor.Flush(); polygonTopCursor.Flush(); polylineCursor.Flush(); if (edit) { workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); DataEditCommon.g_pMyMapCtrl.ActiveView.Refresh(); } return(true); } catch (Exception ex) { if (edit) { workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); } System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { #region 主窗体右键 /////地图视窗鼠标事件 IToolbarMenu mapPopMenu = null; mapPopMenu = new ToolbarMenu(); if (e.button == 2) { /* IMap pMap = axMapControl1.Map; * IActiveView pActiveView = pMap as IActiveView; * IEnvelope pEnv = axMapControl1.TrackRectangle(); * pActiveView.Extent = pEnv; * pActiveView.Refresh();*/ //地图视窗右键菜单功能 mapPopMenu.AddItem(new ControlsSelectTool(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapPanTool(), -1, 1, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapFullExtentCommand(), -1, 2, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapIdentifyTool(), -1, 3, false, esriCommandStyles.esriCommandStyleIconAndText); //识别工具 mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 4, false, esriCommandStyles.esriCommandStyleIconAndText); // mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 5, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsSelectFeaturesTool(), -1, 6, false, esriCommandStyles.esriCommandStyleIconAndText); //选择要素工具 mapPopMenu.AddItem(new ControlsClearSelectionCommand(), -1, 7, false, esriCommandStyles.esriCommandStyleIconAndText); //缩放所选要素 mapPopMenu.AddItem(new ControlsZoomToSelectedCommand(), -1, 8, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapZoomToLastExtentBackCommand(), -1, 9, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapZoomToLastExtentForwardCommand(), -1, 10, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.SetHook(axMapControl1); //// 得到地图视窗右键菜单 mapPopMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd); //弹出显示菜单 } /* if (e.button == 1)//左键因为右键要取消 * { * IMap pMap = axMapControl1.Map; * IActiveView pActiveView = pMap as IActiveView; * IEnvelope pEnv = axMapControl1.TrackRectangle(); * pActiveView.Extent = pEnv; * pActiveView.Refresh(); * } * */ //此事件不会触发 if (e.button == 3)//如果鼠标中间改为ControlsMapPanTool会更好 { IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pActiveView.Extent = pEnv; pActiveView.Refresh(); } #endregion //if (e.button == 2) //{ // IMap pMap = axMapControl1.Map; // IActiveView pActiveView = pMap as IActiveView; // IEnvelope pEnv = axMapControl1.TrackRectangle(); // pActiveView.Extent = pEnv; // pActiveView.Refresh(); //} //网络分析 if (clicked != true) { return; } IPoint ipNew; if (m_ipPoints == null) { m_ipPoints = new MultipointClass(); } ipNew = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; m_ipPoints.AddPoint(ipNew, ref o, ref o); IElement element; ITextElement textelement = new TextElementClass(); element = textelement as IElement; clickedcount++; textelement.Text = clickedcount.ToString(); element.Geometry = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); pGC.AddElement(element, 0); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void AddTextElement(IMap map, IPoint point, string text) { IGraphicsContainer graphicsContainer = map as IGraphicsContainer; IElement element = new TextElementClass(); ITextElement textElement = element as ITextElement; element.Geometry = point; textElement.Text = text; graphicsContainer.AddElement(element, 0); //Flag the new text to invalidate. IActiveView activeView = map as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public static IElement AddTextElement(IMap map, IPoint point, string text) { IGraphicsContainer graphicsContainer = map as IGraphicsContainer; IElement element = new TextElementClass(); ITextElement textElement = element as ITextElement; element.Geometry = point; textElement.Text = text; graphicsContainer.AddElement(element, 0); return element; }
//���ƣȣ��ԣã� public static void HatchDraw(AxMapControl ppAxMapControl, ISimpleLineSymbol pHatchSymMajor, ISimpleLineSymbol pHatchSymMinor, ITextSymbol pTxtSym, IFeatureLayer pFeatLayer, bool bEnds, bool bEndsOnly, double dHatchLen, double dTxtInterval, double dHatchOffset, double dMajorAngle, bool bOverRideMajor, string graphicslayername) { //����ͼ��ͼ��ΪSEWER TV���ͼ�� IFeatureCursor pFeatCursor = pFeatLayer.Search(null, true); SetGraphicsLayer(ppAxMapControl, pFeatLayer.Name, graphicslayername); //����SEWER TV���ͼ��ͼ�� IGraphicsContainer pGraphicsContainer = ppAxMapControl.ActiveView.FocusMap.ActiveGraphicsLayer as IGraphicsContainer; //���ͼ��ͼ�� pGraphicsContainer.DeleteAllElements(); IFeature pFeature = pFeatCursor.NextFeature(); IPolyline pMajorHatchPL = new PolylineClass(); IPolyline pMinorHatchPL = new PolylineClass(); IPolyline pPL; IMAware pPLM; //IMCollection pMColl; IGeometryCollection pGeomColl; ILineElement pLineElement; IElement pElement = null; int cnt; IPath pPath; string txt; double txtlen; IPath pTxtPath; double angle; //IPoint pTxtPt; ISegmentCollection pSC; ISegment pSeg; ISegmentM pSegM; double m1 = 0; //double m2 = 0; //IPoint pFromPt; //IMarkerSymbol pMSym; IMask pMask; ITextElement pTextElement; ISegmentCollection pSegment; ISegmentCollection pPolyline; while (pFeature != null) { pPL = pFeature.Shape as IPolyline; pPLM = pPL as IMAware; if (pPLM.MAware) { if (bEndsOnly) { MakeHatchesEndsOnly(pPL, bEnds, pMajorHatchPL, pMinorHatchPL, dHatchLen, dTxtInterval, dHatchOffset); } else { } // Draw the major hatches if they are lines if (pHatchSymMajor is ILineSymbol) { pLineElement = new LineElementClass(); pLineElement.Symbol = pHatchSymMajor; pElement = pLineElement as IElement; pElement.Geometry = pMajorHatchPL as IGeometry; pGraphicsContainer.AddElement(pElement, 0); } // Draw the major hatches if they are markers and the text... pGeomColl = pMajorHatchPL as IGeometryCollection; cnt = pGeomColl.GeometryCount - 1; for (int j = 0; j <= cnt; j++) { pPath = pGeomColl.get_Geometry(j) as IPath; if (bOverRideMajor) angle = dMajorAngle; else angle = GetAngle(pPath) + dMajorAngle; pSC = pPath as ISegmentCollection; pSeg = pSC.get_Segment(0); pSegM = pSeg as ISegmentM; txt = Convert.ToString(Math.Round(m1, 1)); txtlen = pTxtSym.Size; angle = GetAngle(pPath as ICurve); if (ShouldFlip(angle)) { pTxtPath = MakeTextPath(pPath, txtlen * 2); angle += 180; pTxtSym.RightToLeft = false; pTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } else { //angle = angle; pTxtPath = MakeTextPath(pPath, txtlen); pTxtSym.RightToLeft = false; pTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } pTxtSym.Angle = angle; //Ϊ�ı�����MASK�����û�з��ţ�����Ϊ���� pMask = pTxtSym as IMask; pMask.MaskSize = 2; pMask.MaskStyle = esriMaskStyle.esriMSHalo; pTextElement = new TextElementClass(); pTextElement.Symbol = pTxtSym; pTextElement.Text = txt + " "; pElement = pTextElement as IElement; pSegment = pTxtPath as ISegmentCollection; pPolyline = new PolylineClass(); pPolyline.AddSegmentCollection(pSegment); pElement.Geometry = pPolyline as IGeometry; pGraphicsContainer.AddElement(pElement, 0); } } pFeature = pFeatCursor.NextFeature(); } }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { #region 主窗体右键 /////地图视窗鼠标事件 IToolbarMenu mapPopMenu = null; mapPopMenu = new ToolbarMenu(); if (e.button == 2) { /* IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pActiveView.Extent = pEnv; pActiveView.Refresh();*/ //地图视窗右键菜单功能 mapPopMenu.AddItem(new ControlsSelectTool(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapPanTool(), -1, 1, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapFullExtentCommand(), -1, 2, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapIdentifyTool(), -1, 3, false, esriCommandStyles.esriCommandStyleIconAndText);//识别工具 mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 4, false, esriCommandStyles.esriCommandStyleIconAndText);// mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 5, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsSelectFeaturesTool(), -1, 6, false, esriCommandStyles.esriCommandStyleIconAndText);//选择要素工具 mapPopMenu.AddItem(new ControlsClearSelectionCommand(), -1, 7, false, esriCommandStyles.esriCommandStyleIconAndText);//缩放所选要素 mapPopMenu.AddItem(new ControlsZoomToSelectedCommand(), -1, 8, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapZoomToLastExtentBackCommand(), -1, 9, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapZoomToLastExtentForwardCommand(), -1, 10, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.SetHook(axMapControl1);//// 得到地图视窗右键菜单 mapPopMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);//弹出显示菜单 } /* if (e.button == 1)//左键因为右键要取消 { IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pActiveView.Extent = pEnv; pActiveView.Refresh(); } * */ //此事件不会触发 if (e.button == 3)//如果鼠标中间改为ControlsMapPanTool会更好 { IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pActiveView.Extent = pEnv; pActiveView.Refresh(); } #endregion //if (e.button == 2) //{ // IMap pMap = axMapControl1.Map; // IActiveView pActiveView = pMap as IActiveView; // IEnvelope pEnv = axMapControl1.TrackRectangle(); // pActiveView.Extent = pEnv; // pActiveView.Refresh(); //} //网络分析 if (clicked != true) return; IPoint ipNew; if (m_ipPoints == null) { m_ipPoints = new MultipointClass(); } ipNew = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; m_ipPoints.AddPoint(ipNew, ref o, ref o); IElement element; ITextElement textelement = new TextElementClass(); element = textelement as IElement; clickedcount++; textelement.Text = clickedcount.ToString(); element.Geometry = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); pGC.AddElement(element, 0); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void DrawGrid() { string str = ""; string str2 = ""; ITextElement element = null; ITextElement element2 = null; ITextElement element3 = null; ITextElement element4 = null; double num = 40.0; double num2 = 20.0; double num3 = 10.0; int num4 = 13; int num5 = 10; IPoint point = null; IElement item = null; ITextSymbol symbol = new TextSymbolClass(); ITextSymbol symbol2 = new TextSymbolClass(); ITextSymbol symbol3 = new TextSymbolClass(); ITextSymbol symbol4 = new TextSymbolClass(); ITextSymbol symbol5 = new TextSymbolClass(); ITextSymbol symbol6 = new TextSymbolClass(); int num6 = 0; int num7 = 0; int num8 = 1000; double x = 0.0; double y = 0.0; IPoint point2 = new PointClass(); object missing = System.Type.Missing; IElementProperties2 properties = null; IMarkerElement element6 = null; ISymbol symbol7 = new SimpleMarkerSymbolClass(); ISimpleMarkerSymbol symbol8 = symbol7 as ISimpleMarkerSymbol; IRgbColor color = new RgbColorClass { Red = 0, Blue = 0, Green = 0 }; symbol8.Size = 10.0; symbol8.Style = esriSimpleMarkerStyle.esriSMSCross; symbol8.Color = color; double num11 = 0.0; double num12 = 0.0; double num13 = 0.0; double num14 = 0.0; int num15 = 0; int num16 = 0; int num17 = 0; int num18 = 0; int num19 = 0; double num20 = 0.0; double num21 = 0.0; double num22 = 0.0; double num23 = 0.0; try { symbol = base.FontStyle((double)num4, esriTextHorizontalAlignment.esriTHARight, esriTextVerticalAlignment.esriTVABottom); symbol2 = base.FontStyle((double)num5, esriTextHorizontalAlignment.esriTHALeft, esriTextVerticalAlignment.esriTVABottom); symbol3 = base.FontStyle((double)num5, esriTextHorizontalAlignment.esriTHARight, esriTextVerticalAlignment.esriTVATop); symbol4 = base.FontStyle((double)num4, esriTextHorizontalAlignment.esriTHALeft, esriTextVerticalAlignment.esriTVATop); symbol5 = base.FontStyle((double)num5, esriTextHorizontalAlignment.esriTHARight, esriTextVerticalAlignment.esriTVABottom); symbol6 = base.FontStyle((double)num4, esriTextHorizontalAlignment.esriTHALeft, esriTextVerticalAlignment.esriTVABottom); if (base.LeftUp.Y < base.RightUp.Y) { y = Math.Truncate(base.LeftUp.Y); num23 = (base.RightUp.Y + base.InOutDist) + 1.0; } else { y = Math.Truncate(base.RightUp.Y); num23 = (base.LeftUp.Y + base.InOutDist) + 1.0; } num15 = (int)(y % ((double)num8)); if (num15 != 0) { num12 = y - num15; } else { num12 = y; } if (base.LeftUp.X > base.LeftLow.X) { x = Math.Truncate((double)(base.LeftUp.X + 1.0)); num20 = (base.LeftLow.X - base.InOutDist) - 1.0; } else { x = Math.Truncate((double)(base.LeftLow.X + 1.0)); num20 = (base.LeftUp.X - base.InOutDist) - 1.0; } num15 = (int)(x % ((double)num8)); if (num15 != 0) { num11 = x + (num8 - num15); } else { num11 = x; } if (base.LeftLow.Y < base.RightLow.Y) { y = Math.Truncate(base.LeftLow.Y); num21 = (base.LeftLow.Y - base.InOutDist) - 1.0; } else { y = Math.Truncate(base.RightLow.Y); num21 = (base.RightLow.Y - base.InOutDist) - 1.0; } num15 = (int)(y % ((double)num8)); if (num15 != 0) { num14 = y + (num8 - num15); } else { num14 = y; } if (base.RightUp.X > base.RightLow.X) { x = Math.Truncate(base.RightLow.X); num22 = (base.RightUp.X + base.InOutDist) + 1.0; } else { x = Math.Truncate(base.RightUp.X); num22 = (base.RightLow.X + base.InOutDist) + 1.0; } num15 = (int)(x % ((double)num8)); if (num15 != 0) { num13 = x - num15; } else { num13 = x; } num16 = ((int)(num12 - num14)) / num8; num17 = ((int)(num13 - num11)) / num8; for (num18 = 0; num18 <= num16; num18++) { y = num12 - (num18 * num8); for (num19 = 0; num19 <= num17; num19++) { x = num11 + (num19 * num8); point2.PutCoords(x, y); item = new MarkerElementClass { Geometry = point2 }; element6 = item as IMarkerElement; element6.Symbol = symbol8; properties = item as IElementProperties2; properties.Type = "公里网"; this.ilist_0.Add(item); } } IPolygon polygon = new PolygonClass(); new PolygonElementClass(); polygon = this.method_3(); double num1 = base.LeftUp.X - base.InOutDist; double num24 = base.LeftUp.X; double num25 = base.RightUp.X; double num26 = base.RightUp.X + base.InOutDist; IPoint inPoint = null; IPoint point4 = null; IPoint point5 = null; IPoint point6 = null; IPolyline polyline = new PolylineClass(); IPolyline polyline2 = new PolylineClass(); IPolyline polyline3 = new PolylineClass(); IPoint point7 = null; IPoint point8 = null; IPointCollection points = null; IPointCollection points2 = null; IElement element7 = null; IElement element8 = null; ILineElement element9 = null; ILineSymbol symbol9 = this.method_5(1); for (num18 = 0; num18 <= num16; num18++) { y = num12 - (num18 * num8); point7 = new PointClass(); point8 = new PointClass(); point7.PutCoords(num20, y); point8.PutCoords(num22, y); points = polyline3 as IPointCollection; if (points.PointCount >= 1) { points.RemovePoints(0, points.PointCount); } points.AddPoint(point7, ref missing, ref missing); points.AddPoint(point8, ref missing, ref missing); points = this.method_4(polyline3, polygon); inPoint = points.get_Point(0); point4 = points.get_Point(1); point5 = points.get_Point(2); point6 = points.get_Point(3); element7 = new LineElementClass(); element9 = element7 as ILineElement; element9.Symbol = symbol9; points2 = polyline as IPointCollection; if (points2.PointCount >= 1) { points2.RemovePoints(0, points2.PointCount); } points2.AddPoint(inPoint, ref missing, ref missing); points2.AddPoint(point4, ref missing, ref missing); element7.Geometry = polyline; element8 = new LineElementClass(); element9 = element8 as ILineElement; element9.Symbol = symbol9; points2 = polyline2 as IPointCollection; if (points2.PointCount >= 1) { points2.RemovePoints(0, points2.PointCount); } points2.AddPoint(point5, ref missing, ref missing); points2.AddPoint(point6, ref missing, ref missing); element8.Geometry = polyline2; this.ilist_0.Add(element7); this.ilist_0.Add(element8); element = new TextElementClass(); element2 = new TextElementClass(); element3 = new TextElementClass(); element4 = new TextElementClass(); num6 = (int)Math.Truncate((double)(y / 100000.0)); str = num6.ToString(); num7 = (int)Math.Truncate((double)((y - (num6 * 100000)) / 1000.0)); str2 = num7.ToString(); if (str2.Length < 2) { str2 = "0" + str2; } element.Text = str2; element2.Text = str; element3.Text = str2; element4.Text = str; point = new PointClass(); point.PutCoords(inPoint.X, inPoint.Y + num2); item = element as IElement; item.Geometry = point; element.Symbol = symbol; this.ilist_0.Add(item); if ((num18 == 0) || (num18 == num16)) { point = new PointClass(); point.PutCoords(point4.X, point4.Y + num); item = element2 as IElement; item.Geometry = point; element2.Symbol = symbol2; this.ilist_0.Add(item); } point = new PointClass(); point.PutCoords(point5.X, point5.Y + num2); item = element3 as IElement; item.Geometry = point; element3.Symbol = symbol; this.ilist_0.Add(item); if ((num18 == 0) || (num18 == num16)) { point = new PointClass(); point.PutCoords(point6.X, point6.Y + num); item = element4 as IElement; item.Geometry = point; element4.Symbol = symbol2; this.ilist_0.Add(item); } } for (num18 = 0; num18 <= num17; num18++) { x = num11 + (num18 * num8); point7 = new PointClass(); point8 = new PointClass(); point7.PutCoords(x, num23); point8.PutCoords(x, num21); points = polyline3 as IPointCollection; if (points.PointCount >= 1) { points.RemovePoints(0, points.PointCount); } points.AddPoint(point7, ref missing, ref missing); points.AddPoint(point8, ref missing, ref missing); points = this.method_4(polyline3, polygon); inPoint = points.get_Point(0); point4 = points.get_Point(1); point5 = points.get_Point(2); point6 = points.get_Point(3); element7 = new LineElementClass(); element9 = element7 as ILineElement; element9.Symbol = symbol9; points2 = polyline as IPointCollection; if (points2.PointCount >= 1) { points2.RemovePoints(0, points2.PointCount); } points2.AddPoint(inPoint, ref missing, ref missing); points2.AddPoint(point4, ref missing, ref missing); element7.Geometry = polyline; element8 = new LineElementClass(); element9 = element8 as ILineElement; element9.Symbol = symbol9; points2 = polyline2 as IPointCollection; if (points2.PointCount >= 1) { points2.RemovePoints(0, points2.PointCount); } points2.AddPoint(point5, ref missing, ref missing); points2.AddPoint(point6, ref missing, ref missing); element8.Geometry = polyline2; this.ilist_0.Add(element7); this.ilist_0.Add(element8); element = new TextElementClass(); element2 = new TextElementClass(); element3 = new TextElementClass(); element4 = new TextElementClass(); num6 = (int)Math.Truncate((double)(x / 100000.0)); str = num6.ToString(); str2 = ((int)Math.Truncate((double)((x - (num6 * 100000)) / 1000.0))).ToString(); if (str2.Length < 2) { str2 = "0" + str2; } element.Text = str2; element2.Text = str; element3.Text = str2; element4.Text = str; point = new PointClass(); point.PutCoords(inPoint.X, inPoint.Y - num3); item = element as IElement; item.Geometry = point; element.Symbol = symbol4; this.ilist_0.Add(item); if ((num18 == 0) || (num18 == num17)) { point = new PointClass(); point.PutCoords(inPoint.X, inPoint.Y - num3); item = element2 as IElement; item.Geometry = point; element2.Symbol = symbol3; this.ilist_0.Add(item); } point = new PointClass(); point.PutCoords(point6.X, point6.Y + num3); item = element3 as IElement; item.Geometry = point; element3.Symbol = symbol6; this.ilist_0.Add(item); if ((num18 == 0) || (num18 == num17)) { point = new PointClass(); point.PutCoords(point6.X, point6.Y + num3); item = element4 as IElement; item.Geometry = point; element4.Symbol = symbol5; this.ilist_0.Add(item); } } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { //With this tool the user may place the current Date and Time onto the Page Layout //using the Timestamp format defined by the UI Culture of the current thread //Get the active view IActiveView pActiveView; pActiveView = m_pHookHelper.ActiveView; //Create a new text element ITextElement pTextElement = new TextElementClass(); //Create a text symbol ESRI.ArcGIS.Display.ITextSymbol pTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass(); pTextSymbol.Size = 10; //Create a page point IPoint pPoint; pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //Get the FullDateTimePattern from the CurrentUICulture of the thread string pDateTimePattern; pDateTimePattern = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.FullDateTimePattern.ToString(); //Set the text element properties pTextElement.Symbol = pTextSymbol; pTextElement.Text = System.DateTime.Now.ToString(pDateTimePattern); //QI for IElement IElement pElement; pElement = (IElement)pTextElement; //Set the elements geometry pElement.Geometry = pPoint; //Add the element to the graphics container pActiveView.GraphicsContainer.AddElement(pElement, 0); //Refresh the graphics pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void ShowCallout(IPoint loc, string text) { try { ITextElement pTextElement = new TextElementClass(); IElement pElement; IBalloonCallout pCallout = new BalloonCalloutClass(); IFillSymbol pFill = new SimpleFillSymbolClass(); ILineSymbol pLine = new SimpleLineSymbolClass(); IFormattedTextSymbol pLabelSymbol = new TextSymbolClass(); IRgbColor c = new RgbColorClass(); c.Red = 0; c.Green = 0; c.Blue = 0; IRgbColor d = new RgbColorClass(); d.Red = 255; d.Green = 255; d.Blue = 255; IRgbColor e = new RgbColorClass(); e.Red = 205; e.Green = 192; e.Blue = 176; pLine.Color = c; pFill.Color = d; pFill.Outline = pLine; pCallout.Symbol = pFill; pCallout.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle; pCallout.AnchorPoint = loc; pLabelSymbol.Background = pCallout as ITextBackground; pLabelSymbol.Size = 10.5d; pLabelSymbol.ShadowColor = e; pLabelSymbol.ShadowXOffset = 1.0d; pLabelSymbol.ShadowYOffset = 1.0d; pTextElement.Text = text; pTextElement.Symbol = pLabelSymbol as ITextSymbol; pElement = pTextElement as IElement; double delta = (.1 * mMap.MapScale) / 2; //switch (mMap.MapScale) //{ // case //} IPoint p1 = new PointClass(); p1.X = loc.X + delta; p1.Y = loc.Y + delta; pElement.Geometry = p1; graphicsContainer = mDoc.ActiveView as IGraphicsContainer; graphicsContainer.AddElement(pElement, 0); pElement.Activate(mDoc.ActiveView.ScreenDisplay); mDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null); mMap.ClearSelection(); Timer t = new Timer(); t.Interval = 2000; t.Tick += new EventHandler(t_Tick); t.Start(); } catch (Exception ex) { log.WriteError(ex, TAG, System.Security.Principal.WindowsIdentity.GetCurrent().Name, null); } }
public static IElement CreateElement(IPageLayout ipageLayout_0) { int num; double num1; double num2; ITextSymbol symbol; esriTextHorizontalAlignment horizontalAlignment; esriTextVerticalAlignment verticalAlignment; IScaleText scaleTextClass; UID uIDClass; IMapFrame mapFrame; IEnvelope envelopeClass; IEnvelope envelope; ILegend legendClass2; IScaleBar hollowScaleBarClass; double num3; double num4; INorthArrow markerNorthArrowClass; IPoint position = ElementWizardHelp.GetPosition(ipageLayout_0, out num, out num1, out num2); IElement textElementClass = null; switch (ElementWizardHelp.m_ElementType) { case ElementType.ConstantText: { textElementClass = new TextElementClass(); (textElementClass as IElementProperties).Name = ElementWizardHelp.m_Text; (textElementClass as ITextElement).Text = ElementWizardHelp.m_Text; if (ElementWizardHelp.m_pStyle != null) { ElementWizardHelp.SetTextSymblAlign(ElementWizardHelp.m_pStyle as ITextSymbol, num); (textElementClass as ITextElement).Symbol = ElementWizardHelp.m_pStyle as ITextSymbol; } textElementClass.Geometry = position; if (!ElementWizardHelp.m_IsVerticalText) { (textElementClass as IElementProperties).Type = ""; symbol = (textElementClass as ITextElement).Symbol; if (symbol.Angle != 270) { return(textElementClass); } (symbol as ICharacterOrientation).CJKCharactersRotation = false; symbol.Angle = 0; horizontalAlignment = symbol.HorizontalAlignment; verticalAlignment = symbol.VerticalAlignment; if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } if (verticalAlignment == esriTextVerticalAlignment.esriTVATop) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } (textElementClass as ITextElement).Symbol = symbol; return(textElementClass); } else { (textElementClass as IElementProperties).Type = "竖向"; symbol = (textElementClass as ITextElement).Symbol; (symbol as ICharacterOrientation).CJKCharactersRotation = true; symbol.Angle = 270; horizontalAlignment = symbol.HorizontalAlignment; verticalAlignment = symbol.VerticalAlignment; if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } if (verticalAlignment == esriTextVerticalAlignment.esriTVATop) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } (textElementClass as ITextElement).Symbol = symbol; return(textElementClass); } } case ElementType.SingleText: { textElementClass = new TextElementClass(); (textElementClass as IElementProperties).Name = ElementWizardHelp.m_Text; (textElementClass as ITextElement).Text = string.Concat("=", ElementWizardHelp.m_Text); if (ElementWizardHelp.m_pStyle != null) { ElementWizardHelp.SetTextSymblAlign(ElementWizardHelp.m_pStyle as ITextSymbol, num); (textElementClass as ITextElement).Symbol = ElementWizardHelp.m_pStyle as ITextSymbol; } textElementClass.Geometry = position; if (!ElementWizardHelp.m_IsVerticalText) { (textElementClass as IElementProperties).Type = ""; symbol = (textElementClass as ITextElement).Symbol; if (symbol.Angle != 270) { return(textElementClass); } (symbol as ICharacterOrientation).CJKCharactersRotation = false; symbol.Angle = 0; horizontalAlignment = symbol.HorizontalAlignment; verticalAlignment = symbol.VerticalAlignment; if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } if (verticalAlignment == esriTextVerticalAlignment.esriTVATop) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } (textElementClass as ITextElement).Symbol = symbol; return(textElementClass); } else { (textElementClass as IElementProperties).Type = "竖向"; symbol = (textElementClass as ITextElement).Symbol; (symbol as ICharacterOrientation).CJKCharactersRotation = true; symbol.Angle = 270; horizontalAlignment = symbol.HorizontalAlignment; verticalAlignment = symbol.VerticalAlignment; if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } if (verticalAlignment == esriTextVerticalAlignment.esriTVATop) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } (textElementClass as ITextElement).Symbol = symbol; return(textElementClass); } } case ElementType.MultiText: { textElementClass = new TextElementClass(); (textElementClass as IElementProperties).Name = ElementWizardHelp.m_Text; (textElementClass as ITextElement).Text = string.Concat("M=", ElementWizardHelp.m_Text); if (ElementWizardHelp.m_pStyle != null) { ElementWizardHelp.SetTextSymblAlign(ElementWizardHelp.m_pStyle as ITextSymbol, num); (textElementClass as ITextElement).Symbol = ElementWizardHelp.m_pStyle as ITextSymbol; } textElementClass.Geometry = position; if (!ElementWizardHelp.m_IsVerticalText) { (textElementClass as IElementProperties).Type = ""; symbol = (textElementClass as ITextElement).Symbol; if (symbol.Angle != 270) { return(textElementClass); } (symbol as ICharacterOrientation).CJKCharactersRotation = false; symbol.Angle = 0; horizontalAlignment = symbol.HorizontalAlignment; verticalAlignment = symbol.VerticalAlignment; if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } if (verticalAlignment == esriTextVerticalAlignment.esriTVATop) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } (textElementClass as ITextElement).Symbol = symbol; return(textElementClass); } else { (textElementClass as IElementProperties).Type = "竖向"; symbol = (textElementClass as ITextElement).Symbol; (symbol as ICharacterOrientation).CJKCharactersRotation = true; symbol.Angle = 270; horizontalAlignment = symbol.HorizontalAlignment; verticalAlignment = symbol.VerticalAlignment; if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } if (verticalAlignment == esriTextVerticalAlignment.esriTVATop) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } (textElementClass as ITextElement).Symbol = symbol; return(textElementClass); } } case ElementType.JoinTable: { textElementClass = (new JionTab()).CreateJionTab(ipageLayout_0 as IActiveView, position); return(textElementClass); } case ElementType.ScaleText: { if (ElementWizardHelp.m_pStyle == null) { scaleTextClass = new ScaleTextClass(); } else { scaleTextClass = ElementWizardHelp.m_pStyle as IScaleText; } uIDClass = new UIDClass() { Value = "esriCarto.ScaleText" }; mapFrame = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame; scaleTextClass.MapUnits = mapFrame.Map.DistanceUnits; scaleTextClass.PageUnits = ipageLayout_0.Page.Units; scaleTextClass.Style = esriScaleTextStyleEnum.esriScaleTextAbsolute; INumberFormat numberFormat = scaleTextClass.NumberFormat; if (numberFormat is INumericFormat) { (numberFormat as INumericFormat).RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals; (numberFormat as INumericFormat).UseSeparator = false; (numberFormat as INumericFormat).RoundingValue = 0; scaleTextClass.NumberFormat = numberFormat; } textElementClass = mapFrame.CreateSurroundFrame(uIDClass, scaleTextClass) as IElement; envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8); envelope = new EnvelopeClass(); scaleTextClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope); envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height); textElementClass.Geometry = envelopeClass; return(textElementClass); } case ElementType.CustomLegend: { CustomLegend customLegend = new CustomLegend() { LegendInfo = ElementWizardHelp.m_pLegendInfo }; customLegend.Init(ipageLayout_0 as IActiveView, position); textElementClass = customLegend; return(textElementClass); } case ElementType.Legend: { if (ElementWizardHelp.m_pStyle == null) { legendClass2 = new LegendClass_2(); } else { legendClass2 = ElementWizardHelp.m_pStyle as ILegend; } legendClass2.AutoAdd = true; legendClass2.AutoReorder = true; legendClass2.AutoVisibility = true; uIDClass = new UIDClass() { Value = "esriCarto.Legend" }; mapFrame = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame; textElementClass = mapFrame.CreateSurroundFrame(uIDClass, legendClass2) as IElement; envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8); envelope = new EnvelopeClass(); legendClass2.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope); envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height); textElementClass.Geometry = envelopeClass; return(textElementClass); } case ElementType.Picture: { string lower = System.IO.Path.GetExtension(ElementWizardHelp.m_PictureFileName).ToLower(); textElementClass = null; string str = lower; if (string.IsNullOrEmpty(str)) { textElementClass = new PngPictureElementClass(); (textElementClass as IPictureElement).ImportPictureFromFile(ElementWizardHelp.m_PictureFileName); (textElementClass as IPictureElement).MaintainAspectRatio = true; num3 = 0; num4 = 0; (textElementClass as IPictureElement2).QueryIntrinsicSize(ref num3, ref num4); num3 = num3 * 0.0353; num4 = num4 * 0.0353; (textElementClass as IElementProperties2).AutoTransform = true; envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + num3, position.Y + num4); textElementClass.Geometry = envelopeClass; return(textElementClass); } else if (str == ".bmp") { textElementClass = new BmpPictureElementClass(); } else if (str == ".jpg") { textElementClass = new JpgPictureElementClass(); } else if (str == ".gif") { textElementClass = new GifPictureElementClass(); } else if (str == ".tif") { textElementClass = new TifPictureElementClass(); } else { if (str != ".emf") { textElementClass = new PngPictureElementClass(); (textElementClass as IPictureElement).ImportPictureFromFile(ElementWizardHelp.m_PictureFileName); (textElementClass as IPictureElement).MaintainAspectRatio = true; num3 = 0; num4 = 0; (textElementClass as IPictureElement2).QueryIntrinsicSize(ref num3, ref num4); num3 = num3 * 0.0353; num4 = num4 * 0.0353; (textElementClass as IElementProperties2).AutoTransform = true; envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + num3, position.Y + num4); textElementClass.Geometry = envelopeClass; return(textElementClass); } textElementClass = new EmfPictureElementClass(); } (textElementClass as IPictureElement).ImportPictureFromFile(ElementWizardHelp.m_PictureFileName); (textElementClass as IPictureElement).MaintainAspectRatio = true; num3 = 0; num4 = 0; (textElementClass as IPictureElement2).QueryIntrinsicSize(ref num3, ref num4); num3 = num3 * 0.0353; num4 = num4 * 0.0353; (textElementClass as IElementProperties2).AutoTransform = true; envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + num3, position.Y + num4); textElementClass.Geometry = envelopeClass; return(textElementClass); } case ElementType.OLE: { int screenDisplay = (ipageLayout_0 as IActiveView).ScreenDisplay.hWnd; Common.ExtendClass.IOleFrame oleFrame = new OleFrame(); if (!oleFrame.CreateOleClientItem((ipageLayout_0 as IActiveView).ScreenDisplay, screenDisplay)) { return(textElementClass); } textElementClass = oleFrame as IElement; envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8); envelope = new EnvelopeClass(); textElementClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelope); envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height); textElementClass.Geometry = envelopeClass; return(textElementClass); } case ElementType.ScaleBar: { if (ElementWizardHelp.m_pStyle == null) { hollowScaleBarClass = new HollowScaleBarClass(); } else { hollowScaleBarClass = ElementWizardHelp.m_pStyle as IScaleBar; } uIDClass = new UIDClass() { Value = "esriCarto.ScaleBar" }; mapFrame = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame; hollowScaleBarClass.Units = mapFrame.Map.DistanceUnits; textElementClass = mapFrame.CreateSurroundFrame(uIDClass, hollowScaleBarClass) as IElement; envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8); envelope = new EnvelopeClass(); hollowScaleBarClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope); envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height); textElementClass.Geometry = envelopeClass; return(textElementClass); } case ElementType.North: { if (ElementWizardHelp.m_pStyle == null) { markerNorthArrowClass = new MarkerNorthArrowClass(); } else { markerNorthArrowClass = ElementWizardHelp.m_pStyle as INorthArrow; } envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + 3, position.Y + 3); uIDClass = new UIDClass() { Value = "esriCarto.MarkerNorthArrow" }; mapFrame = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame; textElementClass = mapFrame.CreateSurroundFrame(uIDClass, markerNorthArrowClass) as IElement; envelope = new EnvelopeClass(); markerNorthArrowClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope); envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height); textElementClass.Geometry = envelopeClass; return(textElementClass); } case ElementType.GraphicElement: { return(textElementClass); } case ElementType.DataGraphicElement: { envelopeClass = new EnvelopeClass(); envelopeClass.PutCoords(position.X, position.Y, position.X + 8, position.Y + 8); textElementClass = new DataGraphicsElement() { Geometry = envelopeClass }; return(textElementClass); } default: { return(textElementClass); } } }