一、修改Cesium3DTileFeature的颜色
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (click) {
var pickingEntity = viewer.scene.pick(click.position);
//判断选择是否为Cesium3DTileFeature
if (pickingEntity instanceof Cesium.Cesium3DTileFeature) {
if (pipeHighttimer) ;
clearInterval(pipeHighttimer);
//判断以前是否选择要素
if (pickingEntity != pipePreviousPickedEntity.feature) {
if (pipePreviousPickedEntity.feature != undefined) {
//还原前选择要素的本颜色
pipePreviousPickedEntity.feature.color = pipePreviousPickedEntity.originalColor;
//将当前选择要素及其颜色添加到previousPickedEntity
pipePreviousPickedEntity.feature = pickingEntity;
pipePreviousPickedEntity.originalColor = pickingEntity.color;
}
//将当前选择要素及其颜色添加到previousPickedEntity
pipePreviousPickedEntity.feature = pickingEntity;
pipePreviousPickedEntity.originalColor = pickingEntity.color;
}
//将模型变为黄色高亮
//pickingEntity.color = Cesium.Color.YELLOW.withAlpha(0.9);
var timersun = 0.1;
pipeHighttimer = setInterval(function () {
if (timersun > 1.0)
timersun = 0.1;
timersun += 0.1;
//pickingEntity.color = pickingEntity.color.withAlpha(timersun);
pickingEntity.color = Cesium.Color.RED.withAlpha(timersun);
}, 100);
var cartesian = viewer.scene.pickPosition(click.position);
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
QueryResult.lontable = Cesium.Math.toDegrees(cartographic.longitude); //四舍五入 小数点后保留五位
QueryResult.lattable = Cesium.Math.toDegrees(cartographic.latitude); //四舍五入 小数点后保留五位
QueryResult.height = cartographic.height;
QueryResult.cartesian = cartesian;
pickingEntity.queryResult = QueryResult;
callBackResult(pickingEntity, QueryResult);
}
;
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
handler.setInputAction(function () {
viewer.scene.globe.depthTestAgainstTerrain = true;
viewer.container.style.cursor = "auto";
if (pipeHighttimer) ;
clearInterval(pipeHighttimer);
if (pipePreviousPickedEntity.feature != undefined) {
//还原前选择要素的本颜色
pipePreviousPickedEntity.feature.color = pipePreviousPickedEntity.originalColor;
}
if (handler != null) {
handler.destroy();
handler = null;
}
document.getElementById("pipeQuery").style.visibility = "hidden"; //隐藏
}, 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
}
})
})