Cesium鼠标移动到模型上,给模型添加高亮轮廓(四)
2023-01-09
Cesium虽然也支持两种方式(Entity和Primitive)加载3D Tiles数据,
但因为多数情况下3D Tiles数据都是成片区的数据,数据量比较大,所以为了保证性能,建议使用Primitive方式。
entity和primitives的处理逻辑稍有不同,正因如此,我们需要针对entity和primitives分开写
//绑定鼠标移动到实体上时候的事件 viewer.screenSpaceEventHandler.setInputAction(function onMouseMove( movement ) { var pickedFeature = viewer.scene.pick(movement.endPosition); var selectedEntity = null; if(Cesium.defined(pickedFeature)){ //如果指到primitive,因为其不能调整轮廓,所以当作空地处理 //也可以用 pickedFeature instanceof Cesium.Cesium3DTileFeature 来判断,这样更好一些 if(typeof(pickedFeature.id) == "undefined"){ that.space=1; return; } selectedEntity = entityCollection.getById(pickedFeature.id.id); selectedEntity.model.silhouetteSize=2; if(that.selectedEntity==null){ that.selectedEntity=selectedEntity; return; } //只是在同一模型内部动 if(selectedEntity._id === that.selectedEntity._id && that.space==0){ return; } //从一个模型直接滑动到另一个模型 else if(selectedEntity._id != that.selectedEntity._id) { selectedEntity.model.silhouetteSize=2; that.selectedEntity.model.silhouetteSize=0; that.selectedEntity=selectedEntity; that.space=0; } //经过空白 else if(that.space==1){ selectedEntity.model.silhouetteSize=2; that.space=0; } } //指到空地 else if(!Cesium.defined(pickedFeature) && that.selectedEntity!=null ){ that.selectedEntity.model.silhouetteSize=0; that.space=1; } },Cesium.ScreenSpaceEventType.MOUSE_MOVE);
这是针对entity的代码,而我找了一圈,并没有在primitives中找到silhouetteSize之类的属性
所以如果实在需要的话,就还是用entity加载3dtile