Skip to content
Permalink
Browse files

Default elevation layer for globe

  • Loading branch information
pka committed Oct 5, 2012
1 parent 1a1370f commit 88cd9439b10e3c725b0ff8bfbef398b329b66bf9
@@ -54,7 +54,6 @@
#include <osgEarth/TileSource>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthDrivers/gdal/GDALOptions>
#include "WorldWindOptions"
#include <osgEarthDrivers/tms/TMSOptions>

using namespace osgEarth::Drivers;
@@ -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;
@@ -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,
@@ -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;
@@ -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() );
@@ -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 )
@@ -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();
}
@@ -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;
@@ -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
{
@@ -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
@@ -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/" );
}
}

@@ -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 )
{
@@ -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();
@@ -73,11 +73,6 @@
<string>TMS</string>
</property>
</item>
<item>
<property name="text">
<string>Worldwind</string>
</property>
</item>
</widget>
</item>
</layout>

0 comments on commit 88cd943

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