osgEarth 2.1.1

/home/cube/sources/osgearth/src/applications/osgearth_map/osgearth_map.cpp

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003 * Copyright 2008-2010 Pelican Mapping
00004 * http://osgearth.org
00005 *
00006 * osgEarth is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU Lesser General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU Lesser General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU Lesser General Public License
00017 * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018 */
00019 
00020 #include <osg/Notify>
00021 #include <osgGA/GUIEventHandler>
00022 #include <osgGA/StateSetManipulator>
00023 #include <osgViewer/Viewer>
00024 #include <osgViewer/ViewerEventHandlers>
00025 #include <osgEarth/MapNode>
00026 #include <osgEarthUtil/EarthManipulator>
00027 #include <osgEarthUtil/AutoClipPlaneHandler>
00028 #include <osgEarthUtil/Controls>
00029 #include <osgEarthSymbology/Color>
00030 #include <osgEarthDrivers/tms/TMSOptions>
00031 
00032 using namespace osgEarth;
00033 using namespace osgEarth::Drivers;
00034 using namespace osgEarth::Util;
00035 
00036 int
00037 main(int argc, char** argv)
00038 {
00039     osg::ArgumentParser arguments(&argc,argv);
00040 
00041     // create the map.
00042     Map* map = new Map();
00043 
00044     // add a TMS imager layer:
00045     TMSOptions imagery;
00046     imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/7/";
00047     map->addImageLayer( new ImageLayer("Imagery", imagery) );
00048 
00049     // add a TMS elevation layer:
00050     TMSOptions elevation;
00051     elevation.url() = "http://readymap.org/readymap/tiles/1.0.0/9/";
00052     map->addElevationLayer( new ElevationLayer("Elevation", elevation) );
00053 
00054     // make the map scene graph:
00055     MapNode* node = new MapNode( map );
00056 
00057     // initialize a viewer:
00058     osgViewer::Viewer viewer(arguments);
00059     viewer.setCameraManipulator( new EarthManipulator );
00060     viewer.setSceneData( node );
00061 
00062     // osgEarth benefits from pre-compilation of GL objects in the pager. In newer versions of
00063     // OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks.
00064     viewer.getDatabasePager()->setDoPreCompile( true );
00065 
00066     // add some stock OSG handlers:
00067     viewer.addEventHandler(new osgViewer::StatsHandler());
00068     viewer.addEventHandler(new osgViewer::WindowSizeHandler());
00069     viewer.addEventHandler(new osgViewer::ThreadingHandler());
00070     viewer.addEventHandler(new osgViewer::LODScaleHandler());
00071     viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
00072     viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
00073 
00074     return viewer.run();
00075 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines