private void btnApply_Click(object sender, System.EventArgs e) { string script = this.txtScript.Text.Trim(); if (script != "") { IGeometryRender render = selectedLayer.GetGeometryRender(); if (render != null) { if (render.RenderType == gviRenderType.gviRenderSimple) { ISimpleGeometryRender simpleRender = render as ISimpleGeometryRender; IGeometrySymbol geoSymbol = simpleRender.Symbol; geoSymbol.Script = script; simpleRender.Symbol = geoSymbol; if (!selectedLayer.SetGeometryRender(simpleRender)) { MessageBox.Show("错误码为:" + this.axRenderControl1.GetLastError()); } } } else { ISimpleGeometryRender simpleRender = new SimpleGeometryRender(); switch (type) { case LayerType.ModelPoint: { IModelPointSymbol mps = new ModelPointSymbol(); mps.Script = script; simpleRender.Symbol = mps; } break; case LayerType.Polyline: { ICurveSymbol cs = new CurveSymbol(); cs.Script = script; simpleRender.Symbol = cs; } break; case LayerType.Point: { if (script.Contains("<ImageName>")) { IImagePointSymbol ips = new ImagePointSymbol(); ips.Script = script; simpleRender.Symbol = ips; } else { ISimplePointSymbol sps = new SimplePointSymbol(); sps.Script = script; simpleRender.Symbol = sps; } } break; case LayerType.Polygon: { if (script.Contains("<Height>")) { IPolygon3DSymbol p3s = new Polygon3DSymbol(); p3s.Script = script; simpleRender.Symbol = p3s; } else { ISurfaceSymbol ss = new SurfaceSymbol(); ss.Script = script; simpleRender.Symbol = ss; } } break; } if (!selectedLayer.SetGeometryRender(simpleRender)) { MessageBox.Show("错误码为:" + this.axRenderControl1.GetLastError()); } } } else { selectedLayer.SetGeometryRender(null); } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\7_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\7_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\7_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\7_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\7_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\7_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "GeometrySymbolScript.html"; } layerEnvelopeMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); //-- 配置为简单点 -- ISimplePointSymbol geoSymbol = new SimplePointSymbol(); geoSymbol.Script = "<Size>$(Groupid)*10</Size><FillColor>$(OBJECTID)</FillColor>"; //-- 配置为图片点 -- //IImagePointSymbol geoSymbol = new ImagePointSymbol(); //geoSymbol.Script = "<Size>$(Groupid)*10</Size><ImageName>$(ImageName)</ImageName>"; geoRender.Symbol = geoSymbol; type = LayerType.Point; FeatureLayerVisualize(ci, true, "Point", null, geoRender, type); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); ICurveSymbol geoSymbol = new CurveSymbol(); geoSymbol.Script = "<Color>System.Drawing.Color.Yellow</Color><Width>$(Groupid)*10</Width><ImageName>$(ImageName)</ImageName><RepeatLength>100</RepeatLength>"; geoRender.Symbol = geoSymbol; type = LayerType.Polyline; FeatureLayerVisualize(ci, false, "Polyline", null, geoRender, type); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); //-- 配置为简单面 -- //ISurfaceSymbol geoSymbol = new SurfaceSymbol(); //geoSymbol.Script = "<Color>$(CommunitID)</Color>"; //-- 配置为立体矩形 -- IPolygon3DSymbol geoSymbol = new Polygon3DSymbol(); geoSymbol.Script = "<Color>$(CommunitID)</Color><Height>$(oid)</Height>"; ICurveSymbol curveSymbol = new CurveSymbol(); curveSymbol.Script = "<Color>$(CommunitID)</Color>"; geoSymbol.BoundarySymbol = curveSymbol; geoRender.Symbol = geoSymbol; type = LayerType.Polygon; FeatureLayerVisualize(ci, false, "Polygon", null, geoRender, type); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Script = "<Color>System.Drawing.Color.Yellow</Color>"; geoSymbol.EnableColor = true; // 记得要开启! geoRender.Symbol = geoSymbol; type = LayerType.ModelPoint; FeatureLayerVisualize(ci, false, "ModelPoint", null, geoRender, type); } }