//加载3dTile
- function Load3dTiles() {
- viewer = new Cesium.Viewer('cesiumContainer');
- var city = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
- url: Cesium.IonResource.fromAssetId(3839)
- }));
- var heightOffset = -32;
- city.readyPromise.then(function (tileset) {
- // Position tileset
- var boundingSphere = tileset.boundingSphere;
- var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
- var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
- var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
- var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
- tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
- });
- var defaultStyle = new Cesium.Cesium3DTileStyle({
- color: "color('white')",
- show: true
- });
- city.style = defaultStyle;
- var heightStyle = new Cesium.Cesium3DTileStyle({
- color: {
- conditions: [
- ["${height} >= 300", "rgba(45, 0, 75, 0.5)"],
- ["${height} >= 200", "rgb(102, 71, 151)"],
- ["${height} >= 100", "rgb(170, 162, 204)"],
- ["${height} >= 50", "rgb(224, 226, 238)"],
- ["${height} >= 25", "rgb(252, 230, 200)"],
- ["${height} >= 10", "rgb(248, 176, 87)"],
- ["${height} >= 5", "rgb(198, 106, 11)"],
- ["true", "rgb(127, 59, 8)"]
- ]
- }
- });
- /**
- var tileStyle = document.getElementById('tileStyle');
- function set3DTileStyle() {
- var selectedStyle = tileStyle.options[tileStyle.selectedIndex].value;
- if (selectedStyle === 'none') {
- city.style = defaultStyle;
- } else if (selectedStyle === 'height') {
- city.style = heightStyle;
- } else if (selectedStyle === 'transparent') {
- city.style = transparentStyle;
- }
- }
- tileStyle.addEventListener('change', set3DTileStyle);
- */
- }
- Load3dTiles();