osgEarth开发之三维矢量数据的鼠标选择功能

论坛 期权论坛 期权     
匿名网站用户   2020-12-20 00:44   5998   0
首先,为了可以实现矢量数据的选择,在矢量数据的加载过程中earth文件需要包含
<feature_indexing>true</feature_indexing>
否则,选择不成功
或者在程序中添加代码


osgEarth::Features::FeatureSourceIndexOptions psindexOption;
psindexOption.embedFeatures() = true;
geomOptions.featureIndexing() = psindexOption;




(2)osgEarth为实现矢量数据的点选,设计了一个FeatureQueryTool类,这个类继承自GUIEventHandler类,
其中有个Callback接口
struct Callback : public osg::Referenced
{
struct EventArgs
{
const osgGA::GUIEventAdapter* _ea;
osgGA::GUIActionAdapter* _aa;
osg::Vec3d _worldPoint;
};


// called when a valid feature is found under the mouse coords
virtual void onHit( FeatureSourceIndexNode* index, FeatureID fid, const EventArgs& args ) { }


// called when no feature is found under the mouse coords
virtual void onMiss( const EventArgs& args ) { }
};


该接口定义了单击的事件onHit和onMiss


FeatureQueryTool类定义了成员变量
typedef std::vector< osg::observer_ptr<Callback> > Callbacks;
Callbacks _callbacks;


在handle()函数中可以发现,单击事件挨个调用_callbacks中的函数


在handle()函数中
首先判断鼠标事件是否是release以及一系列的判断
然后定义一个Picker类;
Picker picker(
dynamic_cast<osgViewer::View*>(view),
getMapNode()->getModelLayerGroup() );
并定义一个Intersections
Picker::Hits hits;
typedef osgEarth::PrimitiveIntersector::Intersections Hits;


然户调用picker.pick(ea.getX(), ea.getY(), hits )函数


得到Intersections,再取得onHit函数所需要的参数


调用该函数。


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP