本文主要是介绍标签注释、基础图元--osgearth_annotation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 功能实现
带注释的标签,基础图元
2.代码解析
创建标牌
//设置样式,style可以获取不同类型的样式进行设置Style pm;pm.getOrCreate<IconSymbol>()->url()->setLiteral( "../data/placemark32.png" );pm.getOrCreate<IconSymbol>()->declutter() = true;pm.getOrCreate<TextSymbol>()->halo() = Color("#5f5f5f");//创建标牌并设置地址与样式labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS, -74.00, 40.71), "New York" , pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS, -77.04, 38.85), "Washington, DC", pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS,-118.40, 33.93), "Los Angeles" , pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS, -71.03, 42.37), "Boston" , pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS,-157.93, 21.35), "Honolulu" , pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS, 139.75, 35.68), "Tokyo" , pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS, -90.25, 29.98), "New Orleans" , pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS, -80.28, 25.82), "Miami" , pm));labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS,-117.17, 32.72), "San Diego" , pm));// 添加一个LOD节点:osg::LOD* lod = new osg::LOD();lod->addChild( new PlaceNode(GeoPoint(geoSRS, 14.68, 50.0), "Prague", pm), 0.0, 2e6);labelGroup->addChild( lod );// absolute altitude:labelGroup->addChild( new PlaceNode(GeoPoint(geoSRS, -87.65, 41.90, 1000, ALTMODE_ABSOLUTE), "Chicago", pm));
代码比较简单,就是创建标牌节点并加入场景
osgearth中的画线
Geometry* geom = new Polygon();//输入点集geom->push_back( osg::Vec3d(0, 40, 0) );geom->push_back( osg::Vec3d(-60, 40, 0) );geom->push_back( osg::Vec3d(-60, 60, 0) );geom->push_back( osg::Vec3d(0, 60, 0) );Feature* feature = new Feature(geom, geoSRS);//使用大地坐标系feature->geoInterp() = GEOINTERP_RHUMB_LINE;//画线Style geomStyle;geomStyle.getOrCreate<LineSymbol>()->stroke()->color() = Color::Cyan;//颜色geomStyle.getOrCreate<LineSymbol>()->stroke()->width() = 5.0f;//宽度geomStyle.getOrCreate<LineSymbol>()->tessellationSize()->set(75000, Units::METERS);//还可以设置平滑度等geomStyle.getOrCreate<RenderSymbol>()->depthOffset()->enabled() = true;//是否开启深度测试FeatureNode* fnode = new FeatureNode(feature, geomStyle);annoGroup->addChild( fnode );
点迹线
Geometry* path = new LineString();path->push_back( osg::Vec3d(-74, 40.714, 0) ); // New Yorkpath->push_back( osg::Vec3d(139.75, 35.68, 0) ); // TokyoFeature* pathFeature = new Feature(path, geoSRS);pathFeature->geoInterp() = GEOINTERP_GREAT_CIRCLE;//球面插值Style pathStyle;pathStyle.getOrCreate<LineSymbol>()->stroke()->color() = Color::White;pathStyle.getOrCreate<LineSymbol>()->stroke()->width() = 1.0f;pathStyle.getOrCreate<LineSymbol>()->stroke()->smooth() = true;pathStyle.getOrCreate<LineSymbol>()->tessellationSize()->set(75000, Units::METERS);//75000米一个点pathStyle.getOrCreate<PointSymbol>()->size() = 8;//点的大小pathStyle.getOrCreate<PointSymbol>()->fill()->color() = Color::Red;pathStyle.getOrCreate<PointSymbol>()->smooth() = true;pathStyle.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;//贴地pathStyle.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_GPU;pathStyle.getOrCreate<RenderSymbol>()->depthOffset()->enabled() = true;//OE_INFO << "Path extent = " << pathFeature->getExtent().toString() << std::endl;pathNode = new FeatureNode(pathFeature, pathStyle);annoGroup->addChild( pathNode );LabelNode* label = new LabelNode("Great circle path", labelStyle);label->setPosition(GeoPoint(geoSRS,-170, 61.2));labelGroup->addChild(label);
画圆
Style circleStyle;circleStyle.getOrCreate<PolygonSymbol>()->fill()->color() = Color(Color::Cyan, 0.5);circleStyle.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;circleStyle.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_DRAPE;CircleNode* circle = new CircleNode();circle->set(GeoPoint(geoSRS, -90.25, 29.98, 1000., ALTMODE_RELATIVE),Distance(300, Units::KILOMETERS),circleStyle,Angle(-45.0, Units::DEGREES),Angle(45.0, Units::DEGREES),true);annoGroup->addChild( circle );
加载模型
{Style style;style.getOrCreate<ModelSymbol>()->autoScale() = true;style.getOrCreate<ModelSymbol>()->url()->setLiteral("../data/red_flag.osg.50.scale");ModelNode* modelNode = new ModelNode(mapNode, style);modelNode->setPosition(GeoPoint(geoSRS, -100, 52));annoGroup->addChild(modelNode);}
加载图片
// an image overlay.{ImageOverlay* imageOverlay = 0L;osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile( "../data/USFLAG.TGA" );if (image.valid()){imageOverlay = new ImageOverlay(mapNode, image.get());imageOverlay->setBounds( Bounds( -100.0, 35.0, -90.0, 40.0) );annoGroup->addChild( imageOverlay );editGroup->addChild( new ImageOverlayEditor(imageOverlay) );}}
椭圆
Style ellipseStyle;ellipseStyle.getOrCreate<PolygonSymbol>()->fill()->color() = Color(Color::Orange, 0.75);ellipseStyle.getOrCreate<ExtrusionSymbol>()->height() = 250000.0; // meters MSLEllipseNode* ellipse = new EllipseNode();ellipse->set(GeoPoint(geoSRS, -80.28, 25.82, 0.0, ALTMODE_RELATIVE),Distance(250, Units::MILES),Distance(100, Units::MILES),Angle (0, Units::DEGREES),ellipseStyle,Angle(45.0, Units::DEGREES),Angle(360.0 - 45.0, Units::DEGREES),true);annoGroup->addChild( ellipse );
矩形
Style rectStyle;rectStyle.getOrCreate<PolygonSymbol>()->fill()->color() = Color(Color::Green, 0.5);rectStyle.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;rectStyle.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_DRAPE;RectangleNode* rect = new RectangleNode(GeoPoint(geoSRS, -117.172, 32.721),Distance(300, Units::KILOMETERS ),Distance(600, Units::KILOMETERS ),rectStyle);annoGroup->addChild( rect );
线装要素和块状要素贴地的设置是不一样的。
//线装要素使用CLAMP_TO_TERRAIN+TECHNIQUE_GPU的组合
as->clamping() = osgEarth::AltitudeSymbol::CLAMP_TO_TERRAIN;
as->technique() = osgEarth::AltitudeSymbol::TECHNIQUE_GPU;
面状要素使用
tStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>()->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN;
tStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>()->technique() = osgEarth::Symbology::AltitudeSymbol
这篇关于标签注释、基础图元--osgearth_annotation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!