private void AddPolygon() { GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0)); polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0)); geoPolygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格 stylePolygon.OutLineVisible = true; //显示多边形的边缘线 //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0); geoPolygon.Style = stylePolygon; //把风格添加到多边形上 //创建几何对象并设置属性 GSOFeature f = new GSOFeature(); f.Geometry = geoPolygon; f.Name = "多边形 01"; f.SetFieldValue("description", "a demo polygon"); #region 属性设置 f.Description = "<html>\r\n<head>\r\n<style>\r\n#tab-list {\r\nborder-collapse:collapse;\r\nfont-size:15px;\r\nmargin:20px;\r\ntext-align:left;\r\nwidth:280px;\r\n}\r\n\r\n#tab-list th {\r\nborder-bottom:2px solid #6678B1;\r\ncolor:#003399;\r\nfont-size:14px;\r\nfont-weight:normal;\r\npadding:10px 8px;\r\n}\r\n#tab-list td {\r\nborder-bottom:1px solid #CCCCCC;\r\ncolor:#666699;\r\npadding:6px 8px;\r\n}\r\n</style>\r\n</head>\r\n<body style=\"border:none\">\r\n<center>\r\n<table id=\"tab-list\">\r\n<thead><tr><th>属性名称</th><th>属性值</th></tr></thead>\r\n<tbody>$tablecontent</tbody></table>\r\n</center>\r\n</body>\r\n</html>\r\n"; GSOGeoPolyline3D line = new GSOGeoPolyline3D(); line.AddPart((f.Geometry as GSOGeoPolygon3D)[0]); double length = line.GetSpaceLength(true, 6378137) / 1000; Dictionary <string, string> property = new Dictionary <string, string>(); property.Add("面积", ((f.Geometry as GSOGeoPolygon3D).Area / 1000000).ToString("f4") + "平方千米"); property.Add("周长", length.ToString("f2") + "千米"); f.Description = f.Description.Replace("$tablecontent", maketable(property)); #endregion globeControl1.Globe.MemoryLayer.AddFeature(f); //把几何要素添加到内存图层中 }
// 面 private void btn_Polygon_Click(object sender, System.EventArgs e) { GSOGeoPolygon3D polygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(120.47, 31.3, 0)); polygonPnts.Add(new GSOPoint3d(120.48, 31.3, 0)); polygonPnts.Add(new GSOPoint3d(120.48, 31.25, 0)); polygonPnts.Add(new GSOPoint3d(120.47, 31.2, 0)); polygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D style = new GSOSimplePolygonStyle3D(); style.FillColor = Color.FromArgb(255, Color.Gray); polygon.Style = style; AddNewGeoToLayer(polygon, "面"); }
/// <summary> /// 创建面 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddPolygon_Click(object sender, EventArgs e) { GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0)); polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0)); geoPolygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格 stylePolygon.OutLineVisible = true; //显示多边形的边缘线 //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0); geoPolygon.Style = stylePolygon; //把风格添加到多边形上 //创建几何对象并设置属性 GSOFeature f = new GSOFeature(); f.Geometry = geoPolygon; f.Name = "多边形 01"; f.SetFieldValue("description", "a demo polygon"); //绑定数据 btnRemovePolygon.Tag = f; globeControl1.Globe.MemoryLayer.AddFeature(f); //把几何要素添加到内存图层中 //下面不属于工程内容,只是飞到点的位置 GSOCameraState cs = new GSOCameraState(); cs.Longitude = 116.75; cs.Latitude = 39.8; cs.Altitude = 50000; globeControl1.Globe.FlyToCameraState(cs); }
private void Form1_Load(object sender, EventArgs e) { #region 创建面要素和飞到面 GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0)); polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0)); geoPolygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格 stylePolygon.OutLineVisible = true; //显示多边形的边缘线 //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0); geoPolygon.Style = stylePolygon; //把风格添加到多边形上 //下面不属于工程内容,只是飞到点的位置 GSOCameraState cs = new GSOCameraState(); cs.Longitude = 116.75; cs.Latitude = 39.8; cs.Altitude = 50000; globeControl1.Globe.FlyToCameraState(cs); #endregion //创建几何对象并设置属性 GSOFeature f = new GSOFeature(); f.Geometry = geoPolygon; f.Name = "多边形 01"; f.CustomID = 1; f.SetFieldValue("description", "a demo polygon"); f.Description = "这是一个多边形"; //将面添加到球中 feature = globeControl1.Globe.MemoryLayer.AddFeature(f); //添加的时候获取要素 }
/// <summary> /// 向图层数据中添加要素Feature /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_EditFeature_Click(object sender, EventArgs e) { //新建要素 GSOGeoPolygon3D polygon = new GSOGeoPolygon3D(); GSOPoint3ds points = new GSOPoint3ds(); points.Add(new GSOPoint3d(120, 30, 0)); points.Add(new GSOPoint3d(120.004, 30, 0)); points.Add(new GSOPoint3d(120.002, 30.001, 0)); polygon.AddPart(points); GSOFeature feature = new GSOFeature(); feature.Geometry = polygon; _featureLayer.AddFeature(feature); _glbControl.Globe.MemoryLayer.AddFeature(feature); _glbControl.Globe.FlyToFeature(feature); _featureLayer.Save(); }