osgearth_annotation.rar

  • 南一山
    了解作者
  • C/C++
    开发工具
  • 3KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 4
    下载次数
  • 2019-12-12 16:15
    上传日期
osgEarth例子之一;通过geoSRS,精确坐标,添加标注、国名,图形;例:GeoPoint(geoSRS,-118.40, 33.93), "Los Angeles" )
osgearth_annotation.rar
  • osgearth_annotation.cpp
    15.1KB
内容介绍
/* -*-c++-*- */ /* osgEarth - Geospatial SDK for OpenSceneGraph * Copyright 2019 Pelican Mapping * http://osgearth.org * * osgEarth is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> */ #include <osgEarth/MapNode> #include <osgEarthUtil/EarthManipulator> #include <osgEarthUtil/ExampleResources> #include <osgEarthAnnotation/ImageOverlay> #include <osgEarthAnnotation/CircleNode> #include <osgEarthAnnotation/RectangleNode> #include <osgEarthAnnotation/EllipseNode> #include <osgEarthAnnotation/PlaceNode> #include <osgEarthAnnotation/LabelNode> #include <osgEarthAnnotation/LocalGeometryNode> #include <osgEarthAnnotation/FeatureNode> #include <osgEarthAnnotation/ModelNode> #include <osgEarthAnnotation/AnnotationEditing> #include <osgEarthAnnotation/ImageOverlayEditor> #include <osgEarthSymbology/GeometryFactory> #include <osgViewer/Viewer> using namespace osgEarth; using namespace osgEarth::Annotation; using namespace osgEarth::Features; using namespace osgEarth::Util; //------------------------------------------------------------------ int usage( char** argv ) { OE_WARN << "Usage: " << argv[0] << " <earthfile>" << std::endl; return -1; } //------------------------------------------------------------------ int main(int argc, char** argv) { osg::Group* root = new osg::Group(); // try to load an earth file. osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); viewer.setCameraManipulator( new EarthManipulator() ); // load an earth file and parse demo arguments osg::Node* node = MapNodeHelper().load(arguments, &viewer); if ( !node ) return usage(argv); root->addChild( node ); // find the map node that we loaded. MapNode* mapNode = MapNode::findMapNode(node); if ( !mapNode ) return usage(argv); // Group to hold all our annotation elements. osg::Group* annoGroup = new osg::Group(); MapNode::get(node)->addChild( annoGroup ); // Make a group for labels osg::Group* labelGroup = new osg::Group(); annoGroup->addChild( labelGroup ); osg::Group* editGroup = new osg::Group(); MapNode::get(node)->addChild( editGroup ); // Style our labels: Style labelStyle; labelStyle.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_CENTER_CENTER; labelStyle.getOrCreate<TextSymbol>()->fill()->color() = Color::Yellow; // A lat/long SRS for specifying points. const SpatialReference* geoSRS = mapNode->getMapSRS()->getGeographicSRS(); //-------------------------------------------------------------------- // A series of place nodes (an icon with a text label) { Style pm; pm.getOrCreate<IconSymbol>()->url()->setLiteral( "../data/placemark32.png" ); pm.getOrCreate<IconSymbol>()->declutter() = true; pm.getOrCreate<TextSymbol>()->halo() = Color("#5f5f5f"); // bunch of pins: 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)); // test with an 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)); } //-------------------------------------------------------------------- // a box that follows lines of latitude (rhumb line interpolation, the default) // and flashes on and off using a cull callback. { struct C : public osg::NodeCallback { void operator()(osg::Node* n, osg::NodeVisitor* nv) { static int i=0; i++; if (i % 100 < 50) traverse(n, nv); } }; 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() = 75000; geomStyle.getOrCreate<altitudeSymbol rel='nofollow' onclick='return false;'>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN; geomStyle.getOrCreate<altitudeSymbol rel='nofollow' onclick='return false;'>()->technique() = AltitudeSymbol::TECHNIQUE_GPU; FeatureNode* fnode = new FeatureNode(feature, geomStyle); fnode->addCullCallback(new C()); annoGroup->addChild( fnode ); LabelNode* label = new LabelNode("Rhumb line polygon", labelStyle); label->setPosition(GeoPoint(geoSRS, -30, 50)); labelGroup->addChild(label); } //-------------------------------------------------------------------- // another rhumb box that crosses the antimeridian { Geometry* geom = new Polygon(); geom->push_back( -160., -30. ); geom->push_back( 150., -20. ); geom->push_back( 160., -45. ); geom->push_back( -150., -40. ); Style geomStyle; Feature* feature = new Feature(geom, geoSRS); feature->geoInterp() = GEOINTERP_RHUMB_LINE; geomStyle.getOrCreate<LineSymbol>()->stroke()->color() = Color::Lime; geomStyle.getOrCreate<LineSymbol>()->stroke()->width() = 3.0f; geomStyle.getOrCreate<LineSymbol>()->tessellationSize() = 75000; geomStyle.getOrCreate<altitudeSymbol rel='nofollow' onclick='return false;'>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN; geomStyle.getOrCreate<altitudeSymbol rel='nofollow' onclick='return false;'>()->technique() = AltitudeSymbol::TECHNIQUE_GPU; FeatureNode* gnode = new FeatureNode(feature, geomStyle); annoGroup->addChild( gnode ); LabelNode* label = new LabelNode("Antimeridian polygon", labelStyle); label->setPosition(GeoPoint(geoSRS, -175, -35)); labelGroup->addChild(label); } //-------------------------------------------------------------------- // A path using great-circle interpolation. // Keep a pointer to it so we can modify it later on. FeatureNode* pathNode = 0; { Geome
评论
    相关推荐
    • osg例子.zip
      展示鼠标位置的显示:经纬度,APIs生成,初学者可用
    • osgEarth-and-Floyd-.zip
      一个基于Floyd算法的三维城市漫游系统论文
    • MFC-OsgEarth.rar
      转载mfc下osgEarth工程,sdk 版本osgEarth 2.7 32bit,vs2015编译
    • osgEarth_Annotation-master.zip
      OSG 学习过程案例代码,主要关于osgearth
    • osg_pointcloud.rar
      基于OSG的点云绘制程序,附上点云数据样式文件
    • osgearth1.rar
      使用osg实现地球加载功能,osg入门很好的参考代码,亲测可运行,vs2010环境。
    • osgearth+mfc.rar
      osgearth 与MFC结合使用,一个简单的地球。适合初学者使用
    • OsgEarthMFC.zip
      osgearth 与MFC结合使用,一个简单的地球。适合初学者使用,欢迎下载
    • osgearth-MFC
      vc2008中在MFC读取.EARTH文件
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等