mirror of
https://github.com/jiawanlong/Cesium-Examples.git
synced 2025-07-05 07:37:31 +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.eyJqdGkiOiIyNDMxOTA2NS1lY2Q3LTQ0YmUtOTE1Mi1iNWE2OGYwZjc0MjkiLCJpZCI6MjM1NjMwLCJpYXQiOjE3MzA3MjQzMTJ9.Xhu-9FyVEyqBKWEr0V9Sybt-elTCWHt9peL9-mNh-4E'
|
|||
|
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>
|