Skip to content

Commit

Permalink
Default elevation layer for globe
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Oct 5, 2012
1 parent 1a1370f commit 88cd943
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 50 deletions.
90 changes: 48 additions & 42 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -54,7 +54,6 @@
#include <osgEarth/TileSource>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthDrivers/gdal/GDALOptions>
#include "WorldWindOptions"
#include <osgEarthDrivers/tms/TMSOptions>

using namespace osgEarth::Drivers;
Expand Down Expand Up @@ -165,7 +164,7 @@ struct RefreshControlHandler : public ControlEventHandler
RefreshControlHandler( GlobePlugin* globe ) : mGlobe( globe ) { }
virtual void onClick( Control* /*control*/, int /*mouseButtonMask*/ )
{
mGlobe->layersChanged();
mGlobe->imageLayersChanged();
}
private:
GlobePlugin* mGlobe;
Expand Down Expand Up @@ -203,9 +202,9 @@ void GlobePlugin::initGui()
connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
this, SLOT( extentsChanged() ) );
connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
this, SLOT( layersChanged() ) );
this, SLOT( imageLayersChanged() ) );
connect( mSettingsDialog, SIGNAL( elevationDatasourcesChanged() ),
this, SLOT( layersChanged() ) );
this, SLOT( elevationLayersChanged() ) );
connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this,
SLOT( projectReady() ) );
connect( mQGisIface, SIGNAL( newProjectCreated() ), this,
Expand Down Expand Up @@ -325,13 +324,6 @@ void GlobePlugin::setupMap()
imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/7/";
map->addImageLayer( new ImageLayer( "Imagery", imagery ) );

// add a TMS elevation layer:
/*
TMSOptions elevation;
elevation.url() = "http://readymap.org/readymap/tiles/1.0.0/9/";
map->addElevationLayer( new ElevationLayer("Elevation", elevation) );
*/

MapNodeOptions nodeOptions;
//nodeOptions.proxySettings() =
//nodeOptions.enableLighting() = false;
Expand All @@ -340,22 +332,26 @@ void GlobePlugin::setupMap()
TerrainOptions terrainOptions;
//terrainOptions.loadingPolicy() = loadingPolicy;
terrainOptions.compositingTechnique() = TerrainOptions::COMPOSITING_MULTITEXTURE_FFP;
//terrainOptions.lodFallOff() = 6.0;
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" );
}
*/

mRootNode = new osg::Group();
mRootNode->addChild( mMapNode );

// Add layers to the map
layersChanged();
imageLayersChanged();
elevationLayersChanged();

// model placement utils
mElevationManager = new osgEarth::Util::ElevationManager( mMapNode->getMap() );
Expand Down Expand Up @@ -392,8 +388,7 @@ void GlobePlugin::projectReady()

void GlobePlugin::blankProjectReady()
{ //needs at least http://trac.osgeo.org/qgis/changeset/14452
mSettingsDialog->elevationDatasources()->clearContents();
mSettingsDialog->elevationDatasources()->setRowCount( 0 );
mSettingsDialog->resetElevationDatasources();
}

void GlobePlugin::showCurrentCoordinates( double lon, double lat )
Expand Down Expand Up @@ -714,14 +709,50 @@ void GlobePlugin::extentsChanged()
QgsDebugMsg( "extentsChanged: " + mQGisIface->mapCanvas()->extent().toString() );
}

void GlobePlugin::layersChanged()
void GlobePlugin::imageLayersChanged()
{
if ( mIsGlobeRunning )
{
QgsDebugMsg( "imageLayersChanged: Globe Running, executing" );
osg::ref_ptr<Map> map = mMapNode->getMap();

if ( map->getNumImageLayers() > 1 )
{
mOsgViewer->getDatabasePager()->clear();
}

//remove QGIS layer
if ( mQgisMapLayer )
{
QgsDebugMsg( "removeMapLayer" );
map->removeImageLayer( mQgisMapLayer );
}

//add QGIS layer
QgsDebugMsg( "addMapLayer" );
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
mTileSource->initialize( "", 0 );
ImageLayerOptions options( "QGIS" );
mQgisMapLayer = new ImageLayer( options, mTileSource );
map->addImageLayer( mQgisMapLayer );
mQgisMapLayer->setCache( 0 ); //disable caching
}
else
{
QgsDebugMsg( "layersChanged: Globe NOT running, skipping" );
return;
}
}


void GlobePlugin::elevationLayersChanged()
{
if ( mIsGlobeRunning )
{
QgsDebugMsg( "layersChanged: Globe Running, executing" );
QgsDebugMsg( "elevationLayersChanged: Globe Running, executing" );
osg::ref_ptr<Map> map = mMapNode->getMap();

if ( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1 )
if ( map->getNumElevationLayers() > 1 )
{
mOsgViewer->getDatabasePager()->clear();
}
Expand Down Expand Up @@ -751,15 +782,6 @@ void GlobePlugin::layersChanged()
options.url() = uri.toStdString();
layer = new osgEarth::ElevationLayer( uri.toStdString(), options );
}
else if ( "Worldwind" == type )
{
WorldWindOptions options;
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 )
{
TMSOptions options;
Expand All @@ -770,22 +792,6 @@ void GlobePlugin::layersChanged()

if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
}

//remove QGIS layer
if ( mQgisMapLayer )
{
QgsDebugMsg( "removeMapLayer" );
map->removeImageLayer( mQgisMapLayer );
}

//add QGIS layer
QgsDebugMsg( "addMapLayer" );
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
mTileSource->initialize( "", 0 );
ImageLayerOptions options( "QGIS" );
mQgisMapLayer = new ImageLayer( options, mTileSource );
map->addImageLayer( mQgisMapLayer );
mQgisMapLayer->setCache( 0 ); //disable caching
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -57,8 +57,10 @@ class GlobePlugin : public QObject, public QgisPlugin
//! show the help document
void help();

//! Emitted when a new set of layers has been received
void layersChanged();
//! Emitted when a new set of image layers has been received
void imageLayersChanged();
//! Emitted when a new set of elevation layers has been received
void elevationLayersChanged();
//! Called when the extents of the map change
void extentsChanged();
//! Sync globe extent to mapCanavas
Expand Down
13 changes: 12 additions & 1 deletion src/plugins/globe/globe_plugin_dialog.cpp
Expand Up @@ -155,7 +155,7 @@ void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged( QString type )
else if ( "TMS" == type )
{
elevationActions->setCurrentIndex( 1 );
elevationPath->setText( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
elevationPath->setText( "http://readymap.org/readymap/tiles/1.0.0/9/" );
}
}

Expand Down Expand Up @@ -251,11 +251,22 @@ void QgsGlobePluginDialog::setRow( QTableWidget* widget, int row, const QList<QT
}
}

void QgsGlobePluginDialog::resetElevationDatasources()
{
elevationDatasourcesWidget->clearContents();
elevationDatasourcesWidget->setRowCount( 1 );
elevationDatasourcesWidget->setItem( 0, 0, new QTableWidgetItem("TMS") );
elevationDatasourcesWidget->setItem( 0, 1, new QTableWidgetItem() );
elevationDatasourcesWidget->item( 0, 1 )->setCheckState( Qt::Unchecked );
elevationDatasourcesWidget->setItem( 0, 2, new QTableWidgetItem("http://readymap.org/readymap/tiles/1.0.0/9/") );
}

void QgsGlobePluginDialog::readElevationDatasources()
{
//showMessageBox("reading");
// clear the widget
elevationDatasourcesWidget->clearContents();
elevationDatasourcesWidget->setRowCount( 0 );
int keysCount = QgsProject::instance()->subkeyList( "Globe-Plugin", "/elevationDatasources/" ).count();
for ( int i = 0; i < keysCount; ++i )
{
Expand Down
1 change: 1 addition & 0 deletions src/plugins/globe/globe_plugin_dialog.h
Expand Up @@ -32,6 +32,7 @@ class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiB
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 );
~QgsGlobePluginDialog();
void setViewer( osgViewer::Viewer* viewer ) { mViewer = viewer; }
void resetElevationDatasources();
void readElevationDatasources();
QTableWidget *elevationDatasources() { return elevationDatasourcesWidget; }
void updatePointLayers();
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/globe/globe_plugin_dialog_guibase.ui
Expand Up @@ -73,11 +73,6 @@
<string>TMS</string>
</property>
</item>
<item>
<property name="text">
<string>Worldwind</string>
</property>
</item>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 88cd943

Please sign in to comment.