怎么获取osgEarth::Layer的osgEarth::FeatureSource
时间: 2024-05-04 08:19:22 浏览: 150
要获取 `osgEarth::Layer` 的 `osgEarth::FeatureSource`,可以使用以下方法:
```cpp
osgEarth::FeatureSource* getFeatureSource(osgEarth::Layer* layer)
{
osgEarth::Features::FeatureModelLayer* featureModelLayer = dynamic_cast<osgEarth::Features::FeatureModelLayer*>(layer);
if (featureModelLayer)
{
return featureModelLayer->getFeatureSource();
}
osgEarth::Features::FeatureSourceLayer* featureSourceLayer = dynamic_cast<osgEarth::Features::FeatureSourceLayer*>(layer);
if (featureSourceLayer)
{
return featureSourceLayer->getFeatureSource();
}
return NULL;
}
```
该方法首先尝试将 `osgEarth::Layer` 转换为 `osgEarth::Features::FeatureModelLayer`,如果转换成功,则返回 `FeatureModelLayer` 的 `FeatureSource`。如果转换失败,则尝试将 `osgEarth::Layer` 转换为 `osgEarth::Features::FeatureSourceLayer`,如果转换成功,则返回 `FeatureSourceLayer` 的 `FeatureSource`。如果转换失败,则返回 `NULL`。
阅读全文