title: How to make osgEarth::ModelLayer's model hide if distance exceeds some value?
body: <p>I'm trying to display labels from a model file, and the <code>osgearth_features</code> demo shows how to do this. It works fine for me, but I need the labels to disappear once the distance to the Earth exceeds some value. (I'm using version 25ce0e1 of osgEarth.)</p>
  
  <p>I know that there is <code>PagedLOD</code>, which would help me with hiding an <code>osg::Node</code>. But what I have is <code>osgEarth::ModelLayer</code>, and I can't seem to find a sensible way to insert <code>PagedLOD</code> between <code>MapNode</code> and my labels <code>Node</code>.</p>
  
  <p>My current approach, albeit workable, is somewhat hacky. Here's an experimental change to the original osgearth's <a href="https://github.com/gwaldron/osgearth/blob/25ce0e1b7a47311d1c19f5e76f208d7cd4388f94/src/applications/osgearth_features/osgearth_features.cpp" rel="nofollow noreferrer"><code>osgearth_features.cpp</code></a> to do what I need:</p>
  
  <pre><code>diff --git a/src/applications/osgearth_features/osgearth_features.cpp b/src/applications/osgearth_features/osgearth_features.cpp
  index 2bb1ed8..fbdd3da 100644
  --- a/src/applications/osgearth_features/osgearth_features.cpp
  +++ b/src/applications/osgearth_features/osgearth_features.cpp
  @@ -184,6 +184,12 @@ int main(int argc, char** argv)
           geomOptions.styles()-&gt;addStyle( labelStyle );
  
           map-&gt;addModelLayer( new ModelLayer("labels", geomOptions) );
  +        osg::Group*const modelLayerGroup=mapNode-&gt;getModelLayerGroup();
  +        const int newNumChildren=modelLayerGroup-&gt;getNumChildren();
  +        osg::Node*const model=modelLayerGroup-&gt;getChild(newNumChildren-1);
  +        osg::PagedLOD*const lod=new osg::PagedLOD;
  +        modelLayerGroup-&gt;replaceChild(model,lod);
  +        lod-&gt;addChild(model, 0, 1e7);
       }
  
       if ( !useStencil )
  </code></pre>
  
  <p>This replacement of nodes seems too ugly to me. What is the better, "correct" way to achieve my goal? Or this is the way such things are supposed to be done?</p>