Skip to content

Commit 88cd943

Browse files
committedOct 5, 2012
Default elevation layer for globe
1 parent 1a1370f commit 88cd943

File tree

5 files changed

+65
-50
lines changed

5 files changed

+65
-50
lines changed
 

‎src/plugins/globe/globe_plugin.cpp

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
#include <osgEarth/TileSource>
5555
#include <osgEarthUtil/AutoClipPlaneHandler>
5656
#include <osgEarthDrivers/gdal/GDALOptions>
57-
#include "WorldWindOptions"
5857
#include <osgEarthDrivers/tms/TMSOptions>
5958

6059
using namespace osgEarth::Drivers;
@@ -165,7 +164,7 @@ struct RefreshControlHandler : public ControlEventHandler
165164
RefreshControlHandler( GlobePlugin* globe ) : mGlobe( globe ) { }
166165
virtual void onClick( Control* /*control*/, int /*mouseButtonMask*/ )
167166
{
168-
mGlobe->layersChanged();
167+
mGlobe->imageLayersChanged();
169168
}
170169
private:
171170
GlobePlugin* mGlobe;
@@ -203,9 +202,9 @@ void GlobePlugin::initGui()
203202
connect( mQGisIface->mapCanvas() , SIGNAL( extentsChanged() ),
204203
this, SLOT( extentsChanged() ) );
205204
connect( mQGisIface->mapCanvas(), SIGNAL( layersChanged() ),
206-
this, SLOT( layersChanged() ) );
205+
this, SLOT( imageLayersChanged() ) );
207206
connect( mSettingsDialog, SIGNAL( elevationDatasourcesChanged() ),
208-
this, SLOT( layersChanged() ) );
207+
this, SLOT( elevationLayersChanged() ) );
209208
connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this,
210209
SLOT( projectReady() ) );
211210
connect( mQGisIface, SIGNAL( newProjectCreated() ), this,
@@ -325,13 +324,6 @@ void GlobePlugin::setupMap()
325324
imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/7/";
326325
map->addImageLayer( new ImageLayer( "Imagery", imagery ) );
327326

328-
// add a TMS elevation layer:
329-
/*
330-
TMSOptions elevation;
331-
elevation.url() = "http://readymap.org/readymap/tiles/1.0.0/9/";
332-
map->addElevationLayer( new ElevationLayer("Elevation", elevation) );
333-
*/
334-
335327
MapNodeOptions nodeOptions;
336328
//nodeOptions.proxySettings() =
337329
//nodeOptions.enableLighting() = false;
@@ -340,22 +332,26 @@ void GlobePlugin::setupMap()
340332
TerrainOptions terrainOptions;
341333
//terrainOptions.loadingPolicy() = loadingPolicy;
342334
terrainOptions.compositingTechnique() = TerrainOptions::COMPOSITING_MULTITEXTURE_FFP;
335+
//terrainOptions.lodFallOff() = 6.0;
343336
nodeOptions.setTerrainOptions( terrainOptions );
344337

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

348341
//prefill cache
342+
/*
349343
if ( !QFile::exists( cacheDirectory + "/worldwind_srtm" ) )
350344
{
351345
copyFolder( QgsApplication::pkgDataPath() + "/globe/data/worldwind_srtm", cacheDirectory + "/globe/worldwind_srtm" );
352346
}
347+
*/
353348

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

357352
// Add layers to the map
358-
layersChanged();
353+
imageLayersChanged();
354+
elevationLayersChanged();
359355

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

393389
void GlobePlugin::blankProjectReady()
394390
{ //needs at least http://trac.osgeo.org/qgis/changeset/14452
395-
mSettingsDialog->elevationDatasources()->clearContents();
396-
mSettingsDialog->elevationDatasources()->setRowCount( 0 );
391+
mSettingsDialog->resetElevationDatasources();
397392
}
398393

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

717-
void GlobePlugin::layersChanged()
712+
void GlobePlugin::imageLayersChanged()
713+
{
714+
if ( mIsGlobeRunning )
715+
{
716+
QgsDebugMsg( "imageLayersChanged: Globe Running, executing" );
717+
osg::ref_ptr<Map> map = mMapNode->getMap();
718+
719+
if ( map->getNumImageLayers() > 1 )
720+
{
721+
mOsgViewer->getDatabasePager()->clear();
722+
}
723+
724+
//remove QGIS layer
725+
if ( mQgisMapLayer )
726+
{
727+
QgsDebugMsg( "removeMapLayer" );
728+
map->removeImageLayer( mQgisMapLayer );
729+
}
730+
731+
//add QGIS layer
732+
QgsDebugMsg( "addMapLayer" );
733+
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
734+
mTileSource->initialize( "", 0 );
735+
ImageLayerOptions options( "QGIS" );
736+
mQgisMapLayer = new ImageLayer( options, mTileSource );
737+
map->addImageLayer( mQgisMapLayer );
738+
mQgisMapLayer->setCache( 0 ); //disable caching
739+
}
740+
else
741+
{
742+
QgsDebugMsg( "layersChanged: Globe NOT running, skipping" );
743+
return;
744+
}
745+
}
746+
747+
748+
void GlobePlugin::elevationLayersChanged()
718749
{
719750
if ( mIsGlobeRunning )
720751
{
721-
QgsDebugMsg( "layersChanged: Globe Running, executing" );
752+
QgsDebugMsg( "elevationLayersChanged: Globe Running, executing" );
722753
osg::ref_ptr<Map> map = mMapNode->getMap();
723754

724-
if ( map->getNumImageLayers() > 1 || map->getNumElevationLayers() > 1 )
755+
if ( map->getNumElevationLayers() > 1 )
725756
{
726757
mOsgViewer->getDatabasePager()->clear();
727758
}
@@ -751,15 +782,6 @@ void GlobePlugin::layersChanged()
751782
options.url() = uri.toStdString();
752783
layer = new osgEarth::ElevationLayer( uri.toStdString(), options );
753784
}
754-
else if ( "Worldwind" == type )
755-
{
756-
WorldWindOptions options;
757-
options.elevationCachePath() = cacheDirectory.toStdString() + "/globe/worldwind_srtm";
758-
layer = new osgEarth::ElevationLayer( "WorldWind bil", options );
759-
TerrainEngineNode* terrainEngineNode = mMapNode->getTerrainEngine();
760-
terrainEngineNode->setVerticalScale( 2 );
761-
terrainEngineNode->setElevationSamplingRatio( 0.25 );
762-
}
763785
else if ( "TMS" == type )
764786
{
765787
TMSOptions options;
@@ -770,22 +792,6 @@ void GlobePlugin::layersChanged()
770792

771793
if ( !cache || type == "Worldwind" ) layer->setCache( 0 ); //no tms cache for worldwind (use worldwind_cache)
772794
}
773-
774-
//remove QGIS layer
775-
if ( mQgisMapLayer )
776-
{
777-
QgsDebugMsg( "removeMapLayer" );
778-
map->removeImageLayer( mQgisMapLayer );
779-
}
780-
781-
//add QGIS layer
782-
QgsDebugMsg( "addMapLayer" );
783-
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
784-
mTileSource->initialize( "", 0 );
785-
ImageLayerOptions options( "QGIS" );
786-
mQgisMapLayer = new ImageLayer( options, mTileSource );
787-
map->addImageLayer( mQgisMapLayer );
788-
mQgisMapLayer->setCache( 0 ); //disable caching
789795
}
790796
else
791797
{

‎src/plugins/globe/globe_plugin.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ class GlobePlugin : public QObject, public QgisPlugin
5757
//! show the help document
5858
void help();
5959

60-
//! Emitted when a new set of layers has been received
61-
void layersChanged();
60+
//! Emitted when a new set of image layers has been received
61+
void imageLayersChanged();
62+
//! Emitted when a new set of elevation layers has been received
63+
void elevationLayersChanged();
6264
//! Called when the extents of the map change
6365
void extentsChanged();
6466
//! Sync globe extent to mapCanavas

‎src/plugins/globe/globe_plugin_dialog.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged( QString type )
155155
else if ( "TMS" == type )
156156
{
157157
elevationActions->setCurrentIndex( 1 );
158-
elevationPath->setText( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
158+
elevationPath->setText( "http://readymap.org/readymap/tiles/1.0.0/9/" );
159159
}
160160
}
161161

@@ -251,11 +251,22 @@ void QgsGlobePluginDialog::setRow( QTableWidget* widget, int row, const QList<QT
251251
}
252252
}
253253

254+
void QgsGlobePluginDialog::resetElevationDatasources()
255+
{
256+
elevationDatasourcesWidget->clearContents();
257+
elevationDatasourcesWidget->setRowCount( 1 );
258+
elevationDatasourcesWidget->setItem( 0, 0, new QTableWidgetItem("TMS") );
259+
elevationDatasourcesWidget->setItem( 0, 1, new QTableWidgetItem() );
260+
elevationDatasourcesWidget->item( 0, 1 )->setCheckState( Qt::Unchecked );
261+
elevationDatasourcesWidget->setItem( 0, 2, new QTableWidgetItem("http://readymap.org/readymap/tiles/1.0.0/9/") );
262+
}
263+
254264
void QgsGlobePluginDialog::readElevationDatasources()
255265
{
256266
//showMessageBox("reading");
257267
// clear the widget
258268
elevationDatasourcesWidget->clearContents();
269+
elevationDatasourcesWidget->setRowCount( 0 );
259270
int keysCount = QgsProject::instance()->subkeyList( "Globe-Plugin", "/elevationDatasources/" ).count();
260271
for ( int i = 0; i < keysCount; ++i )
261272
{

‎src/plugins/globe/globe_plugin_dialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiB
3232
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 );
3333
~QgsGlobePluginDialog();
3434
void setViewer( osgViewer::Viewer* viewer ) { mViewer = viewer; }
35+
void resetElevationDatasources();
3536
void readElevationDatasources();
3637
QTableWidget *elevationDatasources() { return elevationDatasourcesWidget; }
3738
void updatePointLayers();

‎src/plugins/globe/globe_plugin_dialog_guibase.ui

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@
7373
<string>TMS</string>
7474
</property>
7575
</item>
76-
<item>
77-
<property name="text">
78-
<string>Worldwind</string>
79-
</property>
80-
</item>
8176
</widget>
8277
</item>
8378
</layout>

0 commit comments

Comments
 (0)