首页 / 浏览问题 / 三维GIS / 问题详情
在鼠标移动事件中,为什么拾取不到S3M对象
21EXP 2020年12月28日

move监听为何获取不到s3m对象?

handler.setInputAction(function (movement) {

                let selectLayer = scene.layers.getSelectedLayer()

                if (selectLayer) {

                    let d = selectLayer.getSelection();

                    selectLayer.setObjsColor(d, new Cesium.Color(1, 0, 0, 1))

                }

            }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

1个回答

selectedLayer意思是被选中的对象。如果想在鼠标移动的时候获取到实体,参考代码

var screenSpaceEventHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

screenSpaceEventHandler.setInputAction(function(movement) {

//最后的屏幕坐标

var haveEn = viewer.scene.pick(movement.endPosition);

if(viewer.scene.pickPositionSupported && Cesium.defined(haveEn) && haveEn.id !== ' '){

clearAlpha();

if(haveEn.id.polygon !== undefined){

var haveEnsNow = haveEn.id.polygon._material._color.getValue();

haveEnsNow.alpha = 1;

haveEn.id.polygon._material._color.setValue(haveEnsNow);

}

}else if(haveEn == undefined){

clearAlpha();

}

}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

function clearAlpha(){

for(var i=0;i

if(viewer.entities.values[i].name == "yanse"){

var haveEnsLast=viewer.entities.values[i]._polygon._material._color.getValue();

haveEnsLast.alpha = 0.2;

viewer.entities.values[i]._polygon._material._color.setValue(haveEnsLast)

}

}

}
6,087EXP 2020年12月28日
...