Skip to content

Commit 43e4ea1

Browse files
committed
Elevation layers from settings dialog
1 parent ea16d7a commit 43e4ea1

File tree

2 files changed

+70
-19
lines changed

2 files changed

+70
-19
lines changed

src/plugins/globe/globe.earth

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
</heightfield>
2727
-->
2828

29+
<!--
2930
<heightfield name="WorldWind bil" driver="worldwind">
3031
<worldwind_cache>/home/pi/devel/gis/qgis/.qgis/cache/globe/worldwind_srtm</worldwind_cache>
3132
<cache_enabled>false</cache_enabled>
3233
</heightfield>
33-
34+
-->
35+
3436
<!--
3537
<heightfield name="aster_dem" driver="gdal">
3638
<url>/home/pi/data/geodata/Lech/ASTGTM_N47E010/ASTGTM_N47E010_dem.tif</url>

src/plugins/globe/globe_plugin.cpp

+67-18
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
7272
mQDockWidget( tr( "Globe" ) ),
7373
mSettingsDialog( theQgisInterface->mainWindow(), QgisGui::ModalDialogFlags ),
7474
mTileSource( 0 ),
75+
mQgisMapLayer( 0 ),
7576
mElevationManager( NULL ),
7677
mObjectPlacer( NULL )
7778
{
@@ -195,21 +196,15 @@ void GlobePlugin::setupMap()
195196
return;
196197
}
197198

198-
osg::ref_ptr<Map> map = earthFile.getMap();
199-
200-
// Add QGIS layer to the map
201-
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
202-
mTileSource->initialize( "" );
203-
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
204-
map->addMapLayer( mQgisMapLayer );
205-
mQgisMapLayer->setCache( 0 ); //disable caching
206-
207199
mRootNode = new osg::Group();
208200

209201
// The MapNode will render the Map object in the scene graph.
210-
mMapNode = new osgEarth::MapNode( map );
202+
mMapNode = new osgEarth::MapNode( earthFile.getMap() );
211203
mRootNode->addChild( mMapNode );
212204

205+
// Add layers to the map
206+
layersChanged();
207+
213208
// model placement utils
214209
mElevationManager = new osgEarthUtil::ElevationManager( mMapNode->getMap() );
215210
mElevationManager->setTechnique( osgEarthUtil::ElevationManager::TECHNIQUE_GEOMETRIC );
@@ -589,18 +584,72 @@ typedef std::list< osg::ref_ptr<VersionedTile> > TileList;
589584
void GlobePlugin::layersChanged()
590585
{
591586
QgsDebugMsg( "layersChanged" );
592-
if( mTileSource && mMapNode->getMap()->getImageMapLayers().size() > 1 )
587+
588+
osg::ref_ptr<Map> map = mMapNode->getMap();
589+
590+
if( map->getImageMapLayers().size() > 1 || map->getHeightFieldMapLayers().size() > 1)
593591
{
594592
viewer.getDatabasePager()->clear();
593+
}
594+
595+
// Remove elevation layers
596+
MapLayerList list = map->getHeightFieldMapLayers();
597+
for( MapLayerList::iterator i = list.begin(); i != list.end(); i++ )
598+
{
599+
map->removeMapLayer( *i );
600+
}
601+
602+
// Add elevation layers
603+
QSettings settings;
604+
QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
605+
QTableWidget* table = mSettingsDialog.elevationDatasources();
606+
for(int i = 0; i < table->rowCount(); ++i)
607+
{
608+
QString type = table->item(i, 0)->text();
609+
QString uri = table->item(i, 1)->text();
610+
MapLayer* layer = 0;
611+
612+
if( "Raster" == type)
613+
{
614+
GDALOptions* options = new GDALOptions();
615+
options->url() = uri.toStdString();
616+
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
617+
}
618+
else if ( "Worldwind" == type )
619+
{
620+
EarthFile* tmpEarth = new EarthFile(); //Hack for programatic WorldWind layer generation
621+
std::string xml = "<map name=\"Dummy\" type=\"geocentric\"><heightfield name=\"WorldWind bil\" driver=\"worldwind\"><worldwind_cache>" + cacheDirectory.toStdString() + "/globe/worldwind_srtm</worldwind_cache></heightfield></map>";
622+
std::stringstream strstr(xml);
623+
tmpEarth->readXML( strstr, "" );
624+
layer = tmpEarth->getMap()->getHeightFieldMapLayers().front();
625+
}
626+
else if ( "TMS" == type )
627+
{
628+
TMSOptions* options = new TMSOptions();
629+
options->url() = uri.toStdString();
630+
layer = new osgEarth::HeightFieldMapLayer( uri.toStdString(), options );
631+
//osgEarth 2.0 API:
632+
//TMSOptions tms( "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml" );
633+
//map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
634+
}
635+
map->addMapLayer( layer );
636+
layer->setCache( 0 ); //TODO: from dialog
637+
}
638+
639+
//remove QGIS layer
640+
if( mQgisMapLayer )
641+
{
595642
QgsDebugMsg( "removeMapLayer" );
596-
mMapNode->getMap()->removeMapLayer( mQgisMapLayer );
597-
QgsDebugMsg( "addMapLayer" );
598-
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
599-
mTileSource->initialize( "", 0 );
600-
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
601-
mMapNode->getMap()->addMapLayer( mQgisMapLayer );
602-
mQgisMapLayer->setCache( 0 ); //disable caching
643+
map->removeMapLayer( mQgisMapLayer );
603644
}
645+
646+
//add QGIS layer
647+
QgsDebugMsg( "addMapLayer" );
648+
mTileSource = new QgsOsgEarthTileSource( mQGisIface );
649+
mTileSource->initialize( "", 0 );
650+
mQgisMapLayer = new ImageMapLayer( "QGIS", mTileSource );
651+
map->addMapLayer( mQgisMapLayer );
652+
mQgisMapLayer->setCache( 0 ); //disable caching
604653
}
605654

606655
void GlobePlugin::unload()

0 commit comments

Comments
 (0)