osgEarth 2.1.1
|
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/Controls>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osgDB/ReadFile>
Go to the source code of this file.
Classes | |
struct | MyMapListener |
struct | LayerEnabledHandler |
struct | LayerOpacityHandler |
struct | AddLayerHandler |
struct | RemoveLayerHandler |
struct | MoveLayerHandler |
Functions | |
osg::Node * | createControlPanel (osgViewer::View *) |
void | updateControlPanel () |
int | main (int argc, char **argv) |
void | createLayerItem (int gridRow, int layerIndex, int numLayers, ImageLayer *layer, bool isActive) |
Variables | |
static osg::ref_ptr< Map > | s_activeMap |
static osg::ref_ptr< Map > | s_inactiveMap |
static Grid * | s_layerBox |
static bool | s_updateRequired = true |
osg::Node* createControlPanel | ( | osgViewer::View * | view | ) |
void createLayerItem | ( | int | gridRow, |
int | layerIndex, | ||
int | numLayers, | ||
ImageLayer * | layer, | ||
bool | isActive | ||
) |
Definition at line 180 of file osgearth_toc.cpp.
{ // a checkbox to enable/disable the layer: CheckBoxControl* enabled = new CheckBoxControl( layer->getEnabled() ); enabled->addEventHandler( new LayerEnabledHandler(layer) ); s_layerBox->setControl( 0, gridRow, enabled ); // the layer name LabelControl* name = new LabelControl( layer->getName() ); s_layerBox->setControl( 1, gridRow, name ); // an opacity slider HSliderControl* opacity = new HSliderControl( 0.0f, 1.0f, layer->getOpacity() ); opacity->setWidth( 125 ); opacity->setHeight( 12 ); opacity->addEventHandler( new LayerOpacityHandler(layer) ); s_layerBox->setControl( 2, gridRow, opacity ); // move buttons if ( layerIndex < numLayers-1 && isActive ) { LabelControl* upButton = new LabelControl( "UP", 14 ); upButton->setBackColor( .4,.4,.4,1 ); upButton->setActiveColor( .8,0,0,1 ); upButton->addEventHandler( new MoveLayerHandler( layer, layerIndex+1 ) ); s_layerBox->setControl( 3, gridRow, upButton ); } if ( layerIndex > 0 && isActive) { LabelControl* upButton = new LabelControl( "DOWN", 14 ); upButton->setBackColor( .4,.4,.4,1 ); upButton->setActiveColor( .8,0,0,1 ); upButton->addEventHandler( new MoveLayerHandler( layer, layerIndex-1 ) ); s_layerBox->setControl( 4, gridRow, upButton ); } // add/remove button: LabelControl* addRemove = new LabelControl( isActive? "REMOVE" : "ADD", 14 ); addRemove->setHorizAlign( Control::ALIGN_CENTER ); addRemove->setBackColor( .4,.4,.4,1 ); addRemove->setActiveColor( .8,0,0,1 ); if ( isActive ) addRemove->addEventHandler( new RemoveLayerHandler(layer) ); else addRemove->addEventHandler( new AddLayerHandler(layer) ); s_layerBox->setControl( 5, gridRow, addRemove ); }
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 51 of file osgearth_toc.cpp.
{ osg::ArgumentParser arguments( &argc,argv ); // load a graph from the command line osg::Node* node = osgDB::readNodeFiles( arguments ); // make sure we loaded a .earth file osgEarth::MapNode* mapNode = MapNode::findMapNode( node ); if ( !mapNode ) { OE_WARN << "No osgEarth MapNode found in the loaded file(s)." << std::endl; return -1; } // the displayed Map: s_activeMap = mapNode->getMap(); s_activeMap->addMapCallback( new MyMapListener() ); // a Map to hold inactive layers (layers that have been removed from the displayed Map) s_inactiveMap = new Map(); s_inactiveMap->addMapCallback( new MyMapListener() ); // configure the viewer. osgViewer::Viewer viewer( arguments ); osg::Group* root = new osg::Group(); // install the control panel root->addChild( createControlPanel( &viewer ) ); root->addChild( node ); // update the control panel with the two Maps: updateControlPanel(); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler( new osgViewer::StatsHandler() ); viewer.setSceneData( root ); // install a proper manipulator viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() ); while( !viewer.done() ) { viewer.frame(); if ( s_updateRequired ) { updateControlPanel(); s_updateRequired = false; } } }
void updateControlPanel | ( | ) |
Definition at line 229 of file osgearth_toc.cpp.
{ // erase all child controls and just rebuild them b/c we're lazy. s_layerBox->clearControls(); int row = 0; LabelControl* activeLabel = new LabelControl( "Map Layers", 20, osg::Vec4f(1,1,0,1) ); s_layerBox->setControl( 1, row++, activeLabel ); // the active map layers: MapFrame mapf( s_activeMap.get(), Map::IMAGE_LAYERS ); int layerNum = mapf.imageLayers().size()-1; for( ImageLayerVector::const_reverse_iterator i = mapf.imageLayers().rbegin(); i != mapf.imageLayers().rend(); ++i ) createLayerItem( row++, layerNum--, mapf.imageLayers().size(), i->get(), true ); MapFrame mapf2( s_inactiveMap.get(), Map::IMAGE_LAYERS ); if ( mapf2.imageLayers().size() > 0 ) { LabelControl* inactiveLabel = new LabelControl( "Removed:", 18, osg::Vec4f(1,1,0,1) ); s_layerBox->setControl( 1, row++, inactiveLabel ); for( unsigned int i=0; i<mapf2.imageLayers().size(); ++i ) { createLayerItem( row++, -1, -1, mapf2.getImageLayerAt(i), false ); } } }
osg::ref_ptr<Map> s_activeMap [static] |
Definition at line 34 of file osgearth_toc.cpp.
osg::ref_ptr<Map> s_inactiveMap [static] |
Definition at line 35 of file osgearth_toc.cpp.
Grid* s_layerBox [static] |
Definition at line 36 of file osgearth_toc.cpp.
bool s_updateRequired = true [static] |
Definition at line 37 of file osgearth_toc.cpp.