Skip to content

Commit

Permalink
Replaced earth file with programmatic map construction
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Jul 5, 2011
1 parent 4c36e58 commit 4408185
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 71 deletions.
3 changes: 0 additions & 3 deletions src/plugins/globe/CMakeLists.txt
Expand Up @@ -69,8 +69,5 @@ INSTALL(TARGETS globeplugin
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

INSTALL (FILES images/world.tif globe.earth
DESTINATION ${QGIS_DATA_DIR}/globe)

INSTALL (DIRECTORY data images/gui
DESTINATION ${QGIS_DATA_DIR}/globe)
45 changes: 0 additions & 45 deletions src/plugins/globe/globe.earth

This file was deleted.

55 changes: 32 additions & 23 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -50,6 +50,7 @@
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/TileSource>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthDrivers/gdal/GDALOptions>
#include "WorldWindOptions"
#include <osgEarthDrivers/tms/TMSOptions>
Expand Down Expand Up @@ -227,6 +228,8 @@ void GlobePlugin::run()
// install the programmable manipulator.
osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
viewer.setCameraManipulator( manip );
// add a handler that will automatically calculate good clipping planes
//viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() );

setupMap();

Expand Down Expand Up @@ -272,38 +275,41 @@ void GlobePlugin::settings()

void GlobePlugin::setupMap()
{
// read base layers from earth file
QString earthFileName = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/globe.earth" );
QFile earthFileTemplate( earthFileName );
if( !earthFileTemplate.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
return;
}

QTextStream in( &earthFileTemplate );
QString earthxml = in.readAll();
QSettings settings;
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
earthxml.replace( "/home/pi/devel/gis/qgis/.qgis/cache", cacheDirectory );
earthxml.replace( "/usr/share/osgearth/data", QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe" ) );
TMSCacheOptions cacheOptions;
cacheOptions.setPath(cacheDirectory.toStdString());

MapOptions mapOptions;
mapOptions.cache() = cacheOptions;
osgEarth::Map *map = new osgEarth::Map(mapOptions);

//Default image layer
GDALOptions driverOptions;
driverOptions.url() = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/world.tif" ).toStdString();
ImageLayerOptions layerOptions( "world", driverOptions );
layerOptions.cacheEnabled() = false;
map->addImageLayer( new osgEarth::ImageLayer( layerOptions ) );

MapNodeOptions nodeOptions;
//nodeOptions.proxySettings() =
//nodeOptions.enableLighting() = false;

//LoadingPolicy loadingPolicy( LoadingPolicy::MODE_SEQUENTIAL );
TerrainOptions terrainOptions;
//terrainOptions.loadingPolicy() = loadingPolicy;
nodeOptions.setTerrainOptions( terrainOptions );

// The MapNode will render the Map object in the scene graph.
mMapNode = new osgEarth::MapNode( map, nodeOptions );

//prefill cache
if( !QFile::exists( cacheDirectory + "/worldwind_srtm" ) )
{
copyFolder( QgsApplication::pkgDataPath() + "/globe/data/worldwind_srtm", cacheDirectory + "/globe/worldwind_srtm" );
}

std::istringstream istream( earthxml.toStdString() );
osg::Node* node = osgDB::readNodeFile( earthFileName.toStdString() ); //TODO: from istream earthFile.readXML( istream, earthFileName.toStdString() )
if( !node )
{
return;
}

mRootNode = new osg::Group();

// The MapNode will render the Map object in the scene graph.
mMapNode = MapNode::findMapNode( node );
mRootNode->addChild( mMapNode );

// Add layers to the map
Expand Down Expand Up @@ -677,8 +683,11 @@ void GlobePlugin::layersChanged()
else if ( "Worldwind" == type )
{
WorldWindOptions options;
//TODO: <heightfield name=\"WorldWind bil\" driver=\"worldwind\"><worldwind_cache>" + cacheDirectory.toStdString() + "/globe/worldwind_srtm";
options.elevationCachePath() = cacheDirectory.toStdString() + "/globe/worldwind_srtm";
layer = new osgEarth::ElevationLayer( "WorldWind bil", options );
TerrainEngineNode* terrainEngineNode = mMapNode->getTerrainEngine();
terrainEngineNode->setVerticalScale(2);
terrainEngineNode->setElevationSamplingRatio(0.25);
}
else if ( "TMS" == type )
{
Expand Down

0 comments on commit 4408185

Please sign in to comment.