/// <summary> /// 设置存储在地图上的注记的字体和大小 /// </summary> /// <param name="map"></param> /// <param name="graphicsLayerName"></param> /// <param name="fontName">注记字体(此值为""、空白字符或null,则不改变注记字体)</param> /// <param name="size">注记大小(此值小于等于0,则不改变注记大小)</param> public static void SetAnnotationFontOnMap(this IMap map, string graphicsLayerName, string fontName = null, int size = 0) { IGraphicsLayer graphicsLayer = map.GetGraphicsLayer(graphicsLayerName); IGraphicsContainer graphicContainer = graphicsLayer as IGraphicsContainer; var txtElements = graphicContainer.GetTextElements(); foreach (var txtElement in txtElements) { ITextSymbol txtSymbol = txtElement.Symbol; //注意不能使用下面这一句,直接设置txtElement.Symbol.Size = size 是无效的,原因未知 //txtElement.Symbol.Size = size; if (size > 0) { txtSymbol.Size = size; } if (!string.IsNullOrEmpty(fontName) && fontName.Trim() != string.Empty) { System.Drawing.Font font = new System.Drawing.Font(fontName, (float)txtSymbol.Size); IFontDisp fontDisp = ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(font) as IFontDisp; txtSymbol.Font = fontDisp; } txtElement.Symbol = txtSymbol; graphicContainer.UpdateElement(txtElement as IElement); } }
/// <summary> /// 更新图饰位置 /// </summary> private void UpdataSurroundPose() { if (m_mapSurroundList == null && m_mapSurroundList.Count < 1) { return; } IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; IEnvelope mapEnvelop = (graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IElement).Geometry.Envelope; MapSurroundEntity mapSurroundEntity; bool isUpdate = false; for (int i = 0; i < m_mapSurroundList.Count; i++) { mapSurroundEntity = m_mapSurroundList[i]; IEnvelope elementEnv = mapSurroundEntity.element.Geometry.Envelope; isUpdate = false; if (mapSurroundEntity.element is IMapSurroundFrame) { isUpdate = UpdateMapSurroundFrame(mapEnvelop, mapSurroundEntity); } else if (mapSurroundEntity.element is ITextElement) { isUpdate = UpdateTextElement(mapEnvelop, mapSurroundEntity); } if (isUpdate) { graphicsContainer.UpdateElement(mapSurroundEntity.element); } } }
/// <summary> /// 宿主地图添加数据后,鸟瞰地图选择一个图层作为背景层 /// </summary> /// <param name="displayTransfromation"></param> /// <param name="sizeChanged"></param> /// <param name="newEnvelope"></param> void DockForm_OnExtentUpdated(object displayTransfromation, bool sizeChanged, object newEnvelope) { pAV.Extent = hook.MapControl.ActiveView.FullExtent; pEle.Geometry = (IGeometry)newEnvelope; pGraCon.UpdateElement(pEle); pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
//地图鼠标移动事件 private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) { lblCoordinate.Text = " 坐标: " + string.Format("{0}, {1} {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4)); IPoint pPoint = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); IEnumElement pEunmEle = queryElementOnMap(pPoint, 0); IElement pEle; IElementProperties pEleProperties; IGraphicsContainer pGContainer = axMapControl1.Map as IGraphicsContainer; if (pEunmEle != null && _pEleTemp == null) { while ((pEle = pEunmEle.Next()) != null) { pEleProperties = (IElementProperties)pEle; string projectID = pEleProperties.Name; List <Button> pListBtn = queryResultButton(projectID); foreach (var item in pListBtn) { item.BackColor = _blackColor; _ListbtnTemp.Add(item); } pGContainer.UpdateElement(setElementStyle(1.5, setRGBColor(0, 0, 200, 255), pEle, true)); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); _pEleTemp = pEle; } } else if (pEunmEle == null && _pEleTemp != null) { foreach (var item in _ListbtnTemp) { item.BackColor = _witheColor; } pGContainer.UpdateElement(setElementStyle(1.5, setRGBColor(255, 0, 0, 255), _pEleTemp, false)); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); _ListbtnTemp.Clear(); _pEleTemp = null; } }
/// <summary> /// 作为MouseLeave事件的响应方法,回滚标注样式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rollBackElementStyle(object sender, System.EventArgs e) { string projectIDstr = ((Button)sender).Tag.ToString(); bool direction = false; double size = 1.5; IRgbColor pColor = setRGBColor(255, 0, 0, 255); IGraphicsContainer pGContainer = axMapControl1.Map as IGraphicsContainer; IElement pEle = queryElementByName(projectIDstr); pEle = setElementStyle(size, pColor, pEle, direction); pGContainer.UpdateElement(pEle); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e) { //移动多边形节点 //当“编辑polygon”被勾选且标记符为2时 if (miEditPolygon.Checked && m_marker == 2) { //删除原多边形的顶点 if (m_list.Count != 0) { for (int j = 0; j < m_list.Count; j++) { m_graphicsContainer.DeleteElement(m_list[j]); } m_list.Clear(); } //停止绘制已选中的polygon m_polygon = ((IPolygonMovePointFeedback)m_DisplayFeedback).Stop(); //如果新polygon不为空,更新被存放的多边形 if (m_polygon != null) { m_hitElement.Geometry = m_polygon; m_graphicsContainer.UpdateElement(m_hitElement); } //将新多边形的点放入新的点集存放并显示 m_PointColl = m_polygon as IPointCollection; for (int k = 1; k < m_PointColl.PointCount; k++) { IMarkerElement p_markerelement = new MarkerElementClass(); ISimpleMarkerSymbol p_simplemarkersymbol = new SimpleMarkerSymbolClass(); p_simplemarkersymbol.Size = 5; IElement p_element = (IElement)p_markerelement; p_markerelement.Symbol = p_simplemarkersymbol as IMarkerSymbol; if (p_element != null) { p_element.Geometry = m_PointColl.get_Point(k); m_graphicsContainer.AddElement(p_element, 0); } m_list.Add(p_element); } this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); //重置编辑符为零 m_marker = 0; } }
internal static void TextElementUpdate(ITextElement textElement, String content, System.Drawing.Font font, Color color) { //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.UpdateElement(element); g_axPageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (Button == 1) { if (m_element is AnnotationElement) { IPoint centerPoint = new PointClass { X = (m_element.Geometry.Envelope.LowerLeft.X + m_element.Geometry.Envelope.LowerRight.X) / 2, Y = (m_element.Geometry.Envelope.LowerLeft.Y + m_element.Geometry.Envelope.UpperRight.Y) / 2 }; if (AnnotationLayer == null) { //ILayer pLayer = CommonFunctions.GetFeatureLayer("注记", m_hookHelper); //AnnotationLayer = pLayer as IFeatureLayer; } //IFeatureClass pFeatureClass = AnnotationLayer.FeatureClass; //IDataset pDataset = (IDataset)pFeatureClass; //IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; //pWorkspaceEdit.StartEditing(true); //pWorkspaceEdit.StartEditOperation(); //pWorkspaceEdit.EnableUndoRedo(); double angle = ((ITextElement)m_viewElement).Symbol.Angle; double oldAngle = ((ITextElement)m_element).Symbol.Angle; ITransform2D pTransform2D = m_element as ITransform2D; pTransform2D.Rotate(centerPoint, (angle - oldAngle) * Math.PI / 180); IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView as IGraphicsContainer; pGraphicsContainer.UpdateElement(m_element); //pWorkspaceEdit.DisableUndoRedo(); //pWorkspaceEdit.StopEditOperation(); //pWorkspaceEdit.StopEditing(true); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_hookHelper.ActiveView.Extent); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, m_element, m_hookHelper.ActiveView.Extent); pGraphicsContainer.DeleteElement(m_viewElement); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, m_viewElement, m_hookHelper.ActiveView.Extent); } m_moving = false; m_element = null; m_point = null; m_viewElement = null; m_oldPoint = null; } }
private void button2_Click(object sender, EventArgs e) { pCharacterOrientation = pTextSymbol as ICharacterOrientation; pCharacterOrientation.CJKCharactersRotation = checkO.Checked; stdole.IFontDisp pFont = pTextSymbol.Font; pFont.Bold = checkB.Checked; pFont.Underline = checkI.Checked; pFont.Italic = checkU.Checked; pTextSymbol.Font = pFont; pTextElement.Text = textBox1.Text; pTextElement.Symbol = pTextSymbol; pGraphicsContainer.UpdateElement(pTextElement as IElement); pPageLayout.ActiveView.Refresh(); //pPageLayout.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); this.Close(); this.Dispose(); }
private void lstGrids_MouseDoubleClick(object sender, MouseEventArgs e) { if (lstGrids.SelectedItems != null) { TaskManager tm = TaskManager.GetInstance(); IPolygon location = tm.GetGridLocation(lstGrids.SelectedItems[0].SubItems[0].Text); if (location != null) { ITopologicalOperator topo = location as ITopologicalOperator; IGeometry buffer = topo.Buffer(10); this.axMapControl1.Extent = buffer.Envelope; IGraphicsContainer gcon = this.axMapControl1.ActiveView.GraphicsContainer; if (m_GridLocation == null) { IRgbColor color = new RgbColorClass(); color.Blue = 255; color.Green = 0; color.Red = 0; ISimpleLineSymbol slsym = new SimpleLineSymbolClass(); slsym.Color = color as IColor; ISimpleFillSymbol sfsym = new SimpleFillSymbolClass(); sfsym.Outline = slsym as ILineSymbol; sfsym.Style = esriSimpleFillStyle.esriSFSNull; m_GridLocation = new PolygonElementClass(); IFillShapeElement pelem = m_GridLocation as IFillShapeElement; pelem.Symbol = sfsym as IFillSymbol; gcon.AddElement(m_GridLocation, 0); } m_GridLocation.Geometry = location as IGeometry; gcon.UpdateElement(m_GridLocation); } } }
private void LocateTask(string taskName) { TaskManager tm = TaskManager.GetInstance(); IPolygon location = tm.GetTaskLocation(taskName); if (location != null) { this.axMapControl2.Extent = location.Envelope; IGraphicsContainer gcon = this.axMapControl2.ActiveView.GraphicsContainer; if (m_TaskLocation == null) { IRgbColor color = new RgbColorClass(); color.Blue = 0; color.Green = 255; color.Red = 0; ISimpleLineSymbol slsym = new SimpleLineSymbolClass(); slsym.Color = color as IColor; ISimpleFillSymbol sfsym = new SimpleFillSymbolClass(); sfsym.Outline = slsym as ILineSymbol; sfsym.Style = esriSimpleFillStyle.esriSFSNull; m_TaskLocation = new PolygonElementClass(); IFillShapeElement pelem = m_TaskLocation as IFillShapeElement; pelem.Symbol = sfsym as IFillSymbol; m_TaskLocation.Geometry = location as IGeometry; gcon.AddElement(m_TaskLocation, 0); } else { m_TaskLocation.Geometry = location as IGeometry; gcon.UpdateElement(m_TaskLocation); } } }
public bool SetElementProp() { try { //if (txtName.Text.Trim() == "") //{ // MessageBox.Show("请输入变量名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);yjl0616 // return false; //} IElementProperties3 pElementProp = m_pOrgElement as IElementProperties3; if (pElementProp != null) { pElementProp.Name = txtName.Text; } //对于FrameElement的情况 if (m_pOrgElement is IFrameElement) { IFrameProperties pFrameProperty = null; IFrameDecoration pFrameDecoration = null; DevComponents.Editors.ComboItem item = cmbBorder.SelectedItem as DevComponents.Editors.ComboItem; if (cmbBorder.SelectedIndex != -1 && item != null) { IBorder pBorder = (IBorder)(item.Tag); pFrameDecoration = (IFrameDecoration)pBorder; pFrameDecoration.HorizontalSpacing = (double)numBorderGapX.Value; pFrameDecoration.VerticalSpacing = (double)numBorderGapY.Value; pFrameDecoration.CornerRounding = (short)numBorderRound.Value; ((IFrameElement)m_pOrgElement).Border = pBorder; } else { ((IFrameElement)m_pOrgElement).Border = null; } item = cmbBack.SelectedItem as DevComponents.Editors.ComboItem; if (cmbBack.SelectedIndex != -1 && item != null) { IBackground pBackground = (IBackground)(item.Tag); pFrameDecoration = (IFrameDecoration)pBackground; pFrameDecoration.HorizontalSpacing = (double)numBackGapX.Value; pFrameDecoration.VerticalSpacing = (double)numBackGapY.Value; pFrameDecoration.CornerRounding = (short)numBackRound.Value; ((IFrameElement)m_pOrgElement).Background = pBackground; } else { ((IFrameElement)m_pOrgElement).Background = null; } item = cmbShadow.SelectedItem as DevComponents.Editors.ComboItem; if (cmbShadow.SelectedIndex != -1 && item != null) { IShadow pShadow = (IShadow)(item.Tag); pFrameDecoration = (IFrameDecoration)pShadow; pFrameDecoration.HorizontalSpacing = (double)numShadowGapX.Value; pFrameDecoration.VerticalSpacing = (double)numShadowGapY.Value; pFrameDecoration.CornerRounding = (short)numShadowRound.Value; pFrameProperty = (IFrameProperties)m_pOrgElement; pFrameProperty.Shadow = pShadow; } else { pFrameProperty = (IFrameProperties)m_pOrgElement; pFrameProperty.Shadow = null; } } IEnvelope pBounds = new EnvelopeClass(); m_pOrgElement.QueryBounds(m_pDisplay, pBounds); //设置偏移 double dx, dy; IPoint pFromPoint = pBounds.LowerLeft; if (chkUseOffDist.Checked) { dx = Convert.ToDouble(numLowerLeftX.Text); dy = Convert.ToDouble(numLowerLeftY.Text); } else { dx = Convert.ToDouble(numLowerLeftX.Text) - pFromPoint.X; dy = Convert.ToDouble(numLowerLeftY.Text) - pFromPoint.Y; } m_pTransform.Move(dx, dy); //设置缩放 pFromPoint = pBounds.LowerLeft; if (chkUsePercent.Checked) { dx = ((Convert.ToDouble(numWidth.Text) / 100) * pBounds.Width) / pBounds.Width; dy = ((Convert.ToDouble(numHeight.Text) / 100) * pBounds.Width) / pBounds.Height; } else { dx = Convert.ToDouble(numWidth.Text) / pBounds.Width; dy = Convert.ToDouble(numHeight.Text) / pBounds.Height; } m_pTransform.Scale(pFromPoint, dx, dy); //设置符号 if (m_pOrgElement is IMarkerElement) { IMarkerElement pMrkElement = m_pOrgElement as IMarkerElement; IMarkerSymbol pSymbol = (IMarkerSymbol)picPoint.Tag; double dblSize = pMrkElement.Symbol.Size; pMrkElement.Symbol = (IMarkerSymbol)picPoint.Tag; pSymbol.Size = dblSize; pMrkElement.Symbol = pSymbol; } else if (m_pOrgElement is ILineElement) { ILineElement pLinElement = m_pOrgElement as ILineElement; pLinElement.Symbol = (ILineSymbol)picLine.Tag; } else if (m_pOrgElement is IFillShapeElement) { IFillShapeElement pFillElement = m_pOrgElement as IFillShapeElement; pFillElement.Symbol = (IFillSymbol)picPoly.Tag; } else if (m_pOrgElement is ITextElement) { ITextElement pTxtElement = m_pOrgElement as ITextElement; pTxtElement.Text = txtText.Text; pTxtElement.Symbol = (ITextSymbol)picText.Tag; } if (m_pOrgElement is IFrameElement) { //判断指北针,比例尺,比例文本 IMapSurroundFrame pMapSurroundFrame = m_pOrgElement as IMapSurroundFrame; if (pMapSurroundFrame != null) { IMapSurround pMapSurround = pMapSurroundFrame.MapSurround; if (pMapSurround != null) { if (pMapSurround is INorthArrow) { pMapSurroundFrame.MapSurround = (IMapSurround)picArrow.Tag; pMapSurroundFrame.MapSurround.Name = "指北针"; } else if (pMapSurround is IScaleBar) { pMapSurroundFrame.MapSurround = (IMapSurround)picScale.Tag; pMapSurroundFrame.MapSurround.Name = "比例尺"; } else if (pMapSurround is IScaleText) { pMapSurroundFrame.MapSurround = (IMapSurround)picScaleText.Tag; pMapSurroundFrame.MapSurround.Name = "比例尺"; } } } } m_pGraphicCtn.UpdateElement(m_pOrgElement); m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); if (chkUseOffDist.Checked) { numLowerLeftX.Text = "0"; numLowerLeftY.Text = "0"; } if (chkUsePercent.Checked) { numHeight.Text = "100"; numWidth.Text = "100"; } return(true); } catch { //MessageBox.Show("保存属性时出现错误,错误描述为:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } // }
void AlignElementMethod(string name, string h, string v, string hDirection, string vDirection, bool isPage) { IElement targetEle = null; double xmin = 0; double xmax = 0; double ymin = 0; double ymax = 0; IEnvelope targetEnv = new EnvelopeClass() as IEnvelope; IGraphicsContainer cont = ArcMap.Document.ActiveView as IGraphicsContainer; if (!isPage) { cont.Reset(); IElement ele = cont.Next(); while (ele != null) { IElementProperties3 pros = ele as IElementProperties3; if (pros.Name == name) { targetEle = ele; break; } ele = cont.Next(); } if (targetEle == null) { return; } targetEle.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, targetEnv); xmin = targetEnv.XMin; xmax = targetEnv.XMax; ymin = targetEnv.YMin; ymax = targetEnv.YMax; } else { IPageLayout layout = ArcMap.Document.ActiveView as IPageLayout; IPage pg = layout.Page; pg.QuerySize(out xmax, out ymax); } double vH = 0; double vV = 0; bool bH = double.TryParse(h, out vH); bool bV = double.TryParse(v, out vV); IGraphicsContainerSelect contAlign = ArcMap.Document.ActiveView as IGraphicsContainerSelect; IEnumElement enumEle = contAlign.SelectedElements; IElement eleSel = enumEle.Next(); while (eleSel != null) { IElementProperties3 pros = eleSel as IElementProperties3; IEnvelope env = new EnvelopeClass() as IEnvelope; eleSel.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, env); double dx = 0; double dy = 0; if (bH) { if (hDirection == "左侧Left") { dx = xmin - env.XMin - vH; } else { dx = xmax - env.XMax + vH; } } if (bV) { if (vDirection == "上侧Top") { dy = ymax - env.YMax + vV; } else { dy = ymin - env.YMin - vV; } } ITransform2D trans = eleSel.Geometry as ITransform2D; trans.Move(dx, dy); eleSel.Geometry = trans as IGeometry; cont.UpdateElement(eleSel); eleSel = enumEle.Next(); } ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGraphicSelection, null, null); }