Map's type changed between geocentric and projected

classic Classic list List threaded Threaded
4 messages Options
ytyisme ytyisme
Reply | Threaded
Open this post in threaded view
|

Map's type changed between geocentric and projected

Under osgEarth 2.7,It's ok when I changed osgEarth::map's coordSysType and don't delete layers.The coord of modelLayer will changed itself.Now  It's not worked when update to "osgEarth Library 2.9.0 DEVELOPMENT".

    osgEarth::Map* oldMap = m_pMapNode->getMap();
    oldMap->endUpdate();

    osgEarth::MapOptions mapOpt;
    if(MAP_3D == m_emType)
    {
        mapOpt.coordSysType() = osgEarth::MapOptions::CSTYPE_GEOCENTRIC;
    }
    else
    {
        mapOpt.coordSysType() = osgEarth::MapOptions::CSTYPE_PROJECTED;
        mapOpt.profile() =  osgEarth::ProfileOptions("plate-carre");
    }

    /// 重新构建 map
    osgEarth::Map* map = new osgEarth::Map( mapOpt );
    map->endUpdate();


    /// 从旧的map中复制图层过来
    osgEarth::LayerVector tmpVector;
    oldMap->getLayers(tmpVector);

    for(osgEarth::LayerVector::iterator i= tmpVector.begin(); i!=tmpVector.end();++i)
    {
        map->addLayer(i->get());
    }


    /// 创建MapNode节点
    osgEarth::MapNode* pNode = new osgEarth::MapNode(map);

    osg::Node::ParentList parents = m_pMapNode->getParents();
    for(osg::Node::ParentList::iterator i = parents.begin(); i != parents.end(); ++i )
    {
        (*i)->replaceChild( m_pMapNode, pNode );
    }

    map->beginUpdate();

    /// 设置 MapNode
    m_pMapNode = pNode;
projected map
after change map coordSysType

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Map's type changed between geocentric and projected

You will have to re-create the layers if you create a different map type. One trick for doing this is:

  ConfigOptions serialized = oldLayer->getConfig();
  ...
  Layer* newLayer = Layer::create(serialized);

Hope this helps.
Glenn Waldron / Pelican Mapping
ytyisme ytyisme
Reply | Threaded
Open this post in threaded view
|

Re: Map's type changed between geocentric and projected

Thank you very much for your reply that perfectly solved my problem!
My code work well under osgEarth 2.7,why?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Map's type changed between geocentric and projected

Not sure. Hard to remember that far back, sorry :)
Glenn Waldron / Pelican Mapping