使用官方github包,部分解釋來源于Viewer - Cesium Documentation Cesium.Ion.defaultAccessToken = "token"; constviewer = newCesium.Viewer("cesiumContainer");
viewer.entities.add({ //entities獲取物體集合 id: "red rectangle,zIndex 1", rectangle: { //設定或者獲取矩形 coordinates: Cesium.Rectangle.fromDegrees(-110.0, 20, -100.5, 30.0), //左下角經緯右上角經緯 material: Cesium.Color.RED, zIndex: 1, //一個屬性,指定用于排序地面幾何的 zIndex,僅當矩形為常量且未指定 //height 或 extrudedHeight 時才有效, }, });
viewer.entities.add({ id: "Textured rectangle, zIndex 2", rectangle: { coordinates: Cesium.Rectangle.fromDegrees(-112.0, 25.0, -102.5, 35.0), material: "../images/Cesium_Logo_Color.jpg", zIndex: 2, }, });
viewer.entities.add({ id: "Blue rectangle, zIndex 3", rectangle: { coordinates: Cesium.Rectangle.fromDegrees(-110.0, 31.0, -100.5, 41.0), material: Cesium.Color.BLUE, zIndex: 3, }, });
viewer.entities.add({ id: "Textured rectangle, zIndex 3", rectangle: { coordinates: Cesium.Rectangle.fromDegrees(-99.5, 20.0, -90.0, 30.0), material: "../images/Cesium_Logo_Color.jpg", zIndex: 3, }, });
viewer.entities.add({ id: "Green rectangle, zIndex 2", rectangle: { coordinates: Cesium.Rectangle.fromDegrees(-97.5, 25.0, -88.0, 35.0), material: Cesium.Color.GREEN, zIndex: 2, }, });
viewer.entities.add({ id: "Blue rectangle, zIndex 1", rectangle: { coordinates: Cesium.Rectangle.fromDegrees(-99.5, 31.0, -90.0, 41.0), material: Cesium.Color.BLUE, zIndex: 1, }, }); if (!Cesium.Entity.supportsPolylinesOnTerrain(viewer.scene)) { //檢查給定場景是否支持夾在地形或 3D 平鋪上的折線, //如果不支持此功能,具有折線圖形的物體將在提供的高度處使用頂點進行渲染, //并使用 `arcType` 引數而不是固定在地面上, window.alert( "Polylines on terrain are not supported on this platform ,Z-index will be ignored" ); } if (!Cesium.Entity.supportsMaterialsforEntitiesOnTerrain(viewer.scene)) { //檢查給定場景是否支持覆寫在地形或 3D 平鋪上的物體上的顏色以外的材質, //如果不支持此功能,則具有非顏色材質但沒有'高度'的物體將被渲染為高度為 0, window.alert( "Textured materials on terrain polygons are not supported on this platform, Z-index will be ignored" ); } viewer.entities.add({ id: "Polyline, zIndex 2", polyline: { positions: Cesium.Cartesian3.fromDegreesArray([ -120.0, 22.0, -80.0, 22.0, ]), //指定定義線帶的 Cartesian3 位置陣列 width: 8.0, material: newCesium.PolylineGlowMaterialProperty({ //映射到折線發光 Material glowPower: 0.2, //發光強度,占總線寬的百分比 color: Cesium.Color.BLUE, //taperPower:一個數字屬性,指定錐形效果的強度, //以總線條長度的百分比表示,如果為 1.0 或更高,則不使用錐形效果, }), zIndex: 2,//深度資訊 clampToGround: true, //指定折線是否應固定在地面上, }, }); viewer.zoomTo(viewer.entities); //zoomTo (target, offset(可選) ) //異步設定相機以查看提供的物體、物體或資料源, //如果資料源仍在加載程序中或可視化仍在加載中,則此方法在執行縮放之前等待資料準備好, //偏移量是本地東西北上參考系中的航向/俯仰/范圍,以邊界球的中心為中心, //航向角和俯仰角在當地東西北上參考系中定義,航向是從 y 軸到 x 軸增加的角度,俯仰是從 xy 平面的旋轉, //正俯仰角在平面上方, //負俯仰角位于平面下方,范圍是到中心的距離,如果范圍為零,則將計算范圍以使整個邊界球體可見, //在 2D 中,必須有自上而下的視圖,攝像機將放置在目標上方向下看,目標上方的高度將是范圍, / /航向將根據偏移量確定,如果無法根據偏移量確定航向,則航向將為北, 運行結果圖:(與代碼略有不同,更換了圖片路徑和內容 (material:))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/549245.html
標籤:GIS
