一、技术原理

CityMaker中图层(featurelayer)符号化指的通过设置颜色或者透明度等样式来改变整个图层的样式,具体详见如图:

CityMaker几何体——符号化 - 图1

图层符号化有两种方法:
·创建图层的时候设置geometryrender;
·通过setGeometryRender设置geometryrender;

几何渲染器IGeometryRender分为简易几何渲染对象ISimpleGeometryRender和多专题的几何渲染器IValueMapGeometryRender

简易几何渲染一般是通过设置几何对象的样式来设置
多专题的几何渲染主要是用渲染方案来设置渲染的效果,渲染方案有两个渲染的规则,一个是范围规则,也就是可以设置在规定范围中显示某种渲染效果,另一个是唯一值渲染规则,也就是可以根据某一类型来实现渲染的效果

二、图层符号化

1. .NET

  1. private Hashtable fcMap = null;
  2. //定义建筑图层
  3. IFeatureLayer BuildingFl=null;
  4. //创建图层
  5. public void CreateFeaturelayer()
  6. {
  7. //几何物体渲染风格
  8. ISimpleGeometryRender geoRender = new SimpleGeometryRender();
  9. IModelPointSymbol geoSymbol = new ModelPointSymbol();
  10. geoSymbol.Color = 0xFFDDDD00; //模型颜色
  11. geoSymbol.EnableColor = true; //需开启,否则颜色设置无效
  12. geoRender.Symbol = geoSymbol;
  13. IFeatureLayer featureLayer = rendercontrol.ObjectManager.CreateFeatureLayer(
  14. fc, geoName, null, geoRender, __rootId);
  15. }
  16. //1、简易几何渲染,通过设置颜色,来渲染模型
  17. public void SimpleSymbol() {
  18. ISimpleGeometryRender geoRender = new SimpleGeometryRender();
  19. IModelPointSymbol geoSymbol = new ModelPointSymbol();
  20. geoSymbol.Color = 0xFF000000; //模型颜色
  21. geoSymbol.EnableColor = true; //需开启,否则颜色设置无效
  22. geoRender.Symbol = geoSymbol;
  23. BuildingFl.SetGeometryRender(geoRender);
  24. }
  25. //2、多专题的几何渲染器,通过设置范围来渲染不同范围的模型
  26. public void ValueSymbol() {
  27. //几何渲染风格
  28. IValueMapGeometryRender geoRender = new ValueMapGeometryRender();
  29. IRangeRenderRule rangeRule = new RangeRenderRule();
  30. rangeRule.LookUpField = "oid";
  31. rangeRule.MaxValue = 60000;
  32. rangeRule.MinValue = 0;
  33. rangeRule.IncludeMin = false;
  34. IModelPointSymbol geoSymbol = new ModelPointSymbol();
  35. geoSymbol.Color = 0xFF7D7D00; //模型颜色
  36. geoSymbol.EnableColor = true; //需开启,否则颜色设置无效
  37. IGeometryRenderScheme grs = new GeometryRenderScheme();
  38. grs.AddRule(rangeRule);
  39. grs.Symbol = geoSymbol;
  40. geoRender.AddScheme(grs);
  41. BuildingFl.SetGeometryRender(geoRender);
  42. }

2. JavaScript

  1. //创建图层
  2. function createFeaturelayer(){
  3. //初始化一个简易几何渲染
  4. var geoRender=__g.new_SimpleGeometryRender;
  5. //此处用的是模型图层为例,其他数据类型类似,只是渲染的几何风格不同
  6. var modelPointSymbol = __g.new_ModelPointSymbol;
  7. modelPointSymbol.color=0x64FFFFFF;
  8. modelPointSymbol.enableColor = true;
  9. geoRender.symbol=modelPointSymbol;
  10. var fl = __g.objectManager.createFeatureLayer(fc, geoName, textRender, geoRender, __rootId);
  11. }
  12. //1、简易几何渲染,通过设置颜色,来渲染模型
  13. function changeSimpleSymbol(){
  14. var geoRender=__g.new_SimpleGeometryRender;
  15. var modelPointSymbol = __g.new_ModelPointSymbol;
  16. modelPointSymbol.color=0xff097CEA;
  17. modelPointSymbol.enableColor = true;
  18. geoRender.symbol=modelPointSymbol;
  19. buildingFl.setGeometryRender(geoRender);
  20. }
  21. //2、多专题的几何渲染器,通过设置范围来渲染不同范围的模型
  22. function changeValueSymbol(){
  23. var geoRender = __g.new_ValueMapGeometryRender;
  24. var rangeRule = __g.new_RangeRenderRule;
  25. rangeRule.lookUpField = "oid";
  26. rangeRule.maxValue = 1290;
  27. rangeRule.minValue = 0;
  28. var geoSymbol = __g.new_ModelPointSymbol;
  29. geoSymbol.color = 0xFFEAD60A;
  30. geoSymbol.enableColor = true; //需开启,否则颜色设置无效
  31. var grs = __g.new_GeometryRenderScheme;
  32. grs.addRule(rangeRule);
  33. grs.symbol = geoSymbol;
  34. geoRender.addScheme(grs);
  35. var rangeRule = __g.new_RangeRenderRule;
  36. rangeRule.lookUpField = "oid";
  37. rangeRule.maxValue = 3290;
  38. rangeRule.minValue = 1290;
  39. var geoSymbol = __g.new_ModelPointSymbol;
  40. geoSymbol.color = 0xcc3103C1; //模型颜色
  41. geoSymbol.enableColor = true; //需开启,否则颜色设置无效
  42. var grs = __g.new_GeometryRenderScheme;
  43. grs.addRule(rangeRule);
  44. grs.symbol = geoSymbol;
  45. geoRender.addScheme(grs);
  46. buildingFl.setGeometryRender(geoRender);
  47. }

3. 注意

  1. 几何渲染风格的enableColor必须设置为true,否则颜色设置无效
  2. 简易几何渲染包含各种数据类型的图层设置,不仅是模型图层,也可以是点线面图层
  3. 专题渲染可以同时添加多个渲染规则