Changeset 4310


Ignore:
Timestamp:
Apr 1, 2014, 2:58:49 PM (10 years ago)
Author:
ldelgass
Message:

Add map graticule. Currently only works in 3D (geocentric) maps.

Location:
trunk/packages/vizservers/geovis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/geovis/Renderer.cpp

    r4308 r4310  
    3838#include <osgEarthUtil/AutoClipPlaneHandler>
    3939#include <osgEarthUtil/MouseCoordsTool>
     40#include <osgEarthUtil/UTMGraticule>
     41#include <osgEarthUtil/MGRSGraticule>
     42#include <osgEarthUtil/GeodeticGraticule>
    4043#include <osgEarthUtil/LatLongFormatter>
    4144#include <osgEarthUtil/GLSLColorFilter>
     
    9194    osgEarth::MapNode *mapNode = new osgEarth::MapNode(map, mapNodeOpts);
    9295    _mapNode = mapNode;
    93     _sceneRoot = mapNode;
     96    _sceneRoot = new osg::Group;
     97    _sceneRoot->addChild(mapNode);
    9498    _viewer->setSceneData(_sceneRoot.get());
    9599
     
    255259}
    256260
     261void Renderer::setGraticule(bool enable, GraticuleType type)
     262{
     263    if (!_mapNode.valid() || !_sceneRoot.valid())
     264        return;
     265    if (enable) {
     266        if (_graticule.valid()) {
     267            _sceneRoot->removeChild(_graticule.get());
     268            _graticule = NULL;
     269        }
     270        switch (type) {
     271        case GRATICULE_UTM: {
     272            osgEarth::Util::UTMGraticule *gr = new osgEarth::Util::UTMGraticule(_mapNode.get());
     273            _sceneRoot->addChild(gr);
     274            _graticule = gr;
     275        }
     276            break;
     277        case GRATICULE_MGRS: {
     278            osgEarth::Util::MGRSGraticule *gr = new osgEarth::Util::MGRSGraticule(_mapNode.get());
     279            _sceneRoot->addChild(gr);
     280            _graticule = gr;
     281        }
     282            break;
     283        case GRATICULE_GEODETIC:
     284        default:
     285            osgEarth::Util::GeodeticGraticule *gr = new osgEarth::Util::GeodeticGraticule(_mapNode.get());
     286            osgEarth::Util::GeodeticGraticuleOptions opt = gr->getOptions();
     287            opt.lineStyle()->getOrCreate<osgEarth::Symbology::LineSymbol>()->stroke()->color().set(1,0,0,1);
     288            gr->setOptions(opt);
     289            _sceneRoot->addChild(gr);
     290            _graticule = gr;
     291        }
     292    } else if (_graticule.valid()) {
     293        _sceneRoot->removeChild(_graticule.get());
     294        _graticule = NULL;
     295    }
     296    _needsRedraw = true;
     297}
     298
    257299void Renderer::initMouseCoordsTool()
    258300{
     
    311353    } else {
    312354        initViewer();
    313         osg::Group *group = new osg::Group;
    314         group->addChild(node);
    315         _sceneRoot = group;
     355        _sceneRoot = new osg::Group;
     356        _sceneRoot->addChild(node);
    316357        _map = mapNode->getMap();
    317358    }
     
    400441        _sceneRoot = sky;
    401442#else
    402         osg::Group *group = new osg::Group();
    403         group->addChild(_mapNode.get());
    404         _sceneRoot = group;
    405         //_sceneRoot = mapNode;
    406 #endif
    407 #endif
    408     } else {
    409         osg::Group *group = new osg::Group();
    410         group->addChild(_mapNode.get());
    411         _sceneRoot = group;
    412         //_sceneRoot = mapNode;
     443        _sceneRoot = new osg::Group();
     444        _sceneRoot->addChild(_mapNode.get());
     445#endif
     446#endif
     447    } else {
     448        _sceneRoot = new osg::Group();
     449        _sceneRoot->addChild(_mapNode.get());
    413450    }
    414451
  • trunk/packages/vizservers/geovis/Renderer.h

    r4307 r4310  
    150150    typedef std::string ColorMapId;
    151151
     152    enum GraticuleType {
     153        GRATICULE_UTM,
     154        GRATICULE_MGRS,
     155        GRATICULE_GEODETIC
     156    };
     157
    152158    Renderer();
    153159    virtual ~Renderer();
     
    172178
    173179    // Map options
     180
     181    void setGraticule(bool enable, GraticuleType type = GRATICULE_GEODETIC);
    174182
    175183    void setViewerLightType(osg::View::LightingMode mode);
     
    379387    std::string _baseURI;
    380388
    381     osg::ref_ptr<osg::Node> _sceneRoot;
     389    osg::ref_ptr<osg::Group> _sceneRoot;
     390    osg::ref_ptr<osg::Group> _graticule;
    382391    osg::ref_ptr<osgEarth::MapNode> _mapNode;
    383392    osg::ref_ptr<osgEarth::Map> _map;
  • trunk/packages/vizservers/geovis/RendererCmd.cpp

    r4308 r4310  
    531531    }
    532532    return (*proc) (clientData, interp, objc, objv);
     533}
     534
     535static int
     536MapGraticuleOp(ClientData clientData, Tcl_Interp *interp, int objc,
     537               Tcl_Obj *const *objv)
     538{
     539    bool state;
     540    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     541        return TCL_ERROR;
     542    }
     543    if (objc > 3) {
     544        Renderer::GraticuleType type;
     545        char *typeStr = Tcl_GetString(objv[3]);
     546        if (typeStr[0] == 'g' && strcmp(typeStr, "geodetic") == 0) {
     547            type = Renderer::GRATICULE_GEODETIC;
     548        } else if (typeStr[0] == 'u' && strcmp(typeStr, "utm") == 0) {
     549            type = Renderer::GRATICULE_UTM;
     550        } else if (typeStr[0] == 'm' && strcmp(typeStr, "mgrs") == 0) {
     551            type = Renderer::GRATICULE_MGRS;
     552        } else {
     553            return TCL_ERROR;
     554        }
     555        g_renderer->setGraticule(state, type);
     556    } else {
     557        g_renderer->setGraticule(state);
     558    }
     559    return TCL_OK;
    533560}
    534561
     
    10591086
    10601087static CmdSpec mapOps[] = {
     1088    {"grid",     1, MapGraticuleOp,   3, 4, "bool ?type?"},
    10611089    {"layer",    2, MapLayerOp,       3, 0, "op ?params...?"},
    10621090    {"load",     2, MapLoadOp,        4, 5, "options"},
Note: See TracChangeset for help on using the changeset viewer.