目标:(一零零)中的问题180
1、瓦片何时删除的事件是无法监听(rex没有提供相应的机制),貌似意义也不大
2、瓦片的添加监听步骤如下:
2.1瓦片在创建、有高程修改时会发出通知
osgEarthDrivers/engine_rex/TileNode.cpp
void
TileNode::create(const TileKey& key, TileNode* parent, EngineContext* context)
{
context->getEngine()->getTerrain()->notifyTileAdded(getKey(), this);
}
void
TileNode::merge(const TerrainTileModel* model, const RenderBindings& bindings)
{
if (newElevationData)
{
_context->getEngine()->getTerrain()->notifyTileAdded(getKey(), this);
}
}
2.2如果存在监听回调类,地形服务接口会在更新队列里添加一个通知操作。
osgEarth/Terrain.cpp
void
Terrain::notifyTileAdded( const TileKey& key, osg::Node* node )
{
if (_callbacksSize > 0)
{
_updateQueue->add(new OnTileAddedOperation(key, node, this));
}
}
2.3在更新遍历地形服务接口时,会通知到每一个回调类。
osgEarth/Terrain.cpp
void
Terrain::update()
{
_updateQueue->runOperations();
}
osg/OpenThread.cpp
void OperationQueue::runOperations(Object* callingObject)
{
if (_currentOperationIterator==_operations.end()) _currentOperationIterator = _operations.begin();
for(;
_currentOperationIterator != _operations.end();
)
{
(*operation)(callingObject);
}
}
osgEarth/Terrain.cpp
void Terrain::OnTileAddedOperation::operator()(osg::Object*)
{
terrain->fireTileAdded( _key, node.get() );
}
void
Terrain::fireTileAdded( const TileKey& key, osg::Node* node )
{
for( CallbackList::iterator i = _callbacks.begin(); i != _callbacks.end(); )
{
i->get()->onTileAdded( key, node, context );
}
}
2.4定义回调类,注册回调类,静等回调通知
#ifndef TILEADDCALLBACK_H
#define TILEADDCALLBACK_H
#include <osgEarth/Terrain>
class TileAddCallback:public osgEarth::TerrainCallback
{
public:
TileAddCallback();
// TerrainCallback interface
public:
void onTileAdded(const osgEarth::TileKey &key, osg::Node *graph, osgEarth::TerrainCallbackContext &context);
};
#endif // TILEADDCALLBACK_H
//监听瓦片添加
TileAddC