首页 / 浏览问题 / 三维GIS / 问题详情
setInputAction和pickEvent
216EXP 2019年03月19日

webgl的三维场景中,同时设置了setInputAction事件和pickEvent事件,需求是在setInputAction事件中,当鼠标在场景中移动时弹出一些监测站点的属性信息;在pickEvent事件中,单击场景中的三维模型,弹出模型的信息。

但是现在setInputAction能在鼠标移动的过程中弹出监测站点的信息,此需求已经满足;但问题是在鼠标移动的过程中也同时会选中三维场景中的模型,如三维管点模型(雨水井、雨水篦等)。而我的需求是在鼠标移动的过程中不要选中管点模型,而是在pickEvent事件中去选中三维管点模型并弹出其属性信息。

1.以上需求需要怎么做呢?超图webgl中有没有setInputAction或者pickEvent的对应事件?

2.setInputAction事件和pickEvent事件在调用的时候先后顺序是什么呢?setInputAction事件和pickEvent事件二者有什么关系呢?

setInputAction的代码如下:

        var Cesium=window.Cesium;
        var _this=this;
        var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
        // handler.setInputAction(function(click) {
        //     var mousePosition = click.position;
        //
        //     var pick = viewer.scene.pick(mousePosition,10,10);
        //     if(typeof (pick)!=="undefined"){
        //         console.log("ScreenSpaceEventType.LEFT_CLICK:",pick);
        //     }
        //     // if(typeof(callback)==="function"){
        //     //     callback(sceneposition);
        //     // }
        // }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        handler.setInputAction(function(click) {
            var mousePosition = click.endPosition;
            var pick = viewer.scene.pick(mousePosition,5,5);
            if(typeof (pick)!=="undefined"&&typeof (pick.id)!=="undefined"){
                var layername=pick.id.name;
                switch (layername) {
                    case "RGCY":
                        var sceneposition = viewer.scene.pickPosition(mousePosition);
                        if (!sceneposition) {
                            sceneposition = Cesium.Cartesian3.fromDegrees(0, 0, 0);
                        }
                        thisMapCon.setscenePosition(sceneposition);
                        _this._RGCYproshow(pick);
                        break;
                    default:
                        $("#bubble").hide();
                        break;
                }

            }else{
                $("#bubble").hide();
            }
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

pickEvent的代码如下:

             function (feature) {
                var entity = viewer.selectedEntity;

                if (feature.PLPTNO !== undefined) {
                    axios.get(url + 'plptno=' + feature.PLPTNO + '&mntpcd=' + feature.MNTPCD)
                        .then(function (response) {
                            // handle success
                            // console.log(response);
                            let res = response.data.data;
                            showBubble(res, entity);
                        })
                        .catch(function (error) {
                            // handle error
                            // console.log(error);
                            alert(error +url+ "服务未启动!");
                        })
                        .then(function () {
                            // always executed
                        });
                } else {
                    axios.get(url + 'plid=' + feature.PLID + '&mntpcd=' + feature.MNTPCD)
                        .then(function (response) {
                            // handle success
                            // console.log(response);
                            let res = response.data.data;
                            showBubble(res, entity);
                        })
                        .catch(function (error) {
                            // handle error
                            // console.log(error);
                            alert(error +url+ "服务未启动!");
                        })
                        .then(function () {
                            // always executed
                        });
                }

1个回答

您在执行setInputAction事件的时候,将模型设置为不可选中。

selectEnabled : Boolean

获取或者设置图层是否可选。
6,215EXP 2019年03月20日
 var entity = viewer.selectedEntity;
        entity.selectEnabled =false;

1.你说的模型设置为不可选,是上面那个代码吗?上面这个代码报错;

2.涂岑比较多,有三十多个,遍历图层分别设置不可选会损耗前端性能。

已在QQ回复
图层是否可选只能针对某一图层,如果设置三十多个图层不可选,每个图层都需要设置。三十多个图层对前端性能损耗不大
...