请问各位高手,在用arcgis engine做开发时,如何将PageLayout中的内容生成 .mxt文件?跪求!多谢!
发布网友
发布时间:2022-04-23 11:23
我来回答
共1个回答
热心网友
时间:2023-10-12 06:40
把对应的元素写成函数调用就行了。
/// <summary>
/// 添加默认固定指北针
/// </summary>
/// <param name="pageLayout"></param>
public static 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 = 30;
markerNorthArrow.MarkerSymbol = markerSymbol;
//QI,确定mapSurroundFrame的位置
IElement element = mapSurroundFrame as IElement;
IEnvelope envelope = new EnvelopeClass();
envelope.PutCoords(19.7, 27, 29,37 );
element.Geometry = envelope;
//使用IGraphicsContainer接口添加显示
container.AddElement(element, 0);
activeView.Refresh();
}
/// <summary>
/// 添加固定比例尺
/// </summary>
/// <param name="pageLayout"></param>
public static void AddScalebar(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.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(1.3, 1.3, 5, 2);
element.Geometry = envelope;
//使用IGraphicsContainer接口添加显示
container.AddElement(element, 0);
activeView.Refresh();
}
/// <summary>
/// 添加固定图例
/// </summary>
/// <param name="axPageLayoutControl1"></param>
public static void AddLegend(AxPageLayoutControl axPageLayoutControl1)
{
IPageLayout pageLayout = axPageLayoutControl1.PageLayout;
IGraphicsContainer container = pageLayout as IGraphicsContainer;
IActiveView activeView = pageLayout as IActiveView;
// 获得MapFrame
IFrameElement frameElement = container.FindFrame(activeView.FocusMap);
//IMapFrame mapFrame = container.FindFrame(activeView.FocusMap) as IMapFrame;
IMapFrame mapFrame = frameElement as IMapFrame;
//根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround
UID uid = new UIDClass();
uid.Value = "esriCarto.Legend";
IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
//设置MapSurroundFrame背景
ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
pLineSymbol.Color = GetRgbColor(0, 0, 0);
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = GetRgbColor(240, 240, 240);
pFillSymbol.Outline = pLineSymbol;
pSymbolBackground.FillSymbol = pFillSymbol;
mapSurroundFrame.Background = pSymbolBackground;
//设置图例的Title
ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2;
legend.Title = "地图图例";
//新图层加载时自动更新
legend.AutoAdd = true;
ILegendFormat format = new LegendFormatClass();
ITextSymbol symbol = new TextSymbolClass();
symbol.Size = 0.3;
format.TitleSymbol = symbol;
legend.Format = format;
//QI,确定mapSurroundFrame的位置
IElement element = mapSurroundFrame as IElement;
IEnvelope envelope = new EnvelopeClass();
envelope.PutCoords(17.7, 1, 20, 9);
element.Geometry = envelope;
//使用IGraphicsContainer接口添加显示
container.AddElement(element, 0);
activeView.Refresh();
}
/// <summary>
/// 添加title
/// </summary>
/// <param name="pageLayout"></param>
/// <param name="s"></param>
public static void AddTitle(AxPageLayoutControl mainPageLayoutControl1, String s)
{
//找到PageLayout
IPageLayout pPageLayout = mainPageLayoutControl1.PageLayout;
//找到元素容器
IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
//创建元素
ITextElement pTextElement = new TextElementClass();
pTextElement.Text = s;
ITextSymbol pTextSymbol = new TextSymbolClass();//Text的符号样式
IRgbColor color = new RgbColorClass();
color.Green = 255;
color.Blue = 255;
color.Red = 0;
pTextSymbol.Color = color as ESRI.ArcGIS.Display.IColor;
pTextSymbol.Size = 20;
pTextSymbol.Color = GetRgbColor(0, 0, 0);
pTextElement.Symbol = pTextSymbol;
//设置位置
IElement pElement = pTextElement as IElement;
IEnvelope envelope = new EnvelopeClass();
envelope.PutCoords(9, 27.3, 13, 30);
pElement.Geometry = envelope;
//pElement.Geometry = mainPageLayoutControl1.TrackRectangle();
//将元素添加到容器中
pGraphicsContainer.AddElement(pElement, 0);
//刷新
mainPageLayoutControl1.Refresh();
}