// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); if ( arguments.read("--help") ) return usage( argv[0] ); bool useRaster = arguments.read("--rasterize"); bool useOverlay = arguments.read("--overlay"); bool useStencil = arguments.read("--stencil"); bool useMem = arguments.read("--mem"); bool useLabels = arguments.read("--labels"); if ( useStencil ) osg::DisplaySettings::instance()->setMinimumNumStencilBits( 8 ); osgViewer::Viewer viewer(arguments); // Start by creating the map: Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // Next we add a feature layer. OGRFeatureOptions featureOptions; if ( !useMem ) { // Configures the feature driver to load the vectors from a shapefile: featureOptions.url() = "../data/world.shp"; } else { // the --mem options tells us to just make an in-memory geometry: Ring* line = new Ring(); line->push_back( osg::Vec3d(-60, 20, 0) ); line->push_back( osg::Vec3d(-120, 20, 0) ); line->push_back( osg::Vec3d(-120, 60, 0) ); line->push_back( osg::Vec3d(-60, 60, 0) ); featureOptions.geometry() = line; } // Define a style for the feature data. Since we are going to render the // vectors as lines, configure the line symbolizer: Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>(); ls->stroke()->color() = Color::Yellow; ls->stroke()->width() = 2.0f; // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; MapNode* mapNode = new MapNode( map, mapNodeOptions ); osg::Group* root = new osg::Group(); root->addChild( mapNode ); viewer.setSceneData( root ); viewer.setCameraManipulator( new EarthManipulator() ); // Process cmdline args MapNodeHelper().parse(mapNode, arguments, &viewer, root, new LabelControl("Features Demo")); if (useStencil) { FeatureStencilModelOptions stencilOptions; stencilOptions.featureOptions() = featureOptions; stencilOptions.styles() = new StyleSheet(); stencilOptions.styles()->addStyle( style ); stencilOptions.enableLighting() = false; stencilOptions.depthTestEnabled() = false; ls->stroke()->width() = 0.1f; map->addModelLayer( new ModelLayer("my features", stencilOptions) ); } else if (useRaster) { AGGLiteOptions rasterOptions; rasterOptions.featureOptions() = featureOptions; rasterOptions.styles() = new StyleSheet(); rasterOptions.styles()->addStyle( style ); map->addImageLayer( new ImageLayer("my features", rasterOptions) ); } else //if (useGeom || useOverlay) { FeatureGeomModelOptions geomOptions; geomOptions.featureOptions() = featureOptions; geomOptions.styles() = new StyleSheet(); geomOptions.styles()->addStyle( style ); geomOptions.enableLighting() = false; ModelLayerOptions layerOptions( "my features", geomOptions ); map->addModelLayer( new ModelLayer(layerOptions) ); } if ( useLabels ) { // set up symbology for drawing labels. We're pulling the label // text from the name attribute, and its draw priority from the // population attribute. Style labelStyle; TextSymbol* text = labelStyle.getOrCreateSymbol<TextSymbol>(); text->content() = StringExpression( "[cntry_name]" ); text->priority() = NumericExpression( "[pop_cntry]" ); text->removeDuplicateLabels() = true; text->size() = 16.0f; text->alignment() = TextSymbol::ALIGN_CENTER_CENTER; text->fill()->color() = Color::White; text->halo()->color() = Color::DarkGray; // and configure a model layer: FeatureGeomModelOptions geomOptions; geomOptions.featureOptions() = featureOptions; geomOptions.styles() = new StyleSheet(); geomOptions.styles()->addStyle( labelStyle ); map->addModelLayer( new ModelLayer("labels", geomOptions) ); } if ( !useStencil ) viewer.getCamera()->addCullCallback( new osgEarth::Util::AutoClipPlaneCullCallback(mapNode) ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); bool useRaster = arguments.read("--rasterize"); bool useOverlay = arguments.read("--overlay"); bool useStencil = arguments.read("--stencil"); bool useMem = arguments.read("--mem"); bool useLabels = arguments.read("--labels"); osgViewer::Viewer viewer(arguments); // Start by creating the map: Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // Next we add a feature layer. First configure a feature driver to // load the vectors from a shapefile: OGRFeatureOptions featureOpt; if ( !useMem ) { featureOpt.url() = "../data/usa.shp"; } else { Ring* line = new Ring(); line->push_back( osg::Vec3d(-60, 20, 0) ); line->push_back( osg::Vec3d(-120, 20, 0) ); line->push_back( osg::Vec3d(-120, 60, 0) ); line->push_back( osg::Vec3d(-60, 60, 0) ); featureOpt.geometry() = line; } // Define a style for the feature data. Since we are going to render the // vectors as lines, configure the line symbolizer: Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>(); ls->stroke()->color() = osg::Vec4f( 1,1,0,1 ); // yellow ls->stroke()->width() = 2.0f; // Add some text labels. if ( useLabels ) { TextSymbol* text = style.getOrCreateSymbol<TextSymbol>(); text->provider() = "overlay"; text->content() = StringExpression( "[name]" ); text->priority() = NumericExpression( "[area]" ); text->removeDuplicateLabels() = true; text->size() = 16.0f; text->fill()->color() = Color::White; text->halo()->color() = Color::DarkGray; } // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; MapNode* mapNode = new MapNode( map, mapNodeOptions ); // Now we'll choose the AGG-Lite driver to render the features. By the way, the // feature data is actually polygons, so we override that to treat it as lines. // We apply the feature driver and set the style as well. if (useStencil) { FeatureStencilModelOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); worldOpt.enableLighting() = false; worldOpt.depthTestEnabled() = false; map->addModelLayer( new ModelLayer( "my features", worldOpt ) ); } else if (useRaster) { AGGLiteOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); map->addImageLayer( new ImageLayer( ImageLayerOptions("world", worldOpt) ) ); } else //if (useGeom || useOverlay) { FeatureGeomModelOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); worldOpt.enableLighting() = false; worldOpt.depthTestEnabled() = false; ModelLayerOptions options( "my features", worldOpt ); options.overlay() = useOverlay; map->addModelLayer( new ModelLayer(options) ); } viewer.setSceneData( mapNode ); viewer.setCameraManipulator( new EarthManipulator() ); if ( !useStencil && !useOverlay ) viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }