Cesium 点击事件

var colorMap  = [];
var selectedEntity = new Cesium.Entity();

var clickHandler = viewer.screenSpaceEventHandler.getInputAction(
     Cesium.ScreenSpaceEventType.LEFT_CLICK
 );
 viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(
     movement
     ) {
         var pickedFeature = viewer.scene.pick(movement.position);
         console.log(pickedFeature);
         if (!Cesium.defined(pickedFeature)) {
             clickHandler(movement);
             return;
         }
         //点击颜色修改
         var selectedMap = colorMap.filter(function(itemFeature){
             return itemFeature.item == pickedFeature;
         });
         if(selectedMap.length<1){
             colorMap.push({"item":pickedFeature,"color":pickedFeature.color});
         }
         for(var x =0; x<colorMap.length;x++){
             var itemFeature = colorMap[x];
             itemFeature.item.color = itemFeature.color;
         }
         //修改点击构件时,构件的颜色
         pickedFeature.color = Cesium.Color.YELLOW;
         var propertyNames = pickedFeature.getPropertyNames();
         // 设置构件的显示隐藏
         //pickedFeature.show = false;
         //获取所有携带属性信息
         var length = propertyNames.length;
         for (var i = 0; i < length; ++i) {
             var propertyName = propertyNames[i];
         }
         var featureName = pickedFeature.getProperty("name");
         selectedEntity.name = featureName;
         selectedEntity.description =
             'Loading <div class="cesium-infoBox-loading"></div>';
         viewer.selectedEntity = selectedEntity;
         selectedEntity.description =
             '<table class="cesium-infoBox-defaultTable"><tbody>' +
             "<tr><th>type</th><td>" +
             pickedFeature.getProperty("type") +
             "</td></tr>" +
             "<tr><th>sphere</th><td>" +
             pickedFeature.getProperty("sphere") +
             "</td></tr>" +
             "<tr><th>slope</th><td>" +
             pickedFeature.getProperty("slope") +
             "</td></tr>" +
             "</tbody></table>";
     },
     Cesium.ScreenSpaceEventType.LEFT_CLICK);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值