最后的圣洁

博客园 首页 新随笔 联系 订阅 管理

 PageLayout作为展示map对象的容器,是一个和和MapControl很相似的控件 ,都能够在之中绘制图形和图形和管理要素。不过,PageLayout可以为不同的用途提供个性化的地图整饰功能。而且,PageLayout不仅可以管理图形元素(Graphic Element)而且可以管理框架元素(Frame Element)。注意:Element(元素)是指不保存进数据库的对象,而只存在内存,当地图发生变化的时候,这些对象就会消失。如DrawShap和DrawText等方法绘制的图形。今天主要讨论框架元素。主要包括:FrameElement,MapsurroundFrame,OLeFrame和TabelFrame等。他们都是作为不可见的容器存在的,MapFrame对象作为Map的容器,用于管理Map对象。MapSurroundFrame主要管理和Map对象相关如 比例尺,注记,指北针之类的对象。此外还有MapGrid 对象模型,可以“近似”的看作一个图层,该图层是添加地图格网的。其主要由GridLine,GridLabel,Gridborder3部分组成,该接口由MapFrame对象实现。当想一个paylout添加地图格网的代码如下:

  1   private void button1_Click(object sender, EventArgs e)
  2         {
  3             this.axPageLayoutControl1.LoadMxFile(@"G:\GeoData\first1.mxd");
  4             IActiveView pAcitiveView = this.axPageLayoutControl1.ActiveView;
  5             IMap pMap = pAcitiveView.FocusMap;
  6             IGraphicsContainer pGraphicsContainer = pAcitiveView as IGraphicsContainer;
  7             //IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
  8             IMapFrame pMapFrame = new MapFrame() as IMapFrame;
  9             pMapFrame.Container = pGraphicsContainer;
 10             pMapFrame.Map = pMap;
 11             //UID uid = new UID();
 12             //uid.Value = "esriCaro.ScaleText";
 13             //IMapSurroundFrame mapsurroundFrame = pMapFrame.CreateSurroundFrame(uid, null);
 14 
 15             //IElement element = mapsurroundFrame as IElement;
 16             //IEnvelope envelope = new Envelope() as IEnvelope;
 17             //envelope.PutCoords(1, 1, 10, 2);
 18             //element.Geometry = envelope;
 19             //element.Activate(pAcitiveView.ScreenDisplay);
 20             //ITrackCancel trackeCancel = new TrackCancel();
 21             //element.Draw(pAcitiveView.ScreenDisplay, trackeCancel);
 22             //pGraphicsContainer.AddElement(element, 0);
 23 
 24             IMapGrids pMapGrids = pMapFrame as IMapGrids;
 25             //创建一个MeasuredGrid对象
 26             IMeasuredGrid pMeasureGrid = new MeasuredGrid() as IMeasuredGrid;
 27             IMapGrid pMapGrid = pMeasureGrid as IMapGrid;
 28             pMeasureGrid.FixedOrigin = true;
 29             pMeasureGrid.Units = pMap.MapUnits;
 30             pMeasureGrid.XIntervalSize = 1000;
 31             pMeasureGrid.YIntervalSize = 1000;
 32             pMeasureGrid.XOrigin = -180;
 33             pMeasureGrid.YOrigin = -90;
 34 
 35             // 设置MeasuredGride投影属性
 36 
 37             IProjectedGrid pProGrid = pMeasureGrid as IProjectedGrid;
 38             pProGrid.SpatialReference = pMap.SpatialReference;
 39             pMapGrid.Name = "Measured Grid";
 40             //创建一个CalibratedMapGridBorder对象并设置为pMapGrid的Border属性
 41             ICalibratedMapGridBorder pCalibratedBorder = new CalibratedMapGridBorder() as ICalibratedMapGridBorder;
 42             pCalibratedBorder.ForegroundColor = GetColor(0, 0, 0);
 43             pCalibratedBorder.BorderWidth = 0.1;
 44             pCalibratedBorder.Interval = 72;
 45             pCalibratedBorder.Alternating = true;
 46             pMapGrid.Border = pCalibratedBorder as IMapGridBorder;
 47             // 创建一个FormattedGridLabel对象
 48             IFormattedGridLabel pFormattedGridLabel = new FormattedGridLabel() as IFormattedGridLabel;
 49             IGridLabel pGridLabel = pFormattedGridLabel as IGridLabel;
 50             stdole.StdFont pFont = new stdole.StdFont();
 51             pFont.Name = "Arial";
 52             pFont.Size = 6;
 53             pGridLabel.Font = pFont as stdole.IFontDisp; ;
 54             pGridLabel.Color = GetColor(4, 4, 3);
 55             pGridLabel.LabelOffset = 4;
 56             pGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisLeft, false);
 57             pGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisRight, false);
 58             INumericFormat pNumericFormat = new NumericFormat() as INumericFormat;
 59             pNumericFormat.AlignmentOption = esriNumericAlignmentEnum.esriAlignRight;
 60             pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits;
 61             pNumericFormat.RoundingValue = 0;
 62             pNumericFormat.ShowPlusSign = false;
 63             pNumericFormat.ZeroPad = true;
 64             pFormattedGridLabel.Format = pNumericFormat as INumberFormat;
 65             //设置pMapGrid的LabelFormat属性
 66             pMapGrid.LabelFormat = pGridLabel;
 67             //添加格网
 68             pMapGrids.AddMapGrid(pMapGrid);
 69             pAcitiveView.Refresh();
 70 
 71        }
 72 
 73            86          
      

但是今天花费了一个小时也没有将Mapgrid显示出来,小可不知道是什么原因,如果那个朋友看出来可以留言给我。上段代码中的注释部分为MapSurround对象的显示。运行正常,因为笔者怀疑可能是在地里格网的参数设置问题!

 

  

posted on 2012-11-23 20:33  最后的圣洁  阅读(672)  评论(0编辑  收藏  举报