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);
Cesium 点击事件
最新推荐文章于 2024-09-30 02:09:07 发布