mirror of
				https://github.com/jiawanlong/Cesium-Examples.git
				synced 2025-11-04 01:04:17 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			92 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!--********************************************************************
 | 
						||
* by jiawanlong
 | 
						||
*********************************************************************-->
 | 
						||
<!DOCTYPE html>
 | 
						||
<html>
 | 
						||
 | 
						||
<head>
 | 
						||
    <meta charset="UTF-8" />
 | 
						||
    <link rel="stylesheet" href="./../../libs/cesium/Cesium1.98/Widgets/widgets.css">
 | 
						||
    <script type="text/javascript" src="./../../libs/cesium/Cesium1.98/Cesium.js"></script>
 | 
						||
</head>
 | 
						||
 | 
						||
<body style="margin: 0; overflow: hidden; background: #fff; width: 100%; height: 100%; position: absolute; top: 0">
 | 
						||
    <div id="map" style="margin: 0 auto; width: 100%; height: 100%"></div>
 | 
						||
    <script type="text/javascript">
 | 
						||
 | 
						||
        Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMjBhMzcxMC0wNjBiLTRmYjItYjY1MC0wMzAwMzMyMGUyMmEiLCJpZCI6MzAzNzc3LCJpYXQiOjE3NDc2Mzk0NTV9.E_90aKtVdzRGlU2z48VwJ4mWvl-uuDkfQBCOO6zbzn4'
 | 
						||
        const viewer = new Cesium.Viewer('map', {});
 | 
						||
 | 
						||
        // Entity -> MaterialProperty
 | 
						||
        // Primitive -> appearance(Material)
 | 
						||
 | 
						||
        // 1、Material类专为Appearance类而生,用于修改Primitive的几何对象材质。
 | 
						||
        // 2、MaterialProperty类专为Entity类而生,用于修改Entity的几何对象材质。
 | 
						||
 | 
						||
 | 
						||
        // -------------------------------------------------------------------Material----------------------------------------------------------------------
 | 
						||
        // 使用Fabric JSON定义材质
 | 
						||
        const material = new Cesium.Material({
 | 
						||
            fabric: {
 | 
						||
                type: "Color",  // 内置材质类型
 | 
						||
                uniforms: {
 | 
						||
                    color: new Cesium.Color(1.0, 1.0, 0.0, 1.0) // 黄色
 | 
						||
                }
 | 
						||
            }
 | 
						||
        });
 | 
						||
 | 
						||
        // 或使用内置简写
 | 
						||
        // const material = Cesium.Material.fromType("Color", {
 | 
						||
        //   color: Cesium.Color.RED
 | 
						||
        // });
 | 
						||
 | 
						||
        const primitive = new Cesium.Primitive({
 | 
						||
            geometryInstances: new Cesium.GeometryInstance(
 | 
						||
                {
 | 
						||
                    id: 'polygon',
 | 
						||
                    geometry: new Cesium.PolygonGeometry({
 | 
						||
                        polygonHierarchy: new Cesium.PolygonHierarchy(
 | 
						||
                            Cesium.Cartesian3.fromDegreesArray([
 | 
						||
                                -115.0, 37.0,
 | 
						||
                                -115.0, 32.0,
 | 
						||
                                -102.0, 31.0,
 | 
						||
                                -102.0, 35.0
 | 
						||
                            ])
 | 
						||
                        ),
 | 
						||
                    })
 | 
						||
                }
 | 
						||
            ),
 | 
						||
            appearance: new Cesium.MaterialAppearance({
 | 
						||
                material: material
 | 
						||
            })
 | 
						||
        });
 | 
						||
 | 
						||
        viewer.scene.primitives.add(primitive);
 | 
						||
        // -------------------------------------------------------------------Material----------------------------------------------------------------------
 | 
						||
 | 
						||
 | 
						||
        // -------------------------------------------------------------------MaterialProperty----------------------------------------------------------------------
 | 
						||
        let entity = viewer.entities.add({
 | 
						||
            polygon: {
 | 
						||
                hierarchy: Cesium.Cartesian3.fromDegreesArray([
 | 
						||
                    -108.0,
 | 
						||
                    42.0,
 | 
						||
                    -100.0,
 | 
						||
                    42.0,
 | 
						||
                    -104.0,
 | 
						||
                    40.0,
 | 
						||
                ]),
 | 
						||
            }
 | 
						||
        });
 | 
						||
 | 
						||
        entity.polygon.material = new Cesium.ImageMaterialProperty({
 | 
						||
            image: './icon.png',
 | 
						||
            repeat: new Cesium.Cartesian2(10, 5),
 | 
						||
            transparent: true
 | 
						||
        });
 | 
						||
        // -------------------------------------------------------------------MaterialProperty----------------------------------------------------------------------
 | 
						||
 | 
						||
    </script>
 | 
						||
</body>
 | 
						||
 | 
						||
</html> |