从3DTileset 对象获取Cesium3DTileFeature 的过程,和逆向操作(基础篇)

我们加载一个3DTileset 到地图里面了,怎样获取这个3DTileset 对象下面的feature呢。比如获取某个房屋的构件“窗子”

1,通过点击事件获取

viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(

        movement

      ) {

        var pickedFeature= viewer.scene.pick(movement.position);

},

      Cesium.ScreenSpaceEventType.LEFT_CLICK);

2,通过对3DTileset 对象添加监听和回调函数获取

function processContentFeatures(content, callback) {

  var featuresLength = content.featuresLength;

  for (var i = 0; i < featuresLength; ++i) {

    var feature = content.getFeature(i);

    callback(feature);

  }

}

function processTileFeatures(tile, callback) {

  var content = tile.content;

  var innerContents = content.innerContents;

  if (Cesium.defined(innerContents)) {

    var length = innerContents.length;

    for (var i = 0; i < length; ++i) {

      processContentFeatures(innerContents[i], callback);

    }

  } else {

    processContentFeatures(content, callback);

  }

}

tileset.tileLoad.addEventListener(function (tile) {

  processTileFeatures(tile, function(data){

console.log(data)

});

});

tileset.tileUnload.addEventListener(function (tile) {

  processTileFeatures(tile, unloadFeature);

});


3,通过tileset tileVisible监听获取 feature

     tileset.tileVisible.addEventListener(function(tile) { 

     var content = tile.content;

       var featuresLength = content.featuresLength; 

      for (var i = 0; i < featuresLength; i++) { 

        let  feature =content.getFeature(i)

      }   

 });

4,通过 _selectedTiles对象获取被选中的featrue

var tiles=tileset._selectedTiles

for(let i=0;i

let tile = tiles[i];

var content = tile.content;

var featuresLength = content.featuresLength;

for (var j = 0; j < featuresLength; j++) {

let feature =content.getFeature(j) console.log( feature)

} }

5,从Cesium3DTileFeature里获取Cesium3DTileset 

pickedFeature.tileset

你可能感兴趣的:(从3DTileset 对象获取Cesium3DTileFeature 的过程,和逆向操作(基础篇))