分级渲染--百度地图路段红黄绿功能
/* 参数一:要渲染的图层
参数二:按照哪个属性渲染
参数三:分级的分解点
参数四:各级的颜色*/
public void linkClassRender(IFeatureLayer layer, string fieldName, List<int> spds, List<IColor> colors)
{
// 获取当前图层,并把它设置成IGeoFeatureLayer的实例
IFeatureLayer pFeatLayer = (IFeatureLayer)layer;
IGeoFeatureLayer pGeoFeatLayer = (IGeoFeatureLayer)layer;
IFeatureClass pFeatClass = pFeatLayer.FeatureClass;
IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();
pClassBreaksRenderer.Field = fieldName;
pClassBreaksRenderer.MinimumBreak = spds[0];
pClassBreaksRenderer.BreakCount = spds.Count - 1;
for (int breakIndex = 0; breakIndex < spds.Count-1; breakIndex++)
{
pClassBreaksRenderer.set_Label(breakIndex, spds[breakIndex] + "-" + spds[breakIndex + 1]);
ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass();
pLineSymbol.Color = colors[breakIndex];
pLineSymbol.Width = 2;
pClassBreaksRenderer.set_Symbol(breakIndex, (ISymbol)pLineSymbol);
pClassBreaksRenderer.set_Break(breakIndex, spds[breakIndex + 1]);
}
// 将等级图渲染对象与渲染图层挂钩
pGeoFeatLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
axMapControl1.Refresh();
}
/* 使用示例*/
protected void Render()
{
FeatureLayer pFLayer = GetLayerbyName("road") as FeatureLayer;
List<int> spdCls = new List<int>();
spdCls.Add(0); spdCls.Add(3); spdCls.Add(5); spdCls.Add(7); spdCls.Add(9);
// 分成4段 0-3 3-5 5-7 7-9
List<IColor> colors = new List<IColor>();
colors.Add(GetIColorByRGB(0,255,0));
colors.Add(GetIColorByRGB(255, 255, 0));
colors.Add(GetIColorByRGB(255, 0, 0));
colors.Add(GetIColorByRGB(125,125,125));
linkClassRender(pFLayer, "SPEEDCLASS", spdCls, colors);
}
public IColor GetIColorByRGB(int r,int g,int b)
{
IRgbColor color1 = new RgbColorClass() ;
color1.Red = r;
color1.Green = g;
color1.Blue = b;
return color1 as IColor;
}