|
50 | 50 | #include <osgEarth/Map>
|
51 | 51 | #include <osgEarth/MapNode>
|
52 | 52 | #include <osgEarth/TileSource>
|
| 53 | +#include <osgEarthUtil/AutoClipPlaneHandler> |
53 | 54 | #include <osgEarthDrivers/gdal/GDALOptions>
|
54 | 55 | #include "WorldWindOptions"
|
55 | 56 | #include <osgEarthDrivers/tms/TMSOptions>
|
@@ -227,6 +228,8 @@ void GlobePlugin::run()
|
227 | 228 | // install the programmable manipulator.
|
228 | 229 | osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
|
229 | 230 | viewer.setCameraManipulator( manip );
|
| 231 | + // add a handler that will automatically calculate good clipping planes |
| 232 | + //viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() ); |
230 | 233 |
|
231 | 234 | setupMap();
|
232 | 235 |
|
@@ -272,38 +275,41 @@ void GlobePlugin::settings()
|
272 | 275 |
|
273 | 276 | void GlobePlugin::setupMap()
|
274 | 277 | {
|
275 |
| - // read base layers from earth file |
276 |
| - QString earthFileName = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/globe.earth" ); |
277 |
| - QFile earthFileTemplate( earthFileName ); |
278 |
| - if( !earthFileTemplate.open( QIODevice::ReadOnly | QIODevice::Text ) ) |
279 |
| - { |
280 |
| - return; |
281 |
| - } |
282 |
| - |
283 |
| - QTextStream in( &earthFileTemplate ); |
284 |
| - QString earthxml = in.readAll(); |
285 | 278 | QSettings settings;
|
286 | 279 | QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
|
287 |
| - earthxml.replace( "/home/pi/devel/gis/qgis/.qgis/cache", cacheDirectory ); |
288 |
| - earthxml.replace( "/usr/share/osgearth/data", QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe" ) ); |
| 280 | + TMSCacheOptions cacheOptions; |
| 281 | + cacheOptions.setPath(cacheDirectory.toStdString()); |
| 282 | + |
| 283 | + MapOptions mapOptions; |
| 284 | + mapOptions.cache() = cacheOptions; |
| 285 | + osgEarth::Map *map = new osgEarth::Map(mapOptions); |
| 286 | + |
| 287 | + //Default image layer |
| 288 | + GDALOptions driverOptions; |
| 289 | + driverOptions.url() = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/world.tif" ).toStdString(); |
| 290 | + ImageLayerOptions layerOptions( "world", driverOptions ); |
| 291 | + layerOptions.cacheEnabled() = false; |
| 292 | + map->addImageLayer( new osgEarth::ImageLayer( layerOptions ) ); |
| 293 | + |
| 294 | + MapNodeOptions nodeOptions; |
| 295 | + //nodeOptions.proxySettings() = |
| 296 | + //nodeOptions.enableLighting() = false; |
| 297 | + |
| 298 | + //LoadingPolicy loadingPolicy( LoadingPolicy::MODE_SEQUENTIAL ); |
| 299 | + TerrainOptions terrainOptions; |
| 300 | + //terrainOptions.loadingPolicy() = loadingPolicy; |
| 301 | + nodeOptions.setTerrainOptions( terrainOptions ); |
| 302 | + |
| 303 | + // The MapNode will render the Map object in the scene graph. |
| 304 | + mMapNode = new osgEarth::MapNode( map, nodeOptions ); |
289 | 305 |
|
290 | 306 | //prefill cache
|
291 | 307 | if( !QFile::exists( cacheDirectory + "/worldwind_srtm" ) )
|
292 | 308 | {
|
293 | 309 | copyFolder( QgsApplication::pkgDataPath() + "/globe/data/worldwind_srtm", cacheDirectory + "/globe/worldwind_srtm" );
|
294 | 310 | }
|
295 | 311 |
|
296 |
| - std::istringstream istream( earthxml.toStdString() ); |
297 |
| - osg::Node* node = osgDB::readNodeFile( earthFileName.toStdString() ); //TODO: from istream earthFile.readXML( istream, earthFileName.toStdString() ) |
298 |
| - if( !node ) |
299 |
| - { |
300 |
| - return; |
301 |
| - } |
302 |
| - |
303 | 312 | mRootNode = new osg::Group();
|
304 |
| - |
305 |
| - // The MapNode will render the Map object in the scene graph. |
306 |
| - mMapNode = MapNode::findMapNode( node ); |
307 | 313 | mRootNode->addChild( mMapNode );
|
308 | 314 |
|
309 | 315 | // Add layers to the map
|
@@ -677,8 +683,11 @@ void GlobePlugin::layersChanged()
|
677 | 683 | else if ( "Worldwind" == type )
|
678 | 684 | {
|
679 | 685 | WorldWindOptions options;
|
680 |
| - //TODO: <heightfield name=\"WorldWind bil\" driver=\"worldwind\"><worldwind_cache>" + cacheDirectory.toStdString() + "/globe/worldwind_srtm"; |
| 686 | + options.elevationCachePath() = cacheDirectory.toStdString() + "/globe/worldwind_srtm"; |
681 | 687 | layer = new osgEarth::ElevationLayer( "WorldWind bil", options );
|
| 688 | + TerrainEngineNode* terrainEngineNode = mMapNode->getTerrainEngine(); |
| 689 | + terrainEngineNode->setVerticalScale(2); |
| 690 | + terrainEngineNode->setElevationSamplingRatio(0.25); |
682 | 691 | }
|
683 | 692 | else if ( "TMS" == type )
|
684 | 693 | {
|
|
0 commit comments