private static IGeoFeatureLayer VisibilityColorsRender(IFeatureLayer layer, IObjectFactory objFactory) { const string fieldName = "IS_VISIBLE"; string[] uniqueValues = new string[2]; int fieldIndex = layer.FeatureClass.Fields.FindField(fieldName); uniqueValues[0] = "0"; uniqueValues[1] = "1"; Type renderType = typeof(UniqueValueRendererClass); string typeRenderID = renderType.GUID.ToString("B"); IUniqueValueRenderer uVRenderer = (IUniqueValueRenderer)objFactory.Create(typeRenderID); uVRenderer.FieldCount = 1; uVRenderer.Field[0] = fieldName; var invisibleSymbol = GetSymbol(layer.FeatureClass.ShapeType, new RgbColor() { Red = 255, Blue = 0, Green = 0 }); var visibleSymbol = GetSymbol(layer.FeatureClass.ShapeType, new RgbColor() { Red = 0, Blue = 0, Green = 255 }); uVRenderer.AddValue(uniqueValues[0], "Visibility", invisibleSymbol); uVRenderer.AddValue(uniqueValues[1], "Visibility", visibleSymbol); IGeoFeatureLayer geoFL = layer as IGeoFeatureLayer; geoFL.Renderer = uVRenderer as IFeatureRenderer; return(geoFL); }
private void btnok_Click(object sender, EventArgs e) { if (treeshow.SelectedIndex == 0) { if (treeadd.SelectedNode == null) { MessageBox.Show("请选择要添加的值", "提示", MessageBoxButtons.OK); } else { string strnode = ""; strnode = treeadd.SelectedNode.Text; if (pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { IClone pSourceClone = pSimpleFillSymbol as IClone; ISimpleFillSymbol pSimpleFillSymb = pSourceClone.Clone() as ISimpleFillSymbol; pUniquerender.AddValue(strnode, "唯一值渲染", (ISymbol)pSimpleFillSymb); ISimpleFillSymbol pNextSymbol = pUniquerender.get_Symbol(strnode) as ISimpleFillSymbol; pNextSymbol.Color = coloru[treeadd.SelectedIndex]; pUniquerender.set_Symbol(strnode, (ISymbol)pNextSymbol); DataRow rowu = dtable2.NewRow(); rowu[1] = strnode; rowu[2] = strnode; rowu[3] = cuntu[treeadd.SelectedIndex]; dtable2.Rows.Add(rowu); gridviewu.Rows[gridviewu.Rows.Count - 2].Cells[0].Style.BackColor = ClsGDBDataCommon.IColorToColor(pNextSymbol.Color); } else if (pFClass.ShapeType == esriGeometryType.esriGeometryLine || pFClass.ShapeType == esriGeometryType.esriGeometryPolyline) { IClone pSourceClone = pLineSymbol as IClone; ISimpleLineSymbol pSimpleFillSymb = pSourceClone.Clone() as ISimpleLineSymbol; pUniquerender.AddValue(strnode, "唯一值渲染", (ISymbol)pSimpleFillSymb); ISimpleLineSymbol pNextSymbol = pUniquerender.get_Symbol(strnode) as ISimpleLineSymbol; pNextSymbol.Color = coloru[treeadd.SelectedIndex]; pUniquerender.set_Symbol(strnode, (ISymbol)pNextSymbol); DataRow rowu = dtable2.NewRow(); rowu[1] = strnode; rowu[2] = strnode; rowu[3] = cuntu[treeadd.SelectedIndex]; dtable2.Rows.Add(rowu); gridviewu.Rows[gridviewu.Rows.Count - 2].Cells[0].Style.BackColor = ClsGDBDataCommon.IColorToColor(pNextSymbol.Color); } else { IClone pSourceClone = pPointSymbol as IClone; ISimpleMarkerSymbol pSimpleFillSymb = pSourceClone.Clone() as ISimpleMarkerSymbol; pUniquerender.AddValue(strnode, "唯一值渲染", (ISymbol)pSimpleFillSymb); ISimpleMarkerSymbol pNextSymbol = pUniquerender.get_Symbol(strnode) as ISimpleMarkerSymbol; pNextSymbol.Color = coloru[treeadd.SelectedIndex]; pUniquerender.set_Symbol(strnode, (ISymbol)pNextSymbol); DataRow rowu = dtable2.NewRow(); rowu[1] = strnode; rowu[2] = strnode; rowu[3] = cuntu[treeadd.SelectedIndex]; dtable2.Rows.Add(rowu); gridviewu.Rows[gridviewu.Rows.Count - 2].Cells[0].Style.BackColor = ClsGDBDataCommon.IColorToColor(pNextSymbol.Color); } addvx.Remove(addvx[treeadd.SelectedIndex]); coloru.Remove(coloru[treeadd.SelectedIndex]); countu.Add(cuntu[treeadd.SelectedIndex]); cuntu.Remove(cuntu[treeadd.SelectedIndex]); treeadd.Nodes[treeadd.SelectedIndex].Remove(); treeadd.SelectedNode = null; gridviewu.CurrentCell = null; } } else { if (treeadd.SelectedNode == null) { MessageBox.Show("请选择要添加的值", "提示", MessageBoxButtons.OK); } else { string strnode = ""; strnode = treeadd.SelectedNode.Text; if (pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { IClone pSourceClone = pSimpleFillSymbol as IClone; ISimpleFillSymbol pSimpleFillSymb = pSourceClone.Clone() as ISimpleFillSymbol; pUniquerendermu.AddValue(strnode, "唯一值渲染", (ISymbol)pSimpleFillSymb); ISimpleFillSymbol pNextSymbol = pUniquerendermu.get_Symbol(strnode) as ISimpleFillSymbol; pNextSymbol.Color = colorumu[treeadd.SelectedIndex]; pUniquerendermu.set_Symbol(strnode, (ISymbol)pNextSymbol); DataRow rowu = dtable3.NewRow(); rowu[1] = strnode; rowu[2] = strnode; rowu[3] = cuntumu[treeadd.SelectedIndex]; dtable3.Rows.Add(rowu); gridviewmu.Rows[gridviewmu.Rows.Count - 2].Cells[0].Style.BackColor = ClsGDBDataCommon.IColorToColor(pNextSymbol.Color); } else if (pFClass.ShapeType == esriGeometryType.esriGeometryLine || pFClass.ShapeType == esriGeometryType.esriGeometryPolyline) { IClone pSourceClone = pLineSymbol as IClone; ISimpleLineSymbol pSimpleFillSymb = pSourceClone.Clone() as ISimpleLineSymbol; pUniquerendermu.AddValue(strnode, "唯一值渲染", (ISymbol)pSimpleFillSymb); ISimpleLineSymbol pNextSymbol = pUniquerendermu.get_Symbol(strnode) as ISimpleLineSymbol; pNextSymbol.Color = colorumu[treeadd.SelectedIndex]; pUniquerendermu.set_Symbol(strnode, (ISymbol)pNextSymbol); DataRow rowu = dtable3.NewRow(); rowu[1] = strnode; rowu[2] = strnode; rowu[3] = cuntumu[treeadd.SelectedIndex]; dtable3.Rows.Add(rowu); gridviewmu.Rows[gridviewmu.Rows.Count - 2].Cells[0].Style.BackColor = ClsGDBDataCommon.IColorToColor(pNextSymbol.Color); } else { IClone pSourceClone = pPointSymbol as IClone; ISimpleMarkerSymbol pSimpleFillSymb = pSourceClone.Clone() as ISimpleMarkerSymbol; pUniquerendermu.AddValue(strnode, "唯一值渲染", (ISymbol)pSimpleFillSymb); ISimpleMarkerSymbol pNextSymbol = pUniquerendermu.get_Symbol(strnode) as ISimpleMarkerSymbol; pNextSymbol.Color = colorumu[treeadd.SelectedIndex]; pUniquerendermu.set_Symbol(strnode, (ISymbol)pNextSymbol); DataRow rowu = dtable3.NewRow(); rowu[1] = strnode; rowu[2] = strnode; rowu[3] = cuntumu[treeadd.SelectedIndex]; dtable3.Rows.Add(rowu); gridviewmu.Rows[gridviewmu.Rows.Count - 2].Cells[0].Style.BackColor = ClsGDBDataCommon.IColorToColor(pNextSymbol.Color); } addvxmu.Remove(addvxmu[treeadd.SelectedIndex]); colorumu.Remove(colorumu[treeadd.SelectedIndex]); countumu.Add(cuntumu[treeadd.SelectedIndex]); cuntumu.Remove(cuntumu[treeadd.SelectedIndex]); treeadd.Nodes[treeadd.SelectedIndex].Remove(); treeadd.SelectedNode = null; gridviewmu.CurrentCell = null; } } }