From 90ad04f281cbc87ffc45bed847ebaaecb188e593 Mon Sep 17 00:00:00 2001 From: Glenn Waldron Date: Mon, 15 Jun 2020 07:30:42 -0400 Subject: [PATCH] Fix osgearth_city example --- .../osgearth_city/osgearth_city.cpp | 26 +++++++-------- src/osgEarth/FeatureModelLayer | 4 +++ src/osgEarth/FeatureModelLayer.cpp | 33 ++++++++++++++----- src/osgEarth/LayerReference | 14 ++++++-- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/applications/osgearth_city/osgearth_city.cpp b/src/applications/osgearth_city/osgearth_city.cpp index cd024abb57..fbadc477c2 100644 --- a/src/applications/osgearth_city/osgearth_city.cpp +++ b/src/applications/osgearth_city/osgearth_city.cpp @@ -67,13 +67,13 @@ main(int argc, char** argv) osg::ArgumentParser arguments(&argc,argv); // create the map. - Map* map = new Map(); + osg::ref_ptr map = new Map(); - addImagery( map ); - addElevation( map ); - addBuildings( map ); - addStreets( map ); - addParks( map ); + addImagery( map.get() ); + addElevation( map.get() ); + addBuildings( map.get() ); + addStreets( map.get() ); + addParks( map.get() ); // initialize a viewer: osgViewer::Viewer viewer(arguments); @@ -85,7 +85,7 @@ main(int argc, char** argv) viewer.setSceneData( root ); // make the map scene graph: - MapNode* mapNode = new MapNode(map); + MapNode* mapNode = new MapNode(map.get()); root->addChild( mapNode ); // zoom to a good startup position @@ -124,13 +124,12 @@ void addBuildings(Map* map) { // create a feature source to load the building footprint shapefile. OGRFeatureSource* data = new OGRFeatureSource(); - data->setName("buildings"); + data->setName("buildings-data"); data->setURL(BUILDINGS_URL); - data->options().buildSpatialIndex() = true; // a style for the building data: Style buildingStyle; - buildingStyle.setName( "buildings" ); + buildingStyle.setName( "default" ); // Extrude the shapes into 3D buildings. ExtrusionSymbol* extrusion = buildingStyle.getOrCreate(); @@ -179,13 +178,13 @@ void addBuildings(Map* map) // tile radius = max range / tile size factor. FeatureDisplayLayout layout; layout.tileSize() = 500; - layout.addLevel( FeatureLevel(0.0f, 20000.0f, "buildings") ); FeatureModelLayer* layer = new FeatureModelLayer(); layer->setName("Buildings"); layer->setFeatureSource(data); layer->setStyleSheet(styleSheet); - layer->options().layout() = layout; + layer->setLayout(layout); + layer->setMaxVisibleRange(20000.0); map->addLayer(layer); } @@ -230,14 +229,15 @@ void addStreets(Map* map) // to determine the tile size, such that tile radius = max range / tile size factor. FeatureDisplayLayout layout; layout.tileSize() = 500; - layout.maxRange() = 5000.0f; // create a model layer that will render the buildings according to our style sheet. FeatureModelLayer* layer = new FeatureModelLayer(); + layer->setName("Streets"); layer->setFeatureSource(data); layer->options().layout() = layout; layer->setStyleSheet(new StyleSheet()); layer->getStyleSheet()->addStyle(style); + layer->setMaxVisibleRange(5000.0f); map->addLayer(layer); } diff --git a/src/osgEarth/FeatureModelLayer b/src/osgEarth/FeatureModelLayer index a4457bd1b5..4fdd95dfec 100644 --- a/src/osgEarth/FeatureModelLayer +++ b/src/osgEarth/FeatureModelLayer @@ -69,6 +69,10 @@ namespace osgEarth void setStyleSheet(StyleSheet* value); StyleSheet* getStyleSheet() const; + //! Set the dislpay layout (optional) + void setLayout(const FeatureDisplayLayout& layout); + const FeatureDisplayLayout& getLayout() const; + void setAlphaBlending(const bool& value); const bool& getAlphaBlending() const; diff --git a/src/osgEarth/FeatureModelLayer.cpp b/src/osgEarth/FeatureModelLayer.cpp index 76560da0e2..acab53dd32 100644 --- a/src/osgEarth/FeatureModelLayer.cpp +++ b/src/osgEarth/FeatureModelLayer.cpp @@ -21,7 +21,7 @@ using namespace osgEarth; -#define LC "[FeatureModelLayer] " +#define LC "[FeatureModelLayer] \"" << getName() << "\": " #define OE_TEST OE_NULL @@ -106,11 +106,14 @@ FeatureModelLayer::init() void FeatureModelLayer::dirty() { - // feature source changed, so the graph needs rebuilding - _graphDirty = true; - - // create the scene graph - create(); + //// feature source changed, so the graph needs rebuilding + //_graphDirty = true; + + //// create the scene graph + //if (isOpen()) + //{ + // create(); + //} } Config @@ -159,6 +162,18 @@ FeatureModelLayer::getStyleSheet() const return options().styleSheet().getLayer(); } +void +FeatureModelLayer::setLayout(const FeatureDisplayLayout& value) +{ + options().layout() = value; +} + +const FeatureDisplayLayout& +FeatureModelLayer::getLayout() const +{ + return options().layout().get(); +} + void FeatureModelLayer::setCreateFeatureNodeFactoryCallback(CreateFeatureNodeFactoryCallback* value) { @@ -260,9 +275,9 @@ FeatureModelLayer::create() { OE_TEST << LC << "create" << std::endl; - if (_graphDirty) + //if (_graphDirty) { - if (getFeatureSource() && getStyleSheet() && _session.valid()) + if (isOpen() && getFeatureSource() && getStyleSheet() && _session.valid()) { _session->setFeatureSource(getFeatureSource()); @@ -278,7 +293,7 @@ FeatureModelLayer::create() if (status.isError()) { - OE_WARN << LC << "INTERNAL ERROR intializing the FMG" << std::endl; + OE_WARN << LC << "ERROR intializing the FMG: " << status.toString() << std::endl; setStatus(status); } else diff --git a/src/osgEarth/LayerReference b/src/osgEarth/LayerReference index b6b85b8248..544ae580d3 100644 --- a/src/osgEarth/LayerReference +++ b/src/osgEarth/LayerReference @@ -77,14 +77,22 @@ namespace osgEarth if (typedLayer) { typedLayer->setReadOptions(readOptions); - const Status& fsStatus = typedLayer->open(); - if (fsStatus.isError()) + const Status& layerStatus = typedLayer->open(); + if (layerStatus.isError()) { - return fsStatus; + return layerStatus; } _layer = typedLayer.get(); } } + else if (_layer && !_layer->isOpen()) + { + const Status& layerStatus = _layer->open(); + if (layerStatus.isError()) + { + return layerStatus; + } + } return Status::OK(); }