private double GetSizeFromItem(object item) { if (item == null) { return(-1); } IMapSurround pMapSurround = item as IMapSurround; if (pMapSurround is IMarkerNorthArrow) { return((pMapSurround as IMarkerNorthArrow).MarkerSymbol.Size); } //if (pSymbol is IMarkerSymbol) //{ // return (pSymbol as IMarkerSymbol).Size; //} //else if (pSymbol is ILineSymbol) //{ // return (pSymbol as ILineSymbol).Width; //} //else if (pSymbol is IFillSymbol) //{ // return (pSymbol as IFillSymbol).Outline.Width; //} else { return(0); } }
private void symbolSize_ValueChanged(object sender, EventArgs e) { IMapSurround pMapSurround = m_styleGalleryItem.Item as IMapSurround; if (symbolSize.Value < 0) { MessageBox.Show("请输入一个大于0的数字。"); } double tempSize = Convert.ToDouble(symbolSize.Value); if (pMapSurround is IMarkerNorthArrow) { IMarkerSymbol markerSymbol = (pMapSurround as IMarkerNorthArrow).MarkerSymbol; markerSymbol.Size = tempSize; (pMapSurround as IMarkerNorthArrow).MarkerSymbol = markerSymbol; //pMapSurround.Refresh(); } else { return; } PreviewImage(); _size = Convert.ToDouble(symbolSize.Value); }
/// <summary> /// 生成一个默认指北针 /// </summary> /// <param name="pageLayoutControl"></param> /// <param name="startX"></param> /// <param name="startY"></param> /// <returns></returns> public static IMapSurround GetDefaultNortthArrow(IPageLayoutControlDefault pageLayoutControl, double startX, double startY) { try { IPageLayout pageLayout = pageLayoutControl.PageLayout; IActiveView pActiveView = pageLayoutControl.ActiveView; IMap map = pActiveView.FocusMap; if (pageLayout == null || map == null) { return(null); } IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(startX, startY, startX + 48, startY + 48); // Specify the location and size of the north arrow IUID uid = new UIDClass(); uid.Value = "esriCarto.MarkerNorthArrow"; // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; // Dynamic Cast IActiveView activeView = pageLayout as IActiveView; // Dynamic Cast IFrameElement frameElement = graphicsContainer.FindFrame(map); IMapFrame mapFrame = frameElement as IMapFrame; // Dynamic Cast IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; IMapSurround mapSurround = mapSurroundFrame.MapSurround; return(mapSurround); } catch (System.Exception ex) { return(null); } }
/// <summary> /// 生成默认比例尺 /// </summary> /// <param name="pageLayoutControl"></param> /// <param name="startX"></param> /// <param name="startY"></param> /// <returns></returns> public static IMapSurround GetDefaultScaleBar(IPageLayoutControlDefault pageLayoutControl, double startX, double startY) { try { IPageLayout pageLayout = pageLayoutControl.PageLayout; IGraphicsContainer container = pageLayout as IGraphicsContainer; IActiveView activeView = pageLayout as IActiveView; // 获得MapFrame IFrameElement frameElement = container.FindFrame(activeView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中比例尺的样式 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(startX, startY, startX + 10, startY + 10); element.Geometry = envelope; mapSurround = mapSurroundFrame.MapSurround; return(mapSurround); } catch (System.Exception ex) { return(null); } }
/// <summary> /// 比例尺 /// </summary> /// <param name="pActiveView"></param> /// <param name="pPageLayout"></param> /// <param name="pEnv"></param> public void makeScaleBar(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv) { IGraphicsContainer container = pPageLayout as IGraphicsContainer; // 获得MapFrame IFrameElement frameElement = container.FindFrame(pActiveView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中比例尺的样式 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; element.Geometry = pEnv; //使用IGraphicsContainer接口添加显示 container.AddElement(element, 0); pActiveView.Refresh(); }
public static void AddNorthArrow(AxPageLayoutControl pageLayoutControl, IEnvelope envelope) { IUID uid = new UIDClass() { Value = "esriCarto.MarkerNorthArrow" }; IFrameElement frameElement = (pageLayoutControl.PageLayout as IGraphicsContainer) .FindFrame(pageLayoutControl.ActiveView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null); // Dynamic Cast IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; element.Activate(pageLayoutControl.ActiveView.ScreenDisplay); (pageLayoutControl.PageLayout as IGraphicsContainer).AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; // Change out the default north arrow IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow; // Dynamic Cast IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol; ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; // Dynamic Cast characterMarkerSymbol.CharacterIndex = 202; markerNorthArrow.MarkerSymbol = characterMarkerSymbol; }
/// <summary> /// 文字比例尺 /// </summary> /// <returns></returns> public bool AddTxtSacleBar() { IStyleSelector pStyleSelector = new ScaleTextSelectorClass(); bool m_bOK = pStyleSelector.DoModal(0); if (m_bOK == true) { IScaleText pScaleText = pStyleSelector.GetStyle(0) as IScaleText; IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(0.2, 0.2, 5, 1); ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "esriCarto.Scaletext"; IMap pMap = mainPage.ActiveView.FocusMap; IGraphicsContainer graphicsContainer = mainPage.ActiveView as IGraphicsContainer; IActiveView activeView = mainPage.ActiveView as IActiveView; IFrameElement frameElement = graphicsContainer.FindFrame(pMap); IMapFrame mapFrame = frameElement as IMapFrame; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); IMapSurround mapsurround = pScaleText as IMapSurround; mapSurroundFrame.MapSurround = mapsurround; IElement element = mapSurroundFrame as IElement; element.Geometry = envelope; element.Activate(activeView.ScreenDisplay); graphicsContainer.AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; } return(true); }
public void AddNorthArrow(IPageLayout pageLayout) { IGraphicsContainer container = pageLayout as IGraphicsContainer; IActiveView activeView = pageLayout as IActiveView; // 获得MapFrame IFrameElement frameElement = container.FindFrame(activeView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.MarkerNorthArrow"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中指北针的点符号 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow; IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol; markerSymbol.Size = 18; markerNorthArrow.MarkerSymbol = markerSymbol; //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(0.2, 0.2, 5, 5); element.Geometry = envelope; //使用IGraphicsContainer接口添加显示 container.AddElement(element, 0); activeView.Refresh(); }
private void btnFillColor_Click(object sender, EventArgs e) { ColorDialog colorDialog = new ColorDialog(); DialogResult result = colorDialog.ShowDialog(); if (result == DialogResult.OK) { btnFillColor.BackColor = colorDialog.Color; IMapSurround pMapSurround = m_styleGalleryItem.Item as IMapSurround; if (pMapSurround == null) { return; } if (pMapSurround is IMarkerNorthArrow) { IMarkerSymbol markerSymbol = (pMapSurround as IMarkerNorthArrow).MarkerSymbol; markerSymbol.Color = ElementPropetyImp.GetRGBColor(colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B); (pMapSurround as IMarkerNorthArrow).MarkerSymbol = markerSymbol; } else { return; } PreviewImage(); } }
public static void addScalebar(AxPageLayoutControl axPageLayoutControl, String type) { IPageLayout pageLayout = axPageLayoutControl.PageLayout; IActiveView activeView = pageLayout as IActiveView; IMap pMap = activeView.FocusMap; IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer; IMapFrame mapFrame = (IMapFrame)pGraphicsContainer.FindFrame(pMap); UID uid = new UIDClass(); uid.Value = type; IMapSurroundFrame pMapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); IMapSurround pMapSurround = pMapSurroundFrame.MapSurround; IScaleBar pScaleBar = (IScaleBar)pMapSurround; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; pScaleBar.UseMapSettings(); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(0.8, 0.8, 13, 2); IElement element = pMapSurroundFrame as IElement; element.Geometry = pEnvelope; pGraphicsContainer.AddElement(element, 0); activeView.Refresh(); }
// 添加图例 public static void MakeLegend(AxPageLayoutControl pageLayoutControl, IEnvelope envelope) { IActiveView pActiveView = pageLayoutControl.ActiveView; UID pUID = new UID() { Value = "esriCarto.Legend" }; IGraphicsContainer pGraphicsContainer = pageLayoutControl.PageLayout as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame; // 根据唯一标识符,创建与之对应的MapSurroundFrame IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null); // 获取PageLayout中的图例元素 IElement pDeleteElement = pageLayoutControl.FindElementByName("Legend"); if (pDeleteElement != null) { pGraphicsContainer.DeleteElement(pDeleteElement); // 如果已存在图例,删除已经存在的图例 } // 设置MapSurroundFrame背景 ISymbolBackground pSymbolBackground = new SymbolBackgroundClass() { FillSymbol = new SimpleFillSymbolClass() { Color = AeUtilsSymbology.GetRgbColor(240, 240, 240), Outline = new SimpleLineSymbolClass() { Color = AeUtilsSymbology.GetRgbColor(0, 0, 0) } } }; pMapSurroundFrame.Background = pSymbolBackground; // 添加图例 IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = envelope as IGeometry; IMapSurround pMapSurround = pMapSurroundFrame.MapSurround; ILegend pLegend = pMapSurround as ILegend; pLegend.ClearItems(); pLegend.Title = "图例"; for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++) { ILegendItem pLegendItem = new HorizontalLegendItemClass() { Layer = pActiveView.FocusMap.get_Layer(i), ShowDescriptions = false, Columns = 1, ShowHeading = true, ShowLabels = true }; pLegend.AddItem(pLegendItem); } pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private IMapSurround CreateMapSurround(UID ipUID, IEnvelope ipEnv, string sName, IMapSurround ipStyle) { IMapSurround ms = null; IMapFrame mf = m_hookHelper.ActiveView.GraphicsContainer.FindFrame( m_hookHelper.ActiveView.FocusMap) as IMapFrame; IMapSurroundFrame msf = mf.CreateSurroundFrame(ipUID, ipStyle); IElement ele = msf as IElement; ele.Geometry = ipEnv; ms = msf.MapSurround; ms.Name = sName; m_hookHelper.ActiveView.GraphicsContainer.AddElement(ele, 0); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); return(ms); }
private void MakeLegend(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv) { UID pID = new UID(); pID.Value = "esriCarto.Legend"; IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame; IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null); //根据唯一标示符,创建与之对应MapSurroundFrame IElement pDeletElement = axPageLayoutControl1.FindElementByName("Legend"); //获取PageLayout中的图例元素 if (pDeletElement != null) { pGraphicsContainer.DeleteElement(pDeletElement); //如果已经存在图例,删除已经存在的图例 } //设置MapSurroundFrame背景 ISymbolBackground pSymbolBackground = new SymbolBackgroundClass(); IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = m_OperatePageLayout.GetRgbColor(0, 0, 0); pFillSymbol.Color = m_OperatePageLayout.GetRgbColor(240, 240, 240); pFillSymbol.Outline = pLineSymbol; pSymbolBackground.FillSymbol = pFillSymbol; pMapSurroundFrame.Background = pSymbolBackground; //添加图例 IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = pEnv as IGeometry; IMapSurround pMapSurround = pMapSurroundFrame.MapSurround; ILegend pLegend = pMapSurround as ILegend; pLegend.ClearItems(); pLegend.Title = "图例"; for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++) { ILegendItem pLegendItem = new HorizontalLegendItemClass(); pLegendItem.Layer = pActiveView.FocusMap.get_Layer(i);//获取添加图例关联图层 pLegendItem.ShowDescriptions = false; pLegendItem.Columns = 1; pLegendItem.ShowHeading = true; pLegendItem.ShowLabels = true; pLegend.AddItem(pLegendItem);//添加图例内容 } pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 获取条块大小 /// </summary> /// <param name="item"></param> /// <returns></returns> private double GetSymbolSizeFromItem(object item) { if (item == null) { return(-1); } IMapSurround pMapSurround = item as IMapSurround; if (pMapSurround is IScaleBar) { return((pMapSurround as IScaleBar).BarHeight); } else { return(0); } }
/// <summary> /// 获得单位的枚举实例对应的整型值 /// </summary> /// <param name="item"></param> /// <returns></returns> private int GetUnitIndexFromItem(object item) { if (item == null) { return(0); } IMapSurround pMapSurround = item as IMapSurround; if (pMapSurround is IScaleBar) { return((int)((pMapSurround as IScaleBar).Units)); } else { return(0); } }
// 指北针 public void AddNorthArrow(AxPageLayoutControl axPageLayout) { //删除已经存在的指北针 IElement pElement = axPageLayout.FindElementByName("NorthArrows"); if (pElement != null) { axPageLayout.ActiveView.GraphicsContainer.DeleteElement(pElement); } IGraphicsContainer container = axPageLayout.PageLayout as IGraphicsContainer; IActiveView activeView = axPageLayout.PageLayout as IActiveView; // 获得MapFrame IFrameElement frameElement = container.FindFrame(activeView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.MarkerNorthArrow"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中指北针的点符号 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow; IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol; markerSymbol.Size = 48; markerNorthArrow.MarkerSymbol = markerSymbol; //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; IEnvelope envelope = new EnvelopeClass(); double x = 15; double y = 22; envelope.PutCoords(x, y, x + 5, y + 5); element.Geometry = envelope; //使用IGraphicsContainer接口添加显示 container.AddElement(element, 0); activeView.Refresh(); }
/// <summary> /// 添加默认图例 /// </summary> /// <param name="layoutControl">布局视图</param> /// <param name="pEnv">矩形框</param> public static void AddDefaultLegend(AxPageLayoutControl layoutControl, IEnvelope pEnv) { IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer; if (pGraphicsContainer == null) { return; } IMap pMap = layoutControl.ActiveView.FocusMap; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; if (pMapFrame == null) { return; } UID pID = new UID { Value = "esriCarto.Legend" }; IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null); //根据唯一标示符,创建与之对应MapSurroundFrame //如果已经存在图例,删除已经存在的图例 MappingHelper.DeleteElementByName(layoutControl, "Legend"); //添加图例 IElement pElement = pMapSurroundFrame as IElement; if (pElement == null) { return; } pElement.Geometry = pEnv; IMapSurround pMapSurround = pMapSurroundFrame.MapSurround; ILegend2 pLegend = pMapSurround as ILegend2; if (pLegend == null) { return; } //设置图例属性 SetLegendProperty(pLegend, pMap); //添加元素 MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Legend"); }
/// <summary> /// 获取文本大小 /// </summary> /// <param name="item"></param> /// <returns></returns> private double GetTextSizeFromItem(object item) { if (item == null) { return(-1); } IMapSurround pMapSurround = item as IMapSurround; if (pMapSurround is IScaleBar) { ITextSymbol textSymbol = (pMapSurround as IScaleBar).LabelSymbol; return(textSymbol.Size); } else { return(0); } }
/// <summary> /// 获取文本字体 /// </summary> /// <param name="item"></param> /// <returns></returns> private stdole.IFontDisp GetTextFontFromItem(object item) { if (item == null) { return(null); } IMapSurround pMapSurround = item as IMapSurround; if (pMapSurround is IScaleBar) { ITextSymbol textSymbol = (pMapSurround as IScaleBar).LabelSymbol; return(textSymbol.Font); } else { return(null); } }
public void AddNorthArrow(IPageLayout pageLayout, IMap map, double posX, double posY, double division) { try { if (pageLayout == null || map == null) { return; } IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(posX - division, posY - division, posX, posY); // Specify the location and size of the north arrow ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "esriCarto.MarkerNorthArrow"; // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location // Activate it and add it to the PageLayout's graphics container IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; // Dynamic Cast IActiveView activeView = pageLayout as IActiveView; // Dynamic Cast IFrameElement frameElement = graphicsContainer.FindFrame(map); IMapFrame mapFrame = frameElement as IMapFrame; // Dynamic Cast IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; element.Activate(activeView.ScreenDisplay); graphicsContainer.AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; // Change out the default north arrow IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow; // Dynamic Cast IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol; ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; // Dynamic Cast characterMarkerSymbol.CharacterIndex = 174; // change the symbol for the North Arrow markerNorthArrow.MarkerSymbol = characterMarkerSymbol; } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
// 比例尺 public void AddScalebar(AxPageLayoutControl axPageLayout) { //删除已经存在的比例尺 IElement pelement = axPageLayout.FindElementByName("AlternatingScaleBar"); if (pelement != null) { axPageLayout.ActiveView.GraphicsContainer.DeleteElement(pelement); } IGraphicsContainer container = axPageLayout.PageLayout as IGraphicsContainer; IActiveView activeView = axPageLayout.PageLayout as IActiveView; // 获得MapFrame IFrameElement frameElement = container.FindFrame(activeView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中比例尺的样式 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; IEnvelope envelope = new EnvelopeClass(); double x = 12; double y = 5; envelope.PutCoords(x, y, x + 1, y + 1); element.Geometry = envelope; //使用IGraphicsContainer接口添加显示 container.AddElement(element, 0); activeView.Refresh(); }
/// <summary> /// Changs the scale bar unit. /// </summary> private void ChangScaleBarUnit() { if (this._styleGalleryItem != null) { IMapSurround mapSurround = this._styleGalleryItem.Item as IMapSurround; if (mapSurround != null) { IScaleBar scaleBar = mapSurround as IScaleBar; if (scaleBar != null) { if (this.cmbScaleBarUnit.SelectedIndex == 0) { scaleBar.Units = esriUnits.esriMeters; } else { scaleBar.Units = esriUnits.esriKilometers; } } } } }
/// <summary> /// 获取条块颜色 /// </summary> /// <param name="item"></param> /// <returns></returns> private Color GetSymbolColorFromItem(object item) { Color fillColor = Color.Black; IRgbColor rgbColor = null; IMapSurround pMapSurround = item as IMapSurround; if (pMapSurround == null) { return(Color.Black); } if (pMapSurround is IScaleBar) { rgbColor = ((pMapSurround as IScaleBar).BarColor) as IRgbColor;; } //颜色控件赋值 if (rgbColor != null) { fillColor = Color.FromArgb(rgbColor.Red, rgbColor.Green, rgbColor.Blue); } return(fillColor); }
public static void AddScalebar(AxPageLayoutControl pageLayoutControl, IEnvelope envelope) { IUID uid = new UIDClass() { Value = "esriCarto.AlternatingScaleBar" }; IFrameElement frameElement = (pageLayoutControl.PageLayout as IGraphicsContainer) .FindFrame(pageLayoutControl.ActiveView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null); // Dynamic Cast IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; element.Activate(pageLayoutControl.ActiveView.ScreenDisplay); (pageLayoutControl.PageLayout as IGraphicsContainer).AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = (IScaleBar)(mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); }
/// <summary> /// 获取一个地图制图元素 /// </summary> /// <param name="ipUID"></param> /// <param name="ipEnv"></param> /// <param name="sName"></param> /// <param name="ipLayoutCtrl"></param> /// <param name="ipStyle"></param> /// <returns></returns> public static IMapSurround CreateMapSurround(UID ipUID, IEnvelope ipEnv, string sName, IPageLayoutControlDefault ipLayoutCtrl, IMapSurround ipStyle) { try { IMapSurround ms = null; IMapFrame mf = ipLayoutCtrl.ActiveView.GraphicsContainer.FindFrame(ipLayoutCtrl.ActiveView.FocusMap) as IMapFrame; IMapSurroundFrame msf = mf.CreateSurroundFrame(ipUID, ipStyle); IElement ele = msf as IElement; ms = msf.MapSurround; ms.Name = sName; ele.Geometry = ipEnv; ipLayoutCtrl.ActiveView.GraphicsContainer.AddElement(ele, 0); ele.Geometry = ipEnv; //再加一句才能根据画出来的范围改变图例大小 ipLayoutCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, ele, null); return(ms); } catch (System.Exception ex) { return(null); } }
public void DeleteMapSurround(IMapSurround MapSurround) { throw new NotImplementedException(); }
public IMapSurround CreateMapSurround(UID clsid, IMapSurround optionalStyle) { throw new NotImplementedException(); }
private bool UseTemplateMxtToPageLayout(AxPageLayoutControl mainPageLayoutControl, string sTemplatePath) { bool success = false; try { IMap map = null; IActiveView activeView = null; IPageLayout curPageLayout = mainPageLayoutControl.PageLayout; activeView = curPageLayout as IActiveView; map = activeView.FocusMap; // 读取模板 IMapDocument tempMapDocument = new MapDocumentClass(); tempMapDocument.Open(sTemplatePath, ""); IPageLayout tempPageLayout = tempMapDocument.PageLayout; IPage tempPage = tempPageLayout.Page; IPage curPage = curPageLayout.Page; // 替换单位及地图方向 curPage.Orientation = tempPage.Orientation; curPage.Units = tempPage.Units; // 替换页面尺寸 Double width, height; tempPage.QuerySize(out width, out height); curPage.PutCustomSize(width, height); // 删除当前layout中除了mapframe外所有element IGraphicsContainer graphicsContainer = curPageLayout as IGraphicsContainer; graphicsContainer.Reset(); IElement element = graphicsContainer.Next(); IMapFrame mapFrame = null; mapFrame = graphicsContainer.FindFrame(map) as IMapFrame; while (element != null) { if (element is IMapFrame) { mapFrame = element as IMapFrame; } else { graphicsContainer.DeleteElement(element); graphicsContainer.Reset(); } element = graphicsContainer.Next(); } // 遍历模板中的PageLayout所有元素,替换当前PageLayout的所有元素 IGraphicsContainer tempGraphicsContainer = tempPageLayout as IGraphicsContainer; tempGraphicsContainer.Reset(); IArray array = new ArrayClass(); while (element != null) { if (element is IMapFrame) { IElement mapFrameElement = mapFrame as IElement; mapFrameElement.Geometry = element.Geometry; } else { if (element is IMapSurroundFrame) { IMapSurroundFrame mapSurroundFrame = element as IMapSurroundFrame; mapSurroundFrame.MapFrame = mapFrame; IMapSurround tempMapSurround = mapSurroundFrame.MapSurround; } array.Add(element); } element = tempGraphicsContainer.Next(); } int elementCount = array.Count; for (int i = 0; i < array.Count; i++) { graphicsContainer.AddElement(array.get_Element(elementCount - 1 - i) as IElement, 0); } activeView.Refresh(); success = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(success); }
/// <summary> /// 模板替换 /// </summary> /// <param name="_pageLayoutCtrl"></param> /// <param name="sTemplatePath"></param> /// <returns></returns> public static bool UseTemplateMxtToPageLayout(AxPageLayoutControl _pageLayoutCtrl, string sTemplatePath) { bool bSuccess = false; try { IMap pMap = null; IActiveView pActiveView = null; IPageLayout pCurPageLayout = _pageLayoutCtrl.PageLayout; pActiveView = pCurPageLayout as IActiveView; pMap = pActiveView.FocusMap; //读取模板 IMapDocument pTempMapDocument = new MapDocumentClass(); pTempMapDocument.Open(sTemplatePath, ""); IPageLayout pTempPageLayout = pTempMapDocument.PageLayout; IPage pTempPage = pTempPageLayout.Page; IPage pCurPage = pCurPageLayout.Page; //替换单位及地图方向 pCurPage.Orientation = pTempPage.Orientation; pCurPage.Units = pTempPage.Units; //替换页面尺寸 Double dWidth; Double dHeight; pTempPage.QuerySize(out dWidth, out dHeight); pCurPage.PutCustomSize(dWidth, dHeight); //删除当前layout中除了mapframe外的所有element IGraphicsContainer pGraph; pGraph = pCurPageLayout as IGraphicsContainer; pGraph.Reset(); IElement pElement = pGraph.Next(); IMapFrame pMapFrame = null; pMapFrame = pGraph.FindFrame(pMap) as IMapFrame; while (pElement != null) { if (pElement is IMapFrame) { pMapFrame = pElement as IMapFrame; } else { pGraph.DeleteElement(pElement); pGraph.Reset(); } pElement = pGraph.Next(); } //遍历模板中的PageLayout所有元素,替换当前PageLayout的所有元素 IGraphicsContainer pTempGraph = pTempPageLayout as IGraphicsContainer; pTempGraph.Reset(); pElement = pTempGraph.Next(); IArray pArray = new ArrayClass(); while (pElement != null) { if (pElement is IMapFrame) { IElement pMapFrameElement = pMapFrame as IElement; pMapFrameElement.Geometry = pElement.Geometry; } else { if (pElement is IMapSurroundFrame) { IMapSurroundFrame pTempMapSurroundFrame = pElement as IMapSurroundFrame; pTempMapSurroundFrame.MapFrame = pMapFrame; IMapSurround pTempMapSurround = pTempMapSurroundFrame.MapSurround; } pArray.Add(pElement); } pElement = pTempGraph.Next(); } int pElementCount = pArray.Count; for (int i = 0; i < pArray.Count; i++) { pGraph.AddElement(pArray.get_Element(pElementCount - 1 - i) as IElement, 0); } pActiveView.Refresh(); bSuccess = true; } catch (Exception ex) { } return(bSuccess); }
public void AddScalebar(IPageLayout pageLayout, IMap map, double posX, double posY, double division, string strMapUnits, short srtDivisions) { try { if (pageLayout == null || map == null) { return; } IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(posX - (division * 2), posY, posX, posY + (division * 0.5)); // Specify the location and size of the scalebar ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location // Activate it and add it to the PageLayout's graphics container IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; // Dynamic Cast IActiveView activeView = pageLayout as IActiveView; // Dynamic Cast IFrameElement frameElement = graphicsContainer.FindFrame(map); IMapFrame mapFrame = frameElement as IMapFrame; // Dynamic Cast IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; element.Activate(activeView.ScreenDisplay); graphicsContainer.AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)(mapSurround)); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); markerScaleBar.Divisions = srtDivisions; markerScaleBar.DivisionsBeforeZero = 0; markerScaleBar.Subdivisions = 0; markerScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarMajorDivisions; if (strMapUnits == "Feet") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet; } //Default Settings else if (strMapUnits == "Miles") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMiles; } else if (strMapUnits == "Meters") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters; } else if (strMapUnits == "Kilometers") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriKilometers; } else { return; } } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }