Skip to content

Commit

Permalink
[globe] Base layer configuration option (TMS only)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 14, 2013
1 parent 9259e27 commit 0a8e4f9
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 19 deletions.
29 changes: 23 additions & 6 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -85,6 +85,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
, mQActionSettingsPointer( NULL )
, mOsgViewer( 0 )
, mViewerWidget( 0 )
, mBaseLayer( 0 )
, mQgisMapLayer( 0 )
, mTileSource( 0 )
, mElevationManager( NULL )
Expand Down Expand Up @@ -117,7 +118,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
}
#endif

mSettingsDialog = new QgsGlobePluginDialog( theQgisInterface->mainWindow(), QgisGui::ModalDialogFlags );
mSettingsDialog = new QgsGlobePluginDialog( theQgisInterface->mainWindow(), this, QgisGui::ModalDialogFlags );
}

//destructor
Expand Down Expand Up @@ -314,8 +315,6 @@ void GlobePlugin::run()
// OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks.
mOsgViewer->getDatabasePager()->setDoPreCompile( true );

mSettingsDialog->setViewer( mOsgViewer );

#ifdef GLOBE_OSG_STANDALONE_VIEWER
mOsgViewer->run();
#endif
Expand Down Expand Up @@ -391,9 +390,6 @@ void GlobePlugin::setupMap()
ImageLayerOptions layerOptions( "world", driverOptions );
map->addImageLayer( new osgEarth::ImageLayer( layerOptions ) );
*/
TMSOptions imagery;
imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/7/";
map->addImageLayer( new ImageLayer( "Imagery", imagery ) );

MapNodeOptions nodeOptions;
//nodeOptions.proxySettings() =
Expand All @@ -409,6 +405,11 @@ void GlobePlugin::setupMap()
// The MapNode will render the Map object in the scene graph.
mMapNode = new osgEarth::MapNode( map, nodeOptions );

if ( settings.value( "/Plugin-Globe/baseLayerEnabled", true ).toBool() )
{
setBaseMap( settings.value( "/Plugin-Globe/baseLayerURL", "http://readymap.org/readymap/tiles/1.0.0/7/" ).toString() );
}

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

Expand Down Expand Up @@ -808,6 +809,22 @@ void GlobePlugin::elevationLayersChanged()
}
}

void GlobePlugin::setBaseMap( QString url )
{
mMapNode->getMap()->removeImageLayer( mBaseLayer );
if ( url.isNull() )
{
mBaseLayer = 0;
}
else
{
TMSOptions imagery;
imagery.url() = url.toStdString();
mBaseLayer = new ImageLayer( "Imagery", imagery );
mMapNode->getMap()->insertImageLayer( mBaseLayer, 0 );
}
}

void GlobePlugin::reset()
{
if ( mViewerWidget )
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/globe/globe_plugin.h
Expand Up @@ -74,10 +74,12 @@ class GlobePlugin : public QObject, public QgisPlugin
//! show the help document
void help();

//! Emitted when a new set of image layers has been received
//! Called when a new set of image layers has been received
void imageLayersChanged();
//! Emitted when a new set of elevation layers has been received
//! Called when a new set of elevation layers has been received
void elevationLayersChanged();
//! Set a different base map (QString::NULL will disable the base map)
void setBaseMap( QString url );
//! Called when the extents of the map change
void extentsChanged();
//! Sync globe extent to mapCanavas
Expand Down Expand Up @@ -107,6 +109,8 @@ class GlobePlugin : public QObject, public QgisPlugin
//! Place an OSG model on the globe
void placeNode( osg::Node* node, double lat, double lon, double alt = 0.0 );

osgViewer::Viewer* osgViewer() { return mOsgViewer; }

//! Recursive copy folder
static void copyFolder( QString sourceFolder, QString destFolder );

Expand Down Expand Up @@ -137,6 +141,8 @@ class GlobePlugin : public QObject, public QgisPlugin
osg::Group* mRootNode;
//! Map node
osgEarth::MapNode* mMapNode;
//! Base layer
osg::ref_ptr<osgEarth::ImageLayer> mBaseLayer;
//! QGIS maplayer
osgEarth::ImageLayer* mQgisMapLayer;
//! Tile source
Expand Down
66 changes: 62 additions & 4 deletions src/plugins/globe/globe_plugin_dialog.cpp
Expand Up @@ -38,15 +38,24 @@
#include <osg/DisplaySettings>

//constructor
QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl )
QgsGlobePluginDialog::QgsGlobePluginDialog(QWidget* parent, GlobePlugin* globe, Qt::WFlags fl )
: QDialog( parent, fl )
, mViewer( 0 )
, mGlobe( globe )
{
setupUi( this );

mBaseLayerComboBox->addItem( "Readymap: NASA BlueMarble Imagery", "http://readymap.org/readymap/tiles/1.0.0/1/" );
mBaseLayerComboBox->addItem( "Readymap: NASA BlueMarble with land removed, only ocean", "http://readymap.org/readymap/tiles/1.0.0/2/" );
mBaseLayerComboBox->addItem( "Readymap: High resolution insets from various locations around the world Austin, TX; Kandahar, Afghanistan; Bagram, Afghanistan; Boston, MA; Washington, DC", "http://readymap.org/readymap/tiles/1.0.0/3/" );
mBaseLayerComboBox->addItem( "Readymap: Global Land Cover Facility 15m Landsat", "http://readymap.org/readymap/tiles/1.0.0/6/" );
mBaseLayerComboBox->addItem( "Readymap: NASA BlueMarble + Landsat + Ocean Masking Layer", "http://readymap.org/readymap/tiles/1.0.0/7/" );
mBaseLayerComboBox->addItem( "[Custom]" );

loadStereoConfig(); //values from settings, default values from OSG
setStereoConfig(); //overwrite with values from QSettings
updateStereoDialog(); //update the dialog gui
loadVideoSettings();
loadMapSettings();

elevationPath->setText( QDir::homePath() );
}
Expand Down Expand Up @@ -128,6 +137,7 @@ void QgsGlobePluginDialog::on_buttonBox_accepted()

saveElevationDatasources();
saveVideoSettings();
saveMapSettings();
accept();
}

Expand Down Expand Up @@ -212,6 +222,20 @@ void QgsGlobePluginDialog::on_elevationDown_clicked()
moveRow( elevationDatasourcesWidget, false );
}

void QgsGlobePluginDialog::on_mBaseLayerComboBox_currentIndexChanged( int index )
{
QVariant url = mBaseLayerComboBox->itemData( index );
if ( url.isValid() )
{
mBaseLayerURL->setEnabled( false );
mBaseLayerURL->setText( url.toString() );
}
else
{
mBaseLayerURL->setEnabled( true );
}
}

void QgsGlobePluginDialog::moveRow( QTableWidget* widget, bool up )
{
//moves QTableWidget row up or down
Expand Down Expand Up @@ -537,11 +561,45 @@ void QgsGlobePluginDialog::saveVideoSettings()
settings.setValue( "/Plugin-Globe/anti-aliasing-level", mAANumSamples->text() );
}

void QgsGlobePluginDialog::loadMapSettings()
{
mBaseLayerGroupBox->setChecked( settings.value( "/Plugin-Globe/baseLayerEnabled", true ).toBool() );
QString mapUrl = settings.value( "/Plugin-Globe/baseLayerURL", "http://readymap.org/readymap/tiles/1.0.0/7/" ).toString();
int urlIndex = mBaseLayerComboBox->findData( mapUrl );

if ( urlIndex != -1 )
{
mBaseLayerComboBox->setCurrentIndex( urlIndex );
}
else
{
mBaseLayerComboBox->setCurrentIndex( mBaseLayerComboBox->findData( QVariant() ) );
}

mBaseLayerURL->setText( mapUrl );
}

void QgsGlobePluginDialog::saveMapSettings()
{
settings.setValue( "/Plugin-Globe/baseLayerEnabled", mBaseLayerGroupBox->isChecked() );
settings.setValue( "/Plugin-Globe/baseLayerURL", mBaseLayerURL->text() );

if ( mBaseLayerGroupBox->isChecked() )
{
mGlobe->setBaseMap( mBaseLayerURL->text() );
}
else
{
mGlobe->setBaseMap( QString::null );
}
}

void QgsGlobePluginDialog::setStereoConfig()
{
if ( mViewer )
osgViewer::Viewer* viewer = mGlobe->osgViewer();
if ( viewer )
{
mViewer->getDatabasePager()->clear();
viewer->getDatabasePager()->clear();
//SETTING THE VALUES IN THE OEGearth instance
setStereoMode();
osg::DisplaySettings::instance()->setScreenDistance( screenDistance->value() );
Expand Down
18 changes: 13 additions & 5 deletions src/plugins/globe/globe_plugin_dialog.h
Expand Up @@ -24,23 +24,22 @@
#include <qgsproject.h>
#include <qgsvectorlayer.h>

class GlobePlugin;

class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiBase
{
Q_OBJECT

public:
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 );
QgsGlobePluginDialog( QWidget * parent, GlobePlugin* globe, Qt::WFlags fl = 0 );
~QgsGlobePluginDialog();
void setViewer( osgViewer::Viewer* viewer ) { mViewer = viewer; }
void resetElevationDatasources();
void readElevationDatasources();
QTableWidget *elevationDatasources() { return elevationDatasourcesWidget; }
void updatePointLayers();
QgsVectorLayer* modelLayer();
QString modelPath() { return modelPathLineEdit->text(); }
private:
osgViewer::Viewer* mViewer;
QSettings settings;

private:
QString openRasterFile();
void updateStereoDialog();
Expand All @@ -61,6 +60,8 @@ class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiB
void setStereoMode();
void loadVideoSettings();
void saveVideoSettings();
void loadMapSettings();
void saveMapSettings();

private slots:
void on_buttonBox_accepted();
Expand Down Expand Up @@ -89,8 +90,15 @@ class QgsGlobePluginDialog: public QDialog, private Ui::QgsGlobePluginDialogGuiB
void on_elevationUp_clicked();
void on_elevationDown_clicked();

//MAP
void on_mBaseLayerComboBox_currentIndexChanged( int index );

signals:
void elevationDatasourcesChanged();

private:
GlobePlugin* mGlobe;
QSettings settings;
};

#endif // QGIS_GLOBE_PLUGIN_DIALOG_H
46 changes: 44 additions & 2 deletions src/plugins/globe/globe_plugin_dialog_guibase.ui
Expand Up @@ -9,7 +9,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>593</width>
<width>1407</width>
<height>534</height>
</rect>
</property>
Expand All @@ -36,8 +36,50 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Map</string>
</attribute>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="mBaseLayerGroupBox">
<property name="title">
<string>Base Layer</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mBaseLayerComboBox"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mBaseLayerURL"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="elevation">
<attribute name="title">
<string>Elevation</string>
Expand Down

0 comments on commit 0a8e4f9

Please sign in to comment.