1. 程式人生 > 實用技巧 >cesium 新增3DTileset

cesium 新增3DTileset

addflood () {
      let params = {}
      findtBuildField(params).then(res => {
        if (res.data.status === 0) {
          let conditions = []
          let tempArr = []
          tempArr = res.data.data
          for (let item of tempArr) { // 設定模型顏色渲染
                if (item.damagefield >= 0 && item.damagefield < 0.1) {
                  conditions.push([
'${buildingId} === ' + item.buildingid, 'color("rgb(26, 150, 64)")'],) } else if (item.damagefield >= 0.1 && item.damagefield < 0.25) { conditions.push(['${buildingId} === ' + item.buildingid, 'color("rgb(166, 217, 106)")'],) } else if (item.damagefield >= 0.25 && item.damagefield < 0.55) { conditions.push([
'${buildingId} === ' + item.buildingid, 'color("rgb(255, 255, 192)")'],) } else if (item.damagefield >= 0.55 && item.damagefield < 0.85) { conditions.push(['${buildingId} === ' + item.buildingid, 'color("rgb(253, 174, 97)")'],) } else if (item.damagefield >= 0.85 && item.damagefield <= 1) { conditions.push([
'${buildingId} === ' + item.buildingid, 'color("rgb(215, 24, 28)")'],) } else { conditions.push(['${buildingId} === ' + item.buildingid, 'color("rgb(26, 150, 64)")'],) // 當item.damagefield === undefined } } let tiles = new Cesium.Cesium3DTileset({ url: './static/shp/tileset.json', // 帶網路屬性模板 }) let m = this._viewer.scene.primitives.add(tiles) m.style = new Cesium.Cesium3DTileStyle({ color: { conditions: conditions } }) } else { console.log(res.data.msg) } }); }

呼叫

this.addflood()