默认头像
路人甲
路人甲
  • 注册日期2004-06-28
  • 发帖数21
  • QQ
  • 铜币234枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:5302回复:7

怎么实现在PageLayout控件中添加了图例、指北针或比例尺等要素 ,用arcengine实现。

楼主#
更多 发布于:2005-09-16 10:58

各位大侠,怎么实现在PageLayout控件中添加了图例、指北针或比例尺等要素 ,用arcengine实现。给个思路。

小弟先谢谢呢!!

喜欢0 评分0
默认头像
路人甲
路人甲
  • 注册日期2006-02-15
  • 发帖数39
  • QQ
  • 铜币207枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-03-20 18:05
Public Sub AddMapSurrounds()
  Dim pMxDoc As IMxDocument
  Dim pActiveView As IActiveView
  Dim pEnv As IEnvelope
  Dim pID As New UID
  Dim pMapSurround As IMapSurround
  Dim pMarkerNorthArrow As IMarkerNorthArrow
  Dim pCharacterMarkerSymbol As ICharacterMarkerSymbol
  
  Set pMxDoc = Application.Document
  Set pActiveView = pMxDoc.PageLayout
  Set pEnv = New Envelope
  
  'Add a north arrow
  pEnv.PutCoords 0.2, 0.2, 1, 1
  pID.Value = "esriCarto.MarkerNorthArrow"
  Set pMapSurround = CreateSurround(pID, pEnv, "North Arrow", pMxDoc.FocusMap, pMxDoc.PageLayout)
  'Change out the default north arrow
  Set pMarkerNorthArrow = pMapSurround 'QI
  Set pCharacterMarkerSymbol = pMarkerNorthArrow.MarkerSymbol 'clones the symbol
  pCharacterMarkerSymbol.CharacterIndex = 200 'change the symbol
  pMarkerNorthArrow.MarkerSymbol = pCharacterMarkerSymbol 'set it back
  
  'Add a legend
  'In this case just use the default legend
  pEnv.PutCoords 1, 1, 3.4, 2.4
  pID.Value = "esriCarto.Legend"
  Set pMapSurround = CreateSurround(pID, pEnv, "Legend", pMxDoc.FocusMap, pMxDoc.PageLayout)
  
  'Refresh the graphics
  pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
End Sub


Private Function CreateSurround(pID As UID, pEnv As IEnvelope, strName As String, _
                           pMap As IMap, pPageLayout As IPageLayout) As IMapSurround
  
  Dim pGraphicsContainer As IGraphicsContainer
  Dim pActiveView As IActiveView
  Dim pMapSurroundFrame As IMapSurroundFrame
  Dim pMapSurround As IMapSurround
  Dim pMapFrame As IMapFrame
  Dim pElement As IElement
  
  'MapSurrounds are held in a MapSurroundFrame
  'MapSurroundFrames are related to MapFrames
  'MapFrames hold Maps
  Set pGraphicsContainer = pPageLayout
  Set pMapFrame = pGraphicsContainer.FindFrame(pMap)
  Set pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, Nothing)
  pMapSurroundFrame.MapSurround.Name = strName

  'Set the geometry of the MapSurroundFrame to give it a location
  'Activate it and add it to the PageLayout's graphics container
  Set pElement = pMapSurroundFrame
  Set pActiveView = pPageLayout
  pElement.Geometry = pEnv
  pElement.Activate pActiveView.ScreenDisplay


  'Allow the legend frame size to be altered after the legend has been
  'added to the GraphicsContainer 
  Dim PTrack As ITrackCancel
  Set PTrack = New CancelTracker
  pElement.Draw pActiveView.ScreenDisplay, PTrack

  pGraphicsContainer.AddElement pElement, 0
  'Re-apply the change to the Legend MapSurroundFrame Geometry 
  pElement.Geometry = pEnv
  
  Set CreateSurround = pMapSurroundFrame.MapSurround
End Function
举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2005-07-27
  • 发帖数6
  • QQ
  • 铜币150枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-06-15 21:52

不错  谢谢

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2005-08-15
  • 发帖数18
  • QQ
  • 铜币221枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-07-26 10:55

有没有添加scalebar的代码阿?

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2006-06-04
  • 发帖数28
  • QQ
  • 铜币198枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-08-02 13:57

//根据UID创建Scale Bar
               UID uID = new UID();
               uID.Value = "esriCarto.ScaleBar";
               IMapSurroundFrame iMapSurFrame = iMapFrame.CreateSurroundFrame(uID, null);

               ISymbolBackground iSymBackg = new SymbolBackgroundClass();
               IFillSymbol iFillSym = new SimpleFillSymbol();
               ILineSymbol iLineSym = new SimpleLineSymbol();
               IRgbColor iRgb = new RgbColorClass();
               iRgb.Red = m_oldLineClr.R;
               iRgb.Green = m_oldLineClr.G;
               iRgb.Blue = m_oldLineClr.B;

               IColor iClr = iRgb;
               iLineSym.Color = iClr;
               iRgb.Red = m_oldFillClr.R;
               iRgb.Green = m_oldFillClr.G;
               iRgb.Blue = m_oldFillClr.B;
               iFillSym.Color = iClr;
               iFillSym.Outline = iLineSym;
               iSymBackg.FillSymbol = iFillSym;
               iMapSurFrame.Background = iSymBackg;

               IElement iElement = iMapSurFrame as IElement;
               iElement.Geometry = iEnv;

               IMapSurround iMapSur = iMapSurFrame.MapSurround;
               //创建一个single alternating scale bar
               IScaleBar iScaleBar = new AlternatingScaleBar();
               iMapSur = iScaleBar;

               //设置Scale Bar的属性,如分割单位、数字显示的位置、label和label显示位置等
               iScaleBar.Division = decimal.ToDouble(DivisionSize.Value);
               iScaleBar.DivisionsBeforeZero = 0;
               iScaleBar.Divisions = decimal.ToInt16(DivisionsSize.Value);
               iScaleBar.Subdivisions = decimal.ToInt16(SubDivisionsSize.Value);
               iScaleBar.Units = (esriUnits)(UnitsCbx.SelectedIndex);
               iScaleBar.UnitLabel = UnitsCbx.Text;
               iScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAfterBar;
               iScaleBar.LabelPosition = esriVertPosEnum.esriAbove;
               iScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint;

               iMapSurFrame.MapSurround = iMapSur;
               iElement = iMapSurFrame as IElement;
               iView.GraphicsContainer.AddElement(iElement, 0);

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2006-06-04
  • 发帖数28
  • QQ
  • 铜币198枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2006-08-02 13:58

//根据UID创建Scale Bar
               UID uID = new UID();
               uID.Value = "esriCarto.ScaleBar";
               IMapSurroundFrame iMapSurFrame = iMapFrame.CreateSurroundFrame(uID, null);

               ISymbolBackground iSymBackg = new SymbolBackgroundClass();
               IFillSymbol iFillSym = new SimpleFillSymbol();
               ILineSymbol iLineSym = new SimpleLineSymbol();
               IRgbColor iRgb = new RgbColorClass();
               iRgb.Red = m_oldLineClr.R;
               iRgb.Green = m_oldLineClr.G;
               iRgb.Blue = m_oldLineClr.B;

               IColor iClr = iRgb;
               iLineSym.Color = iClr;
               iRgb.Red = m_oldFillClr.R;
               iRgb.Green = m_oldFillClr.G;
               iRgb.Blue = m_oldFillClr.B;
               iFillSym.Color = iClr;
               iFillSym.Outline = iLineSym;
               iSymBackg.FillSymbol = iFillSym;
               iMapSurFrame.Background = iSymBackg;

               IElement iElement = iMapSurFrame as IElement;
               iElement.Geometry = iEnv;

               IMapSurround iMapSur = iMapSurFrame.MapSurround;
               //创建一个single alternating scale bar
               IScaleBar iScaleBar = new AlternatingScaleBar();
               iMapSur = iScaleBar;

               //设置Scale Bar的属性,如分割单位、数字显示的位置、label和label显示位置等
               iScaleBar.Division = decimal.ToDouble(DivisionSize.Value);
               iScaleBar.DivisionsBeforeZero = 0;
               iScaleBar.Divisions = decimal.ToInt16(DivisionsSize.Value);
               iScaleBar.Subdivisions = decimal.ToInt16(SubDivisionsSize.Value);
               iScaleBar.Units = (esriUnits)(UnitsCbx.SelectedIndex);
               iScaleBar.UnitLabel = UnitsCbx.Text;
               iScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAfterBar;
               iScaleBar.LabelPosition = esriVertPosEnum.esriAbove;
               iScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint;

               iMapSurFrame.MapSurround = iMapSur;
               iElement = iMapSurFrame as IElement;
               iView.GraphicsContainer.AddElement(iElement, 0);

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2006-06-04
  • 发帖数28
  • QQ
  • 铜币198枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2006-08-02 14:05

//根据UID创建Scale Bar
               UID uID = new UID();
               uID.Value = "esriCarto.ScaleBar";
               IMapSurroundFrame iMapSurFrame = iMapFrame.CreateSurroundFrame(uID, null);

               ISymbolBackground iSymBackg = new SymbolBackgroundClass();
               IFillSymbol iFillSym = new SimpleFillSymbol();
               ILineSymbol iLineSym = new SimpleLineSymbol();
               IRgbColor iRgb = new RgbColorClass();
               iRgb.Red = m_oldLineClr.R;
               iRgb.Green = m_oldLineClr.G;
               iRgb.Blue = m_oldLineClr.B;

               IColor iClr = iRgb;
               iLineSym.Color = iClr;
               iRgb.Red = m_oldFillClr.R;
               iRgb.Green = m_oldFillClr.G;
               iRgb.Blue = m_oldFillClr.B;
               iFillSym.Color = iClr;
               iFillSym.Outline = iLineSym;
               iSymBackg.FillSymbol = iFillSym;
               iMapSurFrame.Background = iSymBackg;

               IElement iElement = iMapSurFrame as IElement;
               iElement.Geometry = iEnv;

               IMapSurround iMapSur = iMapSurFrame.MapSurround;
               //创建一个single alternating scale bar
               IScaleBar iScaleBar = new AlternatingScaleBar();
               iMapSur = iScaleBar;

               //设置Scale Bar的属性,如分割单位、数字显示的位置、label和label显示位置等
               iScaleBar.Division = decimal.ToDouble(DivisionSize.Value);
               iScaleBar.DivisionsBeforeZero = 0;
               iScaleBar.Divisions = decimal.ToInt16(DivisionsSize.Value);
               iScaleBar.Subdivisions = decimal.ToInt16(SubDivisionsSize.Value);
               iScaleBar.Units = (esriUnits)(UnitsCbx.SelectedIndex);
               iScaleBar.UnitLabel = UnitsCbx.Text;
               iScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAfterBar;
               iScaleBar.LabelPosition = esriVertPosEnum.esriAbove;
               iScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint;

               iMapSurFrame.MapSurround = iMapSur;
               iElement = iMapSurFrame as IElement;
               iView.GraphicsContainer.AddElement(iElement, 0);

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2008-01-03
  • 发帖数18
  • QQ
  • 铜币159枚
  • 威望0点
  • 贡献值0点
  • 银元0个
7楼#
发布于:2009-08-15 09:17

这些代码帮助里头都有

举报 回复(0) 喜欢(0)     评分
默认头像

返回顶部