1. 程式人生 > 其它 >Cesium polygon polyline entity 各種貼地 點線面模型貼地 clampToGround

Cesium polygon polyline entity 各種貼地 點線面模型貼地 clampToGround

 

 

1、entity 實體貼地(配置 billboard 的屬性)

entity.billboard.disableDepthTestDistance = Number.POSITIVE_INFINITY; //去掉地形遮擋

 

2、polyline 線條設定貼地

const lineEntitie = viewer.entities.add({
    plotType: 'MilitaryPlot',
    polyline: {
        positions: positions,
        width: 2,
        material: Cesium.Color.fromCssColorString(
'#0BFF0D'), clampToGround: true, }, })

 

3、polygon 貼地似乎不需要設定任何東西。但通常你需要結合邊界線 polyline,這個 polyline 需要設定 clampToGround: true

// positions 的格式是一個笛卡爾陣列 [{x, y, z}, {x, y, z}, {x, y, z}, ...]
// 可以用這種方式轉經緯度陣列:const positions = Cesium.Cartesian3.fromDegreesArray(points)
const entity = viewer.entities.add({
    name: 
'name' + key, polygon: { hierarchy: new Cesium.PolygonHierarchy(positions), material: Cesium.Color.fromCssColorString('#9b9bdd').withAlpha(0.35), classificationType: Cesium.ClassificationType.BOTH, // classificationType: ClassificationType.TERRAIN, }, polyline: { positions: positions, width:
2, material: Cesium.Color.WHITE.withAlpha(0.5), clampToGround: true, }, })

 

4、geojson 資料來源設定貼地(未實戰測試)

let promise = Cesium.GeoJsonDataSource.load(_geojsondata, { clampToGround: true })

// ---

const geoJsonDataSource = new Cesium.CustomDataSource('聚合圖')
viewer.dataSources.add(geoJsonDataSource, { clampToGround: true })

 

5、gltf 模型貼地

據說模型貼地需要設定 heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,但我自測其實不需要。先記著吧。

viewer.entities.add({
    id: `flag-1`,
    name: "flag",
    position: Cesium.Cartesian3.fromDegrees(...item.position),
    model: {
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, // 讓模型在地形上緊貼
        scale: 10,
        uri: './static/models/flag.glb'
    }
})