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 changeOritation(AxPageLayoutControl axPageLayoutControl) { IPageLayout pageLayout = axPageLayoutControl.PageLayout; IActiveView activeView = pageLayout as IActiveView; IMap pMap = activeView.FocusMap; IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer; IMapFrame mapFrame = (IMapFrame)pGraphicsContainer.FindFrame(pMap); IElement pElement = (IElement)mapFrame; IEnvelope pEnvelope = new EnvelopeClass(); if (axPageLayoutControl.Page.Orientation == 2) { pEnvelope.PutCoords(0.5, 0.5, 20.5, 29.2); axPageLayoutControl.Page.PutCustomSize(29.7, 21); axPageLayoutControl.Page.Orientation = 1; } else { pEnvelope.PutCoords(0.5, 0.5, 29.2, 20.5); axPageLayoutControl.Page.PutCustomSize(21, 29.7); axPageLayoutControl.Page.Orientation = 2; } pElement.Geometry = pEnvelope; activeView.Refresh(); }
public void AddNorthArrow(IPageLayout pageLayout, IMap map) { if ((pageLayout == null) || (map == null)) { return; } IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(34, 21, 36, 24); IUID uid = new UIDClass(); uid.Value = "esriCarto.MarkerNorthArrow"; IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; IActiveView activeView = pageLayout as IActiveView; IFrameElement frameElement = graphicsContainer.FindFrame(map); IMapFrame mapFrame = frameElement as IMapFrame; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null); IElement element = mapSurroundFrame as IElement; element.Geometry = envelope; element.Activate(activeView.ScreenDisplay); graphicsContainer.AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow; IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol; ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; characterMarkerSymbol.CharacterIndex = 177; characterMarkerSymbol.Size = 220; //???is this necessary? markerNorthArrow.MarkerSymbol = characterMarkerSymbol; }
public static void CopyAndOverwriteMap(AxMapControl axMapControl, AxPageLayoutControl axPageLayoutControl) { IObjectCopy objectCopy = new ObjectCopyClass(); object toCopyMap = axMapControl.Map; object copiedMap = objectCopy.Copy(toCopyMap); IPageLayout pagelayout = axPageLayoutControl.PageLayout; object overwriteMap = (pagelayout as IActiveView).FocusMap; objectCopy.Overwrite(toCopyMap, ref overwriteMap); IGraphicsContainer pGraphicsContainer = pagelayout as IGraphicsContainer; IMapFrame pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(overwriteMap); IElement pElement = pMapFrame as IElement; IEnumElement pEnumElement = pGraphicsContainer.LocateElementsByEnvelope(pElement.Geometry.Envelope); IElement pElementIcon = pEnumElement.Next(); while (pElementIcon != null) { if (pElementIcon is IMapSurroundFrame) { if ((pElementIcon as IMapSurroundFrame).MapSurround is IScaleBar) { (pElementIcon as IMapSurroundFrame).MapFrame = pMapFrame; } } pElementIcon = pEnumElement.Next(); } axPageLayoutControl.ActiveView.Refresh(); }
//Checks the element names of the page layout //returns boolean true if duplicates exist public static Boolean checkLayoutTextElementsForDuplicates(IMxDocument pMxDoc, string pFrameName) { //create list to store name of text elements List <string> lst = new List <string>(); Boolean duplicates; //check if the frame passed exists in the map document if (PageLayoutProperties.detectMapFrame(pMxDoc, pFrameName)) { //Declare variables IPageLayout pLayout = pMxDoc.PageLayout; IGraphicsContainer pGraphics = pLayout as IGraphicsContainer; pGraphics.Reset(); IElement element = new TextElementClass(); IElementProperties2 pElementProp; ITextElement pTextElement; //loop through the text elements in the frame try { element = (IElement)pGraphics.Next(); while (element != null) { if (element is ITextElement) { pTextElement = element as ITextElement; pElementProp = element as IElementProperties2; //where the name is not blank //System.Diagnostics.Debug.WriteLine(pElementProp.Name); if (pElementProp.Name != "") { //store the name of the elements and the values in the dictionary as pairs lst.Add(pElementProp.Name); } } element = pGraphics.Next() as IElement; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error detecting duplicate elements from the map frame"); System.Diagnostics.Debug.WriteLine(e); } } //Find if duplicates exist int duplicateCount = lst.Count() - lst.Distinct().Count(); if (duplicateCount != 0) { duplicates = true; return(duplicates); } else { duplicates = false; return(duplicates); } }
public void ApplyMapTemplate(IPageLayout ipageLayout_0) { this.GetFocusMapFrame(ipageLayout_0); ((ipageLayout_0 as IActiveView).FocusMap as IMapClipOptions).ClipType = esriMapClipType.esriMapClipNone; if ((ipageLayout_0 as IActiveView).FocusMap is IMapAutoExtentOptions) { ((ipageLayout_0 as IActiveView).FocusMap as IMapAutoExtentOptions).AutoExtentType = esriExtentTypeEnum.esriExtentDefault; } if (this.FixDataRange) { IEnvelope extent = ((ipageLayout_0 as IActiveView).FocusMap as IActiveView).Extent; this.mapTemplate_0.CreateTKByRect(ipageLayout_0 as IActiveView, extent); } else if (this.IsMapNo) { this.mapTemplate_0.CreateTrapezoidTK(ipageLayout_0, MapNoAssistantFactory.CreateMapNoAssistant(this.string_0)); } else if (this.mapTemplate_0.MapFramingType == MapFramingType.StandardFraming) { PointClass class2 = new PointClass { X = this.double_0, Y = this.double_1 }; this.mapTemplate_0.CreateTKN(ipageLayout_0 as IActiveView, class2); } (ipageLayout_0 as IGraphicsContainerSelect).UnselectAllElements(); }
/// <summary> /// 从比例尺列表中,选择能够展示指定要素范围的最合适比例尺 /// </summary> /// <param name="pageLayout">页面布局</param> /// <param name="mapFrame">要设定显示范围及比例尺的地图数据框</param> /// <param name="featureEnv">地图要素显示范围</param> /// <param name="scaleList">比例尺列表,将从中选取最合适的比例尺</param> /// <param name="bufferDistance">要素与图廓的缓冲距离(厘米),即地图实际显示范围是featEnvelope + 2 * bufferDistance</param> /// <returns></returns> public static double SetMapScale(this IPageLayout pageLayout, IMapFrame mapFrame, IEnvelope featureEnv, double[] scaleList, double bufferDistance = 2) { esriUnits pageUnit = pageLayout.Page.Units; esriUnits mapUnit = mapFrame.Map.DistanceUnits; esriUnits cmUnit = esriUnits.esriCentimeters; //厘米 IEnvelope mapFrameEnv = (mapFrame as IElement)?.Geometry.Envelope; IUnitConverter unitConverter = new UnitConverterClass(); double wScale = unitConverter.ConvertUnits(featureEnv.Width, mapUnit, cmUnit) / (unitConverter.ConvertUnits(mapFrameEnv.Width, pageUnit, cmUnit) - 2 * bufferDistance); double hScale = unitConverter.ConvertUnits(featureEnv.Height, mapUnit, cmUnit) / (unitConverter.ConvertUnits(mapFrameEnv.Height, pageUnit, cmUnit) - 2 * bufferDistance); double dScale = wScale > hScale ? wScale : hScale; int maxIndex = 0; while (maxIndex < scaleList.Length && dScale > scaleList[maxIndex]) { maxIndex++;//寻找比要素全图廓显示所确定的比例尺小一级的比例尺 } if (maxIndex == scaleList.Length) { throw new Exception("需要更小的比例尺!"); } return(scaleList[maxIndex]); }
public bool FocusOneElement(IPageLayout ipageLayout_0, IElement ielement_0) { bool result; try { IGraphicsContainerSelect graphicsContainerSelect = ipageLayout_0 as IGraphicsContainerSelect; if (graphicsContainerSelect == null) { result = false; return(result); } IActiveView activeView = ipageLayout_0 as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection, null, null); int elementSelectionCount = graphicsContainerSelect.ElementSelectionCount; if (elementSelectionCount >= 1) { graphicsContainerSelect.UnselectAllElements(); } graphicsContainerSelect.SelectElement(ielement_0); activeView.Refresh(); result = true; return(result); } catch { } result = false; return(result); }
public void makeScaleBar(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv) { IMap pMap = pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; if (pStyleGalleryItem == null) { return; } IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass(); pMapSurroundFrame.MapFrame = pMapFrame; pMapSurroundFrame.MapSurround = (IMapSurround)pStyleGalleryItem.Item; IElement pElement = axPageLayoutControl1.FindElementByName("ScaleBar"); if (pElement != null) { pGraphicsContainer.DeleteElement(pElement); //删除已经存在的比例尺 } IElementProperties pElePro = null; pElement = (IElement)pMapSurroundFrame; pElement.Geometry = (IGeometry)pEnv; pElePro = pElement as IElementProperties; pElePro.Name = "ScaleBar"; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <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>Add a North Arrow to the Page Layout from the Map.</summary> /// ///<param name="pageLayout">An IPageLayout interface.</param> ///<param name="map">An IMap interface.</param> /// ///<remarks></remarks> public void AddNorthArrow(IPageLayout pageLayout, IMap map) { if (pageLayout == null || map == null) { return; } ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); envelope.PutCoords(1, 24, 5, 24); // 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 ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map); ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast element.Geometry = envelope; element.Activate(activeView.ScreenDisplay); graphicsContainer.AddElement(element, 0); ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround; // Change out the default north arrow ESRI.ArcGIS.Carto.IMarkerNorthArrow markerNorthArrow = mapSurround as ESRI.ArcGIS.Carto.IMarkerNorthArrow; // Dynamic Cast ESRI.ArcGIS.Display.IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol; ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol; // Dynamic Cast characterMarkerSymbol.CharacterIndex = 200; // change the symbol for the North Arrow markerNorthArrow.MarkerSymbol = characterMarkerSymbol; }
public void SyncPageLayoutObject(IPageLayout pSourcePage, ref IPageLayout pTargetPage) { try { if ((pSourcePage != null) && (pTargetPage != null)) { IObjectCopy copy = null; copy = new ObjectCopyClass(); object pInObject = null; pInObject = pSourcePage; object obj3 = null; obj3 = copy.Copy(pInObject); object pOverwriteObject = null; pOverwriteObject = pTargetPage; copy.Overwrite(obj3, ref pOverwriteObject); IActiveView view = pTargetPage as IActiveView; if (view.GraphicsContainer != null) { IViewManager manager = view as IViewManager; ISelection elementSelection = manager.ElementSelection; view.Selection = elementSelection; } } } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "SyncPageLayoutObject", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } }
internal IMapFrame GetFocusMapFrame(IPageLayout ipageLayout_0) { IMapFrame mapFrame; IGraphicsContainer ipageLayout0 = ipageLayout_0 as IGraphicsContainer; ipageLayout0.Reset(); IElement element = ipageLayout0.Next(); while (true) { if (element == null) { mapFrame = null; break; } else if (element is IMapFrame) { mapFrame = element as IMapFrame; break; } else { element = ipageLayout0.Next(); } } return(mapFrame); }
/// <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(); }
//Return the scale, spatial reference system and extent properties of a given data frame public static Dictionary <string, string> getDataframeProperties(IMxDocument pMxDoc, string pFrameName) { // Create and initialise variables IPageLayout pLayout = pMxDoc.PageLayout; IMap pMap = Utilities.getMapFrame(pMxDoc, pFrameName); IActiveView pActiveView = pMap as IActiveView; Dictionary <string, string> dict = new Dictionary <string, string>(); string scale = null; string page_size = null; double xMax = 0; double yMax = 0; double xMin = 0; double yMin = 0; //Get the scale, page size and bounding coordinates of the dataframe scale = pMap.MapScale.ToString(); page_size = pLayout.Page.FormID.ToString(); xMax = pActiveView.Extent.XMax; yMax = pActiveView.Extent.YMax; xMin = pActiveView.Extent.XMin; yMin = pActiveView.Extent.YMin; //Add all properties to the dictionary dict.Add("scale", scale); dict.Add("page_size", page_size); dict.Add("xMax", Math.Round(xMax, 2).ToString()); Debug.WriteLine("xMax: " + dict["xMax"]); dict.Add("yMax", Math.Round(yMax, 2).ToString()); dict.Add("xMin", Math.Round(xMin, 2).ToString()); dict.Add("yMin", Math.Round(yMin, 2).ToString()); //Return the dictionary - blank if the the exception handling was invoked. Debug.WriteLine("completed export map extents."); return(dict); }
public override void Update(IPageLayout ipageLayout_0) { if (this.Element != null) { (ipageLayout_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, this.Element, null); IPoint position = this.GetPosition(ipageLayout_0); try { if (this.Element is CustomLegend) { (this.Element as CustomLegend).LegendInfo = this.LegendInfo; (this.Element as CustomLegend).Init(ipageLayout_0 as IActiveView, position); } else { CustomLegend legend2 = new CustomLegend { LegendInfo = this.LegendInfo }; legend2.Init(ipageLayout_0 as IActiveView, position); this.Element = legend2; } (ipageLayout_0 as IActiveView).GraphicsContainer.UpdateElement(base.m_pElement); (ipageLayout_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, base.m_pElement, null); this.Save(); } catch (Exception) { } } }
/// <summary> /// Occurs when this tool is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { try { m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; if (m_hookHelper.ActiveView == null) { m_hookHelper = null; } } catch { m_hookHelper = null; } if (m_hookHelper == null) { base.m_enabled = false; } else { base.m_enabled = true; } pPageLayoutControl = m_hookHelper.Hook as IPageLayoutControl3; IPageLayout pPageLayout = pPageLayoutControl.PageLayout; // TODO: Add other initialization code }
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(); }
public override void Update(IPageLayout ipageLayout_0) { if (base.m_pElement != null) { (ipageLayout_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, base.m_pElement, null); IPoint position = this.GetPosition(ipageLayout_0); try { IEnvelope bounds = new EnvelopeClass(); base.m_pElement.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, bounds); if (!bounds.IsEmpty) { IEnvelope envelope2 = new EnvelopeClass(); envelope2.PutCoords(position.X, position.Y, position.X + bounds.Width, position.Y + bounds.Height); base.m_pElement.Geometry = envelope2; } } catch { } (ipageLayout_0 as IActiveView).GraphicsContainer.UpdateElement(base.m_pElement); (ipageLayout_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, base.m_pElement, null); this.Save(); } }
public InvoiceWriter( IPrinter printer, IPageLayout layout) { _printer = printer; _layout = layout; }
public bool SyncPageLayoutFocusMapToMap(IPageLayout pPageLayout, ref IMap pMap, bool bClearElements) { try { if (pPageLayout == null) { return(false); } if (pMap == null) { return(false); } IActiveView view = pPageLayout as IActiveView; if (view == null) { return(false); } IMap focusMap = view.FocusMap; if (focusMap == null) { return(false); } this.SyncMapObject(focusMap, ref pMap, bClearElements); this.SyncMapExtent(focusMap, pMap, false); return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "SyncPageLayoutFocusMapToMap", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public void ReplacePageLayout(IPageLayout newMap) { if (newMap == null) { throw new Exception("ControlsSynchronizer::ReplaceMap:\r\nNew map for replacement is not initialized!"); } if ((this.axPageLayoutControl == null) || (this.axMapControl == null)) { throw new Exception( "ControlsSynchronizer::ReplaceMap:\r\nEither MapControl or PageLayoutControl are not initialized!"); } bool isMapCtrlactive = this.m_IsMapCtrlactive; this.ActivatePageLayout(); this.axPageLayoutControl.PageLayout = newMap; this.axMapControl.Map = (newMap as IActiveView).FocusMap; this.m_pageLayoutActiveTool = null; this.m_mapActiveTool = null; if (isMapCtrlactive) { this.ActivateMap(); this.axMapControl.ActiveView.Refresh(); } else { this.ActivatePageLayout(); this.axPageLayoutControl.ActiveView.Refresh(); } }
void addNorthArrow(IPageLayout pPageLayout, IEnvelope pEnv, IActiveView pActiveView) { IMap pMap = pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; if (pStyleGalleryItem == null) { return; } IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass(); pMapSurroundFrame.MapFrame = pMapFrame; INorthArrow pNorthArrow = new MarkerNorthArrowClass(); pNorthArrow = pStyleGalleryItem.Item as INorthArrow; pNorthArrow.Size = pEnv.Width * 50; pMapSurroundFrame.MapSurround = (IMapSurround)pNorthArrow; //根据用户的选取,获取相应的MapSurround IElement pElement = axPageLayoutControl1.FindElementByName("NorthArrows"); //获取PageLayout中的指北针元素 if (pElement != null) { pGraphicsContainer.DeleteElement(pElement); //如果存在指北针,删除已经存在的指北针 } IElementProperties pElePro = null; pElement = (IElement)pMapSurroundFrame; pElement.Geometry = (IGeometry)pEnv; pElePro = pElement as IElementProperties; pElePro.Name = "NorthArrows"; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public virtual IElement GetElement(IPageLayout pPageLayout) { if (this.m_pElement == null) { this.CreateElement(pPageLayout); } if (this.m_pElement == null) { return(null); } IPoint position = this.GetPosition(pPageLayout); IEnvelope bounds = new EnvelopeClass(); if (!(this.m_pElement is ILineElement)) { this.m_pElement.QueryBounds((pPageLayout as IActiveView).ScreenDisplay, bounds); if (!bounds.IsEmpty) { IEnvelope envelope2 = new EnvelopeClass(); envelope2.PutCoords(position.X, position.Y, position.X + bounds.Width, position.Y + bounds.Height); try { this.m_pElement.Geometry = envelope2; } catch { } } } return(this.m_pElement); }
public override void Update(IPageLayout ipageLayout_0) { if (this.Element != null) { (ipageLayout_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, this.Element, null); IPoint position = this.GetPosition(ipageLayout_0); (this.Element as TableElement).RowNumber = this.RowNumber; (this.Element as TableElement).ColumnNumber = this.ColumnNumber; IEnvelope to = this.Element.Geometry.Envelope; (this.Element as TableElement).CreateTable(ipageLayout_0 as IActiveView, position, this.sortedList_0); IEnvelope envelope = this.Element.Geometry.Envelope; this.Element.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelope); try { IAffineTransformation2D transformation = new AffineTransformation2DClass(); transformation.DefineFromEnvelopes(envelope, to); (base.m_pElement as ITransform2D).Transform(esriTransformDirection.esriTransformForward, transformation); } catch { } (ipageLayout_0 as IActiveView).GraphicsContainer.UpdateElement(base.m_pElement); (ipageLayout_0 as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, base.m_pElement, null); this.Save(); } }
public static IMapFrame FindFocusMapFrame(IPageLayout ipageLayout_0) { IActiveView view = ipageLayout_0 as IActiveView; IMap focusMap = view.FocusMap; IGraphicsContainer container = ipageLayout_0 as IGraphicsContainer; container.Reset(); for (IElement element = container.Next(); element != null; element = container.Next()) { if (element is IMapFrame) { if (focusMap == (element as IMapFrame).Map) { return(element as IMapFrame); } } else if (element is IGroupElement) { IMapFrame frame2 = FindFocusMapFrame(element as IGroupElement, focusMap); if (frame2 != null) { return(frame2); } } } 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); } }
public override IElement GetElement(IPageLayout ipageLayout_0) { this.CreateElement(ipageLayout_0); if (base.m_pElement == null) { return(null); } IPoint position = this.GetPosition(ipageLayout_0); IEnvelope bounds = new EnvelopeClass(); base.m_pElement.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, bounds); if ((base.m_pElement as IMapSurroundFrame).MapSurround is INorthArrow) { INorthArrow mapSurround = (base.m_pElement as IMapSurroundFrame).MapSurround as INorthArrow; if (mapSurround.Map != (ipageLayout_0 as IActiveView).FocusMap) { mapSurround.Map = (ipageLayout_0 as IActiveView).FocusMap; mapSurround.Refresh(); } } if (!bounds.IsEmpty) { IEnvelope envelope2 = new EnvelopeClass(); envelope2.PutCoords(position.X, position.Y, position.X + bounds.Width, position.Y + bounds.Height); base.m_pElement.Geometry = envelope2; } return(base.m_pElement); }
public void AddMapLegend(IPageLayout pageLayout, IMap map, System.Double posX, System.Double posY, System.Double legW) { try { if (pageLayout == null || map == null) { return; } IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; // Dynamic Cast IMapFrame mapFrame = graphicsContainer.FindFrame(map) as IMapFrame; // Dynamic Cast ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "esriCarto.Legend"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast //Get aspect ratio IQuerySize querySize = mapSurroundFrame.MapSurround as IQuerySize; // Dynamic Cast System.Double w = 0; System.Double h = 0; querySize.QuerySize(ref w, ref h); System.Double aspectRatio = w / h; IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio)); IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; graphicsContainer.AddElement(element, 0); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
public bool SyncPageLayoutMainMapToMap(IPageLayout pPageLayout, ref IMap pMap, bool bClearElements) { try { if (pPageLayout == null) { return(false); } if (pMap == null) { return(false); } IMapFrame mapFrameMain = null; mapFrameMain = GISFunFactory.ElementFun.GetMapFrameMain(pPageLayout, ""); if (mapFrameMain == null) { return(false); } IMap pSourceMap = mapFrameMain.Map; if (pSourceMap == null) { return(false); } this.SyncMapObject(pSourceMap, ref pMap, bClearElements); this.SyncMapExtent(pSourceMap, pMap, false); return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "SyncPageLayoutMainMapToMap", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public bool GetTK(IPageLayout ipageLayout_0) { IEnvelope envelope; IEnvelope envelope2; if (this.string_2.Length == 0) { return(false); } IMapFrame frame = (ipageLayout_0 as IActiveView).GraphicsContainer.FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame; if ((this.double_1 != 0.0) || (this.double_2 != 0.0)) { ipageLayout_0.Page.PutCustomSize(this.double_1 + 6.0, this.double_2 + 6.0); envelope = (frame as IElement).Geometry.Envelope; envelope2 = new EnvelopeClass(); if (this.double_1 == 0.0) { this.double_1 = envelope.Width; } if (this.double_2 == 0.0) { this.double_2 = envelope.Height; } envelope2.PutCoords(envelope.XMin, envelope.YMin, envelope.XMin + this.double_1, envelope.YMin + this.double_2); IAffineTransformation2D transformation = new AffineTransformation2DClass(); transformation.DefineFromEnvelopes(envelope, envelope2); ITransform2D transformd = frame as ITransform2D; transformd.Transform(esriTransformDirection.esriTransformForward, transformation); double dx = 0.0; double dy = 0.0; if (envelope.XMin < 2.0) { dx = 2.0; } if (envelope.YMin < 2.0) { dy = 2.0; } if ((dx != 0.0) && (dy != 0.0)) { transformd.Move(dx, dy); } } if (this.double_0 > 0.0) { envelope = (frame as IElement).Geometry.Envelope; double num3 = (envelope.Width * this.double_0) / 100.0; double num4 = (envelope.Height * this.double_0) / 100.0; IEnvelope extent = (frame.Map as IActiveView).Extent; envelope2 = new EnvelopeClass(); envelope2.PutCoords(extent.XMin, extent.YMin, extent.XMin + num3, extent.YMin + num4); (frame.Map as IActiveView).Extent = envelope2; } frame.Border = null; return(true); }
public PdfEngine(IPageLayout layout, string ourCallsign, int firstPageOffset) { m_OurCallsign = ourCallsign; m_Layout = layout; m_MainTable = new PdfPTable(m_Layout.Columns); m_MainTable.TotalWidth = mm2p(196); int[] widths = new int[m_Layout.Columns]; for (int i = 0; i < m_Layout.Columns; i++) widths[i] = 1; m_MainTable.SetWidths(widths); // Offset the first page by an appropriate number of cells for (int i = 0; i < firstPageOffset; i++) m_MainTable.AddCell(PopulateCell(new LabelEntry())); m_LabelsUsed += firstPageOffset; }
public void createInitialLayout(IPageLayout layout) { // Folders var editorArea = layout.getEditorArea(); var explorerFolder = layout.createFolder("explorer", IPageLayout.LEFT, 0.25f, editorArea); explorerFolder.addView(IPageLayout.ID_PROJECT_EXPLORER); var problemsFolder = layout.createFolder("problems", IPageLayout.BOTTOM, 0.75f, editorArea); problemsFolder.addView(IPageLayout.ID_PROBLEM_VIEW); problemsFolder.addView(IPageLayout.ID_TASK_LIST); problemsFolder.addView(IConsoleConstants.ID_CONSOLE_VIEW); // Shortcuts layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder"); layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file"); layout.addShowViewShortcut("org.eclipse.ui.views.ResourceNavigator"); layout.addShowViewShortcut(IPageLayout.ID_PROJECT_EXPLORER); // Action sets layout.addActionSet(IDebugUIConstants.LAUNCH_ACTION_SET); }
private IMap FindMap(IPageLayout pPageLayout) { IMap pMapReturn = null; try { IGraphicsContainerSelect pGCS = (IGraphicsContainerSelect)pPageLayout; pGCS.SelectAllElements(); IEnumElement pEnumEl = pGCS.SelectedElements; IElement pElement = pEnumEl.Next(); while(pElement != null) { IMapFrame pMapFrame = pElement as IMapFrame; if(pMapFrame != null) { pMapReturn = pMapFrame.Map; break; } pElement = pEnumEl.Next(); } pGCS.UnselectAllElements(); } catch(Exception ex) { Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); util.Logger.Write(" Descrip : Finding the map frame in the template pagelayout. " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug); } return pMapReturn; }
private int PageLayoutMapCount(IPageLayout pPageLayout) { int retVal = 0; try { IGraphicsContainerSelect pGCS = (IGraphicsContainerSelect)pPageLayout; pGCS.SelectAllElements(); IEnumElement pEnumEl = pGCS.SelectedElements; IElement pElement = pEnumEl.Next(); while(pElement != null) { IMapFrame pMapFrame = pElement as IMapFrame; if(pMapFrame != null) { retVal++; } pElement = pEnumEl.Next(); } pGCS.UnselectAllElements(); } catch(Exception ex) { Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); util.Logger.Write(" Descrip : Getting the map count in the template pagelayout. " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug); } return retVal; }
private void ReplaceText(Hashtable searchAndReplaceHT,IPageLayout pPageLayout) { //IMxDocument pMxDoc = null; try { // TODO: //pMxDoc = (IMxDocument)m_app.Document; IGraphicsContainerSelect pGCS = (IGraphicsContainerSelect)pPageLayout; IGraphicsContainer pGC = (IGraphicsContainer)pPageLayout; pGCS.SelectAllElements(); IEnumElement pEnumEl = pGCS.SelectedElements; IElement pElement = pEnumEl.Next(); while (pElement != null) { ITextElement pTextElement = pElement as ITextElement; if (pTextElement != null) { string strText = pTextElement.Text; IDictionaryEnumerator pDicEnum = searchAndReplaceHT.GetEnumerator(); while (pDicEnum.MoveNext()) { string searchText = pDicEnum.Key.ToString(); string replaceText = pDicEnum.Value.ToString(); strText = strText.Replace(searchText, replaceText); } pTextElement.Text = strText; pGC.UpdateElement((IElement)pTextElement); } pElement = pEnumEl.Next(); } pGCS.UnselectAllElements(); } catch (Exception ex) { Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); util.Logger.Write(" Descrip : Performing Search and Replace on map text. " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace, util.Logger.LogLevel.Debug); } finally { //util.Utils.Release(pMxDoc); } }
/// <summary>Gets the extent of the page.</summary> private static IEnvelope GetPageExtent(IPageLayout pageLayout) { double width, height; pageLayout.Page.QuerySize(out width, out height); IEnvelope env = new EnvelopeClass(); env.PutCoords(0, 0, width, height); return env; }
public IElement cambiaEscudo(int clvMunicipio, IPageLayout pPageLayout) { IPictureElement pPicElement = new BmpPictureElementClass(); string escudo = null; try{ escudo = funcAux.buscaEscudo(clvMunicipio); pPicElement.ImportPictureFromFile(escudo); pPicElement.MaintainAspectRatio = true; //Set the New Element to the Picture Element IElement pElement = (IElement)pPicElement; //Create Target Envelope IEnvelope pEnv = new EnvelopeClass(); pEnv.PutCoords(35.6, 24.75, 36.44, 25.78); pElement.Geometry = pEnv; //set the container as the pagelayout and add the element created IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pPageLayout; pGraphicsContainer.AddElement(pElement, 0); IActiveView pActiveView = (IActiveView)pPageLayout; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, pEnv); return pElement; } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.Message); MessageBox.Show("Error: " + ex.StackTrace, "clsMapTools.cambiaEscudo"); return null; } }
/// <summary>Exports the page layout to a file.</summary> /// <param name="pageLayout">The page layout.</param> /// <param name="exportPath">The name of the output file.</param> /// <param name="exportFormat">The format of the output.</param> /// <param name="dpi">The resolution of the output files.</param> void ExportPageLayoutToFile(IPageLayout pageLayout, string exportPath, long dpi, ExportFormat exportFormat) { IExport export = null; // Get the color of the backgrounds for formats that support transparent backgrounds. IColor bgColor = null; switch (exportFormat) { case ExportFormat.GIF: case ExportFormat.PNG: IPage page = pageLayout.Page; bgColor = page.BackgroundColor; break; } // Set "export" to the proper type of Export*Class, and set parameters specific to that image type. switch (exportFormat) { case ExportFormat.AI: export = new ExportAIClass(); var ai = export as IExportAI2; //ai.EmbedFonts = true; break; case ExportFormat.EMF: export = new ExportEMFClass(); var xEmf = export as IExportEMF; //xEmf.Description = break; case ExportFormat.PS: export = new ExportPSClass(); var xPs = export as IExportPS; xPs.EmbedFonts = true; //xPs.Emulsion = //xPs.Image = //xPs.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone //xPs.LanguageLevel = esriExportPSLanguageLevel.esriExportPSLevel3 break; case ExportFormat.SVG: export = new ExportSVGClass(); var xSvg = export as IExportSVG; //xSvg.Compressed = true; //xSvg.EmbedFonts = true; break; case ExportFormat.PDF: export = new ExportPDFClass(); var xPdf = export as IExportPDF; //xPdf.Compressed = true; //xPdf.EmbedFonts = true; //xPdf.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone break; case ExportFormat.GIF: export = new ExportGIFClass(); IExportGIF xGif = export as IExportGIF; xGif.TransparentColor = bgColor; //xGif.BiLevelThreshold = //xGif.CompressionType = esriGIFCompression.esriGIFCompressionNone; //xGif.InterlaceMode = false; break; case ExportFormat.PNG: export = new ExportPNGClass(); IExportPNG xPng = export as IExportPNG; //xPng.BiLevelThreshold = //xPng.InterlaceMode = false; xPng.TransparentColor = bgColor; break; case ExportFormat.BMP: export = new ExportBMPClass(); IExportBMP xBmp = export as IExportBMP; //xBmp.BiLevelThreshold = //xBmp.RLECompression = true; break; case ExportFormat.JPEG: export = new ExportJPEGClass(); IExportJPEG xJpg = export as IExportJPEG; //xJpg.ProgressiveMode = false; //xJpg.Quality = 80; //The JPEG compression / image quality. Range (0..100). Default is 100 (no compression / best quality). break; case ExportFormat.TIFF: export = new ExportTIFFClass(); IExportTIFF xTif = export as IExportTIFF; //xTif.BiLevelThreshold = //xTif.CompressionType = //xTif.GeoTiff = true; //The JPEG or Deflate (depending on the Compression type) compression / image quality. Range (0..100). Default is 100 (no compression / best quality). //xTif.JPEGOrDeflateQuality = 100; break; default: const string MSG_FMT = "Support for \"{0}\" export is not yet implemented."; string message = string.Format(MSG_FMT, Enum.GetName(typeof(ExportFormat), exportFormat)); throw new NotImplementedException(message); } IEnvelope pixelEnv = new EnvelopeClass(); IEnvelope pageExt = GetPageExtent(pageLayout); IPoint upperRight = pageExt.UpperRight; pixelEnv.PutCoords(0, 0, dpi * upperRight.X, dpi * upperRight.Y); export.PixelBounds = pixelEnv; export.Resolution = dpi; export.ExportFileName = exportPath; // //(device coordinates origin is upper left, ypositive is down) tagRECT expRect; expRect.left = (int)export.PixelBounds.LowerLeft.X; expRect.bottom = (int)export.PixelBounds.UpperRight.Y; expRect.right = (int)export.PixelBounds.UpperRight.X; expRect.top = (int)export.PixelBounds.LowerLeft.Y; _app.StatusBar.set_Message(0, string.Format("exporting \"{0}\"", exportPath)); long hdc = export.StartExporting(); IActiveView av = (IActiveView)pageLayout; av.Output((int)hdc, (int)dpi, ref expRect, null, null); export.FinishExporting(); export.Cleanup(); }
private void CopyPasteLayoutElements(IPageLayout pPLdest, IPageLayout pPLtemplate) { try { pPLdest.Page.Units = pPLtemplate.Page.Units; pPLdest.Page.Orientation = pPLtemplate.Page.Orientation; pPLdest.Page.PageToPrinterMapping = pPLtemplate.Page.PageToPrinterMapping; pPLdest.Page.IsPrintableAreaVisible = pPLtemplate.Page.IsPrintableAreaVisible; pPLdest.Page.StretchGraphicsWithPage = pPLtemplate.Page.StretchGraphicsWithPage; IGraphicsContainerSelect pGCSdest = (IGraphicsContainerSelect)pPLdest; IGraphicsContainer pGCdest = (IGraphicsContainer)pPLdest; IGraphicsContainerSelect pGCStemplate = (IGraphicsContainerSelect)pPLtemplate; IGraphicsContainer pGCtemplate = (IGraphicsContainer)pPLtemplate; pGCStemplate.SelectAllElements(); IElementCollection pElementCollection = new ElementCollectionClass(); // get a collection of all elements in the template IEnumElement pEnumElementTemplate = pGCStemplate.SelectedElements; IElement pElementTemplate = pEnumElementTemplate.Next(); while (pElementTemplate != null) { pElementCollection.Add(pElementTemplate,-1); pElementTemplate = pEnumElementTemplate.Next(); } // delete all elements except map frame pGCSdest.SelectAllElements(); IEnumElement pEnumElementDest = pGCSdest.SelectedElements; IElement pElementDest = pEnumElementDest.Next(); System.Collections.Generic.List<IElement> pMapFramesToDelete = new System.Collections.Generic.List<IElement>(); while (pElementDest != null) { IMapFrame pMapFrame = pElementDest as IMapFrame; if (pMapFrame == null) { pGCdest.DeleteElement(pElementDest); } else { // add any map frames in the current document to a List collection pMapFramesToDelete.Add(pElementDest); } pElementDest = pEnumElementDest.Next(); } // add the elements to the destination (current) pagelayout for (int x = pElementCollection.Count - 1; x >= 0; x-- ) { IElement pElemSelected; int linkID; pElementCollection.QueryItem(x,out pElemSelected,out linkID); pGCdest.AddElement(pElemSelected, x); } pGCSdest.UnselectAllElements(); // remove the original maps from the current document foreach (IElement pElem in pMapFramesToDelete) { pGCdest.DeleteElement(pElem); } } catch (Exception ex) { Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); util.Logger.Write(" Descrip : copying and pasting elements " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace, util.Logger.LogLevel.Debug); } }
private void m_Layouts_SelectedIndexChanged(object sender, EventArgs e) { m_PageLayout = (IPageLayout)m_Layouts.SelectedItem; }