Skip to content
Permalink
Browse files

Replaced earth file with programmatic map construction

  • Loading branch information
pka committed Mar 6, 2011
1 parent 4c36e58 commit 4408185d3de856656eecf91b752a47b820d0a0db
Showing with 32 additions and 71 deletions.
  1. +0 −3 src/plugins/globe/CMakeLists.txt
  2. +0 −45 src/plugins/globe/globe.earth
  3. +32 −23 src/plugins/globe/globe_plugin.cpp
@@ -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)

This file was deleted.

@@ -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>
@@ -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();

@@ -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
@@ -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 )
{

0 comments on commit 4408185

Please sign in to comment.
You can’t perform that action at this time.