private void InsertLegendInfoToTree(ILegendInfo pLegendInfo, TOCTreeNode pParantNode) { int legendGroupCount = pLegendInfo.LegendGroupCount; TOCTreeNode pNode = pParantNode; TOCTreeNode node2 = null; for (int i = 0; i < legendGroupCount; i++) { ILegendGroup group = pLegendInfo.get_LegendGroup(i); if (legendGroupCount > 1) { pNode = new TOCTreeNodeEx(group.Heading) { Tag = group }; pParantNode.Nodes.Add(pNode); } int classCount = group.ClassCount; for (int j = 0; j < classCount; j++) { ILegendClass class2 = group.get_Class(j); node2 = new TOCTreeNodeEx(class2.Label, false, true) { Tag = class2 }; pNode.Nodes.Add(node2); } } }
ESRI.ArcGIS.Carto.ILegendGroup ILegendInfo.get_LegendGroup(int Index) { string strHeading = null; ILegendInfo pLegendInfo = null; switch (Index) { case 0: pLegendInfo = m_pMainRend as ILegendInfo; if (m_pMainRend == m_pShapePatternRend) strHeading = "Shape/Pattern: "; else if (m_pMainRend == m_pSizeRend) strHeading = "Size: "; else strHeading = "Color 1: "; break; case 1: if (m_pShapePatternRend != null) { if (m_pSizeRend != null) { pLegendInfo = m_pSizeRend as ILegendInfo; strHeading = "Size: "; } else { pLegendInfo = m_pColorRend1 as ILegendInfo; strHeading = "Color 1: "; } } else { if (m_pSizeRend != null) { pLegendInfo = m_pColorRend1 as ILegendInfo; strHeading = "Color 1: "; } else { pLegendInfo = m_pColorRend2 as ILegendInfo; strHeading = "Color 2: "; } } break; case 2: pLegendInfo = m_pColorRend1 as ILegendInfo; strHeading = "Color 1: "; break; case 3: pLegendInfo = m_pColorRend2 as ILegendInfo; strHeading = "Color 2: "; break; } ILegendGroup pLegendGroup = null; pLegendGroup = pLegendInfo.get_LegendGroup(0); //pLegendGroup.Heading = strHeading & pLegendGroup.Heading return pLegendGroup; }
private void LoopHideLegend(ILayer layer) { ILegendGroup lgroup = null; if (layer is ICompositeLayer && (layer as ICompositeLayer).Count > 0) { ICompositeLayer cplayer = layer as ICompositeLayer; ILayer sublayer = null; for (int j = 0; j < cplayer.Count; j++) { sublayer = cplayer.get_Layer(j); LoopHideLegend(sublayer); } } else { ILegendInfo lInfo = layer as ILegendInfo; if (lInfo != null && lInfo.LegendGroupCount >= 0) { for (int g = 0; g < lInfo.LegendGroupCount; g++) { lgroup = lInfo.get_LegendGroup(g); lgroup.Visible = false; } } } }
/// <summary> /// This recursive method will Populate the treeview. /// </summary> /// <param name="layer">The current layer</param> /// <param name="parentNode">The parent TreeNode</param> private void PopulateTree(ILayer layer, TreeNode parentNode) { TreeNode node = new TreeNode(layer.Name); ILegendInfo legendInfo = layer as ILegendInfo; if (legendInfo != null) { ILegendGroup legendGroup; for (int i = 0; i < legendInfo.LegendGroupCount; ++i) { ILegendClass legendClass; legendGroup = legendInfo.get_LegendGroup(i); for (int j = 0; j < legendGroup.ClassCount; ++j) { IAgEsri3dSymbolHelper symbolHelper = this.m_Renderer.Context.CreateObject("STKesriDisplay10.AgEsri3dSymbolHelper") as IAgEsri3dSymbolHelper;//new AgEsri3dSymbolHelperClass(); symbolHelper.SetUseSymbolSize(true); legendClass = legendGroup.get_Class(j); TreeNode legendClassNode = new TreeNode(legendClass.Label); ISymbol symbol; symbol = legendClass.Symbol; if (symbolHelper != null) { int bmp; bmp = symbolHelper.ToBitmap(symbol); IntPtr bmpPtr = new IntPtr(bmp); legendClassNode.ImageIndex = this.ImageList.Images.Count; legendClassNode.SelectedImageIndex = legendClassNode.ImageIndex; Bitmap bitmap = Bitmap.FromHbitmap(bmpPtr); bitmap.MakeTransparent(Color.FromArgb(85, 85, 85)); bitmap.SetResolution(30, 30); this.ImageList.Images.Add(StandardizeBitmap((bitmap))); } node.Nodes.Add(legendClassNode); } } } node.ImageIndex = NOIMAGE; parentNode.Nodes.Add(node); node.Checked = (layer.Visible && layer.Valid); node.Tag = layer; ICompositeLayer subLayer = layer as ICompositeLayer; if (subLayer != null) { for (int i = 0; i < subLayer.Count; ++i) { PopulateTree(subLayer.get_Layer(i), node); } } }
private void CollapseGroup(ILayer layer) { try { ILegendInfo info = (ILegendInfo)layer; ILegendGroup group = (ILegendGroup)info.get_LegendGroup(0); group.Visible = false; } catch (Exception) { } }
/// <summary> /// 展开/收缩图层的图例(最后需要执行toc的Update方法) /// </summary> /// <param name="layer"></param> /// <param name="isExpand"></param> public void ExpandLegend(ILayer layer, bool isExpand) { ILegendInfo legendInfo = (ILegendInfo)layer; int iLegendGroupCount = legendInfo.LegendGroupCount; for (int i = 0; i < iLegendGroupCount; i++) { var legendGroup = legendInfo.get_LegendGroup(i); legendGroup.Visible = isExpand; } axMapControlMainMap.Update(); }
private void ExpandLayer(IFeatureLayer pFeatureLayer) { ILegendInfo pLegendInfo = null; ILegendGroup pLegendGroup = new LegendGroupClass(); pLegendInfo = pFeatureLayer as ILegendInfo; if (pLegendInfo == null) { return; } pLegendGroup = pLegendInfo.get_LegendGroup(0); pLegendGroup.Visible = true; }
private void FoldLyrsItem_Click(object sender, EventArgs e) { //折叠所有图层 for (int i = 0; i < this.axMapcontrol.LayerCount; i++) { ILegendInfo m_LengendInfo = this.axMapcontrol.get_Layer(i) as ILegendInfo; for (int j = 0; j < m_LengendInfo.LegendGroupCount; j++) { ILegendGroup pLenGroup = m_LengendInfo.get_LegendGroup(j) as ILegendGroup; pLenGroup.Visible = false; } } this.axTOOControl.Update(); }
/// <summary> /// 展开/收缩图层的图例 /// </summary> /// <param name="isExpand"></param> public void ExpandLegend(bool isExpand) { IEnumLayer layers = MapControl.Map.Layers[LayerUid.IFeatureLayer.CreateUid(), true]; layers.Reset(); ILayer layer; while ((layer = layers.Next()) != null) { ILegendInfo legendInfo = (ILegendInfo)layer; for (int i = 0; i < legendInfo.LegendGroupCount; i++) { legendInfo.LegendGroup[i].Visible = true; } } TocControl.Update(); }
private void CollapseLayer(IFeatureLayer pFeatureLayer) { ILegendInfo pLegendInfo = null; ILegendGroup pLegendGroup = new LegendGroupClass(); if (pFeatureLayer.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { #region 如果图层是注记层 //IAnnotationLayer pAnnoLayer = pFeatureLayer as IAnnotationLayer; //IGeoFeatureLayer pGeoFeaLayer = pFeatureLayer as IGeoFeatureLayer; //IFeatureRenderer pRender = pGeoFeaLayer.Renderer; //ISymbol pSym = (pRender as IUniqueValueRenderer).DefaultSymbol; //ISimpleTextSymbol pTextSym = pSym as ISimpleTextSymbol; //ICompositeLayer pComLayer = pAnnoLayer as ICompositeLayer; //IGroupLayer pgLayer = new GroupLayerClass(); //pgLayer.Name = pFeatureLayer.Name; //for (int j = 0; j < pComLayer.Count; j++) //{ // ILayer ppLayer = pComLayer.get_Layer(j); // pgLayer.Add(ppLayer); //} //myHook.MapControl.Map.DeleteLayer(pFeatureLayer as ILayer); //myHook.MapControl.Map.AddLayer(pgLayer); //myHook.MapControl.ActiveView.Refresh(); //pgLayer.Expanded = false; //myHook.TOCControl.Update(); #endregion } else { //如果图层时普通的图层 pLegendInfo = pFeatureLayer as ILegendInfo; if (pLegendInfo == null) { return; } for (int i = 0; i < pLegendInfo.LegendGroupCount; i++) //changed by xisheng 2011.06.16 { //采用唯一值符号多个的一起折叠 pLegendGroup = pLegendInfo.get_LegendGroup(i); pLegendGroup.Visible = false; } } }
private void CollapseLayer(IFeatureLayer pFeatureLayer) { ILegendInfo pLegendInfo = null; ILegendGroup pLegendGroup = new LegendGroupClass(); if (pFeatureLayer.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { #region Èç¹ûͼ²ãÊÇ×¢¼Ç²ã //IAnnotationLayer pAnnoLayer = pFeatureLayer as IAnnotationLayer; //IGeoFeatureLayer pGeoFeaLayer = pFeatureLayer as IGeoFeatureLayer; //IFeatureRenderer pRender = pGeoFeaLayer.Renderer; //ISymbol pSym = (pRender as IUniqueValueRenderer).DefaultSymbol; //ISimpleTextSymbol pTextSym = pSym as ISimpleTextSymbol; //ICompositeLayer pComLayer = pAnnoLayer as ICompositeLayer; //IGroupLayer pgLayer = new GroupLayerClass(); //pgLayer.Name = pFeatureLayer.Name; //for (int j = 0; j < pComLayer.Count; j++) //{ // ILayer ppLayer = pComLayer.get_Layer(j); // pgLayer.Add(ppLayer); //} //myHook.MapControl.Map.DeleteLayer(pFeatureLayer as ILayer); //myHook.MapControl.Map.AddLayer(pgLayer); //myHook.MapControl.ActiveView.Refresh(); //pgLayer.Expanded = false; //myHook.TOCControl.Update(); #endregion } else { //Èç¹ûͼ²ãʱÆÕͨµÄͼ²ã pLegendInfo = pFeatureLayer as ILegendInfo; if (pLegendInfo == null) { return; } pLegendGroup = pLegendInfo.get_LegendGroup(0); pLegendGroup.Visible = false; } }
private void ExpandedLayers(ILayer layer, bool expended) { if (layer is IGroupLayer) { ICompositeLayer pCompositeLayer = (ICompositeLayer)layer; for (int i = 0; i < pCompositeLayer.Count; i++) { ILayer pLayer = pCompositeLayer.Layer[i]; ExpandedLayers(pLayer, expended); } ((IGroupLayer)layer).Expanded = expended; } else if (layer is ILegendInfo) { ILegendInfo pLegendInfo = layer as ILegendInfo; for (int j = 0; j < pLegendInfo.LegendGroupCount; j++) { ILegendGroup pLegendGroup = pLegendInfo.LegendGroup[j]; pLegendGroup.Visible = expended; } } }
private void simpleButtonExpand_Click(object sender, EventArgs e)//TOCC图层文件展开 { UID uid = new UIDClass(); uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; IEnumLayer layers = axMapControlMainMap.Map.get_Layers(uid, true); layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { ILegendInfo pLegendInfo = layer as ILegendInfo; int iLegendGroupCount = pLegendInfo.LegendGroupCount; for (int i = 0; i < iLegendGroupCount; i++) { var lGroup = pLegendInfo.get_LegendGroup(i); lGroup.Visible = true; } } axTOCControlLayerTree.Update(); }
private bool RendererIsValidForType(IFeatureRenderer pFeatRend, eRendererType eMultiRendType) { // indicates whether or not pFeatRend is valid for the eMultiRendType for the current layer // e.g. if pFeatRend is an IProportionalSymbolRenderer, then it's valid for eMultiRendType = eSize ILegendInfo pLegendInfo = null; if (eMultiRendType == eRendererType.eShapePattern) return pFeatRend is IUniqueValueRenderer; else if (eMultiRendType == eRendererType.eColor) { pLegendInfo = pFeatRend as ILegendInfo; return (pFeatRend is IUniqueValueRenderer) | (pFeatRend is IClassBreaksRenderer & ! pLegendInfo.SymbolsAreGraduated); } else // size { pLegendInfo = pFeatRend as ILegendInfo; return (pFeatRend is IClassBreaksRenderer & pLegendInfo.SymbolsAreGraduated) | (pFeatRend is IProportionalSymbolRenderer); } }
public static void UpdateMapUnitPolysRenderer(IWorkspace theWorkspace) { // Get the MapUnitPolys Layer from the ToC IFeatureLayer theLayer = commonFunctions.FindFeatureLayer(theWorkspace, "MapUnitPolys"); // If the layer was not found, don't try and update the renderer! if (theLayer == null) { return; } // Setup the renderer IUniqueValueRenderer theRenderer = new UniqueValueRendererClass(); theRenderer.FieldCount = 1; theRenderer.Field[0] = "MapUnit"; // Setup a couple variables IColor nullColor = new RgbColorClass(); nullColor.NullColor = true; // Setup a blank line ILineSymbol nullLine = new SimpleLineSymbolClass(); nullLine.Color = nullColor; // Setup the "All Other Values" symbol ISimpleFillSymbol defaultSymbol = new SimpleFillSymbolClass(); IColor defaultColor = new RgbColorClass(); defaultColor.RGB = 255; defaultSymbol.Color = defaultColor; defaultSymbol.Outline = nullLine; // Apply the "All other values" symbol to the renderer theRenderer.DefaultSymbol = defaultSymbol as ISymbol; theRenderer.UseDefaultSymbol = true; string theHeading = "Geologic Map Units"; // Get the Legend Items var sortedDmu = GetDmuSortedByHierarchy(theWorkspace); // Loop through the legend items foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> legendEntry in sortedDmu) { DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDmuEntry = legendEntry.Value; // If this is a heading, make it so if (thisDmuEntry.ParagraphStyle.Contains("Heading") == true) { theHeading = thisDmuEntry.Name; continue; } // Make a Simple Fill RuleID ISimpleFillSymbol theSymbol = new SimpleFillSymbolClass(); //theRuleID.Style = esriSimpleFillStyle.esriSFSSolid; // Get the right color IColor symbolColor = new RgbColorClass(); string rgbString = thisDmuEntry.AreaFillRGB; string[] rgbValues = rgbString.Split(';'); // Long integer representations of RGB values are dumb: G*65536 + B*256 + R if (rgbValues.Length < 3) { symbolColor.RGB = 16777215; } else { symbolColor.RGB = int.Parse(rgbValues[0]) + int.Parse(rgbValues[1]) * 256 + int.Parse(rgbValues[2]) * 65536; } theSymbol.Color = symbolColor; theSymbol.Outline = nullLine; // Add it to the renderer theRenderer.AddValue(thisDmuEntry.MapUnit, theHeading, theSymbol as ISymbol); // Give it the right label theRenderer.Label[thisDmuEntry.MapUnit] = thisDmuEntry.MapUnit + " - " + thisDmuEntry.Name; } // Apply the renderer IGeoFeatureLayer geoFLayer = (IGeoFeatureLayer)theLayer; geoFLayer.Renderer = (IFeatureRenderer)theRenderer; // Minimizing the legend info in the Table of Contents is not trivial ILegendInfo layerLegendInfo = (ILegendInfo)theLayer; for (int i = 0; i < layerLegendInfo.LegendGroupCount; i++) { ILegendGroup layerLegendGroup = layerLegendInfo.get_LegendGroup(i); layerLegendGroup.Visible = false; } // Update the views ArcMap.Document.UpdateContents(); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, theLayer, null); }
private void buttonOK_Click(object sender, EventArgs e) { //高程底面 ILayer pBaseLayer = null; ISurface pSurface = null; if (m_pSceneCtrl != null) { try { // m_pSceneCtrl.LoadSxFile(ClsGDBDataCommon.GetParentPathofExe() +@"Resource\DefaultData\Default.sxd"); } catch { } //IScene pScene = new SceneClass(); //pScene.Name = "Scene"; //m_pSceneCtrl.Scene = pScene; IScene pScene = m_pSceneCtrl.Scene; pScene.Name = "Scene"; //ILayer pglayer = new GraphicsLayer3DClass(); //pScene.AddLayer(pglayer); //pScene.ActiveGraphicsLayer = new CompositeGraphicsLayerClass(); pScene.ExaggerationFactor = Convert.ToDouble(doubleInputExaFactor.Value.ToString()); while (pScene.LayerCount > 0) { pScene.DeleteLayer(pScene.get_Layer(0)); } // pScene.ClearLayers(); pScene.AddLayer(pScene.ActiveGraphicsLayer); GC.Collect(); for (int i = 0; i < m_pMapCtrl.Map.LayerCount; i++) { ILayer pMapLayer = m_pMapCtrl.Map.get_Layer(i); ILayer pLayer = pMapLayer; if (comboBoxExBaseHeightLayer.Items.Count > 0) { if (pLayer.Name == comboBoxExBaseHeightLayer.SelectedItem.ToString()) { pBaseLayer = pLayer; } } } if (pBaseLayer is IRasterLayer) { IRaster pRaster = ((IRasterLayer)pBaseLayer).Raster; IRasterBand pBand = ((IRasterBandCollection)pRaster).Item(0); IRasterSurface rsurface = new RasterSurface(); rsurface.RasterBand = pBand; //将dem的数据指定为surface pSurface = rsurface as ISurface; } if (pBaseLayer is ITinLayer) { ITin pTin = ((ITinLayer)pBaseLayer).Dataset; ITinSurface pTinSurface = pTin as ITinSurface; pSurface = pTinSurface as ISurface; } for (int i = 0; i < m_pMapCtrl.Map.LayerCount; i++) { ILayer pMapLayer = m_pMapCtrl.Map.get_Layer(i); ILayer pLayer = pMapLayer; string filepath = ""; string filename = ""; string sourcepath = GetDataLayerPath(pMapLayer as IDataLayer, ref filepath, ref filename); //if (pMapLayer is IRasterLayer) //{ // IRasterLayer prl = new RasterLayerClass(); // prl.CreateFromRaster(((IRasterLayer)pMapLayer).Raster); // pLayer = prl as ILayer; //} if (pMapLayer is IFeatureLayer) { // if (((IFeatureLayer)pMapLayer).FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch) // { IFeatureLayer pfl = new FeatureLayerClass(); IFeatureClass pFc = ((IFeatureLayer)pMapLayer).FeatureClass; if (pFc != null) { pfl.FeatureClass = ((IFeatureLayer)pMapLayer).FeatureClass; pLayer = pfl as ILayer; pLayer.Name = pMapLayer.Name; ///////////////////////////////////////////////////////////////////// //后期添加,用于带进涂层渲染 ///////////////////////////////////////////////////////////////////// IGeoFeatureLayer pGeoFLayer = pfl as IGeoFeatureLayer; IGeoFeatureLayer pGFMapLayer = pMapLayer as IGeoFeatureLayer; if (pGFMapLayer != null) //注记图层为空 { pGeoFLayer.Renderer = pGFMapLayer.Renderer; ILegendInfo pLegend3D = (ILegendInfo)pGeoFLayer; for (int k = 0; k < pLegend3D.LegendGroupCount; k++) { ILegendGroup pLgroup = pLegend3D.LegendGroup[k]; for (int p = 0; p < pLgroup.ClassCount; p++) { ILegendClass pLClass = pLgroup.Class[p]; if (pLClass.Symbol is IMarkerSymbol) { IMarkerSymbol pSMSymbol = pLClass.Symbol as IMarkerSymbol; pSMSymbol.Size /= 20; } } } if (pFc.ShapeType == esriGeometryType.esriGeometryMultipoint || pFc.ShapeType == esriGeometryType.esriGeometryPoint) { if (pGFMapLayer.Renderer is IUniqueValueRenderer) { } } } } // } } #region 这段代码家的有点重复,如果不加有时候会弹出设置数据源的对话框 if (pLayer is IRasterLayer) { I3DProperties properties = null; properties = new Raster3DPropertiesClass(); ILayerExtensions layerextensions = pLayer as ILayerExtensions; object p3d; for (int j = 0; j < layerextensions.ExtensionCount; j++) { p3d = layerextensions.get_Extension(j); if (p3d != null) { properties = p3d as I3DProperties; if (properties != null) { break; } } } properties.BaseOption = esriBaseOption.esriBaseSurface; properties.BaseSurface = pSurface; //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新) //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法 properties.MaxTextureMemory = 268435456; } #endregion pScene.AddLayer(pLayer); //if (((CheckBoxItem)itemPanelSetVisible.Items[i]).Checked == false) //{ // pLayer.Visible = false; //} //else //{ // pLayer.Visible = true; //} if (comboBoxExBaseHeightLayer.Items.Count > 0) { if (pLayer.Name == comboBoxExBaseHeightLayer.SelectedItem.ToString()) { pBaseLayer = pLayer; } } } } if (pSurface != null) { for (int i = 0; i < m_pSceneCtrl.Scene.LayerCount; i++) { ILayer pLayer = m_pSceneCtrl.Scene.get_Layer(i); ILayerExtensions layerextensions = m_pSceneCtrl.Scene.get_Layer(i) as ILayerExtensions; I3DProperties properties = null; if (pLayer is IRasterLayer) { properties = new Raster3DPropertiesClass(); } if (pLayer is IFeatureLayer) { properties = new Feature3DPropertiesClass(); } if (pLayer is ITinLayer) { properties = new Tin3DPropertiesClass(); } object p3d; for (int j = 0; j < layerextensions.ExtensionCount; j++) { p3d = layerextensions.get_Extension(j); if (p3d != null) { properties = p3d as I3DProperties; if (properties != null) { break; } } } if (!(pLayer is IFeatureLayer)) { properties.BaseOption = esriBaseOption.esriBaseSurface; properties.BaseSurface = pSurface; //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新) //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法 properties.MaxTextureMemory = 268435456; } else { IFeatureLayer pFlayer = pLayer as IFeatureLayer; //multipatch的本身有高度信息 if (pFlayer.FeatureClass != null && pFlayer.FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch) { bool needConstantHeight = false; /* * try * { * //把导航点转向角,视场角等信息都设置成不贴在表面而需要根据生产该信息的文件设置高度 * IFeatureClass fc = pFlayer.FeatureClass; * IFeatureCursor pFcursor = fc.Search(null, false); * int OriginalFeatureidx = fc.FindField("OriginalFeatureClass"); * int OriginalFeatureOIDidx = fc.FindField("OID"); * IFeature pF = pFcursor.NextFeature(); * IFeatureLayer pOFeatureLayer = null; * if (OriginalFeatureidx == -1|| OriginalFeatureOIDidx == -1) * { * pF = null; * } * else * { * if (pF != null) * { * //获取路径点图层名称 * string orignalname = pF.get_Value(OriginalFeatureidx).ToString(); * IMap pMap = m_pMapCtrl.Map; * for (int k = 0; k < pMap.LayerCount; k++) * { * if (pMap.get_Layer(k).Name.Equals(orignalname)) * { * pOFeatureLayer = pMap.get_Layer(k) as IFeatureLayer; * break; * } * } * if (pOFeatureLayer == null) * { * pF = null; * } * } * } * * while (pF != null) * { * //IFeatureClass pFClass = pOFeatureLayer.FeatureClass; * //pFClass.FindField(OriginalFeatureOIDidx); * * * pF = pFcursor.NextFeature(); * } * } * catch * { * ; * } */ if (needConstantHeight == false) { properties.BaseOption = esriBaseOption.esriBaseSurface; //I3DProperties2 pr = properties as I3DProperties2; //if (pr != null) //{ // pr.OffsetExpressionString = "0.005"; //} // properties.BaseOption = esriBaseOption.esriBaseExpression; properties.BaseSurface = pSurface; //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新) //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法 properties.MaxTextureMemory = 268435456; } } } // properties.Apply3DProperties(domlayer); // ps.SceneGraph.RefreshViewers(); IActiveView iv = m_pSceneCtrl.Scene as IActiveView; iv.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); } } }
//加载拓扑图层 public static void AddTopoLayer(ref AxMapControl pMapCtrl, string strTopoLayerName, ITopologyWorkspace ipTopologyWS, IFeatureClassContainer ipFeatClassContainer, IFeatureDataset ipFeatDataset) { int nOriginClassID, nDestClassID; ITopology ipTopology; //打开数据集 //ITopologyContainer ipTopoContainer = (ITopologyContainer)ipFeatDataset; IWorkspace2 pWorkspace = (IWorkspace2)ipFeatDataset.Workspace; if (pWorkspace.get_NameExists(esriDatasetType.esriDTTopology, strTopoLayerName)) { ipTopology = ipTopologyWS.OpenTopology(strTopoLayerName); if (ipTopology == null) { return; } ITopologyLayer ipTopologyLayer = new TopologyLayerClass(); ipTopologyLayer.Topology = ipTopology; ILegendInfo legendInfo = (ILegendInfo)ipTopologyLayer; for (int i = 0; i < legendInfo.LegendGroupCount; i++) { ILegendGroup legendgroup = legendInfo.get_LegendGroup(i); ILegendClass legendclass = legendgroup.get_Class(0); switch (legendgroup.Heading) { case "Area Errors": { legendgroup.Heading = ""; legendclass.Label = "面状错误"; legendclass.Description = "面状错误"; break; } case "Line Errors": { legendgroup.Heading = ""; legendclass.Label = "线状错误"; legendclass.Description = "线状错误"; break; } case "Point Errors": { legendgroup.Heading = ""; legendclass.Label = "点状错误"; legendclass.Description = "点状错误"; break; } } } ILayer ipLayer = (ILayer)ipTopologyLayer; ipLayer.Name = strTopoLayerName; //将拓扑检查合并后,将拓扑图层名指定为“拓扑错误”后,采用此方法命名 hehy20080724 /* 将拓扑检查合并后,将拓扑图层名指定为“拓扑错误”后,注销以下代码 hehy20080724 * /////////////////////////////////////////////////// * //得到拓扑层相对应的规则名称 * CModelSchema pModelSchema = new CModelSchema(); * string strRuleName = pModelSchema.GetRuleNameByTopoLayerName(m_pTask.pSchema, strTopoLayerName); * ////////////////////////////////////////////////// * if (strRuleName.Length == 0) * { * ipLayer.Name = strTopoLayerName; * } * else * { * ipLayer.Name = strRuleName; * } */ //把拓扑图层加载到map控件中 //pMapCtrl.AddLayer(ipLayer, pMapCtrl.LayerCount); pMapCtrl.Map.AddLayer(ipLayer); //pMapCtrl.ActiveView.Extent = ipLayer.AreaOfInterest; } }
private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation) // bool hasTopologyStuff, bool hasStationFunction, { // Get references to the map for adding layers and tables IMxDocument MxDoc = (IMxDocument)ArcMap.Document; IMap thisMap = MxDoc.FocusMap; IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap; // Create a group layer IGroupLayer GeoMapGroupLayer = new GroupLayerClass(); GeoMapGroupLayer.Name = "Geologic Map"; // Create a group layer IGroupLayer StationGroupLayer = new GroupLayerClass(); StationGroupLayer.Name = "Observation Data"; //if (hasTopologyStuff == true) { #region "GeologicMapTopology" ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology"); ITopologyLayer geoMapTopoTL = new TopologyLayerClass(); geoMapTopoTL.Topology = geoMapTopo; ILayer geoMapTopoL = (ILayer)geoMapTopoTL; geoMapTopoL.Name = "Geologic Map Topology"; geoMapTopoL.Visible = false; // Minimizing the legend info in the Table of Contents is not trivial ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL; ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2); geoMapTopoLegendGroup.Visible = false; GeoMapGroupLayer.Add(geoMapTopoL); #endregion } { #region "OrientationPoints" IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints"); IFeatureLayer orientationPointsFL = new FeatureLayerClass(); orientationPointsFL.FeatureClass = orientationPointsFC; orientationPointsFL.Name = "Orientation Points"; orientationPointsFL.DisplayField = "Type"; if (useRepresentation == true) { // Set the layer renderer to use representations IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL; IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass(); orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep"); orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints"); } ILegendInfo orientationPointsLegendInfo = (ILegendInfo)orientationPointsFL; ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0); orientationPointsLegendGroup.Visible = false; StationGroupLayer.Add(orientationPointsFL); #endregion #region "ObservationData" string[] arr = new string[4]; // Initialize arr[0] = "Stations"; // Element 1 arr[1] = "GenericPoints"; // Element 2 arr[2] = "GenericSamples"; // Element 3 arr[3] = "GeochronPoints"; // Element 4 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; FL.Visible = false; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; StationGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } //add station group layer to map document GeoMapGroupLayer.Add(StationGroupLayer); { #region "LinesWithoutRepresentations" string[] arr = new string[2]; // Initialize arr[0] = "CartographicLines"; // Element 1 arr[1] = "IsoValueLines"; // Element 2 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; FL.Visible = false; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "LinesWithRepresentations" string[] arr = new string[2]; // Initialize arr[0] = "GeologicLines"; // Element 1 arr[1] = "ContactsAndFaults"; // Element 2 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; if (useRepresentation == true) { // Set the layer renderer to use representations IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL; IRepresentationRenderer RepRend = new RepresentationRendererClass(); RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep"); GeoFL.Renderer = (IFeatureRenderer)RepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s); } ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "Polygons" string[] arr = new string[3]; // Initialize arr[0] = "DataSourcePolys"; // Element 1 arr[1] = "MapUnitPolys"; // Element 2 arr[2] = "OtherPolys"; // Element 3 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "Tables" string[] arr = new string[7]; // Initialize arr[0] = "DataSources"; // Element 1 arr[1] = "DescriptionOfMapUnits"; // Element 2 arr[2] = "ExtendedAttributes"; // Element 3 arr[3] = "GeologicEvents"; // Element 4 arr[4] = "Glossary"; // Element 5 arr[5] = "Notes"; // Element 6 arr[6] = "StandardLithology"; // Element 7 foreach (string s in arr) { try { ITable Table = commonFunctions.OpenTable(ValidNcgmpDatabase, s); IStandaloneTable Standalone = new StandaloneTableClass(); Standalone.Table = Table; Standalone.Name = s; thisMapTables.AddStandaloneTable(Standalone); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } // Add the Geologic Map Group Layer to the map GeoMapGroupLayer.Expanded = true; thisMap.AddLayer(GeoMapGroupLayer); // Adjust the MapUnitPolys Renderer commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase); // Adjust the MapUnitPolys Feature Templates commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase); }
private int GetSymbolIndex(ISymbol pSym, IClassBreaksRenderer pRend) { // given an input symbol and a renderer, this function returns the index of // the class that the symbol represents in the renderer int i = 0; int iNumBreaks = 0; iNumBreaks = pRend.BreakCount; i = 0; ILegendInfo pLegendInfo = null; pLegendInfo = pRend as ILegendInfo; while (i < iNumBreaks - 1) { if (pLegendInfo.SymbolsAreGraduated) { // compare based on size if (SymbolsAreSameSize(pSym, pRend.get_Symbol(i))) break; } else { // compare based on color if (SymbolsAreSameColor(pSym, pRend.get_Symbol(i))) break; } i = i + 1; } return i; // NOTE: for some reason we can't test that the symbol objects are the same, so above we do quick test for equal properties instead //Do While (i < iNumBreaks - 1) // If pSym Is pRend.Symbol(i) Then Exit Do // i = i + 1 //Loop //Return i // (I think this only works for renderer that does Graduated symbols) //If m_ShapeType = esriGeometryType.esriGeometryPoint Or m_ShapeType = esriGeometryType.esriGeometryPolygon Then // ' determine the symbol index based on marker symbol size // pInMarkerSym = pSym // i = 0 // pClassMarkerSym = pRend.Symbol(0) // dblSize = pClassMarkerSym.Size // Do While (i < iNumBreaks - 1) And (pInMarkerSym.Size > dblSize) // pClassMarkerSym = pRend.Symbol(i) // dblSize = pClassMarkerSym.Size // i = i + 1 // Loop // iReturnVal = i //Else ' m_shapetype = esriGeometryLine // ' determine the symbol index based on line symbol width // pInLineSym = pSym // i = 0 // pClassLineSym = pRend.Symbol(0) // dblWidth = pClassLineSym.Width // Do While (i < iNumBreaks - 1) And (pInLineSym.Width > dblWidth) // pClassLineSym = pRend.Symbol(i) // dblSize = pClassLineSym.Width // i = i + 1 // Loop // iReturnVal = i //End If }