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
| const viewer = new Cesium.Viewer("cesiumContainer", { geocoder: false, sceneModePicker: false, homeButton: false, navigationHelpButton: false, baseLayerPicker: false, navigationInstructionsInitiallyVisible: false, fullscreenButton: false, selectionIndicator: false, skyBox: false, timeline: false, animation: false, shouldAnimate: true, infoBox: false, });
viewer.cesiumWidget.creditContainer.style.display = "none";
Sandcastle.addDefaultToolbarButton("使用默认样式(加载数据)", function () { viewer.dataSources.add( Cesium.GeoJsonDataSource.load("../SampleData/ne_10m_us_states.topojson"), ); });
Sandcastle.addToolbarButton("使用基本样式选项加载(数据)", function () { viewer.dataSources.add( Cesium.GeoJsonDataSource.load("../SampleData/ne_10m_us_states.topojson", { stroke: Cesium.Color.HOTPINK, fill: Cesium.Color.PINK.withAlpha(0.5), strokeWidth: 3, }), ); });
Sandcastle.addToolbarButton("加载(数据)后应用自定义图形", function () { Cesium.Math.setRandomNumberSeed(0);
const promise = Cesium.GeoJsonDataSource.load( "../SampleData/ne_10m_us_states.topojson", ); promise .then(function (dataSource) { viewer.dataSources.add(dataSource);
const entities = dataSource.entities.values;
const colorHash = {}; for (let i = 0; i < entities.length; i++) { const entity = entities[i]; const name = entity.name; let color = colorHash[name]; if (!color) { color = Cesium.Color.fromRandom({ alpha: 1.0, }); colorHash[name] = color; }
entity.polygon.material = color; entity.polygon.outline = false;
entity.polygon.extrudedHeight = entity.properties.Population / 50.0; } }) .catch(function (error) { window.alert(error); }); });
Sandcastle.reset = function () { viewer.dataSources.removeAll();
viewer.camera.lookAt( Cesium.Cartesian3.fromDegrees(-98.0, 40.0), new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0), );
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); };
|