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 105 106 107 108 109
| const viewer = new Cesium.Viewer("cesiumContainer", { sceneModePicker: false, homeButton: false, navigationHelpButton: false, baseLayerPicker: false, navigationInstructionsInitiallyVisible: false, animation: false, timeline: false, fullscreenButton: false, selectionIndicator: false, skyBox: false, shouldAnimate: true, geocoder: Cesium.IonGeocodeProviderType.GOOGLE, globe: false, });
viewer.cesiumWidget.creditContainer.style.display = "none"; viewer.scene.debugShowFramesPerSecond = true;
viewer.scene.skyAtmosphere.show = true;
viewer.clock.currentTime = Cesium.JulianDate.fromIso8601( "2020-01-09T23:00:39.018261982600961346Z" );
let googleTileset; try { googleTileset = await Cesium.createGooglePhotorealistic3DTileset({ onlyUsingWithGoogleGeocoder: true, }); viewer.scene.primitives.add(googleTileset); } catch (error) { console.log(`Error loading Photorealistic 3D Tiles tileset. ${error}`); }
let footprint; try { const resource = await Cesium.IonResource.fromAssetId(2533131); const dataSource = await Cesium.GeoJsonDataSource.load(resource, { clampToGround: true, });
viewer.dataSources.add(dataSource);
footprint = dataSource.entities.values.find((entity) => Cesium.defined(entity.polygon) ); footprint.polygon.outline = false;
const cameraOffset = new Cesium.HeadingPitchRange( Cesium.Math.toRadians(95.0), Cesium.Math.toRadians(-75.0), 800.0 ); viewer.zoomTo(footprint, cameraOffset); viewer.homeButton.viewModel.command.beforeExecute.addEventListener((e) => { e.cancel = true; viewer.zoomTo(footprint, cameraOffset); }); } catch (error) { console.log(`Error loading geojson. ${error}`); }
const positions = footprint.polygon.hierarchy.getValue().positions; const clippingPolygons = new Cesium.ClippingPolygonCollection({ polygons: [ new Cesium.ClippingPolygon({ positions: positions, }), ], }); googleTileset.clippingPolygons = clippingPolygons;
let buildingTileset; try { buildingTileset = await Cesium.Cesium3DTileset.fromIonAssetId(2533124); viewer.scene.primitives.add(buildingTileset); } catch (error) { console.log(`Error loading design tileset. ${error}`); }
Sandcastle.addToggleButton( "显示拟建设计方案的3D模型", true, function (checked) { buildingTileset.show = checked; } );
Sandcastle.addToggleButton("显示范围", true, function (checked) { footprint.show = checked; });
Sandcastle.addToggleButton("裁剪目标区域", true, function (checked) { clippingPolygons.enabled = checked; });
Sandcastle.addToggleButton("反选裁剪区域", false, function (checked) { clippingPolygons.inverse = checked; });
|