首先,为了可以实现矢量数据的选择,在矢量数据的加载过程中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函数所需要的参数
调用该函数。

|
|