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
| const viewer = new Cesium.Viewer("cesiumContainer", { sceneModePicker: false, homeButton: false, navigationHelpButton: false, baseLayerPicker: false, navigationInstructionsInitiallyVisible: false, fullscreenButton: false, selectionIndicator: false, skyBox: false, timeline: false, animation: false, shouldAnimate: true, infoBox: false, geocoder: Cesium.IonGeocodeProviderType.GOOGLE,
globe: false, }); viewer.cesiumWidget.creditContainer.style.display = "none";
viewer.scene.skyAtmosphere.show = true;
try { const googleTileset = await Cesium.createGooglePhotorealistic3DTileset({
onlyUsingWithGoogleGeocoder: true, }); viewer.scene.primitives.add(googleTileset); } catch (error) { console.log(`创建 world terrain 时出错. ${error}`); }
const targetHighlight = new Cesium.Entity({ polygon: { hierarchy: Cesium.Cartesian3.fromDegreesArray( [ [-105.0077102972673, 39.75198671798765], [-105.0095858062031, 39.75049417970743], [-105.00969000114443, 39.75035082687128], [-105.00972838875393, 39.75013579705808], [-105.00971742086537, 39.74997136204101], [-105.00962967775735, 39.749768979944236], [-105.00932806082336, 39.74928832007956], [-105.00887837739427, 39.749444324087904], [-105.00854934073887, 39.749663572365904], [-105.00822578802776, 39.749967145754084], [-105.00715641889735, 39.751312128419926], [-105.00715641889735, 39.75135429046085], [-105.0077102972673, 39.75198671798765], ].flat(2) ), material: Cesium.Color.YELLOW.withAlpha(0.6), classificationType: Cesium.ClassificationType.CESIUM_3D_TILE, }, }); viewer.entities.add(targetHighlight);
let buildingTileset; try { buildingTileset = await Cesium.Cesium3DTileset.fromIonAssetId(1670818); viewer.scene.primitives.add(buildingTileset); } catch (error) { console.log(`加载建筑物瓦片集出错.${error}`); }
const cameraOffset = new Cesium.HeadingPitchRange( Cesium.Math.toRadians(95.0), Cesium.Math.toRadians(-18.0), 600.0 ); viewer.zoomTo(buildingTileset, cameraOffset);
Sandcastle.addToggleButton("显示建筑物", true, function (checked) { buildingTileset.show = checked; });
Sandcastle.addToggleButton( "高亮显示目标位置", true, function (checked) { if (checked) { viewer.entities.add(targetHighlight); } else { viewer.entities.remove(targetHighlight); } } );
|