Skip to content

拾取对象

操作鼠标触发事件

Javascript
var handler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
   handler.setInputAction(function(movement) {
       //movement.position当前的屏幕坐标
       var posit = viewer.scene.pickPosition(movement.position);

   }, LSGlobe.ScreenSpaceEventType.LEFT_CLICK);
//LEFT_DOWN左键按下时触发
//LEFT_UP 左键弹起时触发
//LEFT_CLICK 左击时触发
//RIGHT_CLICK 右击时触发
//DOUBLE_CLICK 双击时触发
//MOUSE_MOVE 鼠标移动时触发
//注销鼠标事件
//Handler.destroy();

拾取场景对象

Javascript
var handler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(movement) {
    viewer.scene.useDepthPicking = false;
    var aPickObj = scene.drillPick(movement.position);
    viewer.scene.useDepthPicking = true;
    for (var i = 0; i < aPickObj.length; i++) {
        var posit = aPickObj[i];
        if (posit.id && posit.id.billboard && posit.id.label) {
            //posit.id就是标会点对象
        }
    }
}, LSGlobe.ScreenSpaceEventType.LEFT_CLICK);

示例代码 code

code示例地址

Released under the MIT License.