osgearth
osgearth copied to clipboard
AnnotationLayer serialization
Looks like there is problem with serialization of AnnotationLayer.
- Create empty AnnotationLayer
- Add some AnnotationNode to it (in my case, MapNode)
- 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.
Thanks. If you are able to engineer a solution to this, please submit a PR and we'll integrate it.
Works in master branch