在osgearth3.2版本中如何为地球添加经纬线呢
我在osgearth官网上看到一个添加经纬度的API,但找了好多地方都没有看到它是怎么用的
如下是官网提示:
如下为期望效果,但这篇博客的osgearth版本是2点几,中间有些函数不适用(参考https://blog.csdn.net/ljjjjjjjjjjj/article/details/119878098?ops_request_misc=&request_id=&biz_id=102&utm_term=osgearth%E7%BB%8F%E7%BA%AC%E7%BA%BF&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-119878098.142^v86^insert_down38v5,239^v2^insert_chatgpt&spm=1018.2226.3001.4449):
求指点
软件运行环境为KVM虚拟系统,虚拟系统为Win7 SP1 64位专业版。
启动运行项目软件的操作系统都是虚拟系统,终端机为千元左右的低配NUC主机,通过终端机访问服务器的KVM虚拟系统实现对系统和软件的操作。
我虽然是资深的IT专家,但是我的主要领域不在osgearth上,因此无法提供完整的代码解决方案。但是根据我了解到的osgearth API文档和示例,以下是可能的解决方案:
// 创建一个经线 osg::ref_ptr feature = new osgEarth::Features::Feature(new osgEarth::Symbology::LineString(osgEarth::Symbology::Geometry::TYPE_LINESTRING)); feature->getOrCreateProperties()["name"] = "Longitude Line"; osgEarth::Features::FeatureList featureList; featureList.push_back(feature.get()); osgEarth::Features::FeatureSource* featureSource = new osgEarth::Features::FeatureSource(new osgEarth::Features::FeatureModelSource(featureList)); osg::ref_ptr layer = new osgEarth::Annotation::AnnotationLayer(); layer->setName("Longitude Line Layer"); layer->getOrCreateStateSet()->setRenderBinDetails(0, "RenderBin"); layer->addChild(new osgEarth::Annotation::FeatureNode(feature.get(), new osgEarth::Annotation::LocalGeometryNodePolicy())); osg_earth_map->addLayer(layer);
// 创建一个纬线 // 与创建经线的方法类似,只是要使用osgEarth::Symbology::Geometry::TYPE_LINEPOLYGON作为线类型,同时要设置填充颜色和线宽等属性
// 创建水平线段 osgEarth::Util::SDFGeometryOptions lineOpts; lineOpts.name() = "My Line"; lineOpts.fill() = osgEarth::Symbology::Color::Transparent; lineOpts.stroke() = osgEarth::Symbology::Color::Red; lineOpts.lineSymbol()->stroke()->width() = 2.0f; lineOpts.addLine(osg::Vec3d(0.0, 0.0, 0.0), osg::Vec3d(1.0, 0.0, 0.0)); osg::ref_ptr lineNode = new osgEarth::Annotation::FeatureNode(osgEarth::Features::Feature::create(lineOpts.create()));
// 创建竖直线段 // 与创建水平线段的方法类似,只是要修改起点和终点的坐标
// 读取经纬线图层文件 std::string vectorFile = "/path/to/line.shp"; osg::ref_ptr vectorSource = osgEarth::Features::FeatureSourceFactory::create("shp", osgEarth::ConfigOptions("file://" + vectorFile));
// 创建经纬线图层 osg::ref_ptr vectorLayer = new osgEarth::Annotation::AnnotationLayer(); vectorLayer->setName("Vector Line Layer"); vectorLayer->getOrCreateStateSet()->setRenderBinDetails(0, "RenderBin"); vectorLayer->addChild(new osgEarth::Annotation::FeaturesNode(vectorSource.get())); osg_earth_map->addLayer(vectorLayer);
以上是几种可能的解决方案,可根据实际需求选择适合的方法。希望能对你有所帮助。