Skip to content

Commit

Permalink
Fix osgearth_city example
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Jun 15, 2020
1 parent 0946910 commit 90ad04f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
26 changes: 13 additions & 13 deletions src/applications/osgearth_city/osgearth_city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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);
Expand All @@ -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
Expand Down Expand Up @@ -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<ExtrusionSymbol>();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/osgEarth/FeatureModelLayer
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
33 changes: 24 additions & 9 deletions src/osgEarth/FeatureModelLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

using namespace osgEarth;

#define LC "[FeatureModelLayer] "
#define LC "[FeatureModelLayer] \"" << getName() << "\": "

#define OE_TEST OE_NULL

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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());

Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/osgEarth/LayerReference
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 90ad04f

Please sign in to comment.