Пример #1
0
        private static void AddSymbolNode(TreeNodeComLayer tnComLayer, object renderer)
        {
            int             index;
            LogicBaseTree   logicBT    = new LogicBaseTree();
            ImageCollection treeImages = logicBT.TreeList.StateImageList as ImageCollection;

            if (renderer is SimpleRenderer)
            {
                ISimpleRenderer simpleRenderer = (ISimpleRenderer)renderer;
                ISymbol         symbol         = simpleRenderer.Symbol;
                Image           img            = ConvertSymbolToImage.Convert(symbol, 16, 16);
                index = treeImages.Images.Add(img);
                //img.Save("d:\\" + index + ".JPG");

                string         label    = simpleRenderer.Label;
                TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                {
                    Name = label, CustomValue = symbol
                };
                tnSymbol.ImageIndex = index;
                tnComLayer.Add(tnSymbol);
            }
            else if (renderer is UniqueValueRenderer)
            {
                string renderLabel = "";
                IUniqueValueRenderer uniqueValueRenderer = renderer as IUniqueValueRenderer;
                for (int i = 0; i < uniqueValueRenderer.FieldCount - 1; i++)
                {
                    renderLabel += uniqueValueRenderer.get_Field(i) + " /";
                }
                renderLabel += uniqueValueRenderer.get_Field(uniqueValueRenderer.FieldCount - 1);//FieldCount为地物分类数
                //getImage(esriGeometryType.esriGeometryPolygon, Color.White).Save("D:\\111.jpg");
                index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                {
                    Name = renderLabel, CustomValue = uniqueValueRenderer
                };
                tnChartNode.ImageIndex = index;
                tnComLayer.Add(tnChartNode);

                for (int i = 0; i < uniqueValueRenderer.ValueCount; i++)//ValueCount为地物分类下的设施种类数
                {
                    ISymbol symbol = uniqueValueRenderer.get_Symbol(uniqueValueRenderer.get_Value(i));

                    Image img = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    //img.Save("D:\\121121.jpg");


                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = uniqueValueRenderer.get_Label(uniqueValueRenderer.get_Value(i)), CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
                if (uniqueValueRenderer.UseDefaultSymbol)
                {
                    ISymbol symbol = uniqueValueRenderer.DefaultSymbol;
                    Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = uniqueValueRenderer.DefaultLabel, CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
            }
            else if (renderer is IChartRenderer)
            {
                IChartRenderer  chartRenderer = renderer as IChartRenderer;
                IRendererFields pFields       = chartRenderer as IRendererFields;
                string          renderLabel   = "";
                for (int i = 0; i < pFields.FieldCount - 1; i++)
                {
                    renderLabel += pFields.get_FieldAlias(i) + " /";
                }
                renderLabel += pFields.get_FieldAlias(pFields.FieldCount - 1);

                index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                {
                    Name = renderLabel, CustomValue = chartRenderer
                };
                tnChartNode.ImageIndex = index;
                tnComLayer.Add(tnChartNode);


                ISymbolArray symArray = chartRenderer.ChartSymbol as ISymbolArray;
                for (int i = 0; i < symArray.SymbolCount; i++)
                {
                    ISymbol symbol = symArray.get_Symbol(i);

                    Image img = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = pFields.get_FieldAlias(i), CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
            }
            else if (renderer is IClassBreaksRenderer)
            {
                IClassBreaksRenderer classRenderer = renderer as IClassBreaksRenderer;
                index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                {
                    Name = classRenderer.Field, CustomValue = classRenderer
                };
                tnChartNode.ImageIndex = index;
                tnComLayer.Add(tnChartNode);


                for (int i = 0; i < classRenderer.BreakCount; i++)
                {
                    ISymbol symbol = classRenderer.get_Symbol(i);

                    Image img = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = classRenderer.get_Label(i), CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
            }
            else if (renderer is IRasterRenderer)
            {
                if (renderer is IRasterClassifyColorRampRenderer)
                {
                    //MessageBox.Show("IRasterClassifyColorRampRenderer");
                }
                else if (renderer is IRasterUniqueValueRenderer)
                {
                    //MessageBox.Show("IRasterUniqueValueRenderer");
                }
                else if (renderer is IRasterStretchColorRampRenderer)
                {
                    ////MessageBox.Show("IRasterStretchColorRampRenderer");
                    IRasterStretchColorRampRenderer pRSCRR = renderer as IRasterStretchColorRampRenderer;

                    index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));
                    TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                    {
                        Name = "<Value>", CustomValue = pRSCRR
                    };
                    tnChartNode.ImageIndex = index;
                    tnComLayer.Add(tnChartNode);

                    if (pRSCRR.ColorRamp.Size >= 3)
                    {
                        IEnumColors colors = pRSCRR.ColorRamp.Colors;
                        colors.Reset();
                        IColor  c      = colors.Next();
                        Color[] cArray = new Color[3];
                        int     count  = 0;
                        while (c != null)
                        {
                            count++;
                            if (count == 1)
                            {
                                cArray[0] = Color.FromArgb(c.RGB);
                            }
                            else if (count == pRSCRR.ColorRamp.Size / 2)
                            {
                                cArray[1] = Color.FromArgb(c.RGB);
                            }
                            else if (count == pRSCRR.ColorRamp.Size)
                            {
                                cArray[2] = Color.FromArgb(c.RGB);
                            }
                            c = colors.Next();
                        }
                        for (int i = 0; i < 3; i++)
                        {
                            Image img = getImage(esriGeometryType.esriGeometryPolygon, cArray[i]);
                            index = treeImages.Images.Add(img);

                            string label = "";
                            if (i == 0)
                            {
                                label = pRSCRR.LabelLow;
                            }
                            else if (i == 1)
                            {
                                label = pRSCRR.LabelMedium;
                            }
                            else if (i == 2)
                            {
                                label = pRSCRR.LabelHigh;
                            }

                            TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                            {
                                Name = label, CustomValue = cArray[i]
                            };
                            tnSymbol.ImageIndex = index;
                            tnComLayer.Add(tnSymbol);
                        }
                    }
                }

                else if (renderer is IRasterRGBRenderer)
                {
                    //MessageBox.Show("IRasterRGBRenderer");
                }
                else if (renderer is IRasterColormap)
                {
                    //MessageBox.Show("IRasterColormap");
                }
                else
                {
                    //MessageBox.Show("未处理的IRasterRenderer类型:  " + renderer.GetType().FullName);
                }
            }
            else if (renderer is ITinRenderer)
            {
                if (renderer is ITinColorRampRenderer)
                {
                    ////MessageBox.Show("ITinColorRampRenderer");
                    ITinColorRampRenderer pTCRR = renderer as ITinColorRampRenderer;

                    index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));
                    TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                    {
                        Name = "Elevation", CustomValue = pTCRR
                    };
                    tnChartNode.ImageIndex = index;
                    tnComLayer.Add(tnChartNode);



                    for (int i = 0; i < pTCRR.BreakCount; i++)
                    {
                        ISymbol symbol = pTCRR.get_Symbol(i);
                        Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                        index = treeImages.Images.Add(img);
                        TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                        {
                            Name = pTCRR.get_Label(i), CustomValue = symbol
                        };
                        tnSymbol.ImageIndex = index;
                        tnComLayer.Add(tnSymbol);
                    }
                }
                else if (renderer is ITinUniqueValueRenderer)
                {
                    ////MessageBox.Show("ITinUniqueValueRenderer");
                    ITinUniqueValueRenderer pTUVR = renderer as ITinUniqueValueRenderer;

                    index = treeImages.Images.Add(getImage(esriGeometryType.esriGeometryPolygon, Color.White));

                    TreeNodeSymbol tnChartNode = new TreeNodeSymbol()
                    {
                        Name = "Elevation", CustomValue = pTUVR
                    };
                    tnChartNode.ImageIndex = index;
                    tnComLayer.Add(tnChartNode);


                    for (int i = 0; i < pTUVR.ValueCount; i++)
                    {
                        string  val    = pTUVR.get_Value(i);
                        ISymbol symbol = pTUVR.get_Symbol(val);
                        Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                        index = treeImages.Images.Add(img);

                        TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                        {
                            Name = pTUVR.get_Label(val), CustomValue = symbol
                        };
                        tnSymbol.ImageIndex = index;
                        tnComLayer.Add(tnSymbol);
                    }
                    if (pTUVR.UseDefaultSymbol)
                    {
                        ISymbol symbol = pTUVR.DefaultSymbol;
                        Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                        index = treeImages.Images.Add(img);

                        TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                        {
                            Name = pTUVR.DefaultLabel, CustomValue = symbol
                        };
                        tnSymbol.ImageIndex = index;
                        tnComLayer.Add(tnSymbol);
                    }
                }
                else if (renderer is ITinSingleSymbolRenderer)
                {
                    ////MessageBox.Show("ITinSingleSymbolRenderer");
                    ITinSingleSymbolRenderer pTSSR = renderer as ITinSingleSymbolRenderer;
                    ISymbol symbol = pTSSR.Symbol;
                    Image   img    = ConvertSymbolToImage.Convert(symbol, 16, 16);
                    index = treeImages.Images.Add(img);

                    TreeNodeSymbol tnSymbol = new TreeNodeSymbol()
                    {
                        Name = pTSSR.Label, CustomValue = symbol
                    };
                    tnSymbol.ImageIndex = index;
                    tnComLayer.Add(tnSymbol);
                }
                else
                {
                    //MessageBox.Show("未处理的ITinRenderer类型:  " + renderer.GetType().FullName);
                }
            }
            else
            {
                //MessageBox.Show("未处理的Renderer类型:  " + renderer.GetType().FullName);
            }
        }
Пример #2
0
        public static void AddComLayerNode(TreeList parentTree, TreeNodeComLayer node, ILayer layer, List <ILayer> loadlayer)
        {
            object           renderer = null;
            TreeNodeComLayer comLayerNode;

            if (layer is ICadLayer)
            {
                return;
            }
            if (node == null)//如果当前节点为空
            {
                comLayerNode = new TreeNodeComLayer()
                {
                    Name = layer.Name, CustomValue = layer
                };
                comLayerNode.OwnNode    = parentTree.AppendNode(new object[] { comLayerNode.Name }, (TreeListNode)null);//为树创建根节点
                comLayerNode.ImageIndex = 0;
                node             = comLayerNode;
                rootNode         = comLayerNode;
                rootNode.Visible = true;
            }
            else
            {
                comLayerNode = new TreeNodeComLayer()
                {
                    Name = layer.Name, CustomValue = layer
                };
                comLayerNode.Visible = true;
                if (comLayerNode.Name.Contains("注记"))
                {
                    comLayerNode.ImageIndex = 10;
                }
                else
                {
                    comLayerNode.ImageIndex = 0;
                }
                node.Add(comLayerNode);                 //为当前节点添加子节点
            }
            if (layer is ESRI.ArcGIS.Carto.IGroupLayer) //如果图层是复合图层组
            {
                ICompositeLayer comLayer = layer as ICompositeLayer;
                for (int i = 0; i < comLayer.Count; i++)
                {
                    AddComLayerNode(parentTree, comLayerNode, comLayer.get_Layer(i), loadlayer);//递归
                    comLayerNode.CollapseAll();
                }
            }
            else if (layer is IGeoFeatureLayer) //如果图层是地理要素图层
            {
                loadlayer.Add(layer);           //将该图层添加到待加载图层
                IGeoFeatureLayer geoFtLayer = layer as IGeoFeatureLayer;

                if (geoFtLayer == null)
                {
                    return;
                }
                if (geoFtLayer.FeatureClass == null)
                {
                    node.CollapseAll(); return;
                }
                esriGeometryType geoType = geoFtLayer.FeatureClass.ShapeType;
                switch (geoType)
                {
                case esriGeometryType.esriGeometryPoint:
                case esriGeometryType.esriGeometryMultipoint:
                    comLayerNode.ImageIndex = 4;
                    break;

                case esriGeometryType.esriGeometryLine:
                case esriGeometryType.esriGeometryPolyline:
                    comLayerNode.ImageIndex = 5;
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    comLayerNode.ImageIndex = 6;
                    break;
                }
                renderer = geoFtLayer.Renderer;

                AddSymbolNode(comLayerNode, renderer);//对当前树节点进行符号化
                node.CollapseAll();
                comLayerNode.CollapseAll();
                if (geoFtLayer.FeatureClass == null)
                {
                    return;
                }
                DF2DFeatureClass dffc = new DF2DFeatureClass(geoFtLayer.FeatureClass, comLayerNode);//根据当前要素类创建DF2DFC,并添加到管理类
                dffc.SetLayer(layer);
                DF2DFeatureClassManager.Instance.Add(dffc);
                DF2DFeatureClassManager.Instance.Add(comLayerNode);
            }

            else if (layer is IRasterLayer) //如果图层是栅格图层
            {
                loadlayer.Add(layer);       //将该图层添加到待加载图层
                //comLayerNode.Visible = true; //当前图层为可见(显示影像图)
                IRasterLayer rasterLayer = layer as IRasterLayer;
                IRaster      raster      = rasterLayer.Raster;
                if (raster == null)
                {
                    return;
                }
                DF2DRaster dfrd = new DF2DRaster(raster, comLayerNode);
                dfrd.SetLayer(layer);
                DF2DRasterManager.Instance.Add(dfrd);
            }
            else if (layer is IAnnotationLayer)
            {
                loadlayer.Add(layer);
                IFeatureLayer featureLayer = layer as IFeatureLayer;
                if (featureLayer.FeatureClass == null)
                {
                    return;
                }
                DF2DFeatureClass dffc = new DF2DFeatureClass(featureLayer.FeatureClass, comLayerNode);
                dffc.SetLayer(layer);
                DF2DFeatureClassManager.Instance.Add(dffc);
                DF2DFeatureClassManager.Instance.Add(comLayerNode);
            }


            else
            {
                loadlayer.Add(layer);//其它图层也加入待加载图层
            }
        }