1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| const viewer = new Cesium.Viewer("cesiumContainer", { geocoder: false, homeButton: false, navigationHelpButton: false, navigationInstructionsInitiallyVisible: false, animation: false, timeline: false, fullscreenButton: false, skyBox: false, sceneModePicker: false, baseLayerPicker: false, terrain: Cesium.Terrain.fromWorldTerrain(), }); viewer.cesiumWidget.creditContainer.style.display = "none";
const scene = viewer.scene;
if (!scene.clampToHeightSupported) { window.alert("该浏览器不支持clampToHeightMostDetailed."); }
scene.camera.setView({ destination: new Cesium.Cartesian3( 1216411.0748779264, -4736313.10747583, 4081359.5125561724, ), orientation: new Cesium.HeadingPitchRoll( 4.239925103568368, -0.4911293834802475, 6.279849292088564, ), endTransform: Cesium.Matrix4.IDENTITY, });
try { const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(40866); scene.primitives.add(tileset); } catch (error) { console.log(`tileset加载出错: ${error}`); }
async function sampleHeights() { viewer.entities.removeAll();
const cartesian1 = new Cesium.Cartesian3( 1216390.063324395, -4736314.814479433, 4081341.9787972216, ); const cartesian2 = new Cesium.Cartesian3( 1216329.5413318684, -4736272.029009798, 4081407.9342479417, );
const count = 30; const cartesians = new Array(count); for (let i = 0; i < count; ++i) { const offset = i / (count - 1); cartesians[i] = Cesium.Cartesian3.lerp( cartesian1, cartesian2, offset, new Cesium.Cartesian3(), ); }
const clampedCartesians = await scene.clampToHeightMostDetailed(cartesians);
for (let i = 0; i < count; ++i) { viewer.entities.add({ position: clampedCartesians[i], ellipsoid: { radii: new Cesium.Cartesian3(0.2, 0.2, 0.2), material: Cesium.Color.RED, }, }); }
viewer.entities.add({ polyline: { positions: clampedCartesians, arcType: Cesium.ArcType.NONE, width: 2, material: new Cesium.PolylineOutlineMaterialProperty({ color: Cesium.Color.YELLOW, }), depthFailMaterial: new Cesium.PolylineOutlineMaterialProperty({ color: Cesium.Color.YELLOW, }), }, }); }
sampleHeights();
|