//普通entity加载模型
- function LoadEntityModel() {
- var redPolygon = viewer.entities.add({
- name: "Red polygon on surface",
- polygon: {
- hierarchy: Cesium.Cartesian3.fromDegreesArray([
- 113.490283, 28.884350000000005,
- 113.53232437057214, 28.86366476861567,
- 113.52849410091294, 28.789783075024378,
- 113.33021641184426, 28.783389028027322,
- 113.490283, 28.884350000000005,
- ]),
- material: Cesium.Color.RED,
- },
- });
- viewer.zoomTo(redPolygon);
- }
- //LoadEntityModel();
//DataSource管理entity模型
- function UseDataSourceEntity() {
- //先创建一个CustomDataSource源,然后把entity存入这里面
- let Polygon = new Cesium.CustomDataSource("paowuxian");
- viewer.dataSources.add(Polygon);
- //添加数据的方式
- Polygon.entities.add({
- polygon: {
- hierarchy: Cesium.Cartesian3.fromDegreesArray([
- 113.490283, 28.884350000000005,
- 113.53232437057214, 28.86366476861567,
- 113.52849410091294, 28.789783075024378,
- 113.33021641184426, 28.783389028027322,
- 113.490283, 28.884350000000005,
- ]),
- material: Cesium.Color.BLUE,
- },
- });
- //清除数据的方式 这样就不会清除上面的数据
- //Polygon.entities.removeAll()
- viewer.zoomTo(Polygon);
- }
- //UseDataSourceEntity();
//图元管理entity模型
- function UseDataSourceTuYuanEntity() {
- let ldCollection = new Cesium.PrimitiveCollection("tuyuan");
- viewer.scene.primitives.add(ldCollection);
- //先创建一个CustomDataSource源,然后把entity存入这里面
- let Polygon = new Cesium.CustomDataSource("paowuxian");
- viewer.dataSources.add(Polygon);
- //添加数据的方式
- Polygon.entities.add({
- polygon: {
- hierarchy: Cesium.Cartesian3.fromDegreesArray([
- 113.490283, 28.884350000000005,
- 113.53232437057214, 28.86366476861567,
- 113.52849410091294, 28.789783075024378,
- 113.33021641184426, 28.783389028027322,
- 113.490283, 28.884350000000005,
- ]),
- material: Cesium.Color.GREEN,
- },
- });
- ldCollection.add(Polygon);
- //清除图元
- // ldCollection.clear()
- viewer.zoomTo(Polygon);
- }
- //UseDataSourceTuYuanEntity();
//使用图元Primitive
- function UsePrimitive() {
- var scene = viewer.scene
- var instance = new Cesium.GeometryInstance({
- geometry: new Cesium.RectangleGeometry({
- rectangle: Cesium.Rectangle.fromDegrees(-100.0, 20.0, -90.0, 30.0),
- vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
- })
- });
- let primitive1 = new Cesium.Primitive({
- geometryInstances: instance,
- appearance: new Cesium.EllipsoidSurfaceAppearance({
- material: new Cesium.Material({
- fabric: {
- type: 'Image',
- uniforms: {
- image: '../img/earth.png',
- color: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
- cellAlpha: 1
- },
- source: `
- uniform vec4 color;
- uniform float cellAlpha;
- czm_material czm_getMaterial(czm_materialInput materialInput)
- {
- czm_material material = czm_getDefaultMaterial(materialInput);
- vec2 st = materialInput.st;
- float aa = st.s * st.t;
- vec3 halfColor = color.rgb * aa + texture2D(image, materialInput.st).rgb * (1.0 - aa);
- halfColor *= 0.5;
- material.diffuse = halfColor;
- material.emission = halfColor;
- // material.alpha = color.a * aa;
- material.alpha = 1.0;
- return material;
- }
- `
- }
- })
- })
- })
- scene.primitives.add(primitive1);
- }
- //UsePrimitive();