一、修改Cesium3DTileFeature的颜色

  1. var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  2. handler.setInputAction(function (click) {
  3. var pickingEntity = viewer.scene.pick(click.position);
  4. //判断选择是否为Cesium3DTileFeature
  5. if (pickingEntity instanceof Cesium.Cesium3DTileFeature) {
  6. if (pipeHighttimer) ;
  7. clearInterval(pipeHighttimer);
  8. //判断以前是否选择要素
  9. if (pickingEntity != pipePreviousPickedEntity.feature) {
  10. if (pipePreviousPickedEntity.feature != undefined) {
  11. //还原前选择要素的本颜色
  12. pipePreviousPickedEntity.feature.color = pipePreviousPickedEntity.originalColor;
  13. //将当前选择要素及其颜色添加到previousPickedEntity
  14. pipePreviousPickedEntity.feature = pickingEntity;
  15. pipePreviousPickedEntity.originalColor = pickingEntity.color;
  16. }
  17. //将当前选择要素及其颜色添加到previousPickedEntity
  18. pipePreviousPickedEntity.feature = pickingEntity;
  19. pipePreviousPickedEntity.originalColor = pickingEntity.color;
  20. }
  21. //将模型变为黄色高亮
  22. //pickingEntity.color = Cesium.Color.YELLOW.withAlpha(0.9);
  23. var timersun = 0.1;
  24. pipeHighttimer = setInterval(function () {
  25. if (timersun > 1.0)
  26. timersun = 0.1;
  27. timersun += 0.1;
  28. //pickingEntity.color = pickingEntity.color.withAlpha(timersun);
  29. pickingEntity.color = Cesium.Color.RED.withAlpha(timersun);
  30. }, 100);
  31. var cartesian = viewer.scene.pickPosition(click.position);
  32. var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
  33. QueryResult.lontable = Cesium.Math.toDegrees(cartographic.longitude); //四舍五入 小数点后保留五位
  34. QueryResult.lattable = Cesium.Math.toDegrees(cartographic.latitude); //四舍五入 小数点后保留五位
  35. QueryResult.height = cartographic.height;
  36. QueryResult.cartesian = cartesian;
  37. pickingEntity.queryResult = QueryResult;
  38. callBackResult(pickingEntity, QueryResult);
  39. }
  40. ;
  41. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  42. handler.setInputAction(function () {
  43. viewer.scene.globe.depthTestAgainstTerrain = true;
  44. viewer.container.style.cursor = "auto";
  45. if (pipeHighttimer) ;
  46. clearInterval(pipeHighttimer);
  47. if (pipePreviousPickedEntity.feature != undefined) {
  48. //还原前选择要素的本颜色
  49. pipePreviousPickedEntity.feature.color = pipePreviousPickedEntity.originalColor;
  50. }
  51. if (handler != null) {
  52. handler.destroy();
  53. handler = null;
  54. }
  55. document.getElementById("pipeQuery").style.visibility = "hidden"; //隐藏
  56. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

二、通过修改style样式,来修改模型高亮

let layer = new mars3d.layer.TilesetLayer({
    name: '地下管网',
  url: ''
})
map.addLayer(layer)
// 监听layer中的左键监听事件
layer.on(mars3d.EventType.click, e => {
  const pickedFeature = e.pickedObject
    const usId = pickedFeature.getProperty('gw_id')
  const hightArray = []
  const highttemp = []
  const timersun = 0.1
  consst highttemp1 = "${gw_id} ==='" + usId + "'"
  highttemp.push(highttemp1)
  const highttemp2 = "rgba(255, 0, 0," + (+timersun) + ")"
  highttemp.push(highttemp2)
  hightArray.push(highttemp)
  hightArray.push(['true', 'rgb(255, 255, 255)'])
  layer.style = new Cesium.Cesium3DTileStyle({
      color: {
        conditions: hightArray
    }
  })
})