osgearth icon indicating copy to clipboard operation
osgearth copied to clipboard

AnnotationLayer serialization

Open RhythmOfTension opened this issue 2 years ago • 1 comments

Looks like there is problem with serialization of AnnotationLayer.

  1. Create empty AnnotationLayer
  2. Add some AnnotationNode to it (in my case, MapNode)
  3. Call getConfig() method

Config will only contain VisibleLayer options, but not annotations.

So i found some workaround:

osgEarth::Config layerConf = layer->getConfig();

const osgEarth::AnnotationLayer* annoLayer = dynamic_cast<const osgEarth::AnnotationLayer*>(layer);
if (annoLayer) {
    osgEarth::Config annoConf = osgEarth::Util::AnnotationRegistry::instance()->getConfig(annoLayer->getGroup());
    osgEarth::ConfigSet confSet = annoConf.children();
    layerConf.add(confSet);
}

But this method have some problems if AnnotationLayer is not created as new, but already deserialized before. So i serialize (with code above) AnnotationLayer, created via steps 1-3, then i deserialize it like that:

for (osgEarth::ConfigSet::const_iterator it = inputConfig.children().begin(); it != inputConfig.children().end(); ++it) {
    osg::ref_ptr<osgEarth::Layer> layer = osgEarth::Layer::create(*it);
    . . .
}

After this, i'm trying to serialize it again with this code, but annotations now duplicated because layer->getConfig() now contains annotations.

RhythmOfTension avatar Oct 01 '21 13:10 RhythmOfTension

Thanks. If you are able to engineer a solution to this, please submit a PR and we'll integrate it.

gwaldron avatar Oct 05 '21 20:10 gwaldron

Works in master branch

gwaldron avatar Oct 24 '23 13:10 gwaldron