调试osgEarth(七)地图map图层的构建过程-添加layer(1)

首先感谢@hankern

学习链接https://blog.youkuaiyun.com/hankern/article/details/83933900

现在周六,看看周末能不能把这节了结了,加油。

 

先回顾下流程,熟悉下自己的位置

看看总体流程

从conf->node->mapNode。目前在node

再往下走,是根据mapOption->map初始化->map加各种层。目前在map初始化

从map初始化看,Profile->_readOptions->cacheSettings(cache设置)->LayerCB(层变化时引起回调)->ElevationPool,目前结束.

下一步该进行map加各种层了。也就是map真正要起作用了

递归

 

这里到关键词Image了,影像层

跟进去

image有3个children,driver,name和url

可以看到,image的children,key =driver时,value = gdal

下一步要改key了,image->GDALImage

因为key发生了变化,key0!= c.key()了,所以下面的条件也满足,继续跟进去,把已经运行过的children=key去掉

 

继续遍历其它两个child

因为base.earth只有影像,所以只有一个image的driver起作用,

多了一个key,GDALI

### OGRFeatureSource 图层功能介绍 OGRFeatureSource 是 osgEarth 中用于加载和渲染基于 OGR(GDAL 的矢量数据访问库)支持的矢量图层的一种图层类型。该图层可以读取多种格式的矢量数据,包括但不限于 Shapefile、GeoJSON、KML、PostGIS、CSV 等,适用于地图中点、线、面要素的可视化展示[^1]。 OGRFeatureSource 的主要功能包括: - **矢量数据加载**:支持从本地文件、数据库或网络资源加载矢量数据。 - **样式化渲染**:支持通过 `osgEarth::Style` 定义图层的显示样式,如颜色、线宽、填充模式等。 - **空间索引构建**:在加载过程中可自动构建空间索引,提高大规模矢量数据的渲染效率。 - **动态更新与交互**:结合 osgEarth 的交互机制,可实现矢量要素的动态高亮、查询和交互操作。 ### 使用指南 #### 1. 创建 OGRFeatureSource 图层 首先,需准备一个 OGR 支持的矢量数据文件(如 Shapefile)。以下是一个创建 OGRFeatureSource 图层并将其添加地图的示例代码: ```cpp osg::Geode* createOGRFeatureLayer(const std::string& filePath, const osgEarth::Style& style) { osgEarth::ImageLayerOptions options("ogr_layer"); options.setURL(filePath); // 设置样式 options.style() = style; // 创建图层 osg::Geode* geode = new osg::Geode(); osgEarth::ModelLayer* layer = new osgEarth::ModelLayer(options); geode->addDrawable(layer->getDrawable()); return geode; } ``` #### 2. 设置图层样式 通过 `osgEarth::Style` 可定义图层的外观样式,例如点、线、面的绘制方式: ```cpp osgEarth::Style createLineStyle() { osgEarth::Style style; style.getOrCreate<osgEarth::LineSymbol>()->stroke()->color() = osgEarth::Color::Red; style.getOrCreate<osgEarth::LineSymbol>()->stroke()->width() = 2.0f; return style; } osgEarth::Style createPolygonStyle() { osgEarth::Style style; style.getOrCreate<osgEarth::PolygonSymbol>()->fill()->color() = osgEarth::Color::Blue; style.getOrCreate<osgEarth::PolygonSymbol>()->fill()->alpha() = 0.5f; return style; } ``` #### 3. 添加图层地图 将创建的图层添加到 `osgEarth::Map` 或 `osgViewer::View` 中进行渲染: ```cpp osgViewer::View* view = new osgViewer::View(); osg::Group* root = new osg::Group(); osg::Geode* featureLayer = createOGRFeatureLayer("path/to/your/data.shp", createLineStyle()); root->addChild(featureLayer); view->setSceneData(root); ``` #### 4. 性能优化建议 - **启用空间索引**:对于大规模矢量数据,建议在创建图层时启用空间索引,以提升渲染效率: ```cpp options.spatialReference() = osgEarth::SpatialReference::get("wgs84"); options.cachePolicy() = osgEarth::CachePolicy::USAGE_READ_ONLY; ``` - **LOD 控制**:通过设置图层的 LOD 范围,控制矢量图层在不同缩放级别下的显示状态,避免低层级下渲染过多数据: ```cpp options.minLevel() = 5; options.maxLevel() = 12; ``` - **动态更新**:若图层数据需动态更新,建议结合 `osg::Geode` 和 `osg::GeodeCallback` 实现增量更新,避免频繁重建整个图层--- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值