这是我们GIS课程的结课作业,只能说,大心血
链接在最后,但是还是希望大家可以看看代码,可以留言相互交流学习。
目录
链接在最后,但是还是希望大家可以看看代码,可以留言相互交流学习。
添加图名
public void AddTitle(IPageLayout pageLayout, String s)
{
//找到PageLayout
IPageLayout pPageLayout = mainPageLayoutControl1.PageLayout;
//找到元素容器
IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
//创建元素
ITextElement pTextElement = new TextElementClass();
pTextElement.Text = s;
ITextSymbol pTextSymbol = new TextSymbolClass();//Text的符号样式
pTextSymbol.Size = 30;
pTextSymbol.Color = GetRGB(0, 0, 0);
pTextElement.Symbol = pTextSymbol;
//设置位置
IElement pElement = pTextElement as IElement;
pElement.Geometry = mainPageLayoutControl1.TrackRectangle();
//将元素添加到容器中
pGraphicsContainer.AddElement(pElement, 0);
//刷新
mainPageLayoutControl1.Refresh();
}
指北针
IMapFrame pMapFrame = ((IActiveView)this.mainPageLayoutControl1.PageLayout).GraphicsContainer.FindFrame(this.mainPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
IElement pElement = pMapFrame as IElement;
UID pID = new UIDClass();
pID.Value = "esriCarto.MarkerNorthArrow";
IEnvelope pEnv = new EnvelopeClass();
pEnv.PutCoords(16, 24, 22, 26);
AddNorthArrow NForm = new AddNorthArrow(mainPageLayoutControl1.ActiveView, esriSymbologyStyleClass.esriStyleClassNorthArrows);//axPageLayoutControl1.ActiveView, esriSymbologyStyleClass.esriStyleClassNorthArrows
NForm.ShowDialog();
IStyleGalleryItem styleGalleryItem = NForm.m_styleGalleryItem;
NForm.Dispose();
if (styleGalleryItem == null) return;
IMapSurround pMapSurround = this.CreateSurround(pID, pEnv, styleGalleryItem, pMapFrame, this.mainPageLayoutControl1.PageLayout);
this.mainPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
比例尺(类似指北针。从样式库里添加)
IMapFrame pMapFrame = ((IActiveView)this.mainPageLayoutControl1.PageLayout).GraphicsContainer.FindFrame(this.mainPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
IElement pElement = pMapFrame as IElement;
UID pID = new UIDClass();
pID.Value = "esriCarto.ScaleLine";
IEnvelope pEnv = new EnvelopeClass();
pEnv.PutCoords(2, 3, 3, 5);
AddScalebar SForm = new AddScalebar(mainPageLayoutControl1.ActiveView, esriSymbologyStyleClass.esriStyleClassScaleBars);
SForm.ShowDialog();
IStyleGalleryItem styleGalleryItem = SForm.m_styleGalleryItem;
SForm.Dispose();
if (styleGalleryItem == null) return;
IMapSurround pMapSurround = this.CreateSurround(pID, pEnv, styleGalleryItem, pMapFrame, this.mainPageLayoutControl1.PageLayout);
this.mainPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);