PIE SDK中關於矢量渲染提供了多種方案,包括簡單渲染、分級渲染、惟一值渲染,這幾種渲染方式具備必定的通用性,能夠知足用戶絕大多數的需求。ide
當面對複雜的業務,當前渲染方案沒法知足用戶需求時,可選擇進行自定義渲染方案的編寫,針對不一樣的業務編寫自定義的邏輯和行業特定的符號。函數
目前PIE SDK自定義渲染只支持矢量數據。spa
第一步3d |
新建自定義渲染方案類,繼承至PIE.Carto.CustomerFeatureRendercode |
第二步視頻 |
重寫CustomerFeatureRender類中的GetSymbolByFeature()方法對象 |
第三步blog |
實例化自定義渲染類對象繼承 |
第四步教程 |
矢量渲染器接口轉換 |
第五步 |
矢量圖層渲染賦值 |
接口/類 |
方法 |
說明 |
Carto.CustomerFeatureRender |
GetSymbolByFeature() |
根據要素得到對應渲染符號 |
項目路徑 |
百度雲盤地址下/PIE示例程序/07圖層渲染/04.矢量自定義渲染 |
數據路徑 |
百度雲盤地址下/PIE示例數據/矢量數據/Shape/省級行政區.shp |
視頻路徑 |
百度雲盤地址下/PIE視頻教程/07圖層渲染/04.矢量自定義渲染.avi |
示例代碼 |
|
![]() 1 方法(一) 2 //當前選擇圖層 3 if (mapControlMain.ActiveView.CurrentLayer == null) return; 4 //是否爲矢量圖層 5 IFeatureLayer featureLayer = mapControlMain.ActiveView.CurrentLayer as IFeatureLayer; 6 if (featureLayer == null) return; 7 //實例化自定義渲染對象 8 DefineRender render = new DefineRender(); 9 featureLayer.Render = render as IFeatureRender; 10 //視圖刷新 11 mapControlMain.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll); 12 13 方法(二) 14 /// <summary> 15 /// 自定義渲染類 16 /// 繼承至CustomerFeatureRender類,重寫GetSymbolByFeature方法便可。 17 /// </summary> 18 public class DefineRender : PIE.Carto.CustomerFeatureRender 19 { 20 /// <summary> 21 /// 構造函數 22 /// </summary> 23 public DefineRender() 24 { 25 } 26 public override ISymbol GetSymbolByFeature(IFeature feature) 27 { 28 //根據點線面,返回不一樣的符號,本示例生成面狀符號 29 //主要是根據不一樣的值,進行邏輯編寫 30 GeometryType pGeometry = feature.Geometry.GetGeometryType(); 31 if (pGeometry == GeometryType.GeometryPoint) 32 { 33 //點符號 34 IMarkerSymbol markSymbol = new SimpleMarkerSymbol(); 35 return (markSymbol as ISymbol); 36 } 37 else if (pGeometry == GeometryType.GeometryPolyline) 38 { 39 //線符號 40 ILineSymbol lineSymbol = new SimpleLineSymbol(); 41 lineSymbol.Width = 2; 42 lineSymbol.Color = Color.AliceBlue; 43 return (lineSymbol as ISymbol); 44 } 45 else if (pGeometry == GeometryType.GeometryPolygon||pGeometry==GeometryType.GeometryMultiPolygon) 46 { 47 object value = feature.GetValue("HighSchool");//取值字段可根據實際數據進行修改 48 //面符號 49 50 IFillSymbol fillSymbol = new SimpleFillSymbol(); 51 52 ILineSymbol lineSymbol = new SimpleLineSymbol(); 53 lineSymbol.Width = 2; 54 lineSymbol.Color = Color.AliceBlue; 55 56 fillSymbol.OutlineSymbol = lineSymbol; 57 fillSymbol.Color = Color.CornflowerBlue; 58 59 string ssStr = value.ToString(); 60 int valueTemp = Convert.ToInt32(ssStr); 61 //篇幅有限,只對一些值進行符號賦值,其他的採用默認符號 62 if (valueTemp<5000) 63 { 64 fillSymbol.Color = Color.Pink; 65 } 66 else if (valueTemp<10000) 67 { 68 fillSymbol.Color = Color.RosyBrown; 69 } 70 else if(valueTemp<15000) 71 { 72 fillSymbol.Color = Color.Blue; 73 } 74 else 75 { 76 fillSymbol.Color = Color.AliceBlue; 77 } 78 return (fillSymbol as ISymbol); 79 } 80 else 81 { 82 return null; 83 } 84 } 85 } |