Cesium学习笔记(一)添加实体

来源:互联网 发布:svg js设置 transform 编辑:程序博客网 时间:2024/05/16 20:28

可以选实体对象:

名称 类型 备注 box BoxGraphics 盒子实体 corridor CorridorGraphics 走廊实体 cylinder CylinderGraphics 椎体实体 ellipse EllipseGraphics 圆和椭圆实体 ellipsoid EllipsoidGraphics 球体和椭圆体 wall WallGraphics 墙 polygon PolygonGraphics 多边形实体 polyline PolylineGraphics 折线实体 rectangle RectangleGraphics 矩形

初始化:

    <div id="cesiumDemo"></div>    <script type="text/javascript">        var view = new Cesium.Viewer('cesiumDemo',{            baseLayerPicker: false,            imageryProvider: new Cesium.ArcGisMapServerImageryProvider({                url: 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer'            })        });    </script>

盒子

        view.entities.add({           name: 'box',            position: Cesium.Cartesian3.fromDegrees(116.543398,39.881501,0),            box:{                dimensions: new Cesium.Cartesian3(40000.0,40000.0,30000.0),                material: Cesium.Color.RED            }        });

效果图:

这里写图片描述

走廊

        view.entities.add({            name: 'corridor',            corridor:{                positions: Cesium.Cartesian3.fromDegreesArray([                    -100.0, 40.0,                    -105.0, 40.0,                    -105.0, 35.0                ]),                width:200000, //宽度必须设置                material: Cesium.Color.RED            }        });

效果图

这里写图片描述

椎体圆柱体

    view.entities.add({            name: 'cylinder',            position: Cesium.Cartesian3.fromDegrees(116.274913,38.716066,0),            cylinder:{                length:50000, // 圆柱体高度                topRadius: 30000,// 圆柱体顶部半径                bottomRadius:30000, // 圆柱体底部半径                material: Cesium.Color.RED            }        });

效果图 (顶部半径改为0就是椎体)

这里写图片描述

椭圆

        view.entities.add({            name: 'ellipse',            position: Cesium.Cartesian3.fromDegrees(114.690446,38.465178,0),            ellipse: {                semiMajorAxis: 40000, // 长轴长度                semiMinorAxis: 30000, // 短轴长度                material:Cesium.Color.RED            }        });

效果图

这里写图片描述

球体和椭圆体

        view.entities.add({            name: 'ellipsoid',            position: Cesium.Cartesian3.fromDegrees(114.04884,37.771145,0),            ellipsoid:{                radii: new Cesium.Cartesian3(30000, 30000, 30000), //设置球体的xyz                material: Cesium.Color.RED            }        });

这里写图片描述

        view.entities.add({            name: 'wall',            wall:{                positions : Cesium.Cartesian3.fromDegreesArray([-115.0, 50.0,                    -112.5, 50.0,                    -110.0, 50.0,                    -107.5, 50.0,                    -105.0, 50.0,                    -102.5, 50.0,                    -100.0, 50.0,                    -97.5, 50.0,                    -95.0, 50.0,                    -92.5, 50.0,                    -90.0, 50.0]),                maximumHeights : [100000, 200000, 100000, 200000, 100000, 200000, 100000, 200000, 100000, 200000, 100000],                minimumHeights : [0, 100000,  0, 100000, 0, 100000, 0, 100000, 0, 100000, 0],                material: Cesium.Color.RED            }        });

效果图

这里写图片描述

线

    var model = view.entities.add({            name: 'polyline',            polyline: {                positions: Cesium.Cartesian3.fromDegreesArray([                    115.250413,35.887456,                    117.250413,35.887456                ]),                width: 10,                material: Cesium.Color.RED            }        });

效果图

这里写图片描述

material可以支持其他样式填充:

PolylineArrowMaterialProperty
PolylineDashMaterialProperty
PolylineGlowMaterialProperty
PolylineOutlineMaterialProperty

多边形

        view.entities.add({            name: 'polygon',            polygon:  {                hierarchy : Cesium.Cartesian3.fromDegreesArray([                    -109.080842,45.002073,                    -105.91517,45.002073,                    -104.058488,44.996596,                    -104.053011,43.002989,                    -104.053011,41.003906,                    -105.728954,40.998429,                    -107.919731,41.003906,                    -109.04798,40.998429,                    -111.047063,40.998429,                    -111.047063,42.000709,                    -111.047063,44.476286,                    -111.05254,45.002073]),                height : 0,                material : Cesium.Color.RED.withAlpha(0.5),                outline : true,                outlineColor : Cesium.Color.BLACK            }        });

效果图

这里写图片描述

矩形

    view.entities.add({            name: 'rectangle',            rectangle: {                coordinates: Cesium.Rectangle.fromDegrees(-160.0, 0.0, -140.0, 30.0),                material : Cesium.Color.GREEN.withAlpha(0.5),                rotation : Cesium.Math.toRadians(45),                extrudedHeight : 300000.0,                height : 100000.0,                outline : true,                outlineColor : Cesium.Color.BLACK            }        });

效果图

这里写图片描述

原创粉丝点击