一、技术原理
CityMaker中图层(featurelayer)符号化指的通过设置颜色或者透明度等样式来改变整个图层的样式,具体详见如图:
图层符号化有两种方法:
·创建图层的时候设置geometryrender;
·通过setGeometryRender设置geometryrender;
几何渲染器IGeometryRender分为简易几何渲染对象ISimpleGeometryRender和多专题的几何渲染器IValueMapGeometryRender
简易几何渲染一般是通过设置几何对象的样式来设置
多专题的几何渲染主要是用渲染方案来设置渲染的效果,渲染方案有两个渲染的规则,一个是范围规则,也就是可以设置在规定范围中显示某种渲染效果,另一个是唯一值渲染规则,也就是可以根据某一类型来实现渲染的效果
二、图层符号化
1. .NET
private Hashtable fcMap = null;
//定义建筑图层
IFeatureLayer BuildingFl=null;
//创建图层
public void CreateFeaturelayer()
{
//几何物体渲染风格
ISimpleGeometryRender geoRender = new SimpleGeometryRender();
IModelPointSymbol geoSymbol = new ModelPointSymbol();
geoSymbol.Color = 0xFFDDDD00; //模型颜色
geoSymbol.EnableColor = true; //需开启,否则颜色设置无效
geoRender.Symbol = geoSymbol;
IFeatureLayer featureLayer = rendercontrol.ObjectManager.CreateFeatureLayer(
fc, geoName, null, geoRender, __rootId);
}
//1、简易几何渲染,通过设置颜色,来渲染模型
public void SimpleSymbol() {
ISimpleGeometryRender geoRender = new SimpleGeometryRender();
IModelPointSymbol geoSymbol = new ModelPointSymbol();
geoSymbol.Color = 0xFF000000; //模型颜色
geoSymbol.EnableColor = true; //需开启,否则颜色设置无效
geoRender.Symbol = geoSymbol;
BuildingFl.SetGeometryRender(geoRender);
}
//2、多专题的几何渲染器,通过设置范围来渲染不同范围的模型
public void ValueSymbol() {
//几何渲染风格
IValueMapGeometryRender geoRender = new ValueMapGeometryRender();
IRangeRenderRule rangeRule = new RangeRenderRule();
rangeRule.LookUpField = "oid";
rangeRule.MaxValue = 60000;
rangeRule.MinValue = 0;
rangeRule.IncludeMin = false;
IModelPointSymbol geoSymbol = new ModelPointSymbol();
geoSymbol.Color = 0xFF7D7D00; //模型颜色
geoSymbol.EnableColor = true; //需开启,否则颜色设置无效
IGeometryRenderScheme grs = new GeometryRenderScheme();
grs.AddRule(rangeRule);
grs.Symbol = geoSymbol;
geoRender.AddScheme(grs);
BuildingFl.SetGeometryRender(geoRender);
}
2. JavaScript
//创建图层
function createFeaturelayer(){
//初始化一个简易几何渲染
var geoRender=__g.new_SimpleGeometryRender;
//此处用的是模型图层为例,其他数据类型类似,只是渲染的几何风格不同
var modelPointSymbol = __g.new_ModelPointSymbol;
modelPointSymbol.color=0x64FFFFFF;
modelPointSymbol.enableColor = true;
geoRender.symbol=modelPointSymbol;
var fl = __g.objectManager.createFeatureLayer(fc, geoName, textRender, geoRender, __rootId);
}
//1、简易几何渲染,通过设置颜色,来渲染模型
function changeSimpleSymbol(){
var geoRender=__g.new_SimpleGeometryRender;
var modelPointSymbol = __g.new_ModelPointSymbol;
modelPointSymbol.color=0xff097CEA;
modelPointSymbol.enableColor = true;
geoRender.symbol=modelPointSymbol;
buildingFl.setGeometryRender(geoRender);
}
//2、多专题的几何渲染器,通过设置范围来渲染不同范围的模型
function changeValueSymbol(){
var geoRender = __g.new_ValueMapGeometryRender;
var rangeRule = __g.new_RangeRenderRule;
rangeRule.lookUpField = "oid";
rangeRule.maxValue = 1290;
rangeRule.minValue = 0;
var geoSymbol = __g.new_ModelPointSymbol;
geoSymbol.color = 0xFFEAD60A;
geoSymbol.enableColor = true; //需开启,否则颜色设置无效
var grs = __g.new_GeometryRenderScheme;
grs.addRule(rangeRule);
grs.symbol = geoSymbol;
geoRender.addScheme(grs);
var rangeRule = __g.new_RangeRenderRule;
rangeRule.lookUpField = "oid";
rangeRule.maxValue = 3290;
rangeRule.minValue = 1290;
var geoSymbol = __g.new_ModelPointSymbol;
geoSymbol.color = 0xcc3103C1; //模型颜色
geoSymbol.enableColor = true; //需开启,否则颜色设置无效
var grs = __g.new_GeometryRenderScheme;
grs.addRule(rangeRule);
grs.symbol = geoSymbol;
geoRender.addScheme(grs);
buildingFl.setGeometryRender(geoRender);
}
3. 注意
- 几何渲染风格的enableColor必须设置为true,否则颜色设置无效
- 简易几何渲染包含各种数据类型的图层设置,不仅是模型图层,也可以是点线面图层
- 专题渲染可以同时添加多个渲染规则